##// END OF EJS Templates
revert: add some inline comments...
Pierre-Yves David -
r21575:8262c2a3 default
parent child Browse files
Show More
@@ -2259,18 +2259,22 b' def revert(ui, repo, ctx, parents, *pats'
2259 2259 # so have to walk both. do not print errors if files exist in one
2260 2260 # but not other.
2261 2261
2262 # `names` is a mapping for all elements in working copy and target revision
2263 # The mapping is in the form:
2264 # <asb path in repo> -> (<path from CWD>, <exactly specified by matcher?>)
2262 2265 names = {}
2263 2266
2264 2267 wlock = repo.wlock()
2265 2268 try:
2266 # walk dirstate.
2269 ## filling of the `names` mapping
2270 # walk dirstate to fill `names`
2267 2271
2268 2272 m = scmutil.match(repo[None], pats, opts)
2269 2273 m.bad = lambda x, y: False
2270 2274 for abs in repo.walk(m):
2271 2275 names[abs] = m.rel(abs), m.exact(abs)
2272 2276
2273 # walk target manifest.
2277 # walk target manifest to fill `names`
2274 2278
2275 2279 def badfn(path, msg):
2276 2280 if path in names:
@@ -2291,11 +2295,13 b' def revert(ui, repo, ctx, parents, *pats'
2291 2295
2292 2296 # get the list of subrepos that must be reverted
2293 2297 targetsubs = sorted(s for s in ctx.substate if m(s))
2298
2299 # Find status of all file in `names`. (Against working directory parent)
2294 2300 m = scmutil.matchfiles(repo, names)
2295 2301 changes = repo.status(match=m)[:4]
2296 2302 modified, added, removed, deleted = map(set, changes)
2297 2303
2298 # if f is a rename, also revert the source
2304 # if f is a rename, update `names` to also revert the source
2299 2305 cwd = repo.getcwd()
2300 2306 for f in added:
2301 2307 src = repo.dirstate.copied(f)
@@ -2303,11 +2309,15 b' def revert(ui, repo, ctx, parents, *pats'
2303 2309 removed.add(src)
2304 2310 names[src] = (repo.pathto(src, cwd), True)
2305 2311
2312 ## computation of the action to performs on `names` content.
2313
2306 2314 def removeforget(abs):
2307 2315 if repo.dirstate[abs] == 'a':
2308 2316 return _('forgetting %s\n')
2309 2317 return _('removing %s\n')
2310 2318
2319 # action to be actually performed by revert
2320 # (<list of file>, message>) tuple
2311 2321 revert = ([], _('reverting %s\n'))
2312 2322 add = ([], _('adding %s\n'))
2313 2323 remove = ([], removeforget)
@@ -2327,7 +2337,9 b' def revert(ui, repo, ctx, parents, *pats'
2327 2337 )
2328 2338
2329 2339 for abs, (rel, exact) in sorted(names.items()):
2340 # hash on file in target manifest (or None if missing from target)
2330 2341 mfentry = mf.get(abs)
2342 # target file to be touch on disk (relative to cwd)
2331 2343 target = repo.wjoin(abs)
2332 2344 def handle(xlist, dobackup):
2333 2345 xlist[0].append(abs)
@@ -2344,6 +2356,9 b' def revert(ui, repo, ctx, parents, *pats'
2344 2356 if not isinstance(msg, basestring):
2345 2357 msg = msg(abs)
2346 2358 ui.status(msg % rel)
2359 # search the entry in the dispatch table.
2360 # if the file is in any of this sets, it was touched in the working
2361 # directory parent and we are sure it needs to be reverted.
2347 2362 for table, hitlist, misslist, backuphit, backupmiss in disptable:
2348 2363 if abs not in table:
2349 2364 continue
@@ -2354,17 +2369,22 b' def revert(ui, repo, ctx, parents, *pats'
2354 2369 handle(misslist, backupmiss)
2355 2370 break
2356 2371 else:
2372 # Not touched in current dirstate.
2373
2374 # file is unknown in parent, restore older version or ignore.
2357 2375 if abs not in repo.dirstate:
2358 2376 if mfentry:
2359 2377 handle(add, True)
2360 2378 elif exact:
2361 2379 ui.warn(_('file not managed: %s\n') % rel)
2362 2380 continue
2363 # file has not changed in dirstate
2381
2382 # parent is target, no changes mean no changes
2364 2383 if node == parent:
2365 2384 if exact:
2366 2385 ui.warn(_('no changes needed to %s\n') % rel)
2367 2386 continue
2387 # no change in dirstate but parent and target may differ
2368 2388 if pmf is None:
2369 2389 # only need parent manifest in this unlikely case,
2370 2390 # so do not read by default
General Comments 0
You need to be logged in to leave comments. Login now