Mercurial > public > mercurial-scm > hg-stable
diff mercurial/logcmdutil.py @ 45484:5f0eeda2005d
log: make -frREV PATH detect missing files before falling back to slow path
If -rREV isn't specified, "log --follow" would abort on nonexistent paths.
Let's implement this behavior for "-frREV" case as we have ctx.hasdir() now.
Otherwise "log -frREV PATH" would silently fall back to slow path and files
wouldn't be followed across renames.
The loop is quadratic (as before), but the size of the startctxs and
match.files() should be small in general.
Some tests are marked as BROKEN since file renames aren't tracked in the
slow path. This is a known limitation of the current history traversal
function.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 12 Sep 2020 07:23:47 +0900 |
parents | 07324227f6b7 |
children | 142f0dcf90d0 |
line wrap: on
line diff
--- a/mercurial/logcmdutil.py Fri Sep 11 15:13:35 2020 +0900 +++ b/mercurial/logcmdutil.py Sat Sep 12 07:23:47 2020 +0900 @@ -692,13 +692,27 @@ if not slowpath: follow = opts.get(b'follow') or opts.get(b'follow_first') if follow and opts.get(b'rev'): + # There may be the case that a path doesn't exist in some (but + # not all) of the specified start revisions, but let's consider + # the path is valid. Missing files will be warned by the matcher. startctxs = [repo[r] for r in revs] 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 - break + found = False + for c in startctxs: + if f in c: + found = True + elif c.hasdir(f): + # If a directory exists in any of the start revisions, + # take the slow path. + found = slowpath = True + if not found: + raise error.Abort( + _( + b'cannot follow file not in any of the specified ' + b'revisions: "%s"' + ) + % f + ) elif follow: for f in match.files(): if f not in wctx: