##// END OF EJS Templates
log: pass around --follow/--follow-first options by walkopts
Yuya Nishihara -
r46140:24df19a9 default
parent child Browse files
Show More
@@ -686,6 +686,9 b' class walkopts(object):'
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 # 0: no follow, 1: follow first, 2: follow both parents
690 follow = attr.ib(default=0) # type: int
691
689
692
690 def parseopts(ui, pats, opts):
693 def parseopts(ui, pats, opts):
691 # type: (Any, List[bytes], Dict[bytes, Any]) -> walkopts
694 # type: (Any, List[bytes], Dict[bytes, Any]) -> walkopts
@@ -693,7 +696,14 b' def parseopts(ui, pats, opts):'
693
696
694 The returned walkopts will be passed in to getrevs().
697 The returned walkopts will be passed in to getrevs().
695 """
698 """
696 return walkopts(pats=pats, opts=opts)
699 if opts.get(b'follow_first'):
700 follow = 1
701 elif opts.get(b'follow'):
702 follow = 2
703 else:
704 follow = 0
705
706 return walkopts(pats=pats, opts=opts, follow=follow)
697
707
698
708
699 def _makematcher(repo, revs, wopts):
709 def _makematcher(repo, revs, wopts):
@@ -716,8 +726,7 b' def _makematcher(repo, revs, wopts):'
716 not match.always() and wopts.opts.get(b'removed')
726 not match.always() and wopts.opts.get(b'removed')
717 )
727 )
718 if not slowpath:
728 if not slowpath:
719 follow = wopts.opts.get(b'follow') or wopts.opts.get(b'follow_first')
729 if wopts.follow and wopts.opts.get(b'rev'):
720 if follow and wopts.opts.get(b'rev'):
721 # There may be the case that a path doesn't exist in some (but
730 # There may be the case that a path doesn't exist in some (but
722 # not all) of the specified start revisions, but let's consider
731 # not all) of the specified start revisions, but let's consider
723 # the path is valid. Missing files will be warned by the matcher.
732 # the path is valid. Missing files will be warned by the matcher.
@@ -739,7 +748,7 b' def _makematcher(repo, revs, wopts):'
739 )
748 )
740 % f
749 % f
741 )
750 )
742 elif follow:
751 elif wopts.follow:
743 for f in match.files():
752 for f in match.files():
744 if f not in wctx:
753 if f not in wctx:
745 # If the file exists, it may be a directory, so let it
754 # If the file exists, it may be a directory, so let it
@@ -829,8 +838,6 b' def _makenofollowfilematcher(repo, pats,'
829 def _makerevset(repo, wopts, slowpath):
838 def _makerevset(repo, wopts, slowpath):
830 """Return a revset string built from log options and file patterns"""
839 """Return a revset string built from log options and file patterns"""
831 opts = dict(wopts.opts)
840 opts = dict(wopts.opts)
832 # follow or not follow?
833 follow = opts.get(b'follow') or opts.get(b'follow_first')
834
841
835 # branch and only_branch are really aliases and must be handled at
842 # branch and only_branch are really aliases and must be handled at
836 # the same time
843 # the same time
@@ -854,7 +861,7 b' def _makerevset(repo, wopts, slowpath):'
854 for p in opts.get(b'exclude', []):
861 for p in opts.get(b'exclude', []):
855 matchargs.append(b'x:' + p)
862 matchargs.append(b'x:' + p)
856 opts[b'_matchfiles'] = matchargs
863 opts[b'_matchfiles'] = matchargs
857 elif not follow:
864 elif not wopts.follow:
858 opts[b'_patslog'] = list(wopts.pats)
865 opts[b'_patslog'] = list(wopts.pats)
859
866
860 expr = []
867 expr = []
@@ -882,12 +889,11 b' def _makerevset(repo, wopts, slowpath):'
882
889
883 def _initialrevs(repo, wopts):
890 def _initialrevs(repo, wopts):
884 """Return the initial set of revisions to be filtered or followed"""
891 """Return the initial set of revisions to be filtered or followed"""
885 follow = wopts.opts.get(b'follow') or wopts.opts.get(b'follow_first')
886 if wopts.opts.get(b'rev'):
892 if wopts.opts.get(b'rev'):
887 revs = scmutil.revrange(repo, wopts.opts[b'rev'])
893 revs = scmutil.revrange(repo, wopts.opts[b'rev'])
888 elif follow and repo.dirstate.p1() == nullid:
894 elif wopts.follow and repo.dirstate.p1() == nullid:
889 revs = smartset.baseset()
895 revs = smartset.baseset()
890 elif follow:
896 elif wopts.follow:
891 revs = repo.revs(b'.')
897 revs = repo.revs(b'.')
892 else:
898 else:
893 revs = smartset.spanset(repo)
899 revs = smartset.spanset(repo)
@@ -901,8 +907,6 b' def getrevs(repo, wopts):'
901
907
902 differ is a changesetdiffer with pre-configured file matcher.
908 differ is a changesetdiffer with pre-configured file matcher.
903 """
909 """
904 follow = wopts.opts.get(b'follow') or wopts.opts.get(b'follow_first')
905 followfirst = wopts.opts.get(b'follow_first')
906 limit = getlimit(wopts.opts)
910 limit = getlimit(wopts.opts)
907 revs = _initialrevs(repo, wopts)
911 revs = _initialrevs(repo, wopts)
908 if not revs:
912 if not revs:
@@ -911,11 +915,13 b' def getrevs(repo, wopts):'
911 wopts = attr.evolve(wopts, pats=pats)
915 wopts = attr.evolve(wopts, pats=pats)
912
916
913 filematcher = None
917 filematcher = None
914 if follow:
918 if wopts.follow:
915 if slowpath or match.always():
919 if slowpath or match.always():
916 revs = dagop.revancestors(repo, revs, followfirst=followfirst)
920 revs = dagop.revancestors(repo, revs, followfirst=wopts.follow == 1)
917 else:
921 else:
918 revs, filematcher = _fileancestors(repo, revs, match, followfirst)
922 revs, filematcher = _fileancestors(
923 repo, revs, match, followfirst=wopts.follow == 1
924 )
919 revs.reverse()
925 revs.reverse()
920 if filematcher is None:
926 if filematcher is None:
921 filematcher = _makenofollowfilematcher(repo, wopts.pats, wopts.opts)
927 filematcher = _makenofollowfilematcher(repo, wopts.pats, wopts.opts)
General Comments 0
You need to be logged in to leave comments. Login now