# HG changeset patch # User Yuya Nishihara # Date 1599804538 -32400 # Node ID a03fde1077ce566fa7c0cf943cc91028d7845d8f # Parent 6e474eec4be6a1fcf9f4327749b925da2ef66844 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')". diff -r 6e474eec4be6 -r a03fde1077ce mercurial/logcmdutil.py --- a/mercurial/logcmdutil.py Wed Aug 26 16:37:23 2020 +0530 +++ b/mercurial/logcmdutil.py Fri Sep 11 15:08:58 2020 +0900 @@ -691,39 +691,47 @@ slowpath = match.anypats() or (not match.always() and opts.get(b'removed')) if not slowpath: follow = opts.get(b'follow') or opts.get(b'follow_first') - startctxs = [] if follow and opts.get(b'rev'): startctxs = [repo[r] for r in revs] - for f in match.files(): - if follow and startctxs: + for f in match.files(): # No idea if the path was a directory at that revision, so # take the slow path. if any(f not in c for c in startctxs): slowpath = True continue - elif follow and f not in wctx: - # If the file exists, it may be a directory, so let it - # take the slow path. - if os.path.exists(repo.wjoin(f)): - slowpath = True - continue - else: - raise error.Abort( - _( - b'cannot follow file not in parent ' - b'revision: "%s"' - ) - % f - ) - filelog = repo.file(f) - if not filelog: - # A zero count may be a directory or deleted file, so - # try to find matching entries on the slow path. - if follow: + filelog = repo.file(f) + if not filelog: raise error.Abort( _(b'cannot follow nonexistent file: "%s"') % f ) - slowpath = True + elif follow: + for f in match.files(): + if f not in wctx: + # If the file exists, it may be a directory, so let it + # take the slow path. + if os.path.exists(repo.wjoin(f)): + slowpath = True + continue + else: + raise error.Abort( + _( + b'cannot follow file not in parent ' + b'revision: "%s"' + ) + % f + ) + filelog = repo.file(f) + if not filelog: + raise error.Abort( + _(b'cannot follow nonexistent file: "%s"') % f + ) + else: + for f in match.files(): + filelog = repo.file(f) + if not filelog: + # A zero count may be a directory or deleted file, so + # try to find matching entries on the slow path. + slowpath = True # We decided to fall back to the slowpath because at least one # of the paths was not a file. Check to see if at least one of them diff -r 6e474eec4be6 -r a03fde1077ce tests/test-log.t --- a/tests/test-log.t Wed Aug 26 16:37:23 2020 +0530 +++ b/tests/test-log.t Fri Sep 11 15:08:58 2020 +0900 @@ -2308,6 +2308,20 @@ $ hg log -T '== {rev} ==\n' -fr'wdir()' --git --stat notfound notfound: $ENOENT$ +follow added/removed files from wdir parent + + $ hg log -T '{rev}\n' -f d1/f2 + abort: cannot follow nonexistent file: "d1/f2" + [255] + + $ hg log -T '{rev}\n' -f f1-copy + abort: cannot follow nonexistent file: "f1-copy" + [255] + + $ hg log -T '{rev}\n' -f .d6/f1 + abort: cannot follow file not in parent revision: ".d6/f1" + [255] + $ hg revert -aqC Check that adding an arbitrary name shows up in log automatically