comparison mercurial/cmdutil.py @ 35687:67893a516272

log: follow file history across copies even with -rREV (BC) (issue4959) Still it falls back to changelog path if glob patterns or missing paths are specified. This will be changed later. .. bc:: ``log --follow -rREV FILE..`` now follows file history across copies and renames.
author Yuya Nishihara <yuya@tcha.org>
date Wed, 03 Jan 2018 15:58:59 +0900
parents b25fa5da4ca2
children 84d0e99c063a
comparison
equal deleted inserted replaced
35686:b25fa5da4ca2 35687:67893a516272
2320 if stopiteration: 2320 if stopiteration:
2321 break 2321 break
2322 2322
2323 return iterate() 2323 return iterate()
2324 2324
2325 def _makelogmatcher(repo, pats, opts): 2325 def _makelogmatcher(repo, revs, pats, opts):
2326 """Build matcher and expanded patterns from log options 2326 """Build matcher and expanded patterns from log options
2327
2328 If --follow, revs are the revisions to follow from.
2327 2329
2328 Returns (match, pats, slowpath) where 2330 Returns (match, pats, slowpath) where
2329 - match: a matcher built from the given pats and -I/-X opts 2331 - match: a matcher built from the given pats and -I/-X opts
2330 - pats: patterns used (globs are expanded on Windows) 2332 - pats: patterns used (globs are expanded on Windows)
2331 - slowpath: True if patterns aren't as simple as scanning filelogs 2333 - slowpath: True if patterns aren't as simple as scanning filelogs
2337 wctx = repo[None] 2339 wctx = repo[None]
2338 match, pats = scmutil.matchandpats(wctx, pats, opts) 2340 match, pats = scmutil.matchandpats(wctx, pats, opts)
2339 slowpath = match.anypats() or (not match.always() and opts.get('removed')) 2341 slowpath = match.anypats() or (not match.always() and opts.get('removed'))
2340 if not slowpath: 2342 if not slowpath:
2341 follow = opts.get('follow') or opts.get('follow_first') 2343 follow = opts.get('follow') or opts.get('follow_first')
2344 startctxs = []
2345 if follow and opts.get('rev'):
2346 startctxs = [repo[r] for r in revs]
2342 for f in match.files(): 2347 for f in match.files():
2343 if follow and f not in wctx: 2348 if follow and startctxs:
2349 # No idea if the path was a directory at that revision, so
2350 # take the slow path.
2351 if any(f not in c for c in startctxs):
2352 slowpath = True
2353 continue
2354 elif follow and f not in wctx:
2344 # If the file exists, it may be a directory, so let it 2355 # If the file exists, it may be a directory, so let it
2345 # take the slow path. 2356 # take the slow path.
2346 if os.path.exists(repo.wjoin(f)): 2357 if os.path.exists(repo.wjoin(f)):
2347 slowpath = True 2358 slowpath = True
2348 continue 2359 continue
2516 is a callable taking a revision number and returning a match objects 2527 is a callable taking a revision number and returning a match objects
2517 filtering the files to be detailed when displaying the revision. 2528 filtering the files to be detailed when displaying the revision.
2518 """ 2529 """
2519 follow = opts.get('follow') or opts.get('follow_first') 2530 follow = opts.get('follow') or opts.get('follow_first')
2520 followfirst = opts.get('follow_first') 2531 followfirst = opts.get('follow_first')
2521 if opts.get('rev'):
2522 # TODO: do not mutate opts here
2523 opts.pop('follow', None)
2524 opts.pop('follow_first', None)
2525 limit = loglimit(opts) 2532 limit = loglimit(opts)
2526 revs = _logrevs(repo, opts) 2533 revs = _logrevs(repo, opts)
2527 if not revs: 2534 if not revs:
2528 return smartset.baseset(), None 2535 return smartset.baseset(), None
2529 match, pats, slowpath = _makelogmatcher(repo, pats, opts) 2536 match, pats, slowpath = _makelogmatcher(repo, revs, pats, opts)
2530 if follow: 2537 if follow:
2531 if opts.get('rev') or slowpath or not pats: 2538 if slowpath or not pats:
2532 revs = dagop.revancestors(repo, revs, followfirst=followfirst) 2539 revs = dagop.revancestors(repo, revs, followfirst=followfirst)
2533 else: 2540 else:
2534 revs = _fileancestors(repo, revs, match, followfirst) 2541 revs = _fileancestors(repo, revs, match, followfirst)
2535 revs.reverse() 2542 revs.reverse()
2536 expr, filematcher = _makelogrevset(repo, match, pats, slowpath, opts) 2543 expr, filematcher = _makelogrevset(repo, match, pats, slowpath, opts)