Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/logcmdutil.py @ 45570:bddf70c93614
log: parse --limit option by logcmdutil.parseopts()
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 12 Sep 2020 21:39:58 +0900 |
parents | 24df19a9ab87 |
children | 9a26fea2b518 |
comparison
equal
deleted
inserted
replaced
45569:24df19a9ab87 | 45570:bddf70c93614 |
---|---|
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 | 689 # 0: no follow, 1: follow first, 2: follow both parents |
690 follow = attr.ib(default=0) # type: int | 690 follow = attr.ib(default=0) # type: int |
691 | 691 |
692 # limit number of changes displayed; None means unlimited | |
693 limit = attr.ib(default=None) # type: Optional[int] | |
694 | |
692 | 695 |
693 def parseopts(ui, pats, opts): | 696 def parseopts(ui, pats, opts): |
694 # type: (Any, List[bytes], Dict[bytes, Any]) -> walkopts | 697 # type: (Any, List[bytes], Dict[bytes, Any]) -> walkopts |
695 """Parse log command options into walkopts | 698 """Parse log command options into walkopts |
696 | 699 |
701 elif opts.get(b'follow'): | 704 elif opts.get(b'follow'): |
702 follow = 2 | 705 follow = 2 |
703 else: | 706 else: |
704 follow = 0 | 707 follow = 0 |
705 | 708 |
706 return walkopts(pats=pats, opts=opts, follow=follow) | 709 return walkopts(pats=pats, opts=opts, follow=follow, limit=getlimit(opts)) |
707 | 710 |
708 | 711 |
709 def _makematcher(repo, revs, wopts): | 712 def _makematcher(repo, revs, wopts): |
710 """Build matcher and expanded patterns from log options | 713 """Build matcher and expanded patterns from log options |
711 | 714 |
905 # type: (Any, walkopts) -> Tuple[smartset.abstractsmartset, Optional[changesetdiffer]] | 908 # type: (Any, walkopts) -> Tuple[smartset.abstractsmartset, Optional[changesetdiffer]] |
906 """Return (revs, differ) where revs is a smartset | 909 """Return (revs, differ) where revs is a smartset |
907 | 910 |
908 differ is a changesetdiffer with pre-configured file matcher. | 911 differ is a changesetdiffer with pre-configured file matcher. |
909 """ | 912 """ |
910 limit = getlimit(wopts.opts) | |
911 revs = _initialrevs(repo, wopts) | 913 revs = _initialrevs(repo, wopts) |
912 if not revs: | 914 if not revs: |
913 return smartset.baseset(), None | 915 return smartset.baseset(), None |
914 match, pats, slowpath = _makematcher(repo, revs, wopts) | 916 match, pats, slowpath = _makematcher(repo, revs, wopts) |
915 wopts = attr.evolve(wopts, pats=pats) | 917 wopts = attr.evolve(wopts, pats=pats) |
941 # User-specified revs might be unsorted | 943 # User-specified revs might be unsorted |
942 revs.sort(reverse=True) | 944 revs.sort(reverse=True) |
943 if expr: | 945 if expr: |
944 matcher = revset.match(None, expr) | 946 matcher = revset.match(None, expr) |
945 revs = matcher(repo, revs) | 947 revs = matcher(repo, revs) |
946 if limit is not None: | 948 if wopts.limit is not None: |
947 revs = revs.slice(0, limit) | 949 revs = revs.slice(0, wopts.limit) |
948 | 950 |
949 differ = changesetdiffer() | 951 differ = changesetdiffer() |
950 differ._makefilematcher = filematcher | 952 differ._makefilematcher = filematcher |
951 return revs, differ | 953 return revs, differ |
952 | 954 |