Patchwork [2,of,3] log: fix -fr'wdir()' PATH to follow newly added file

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 14, 2020, 1:25 p.m.
Message ID <21487b54666e457374fa.1600089927@mimosa>
Download mbox | patch
Permalink /patch/47165/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 14, 2020, 1:25 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1599804815 -32400
#      Fri Sep 11 15:13:35 2020 +0900
# Node ID 21487b54666e457374fa669ffe3005f3840353c6
# Parent  306c09f80dd9659aa9f0eebe1baa328afa3b7977
log: fix -fr'wdir()' PATH to follow newly added file

Testing filelog doesn't make sense in this case because the file existence
is tested against the specified changectxs. If the filelog is empty and
if startctxs != [wctx], 'f not in c' should be triggered.

Patch

diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py
--- a/mercurial/logcmdutil.py
+++ b/mercurial/logcmdutil.py
@@ -698,12 +698,7 @@  def _makematcher(repo, revs, pats, opts)
                 # take the slow path.
                 if any(f not in c for c in startctxs):
                     slowpath = True
-                    continue
-                filelog = repo.file(f)
-                if not filelog:
-                    raise error.Abort(
-                        _(b'cannot follow nonexistent file: "%s"') % f
-                    )
+                    break
         elif follow:
             for f in match.files():
                 if f not in wctx:
@@ -722,6 +717,8 @@  def _makematcher(repo, revs, pats, opts)
                         )
                 filelog = repo.file(f)
                 if not filelog:
+                    # A file exists in wdir but not in history, which means
+                    # the file isn't committed yet.
                     raise error.Abort(
                         _(b'cannot follow nonexistent file: "%s"') % f
                     )
diff --git a/tests/test-log.t b/tests/test-log.t
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -2295,15 +2295,21 @@  follow files from wdir
    1 files changed, 1 insertions(+), 0 deletions(-)
   
 
- BROKEN: added file should exist in wdir
   $ hg log -T '== {rev} ==\n' -fr'wdir()' --git --stat d1/f2
-  abort: cannot follow nonexistent file: "d1/f2"
-  [255]
+  == 2147483647 ==
+   d1/f2 |  1 +
+   1 files changed, 1 insertions(+), 0 deletions(-)
+  
 
- BROKEN: copied file should exist in wdir
   $ hg log -T '== {rev} ==\n' -fr'wdir()' --git --stat f1-copy
-  abort: cannot follow nonexistent file: "f1-copy"
-  [255]
+  == 2147483647 ==
+   f1-copy |  1 +
+   1 files changed, 1 insertions(+), 0 deletions(-)
+  
+  == 0 ==
+   d1/f1 |  1 +
+   1 files changed, 1 insertions(+), 0 deletions(-)
+  
 
   $ hg log -T '== {rev} ==\n' -fr'wdir()' --git --stat notfound
   notfound: $ENOENT$