comparison mercurial/logcmdutil.py @ 45568:9a26fea2b518

log: pass around --rev option by walkopts
author Yuya Nishihara <yuya@tcha.org>
date Sat, 12 Sep 2020 21:45:37 +0900
parents bddf70c93614
children c11099cc1de4
comparison
equal deleted inserted replaced
45567:bddf70c93614 45568:9a26fea2b518
684 684
685 # raw command-line parameters, which a matcher will be built from 685 # raw command-line parameters, which a matcher will be built from
686 pats = attr.ib() # type: List[bytes] 686 pats = attr.ib() # type: List[bytes]
687 opts = attr.ib() # type: Dict[bytes, Any] 687 opts = attr.ib() # type: Dict[bytes, Any]
688 688
689 # a list of revset expressions to be traversed; if follow, it specifies
690 # the start revisions
691 revspec = attr.ib() # type: List[bytes]
692
689 # 0: no follow, 1: follow first, 2: follow both parents 693 # 0: no follow, 1: follow first, 2: follow both parents
690 follow = attr.ib(default=0) # type: int 694 follow = attr.ib(default=0) # type: int
691 695
692 # limit number of changes displayed; None means unlimited 696 # limit number of changes displayed; None means unlimited
693 limit = attr.ib(default=None) # type: Optional[int] 697 limit = attr.ib(default=None) # type: Optional[int]
704 elif opts.get(b'follow'): 708 elif opts.get(b'follow'):
705 follow = 2 709 follow = 2
706 else: 710 else:
707 follow = 0 711 follow = 0
708 712
709 return walkopts(pats=pats, opts=opts, follow=follow, limit=getlimit(opts)) 713 return walkopts(
714 pats=pats,
715 opts=opts,
716 revspec=opts.get(b'rev', []),
717 follow=follow,
718 limit=getlimit(opts),
719 )
710 720
711 721
712 def _makematcher(repo, revs, wopts): 722 def _makematcher(repo, revs, wopts):
713 """Build matcher and expanded patterns from log options 723 """Build matcher and expanded patterns from log options
714 724
727 match, pats = scmutil.matchandpats(wctx, wopts.pats, wopts.opts) 737 match, pats = scmutil.matchandpats(wctx, wopts.pats, wopts.opts)
728 slowpath = match.anypats() or ( 738 slowpath = match.anypats() or (
729 not match.always() and wopts.opts.get(b'removed') 739 not match.always() and wopts.opts.get(b'removed')
730 ) 740 )
731 if not slowpath: 741 if not slowpath:
732 if wopts.follow and wopts.opts.get(b'rev'): 742 if wopts.follow and wopts.revspec:
733 # There may be the case that a path doesn't exist in some (but 743 # There may be the case that a path doesn't exist in some (but
734 # not all) of the specified start revisions, but let's consider 744 # not all) of the specified start revisions, but let's consider
735 # the path is valid. Missing files will be warned by the matcher. 745 # the path is valid. Missing files will be warned by the matcher.
736 startctxs = [repo[r] for r in revs] 746 startctxs = [repo[r] for r in revs]
737 for f in match.files(): 747 for f in match.files():
890 return expr 900 return expr
891 901
892 902
893 def _initialrevs(repo, wopts): 903 def _initialrevs(repo, wopts):
894 """Return the initial set of revisions to be filtered or followed""" 904 """Return the initial set of revisions to be filtered or followed"""
895 if wopts.opts.get(b'rev'): 905 if wopts.revspec:
896 revs = scmutil.revrange(repo, wopts.opts[b'rev']) 906 revs = scmutil.revrange(repo, wopts.revspec)
897 elif wopts.follow and repo.dirstate.p1() == nullid: 907 elif wopts.follow and repo.dirstate.p1() == nullid:
898 revs = smartset.baseset() 908 revs = smartset.baseset()
899 elif wopts.follow: 909 elif wopts.follow:
900 revs = repo.revs(b'.') 910 revs = repo.revs(b'.')
901 else: 911 else: