Mercurial > public > mercurial-scm > hg
comparison mercurial/logcmdutil.py @ 45471:a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
The test conditions are branchy depending on --follow and --rev options,
so it should be better to switch first by --follow --rev.
Note that revs is not empty so "if follow and startctxs" can be replaced
with "if follow and opts.get(b'rev')".
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Fri, 11 Sep 2020 15:08:58 +0900 |
parents | 4532e7ebde4d |
children | 07324227f6b7 |
comparison
equal
deleted
inserted
replaced
45470:6e474eec4be6 | 45471:a03fde1077ce |
---|---|
689 wctx = repo[None] | 689 wctx = repo[None] |
690 match, pats = scmutil.matchandpats(wctx, pats, opts) | 690 match, pats = scmutil.matchandpats(wctx, pats, opts) |
691 slowpath = match.anypats() or (not match.always() and opts.get(b'removed')) | 691 slowpath = match.anypats() or (not match.always() and opts.get(b'removed')) |
692 if not slowpath: | 692 if not slowpath: |
693 follow = opts.get(b'follow') or opts.get(b'follow_first') | 693 follow = opts.get(b'follow') or opts.get(b'follow_first') |
694 startctxs = [] | |
695 if follow and opts.get(b'rev'): | 694 if follow and opts.get(b'rev'): |
696 startctxs = [repo[r] for r in revs] | 695 startctxs = [repo[r] for r in revs] |
697 for f in match.files(): | 696 for f in match.files(): |
698 if follow and startctxs: | |
699 # No idea if the path was a directory at that revision, so | 697 # No idea if the path was a directory at that revision, so |
700 # take the slow path. | 698 # take the slow path. |
701 if any(f not in c for c in startctxs): | 699 if any(f not in c for c in startctxs): |
702 slowpath = True | 700 slowpath = True |
703 continue | 701 continue |
704 elif follow and f not in wctx: | 702 filelog = repo.file(f) |
705 # If the file exists, it may be a directory, so let it | 703 if not filelog: |
706 # take the slow path. | |
707 if os.path.exists(repo.wjoin(f)): | |
708 slowpath = True | |
709 continue | |
710 else: | |
711 raise error.Abort( | |
712 _( | |
713 b'cannot follow file not in parent ' | |
714 b'revision: "%s"' | |
715 ) | |
716 % f | |
717 ) | |
718 filelog = repo.file(f) | |
719 if not filelog: | |
720 # A zero count may be a directory or deleted file, so | |
721 # try to find matching entries on the slow path. | |
722 if follow: | |
723 raise error.Abort( | 704 raise error.Abort( |
724 _(b'cannot follow nonexistent file: "%s"') % f | 705 _(b'cannot follow nonexistent file: "%s"') % f |
725 ) | 706 ) |
726 slowpath = True | 707 elif follow: |
708 for f in match.files(): | |
709 if f not in wctx: | |
710 # If the file exists, it may be a directory, so let it | |
711 # take the slow path. | |
712 if os.path.exists(repo.wjoin(f)): | |
713 slowpath = True | |
714 continue | |
715 else: | |
716 raise error.Abort( | |
717 _( | |
718 b'cannot follow file not in parent ' | |
719 b'revision: "%s"' | |
720 ) | |
721 % f | |
722 ) | |
723 filelog = repo.file(f) | |
724 if not filelog: | |
725 raise error.Abort( | |
726 _(b'cannot follow nonexistent file: "%s"') % f | |
727 ) | |
728 else: | |
729 for f in match.files(): | |
730 filelog = repo.file(f) | |
731 if not filelog: | |
732 # A zero count may be a directory or deleted file, so | |
733 # try to find matching entries on the slow path. | |
734 slowpath = True | |
727 | 735 |
728 # We decided to fall back to the slowpath because at least one | 736 # We decided to fall back to the slowpath because at least one |
729 # of the paths was not a file. Check to see if at least one of them | 737 # of the paths was not a file. Check to see if at least one of them |
730 # existed in history - in that case, we'll continue down the | 738 # existed in history - in that case, we'll continue down the |
731 # slowpath; otherwise, we can turn off the slowpath | 739 # slowpath; otherwise, we can turn off the slowpath |