[PATCH 4 of 5] log: handle removed files with --line-range patterns

Denis Laxalde denis at laxalde.org
Thu Oct 19 09:51:49 EDT 2017


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1508417710 -7200
#      Thu Oct 19 14:55:10 2017 +0200
# Node ID d07a2cce2a4826f69cf2a6db12cc6721d95002a2
# Parent  ce22c9db68b10ac17086a4f213b22d3304f09bad
# EXP-Topic followlines-cli
log: handle removed files with --line-range patterns

I.e. abort when the pattern corresponds to a removed file, as done with bare
file patterns.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2627,6 +2627,9 @@ def getloglinerangerevs(repo, userrevs, 
     # Two-levels map of "rev -> file ctx -> [line range]".
     linerangesbyrev = {}
     for fname, (fromline, toline) in _parselinerangelogopt(repo, opts):
+        if fname not in wctx:
+            raise error.Abort(_('cannot follow file not in parent '
+                                'revision: "%s"') % fname)
         fctx = wctx.filectx(fname)
         for fctx, linerange in dagop.blockancestors(fctx, fromline, toline):
             rev = fctx.introrev()
diff --git a/tests/test-log-linerange.t b/tests/test-log-linerange.t
--- a/tests/test-log-linerange.t
+++ b/tests/test-log-linerange.t
@@ -842,6 +842,14 @@ Non-exact pattern kinds are not allowed.
   hg: parse error: line range pattern 'glob:*a*' must match exactly one file
   [255]
 
+We get an error for removed files.
+
+  $ hg rm dir/baz
+  $ hg ci -m 'remove baz' --quiet
+  $ hg log -f -L dir/baz,5:7 -p
+  abort: cannot follow file not in parent revision: "dir/baz"
+  [255]
+
 Graph log does work yet.
 
   $ hg log -f -L dir/baz,5:7 --graph


More information about the Mercurial-devel mailing list