Patchwork log: make --patch --follow work inside a subdirectory

login
register
mail settings
Submitter Siddharth Agarwal
Date July 12, 2014, 10:19 a.m.
Message ID <0541680b3ed0f7068efc.1405160349@dev1738.prn1.facebook.com>
Download mbox | patch
Permalink /patch/5145/
State Accepted
Commit 584bbfd1b50dad59871dcc7eba258491a2cb395f
Headers show

Comments

Siddharth Agarwal - July 12, 2014, 10:19 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1405156997 25200
#      Sat Jul 12 02:23:17 2014 -0700
# Node ID 0541680b3ed0f7068efcd2baa7696d2d07740605
# Parent  369ccce1dabdc8c1eed577c9f1b5cda673dfd2b3
log: make --patch --follow work inside a subdirectory

Previously, the 'patch' code for hg log --patch --follow would try to resolve
patterns relative to the repository root rather than the current working
directory. Fix that by using match.files instead of pats, as done elsewhere
nearby.
Siddharth Agarwal - July 12, 2014, 10:31 a.m.
On 07/12/2014 03:19 AM, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0@fb.com>
> # Date 1405156997 25200
> #      Sat Jul 12 02:23:17 2014 -0700
> # Node ID 0541680b3ed0f7068efcd2baa7696d2d07740605
> # Parent  369ccce1dabdc8c1eed577c9f1b5cda673dfd2b3
> log: make --patch --follow work inside a subdirectory

This should have been flagged stable.

>
> Previously, the 'patch' code for hg log --patch --follow would try to resolve
> patterns relative to the repository root rather than the current working
> directory. Fix that by using match.files instead of pats, as done elsewhere
> nearby.
>
> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py
> +++ b/mercurial/cmdutil.py
> @@ -1488,7 +1488,7 @@
>   
>       return iterate()
>   
> -def _makelogfilematcher(repo, pats, followfirst):
> +def _makelogfilematcher(repo, files, followfirst):
>       # When displaying a revision with --patch --follow FILE, we have
>       # to know which file of the revision must be diffed. With
>       # --follow, we want the names of the ancestors of FILE in the
> @@ -1502,7 +1502,7 @@
>       wctx = repo[None]
>   
>       def populate():
> -        for fn in pats:
> +        for fn in files:
>               for i in ((pctx[fn],), pctx[fn].ancestors(followfirst=followfirst)):
>                   for c in i:
>                       fcache.setdefault(c.linkrev(), set()).add(c.path())
> @@ -1627,7 +1627,9 @@
>       filematcher = None
>       if opts.get('patch') or opts.get('stat'):
>           if follow:
> -            filematcher = _makelogfilematcher(repo, pats, followfirst)
> +            # _makelogfilematcher expects its files argument to be relative to
> +            # the repo root, so use match.files(), not pats.
> +            filematcher = _makelogfilematcher(repo, match.files(), followfirst)
>           else:
>               filematcher = lambda rev: match
>   
> diff --git a/tests/test-log.t b/tests/test-log.t
> --- a/tests/test-log.t
> +++ b/tests/test-log.t
> @@ -223,6 +223,43 @@
>     +a
>     
>   
> +log -pf b inside dir
> +
> +  $ hg --cwd=dir log -pf b
> +  changeset:   2:f8954cd4dc1f
> +  user:        test
> +  date:        Thu Jan 01 00:00:03 1970 +0000
> +  summary:     c
> +
> +  diff -r d89b0a12d229 -r f8954cd4dc1f dir/b
> +  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
> +  +++ b/dir/b	Thu Jan 01 00:00:03 1970 +0000
> +  @@ -0,0 +1,1 @@
> +  +a
> +
> +  changeset:   1:d89b0a12d229
> +  user:        test
> +  date:        Thu Jan 01 00:00:02 1970 +0000
> +  summary:     b
> +
> +  diff -r 9161b9aeaf16 -r d89b0a12d229 b
> +  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
> +  +++ b/b	Thu Jan 01 00:00:02 1970 +0000
> +  @@ -0,0 +1,1 @@
> +  +a
> +
> +  changeset:   0:9161b9aeaf16
> +  user:        test
> +  date:        Thu Jan 01 00:00:01 1970 +0000
> +  summary:     a
> +
> +  diff -r 000000000000 -r 9161b9aeaf16 a
> +  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
> +  +++ b/a	Thu Jan 01 00:00:01 1970 +0000
> +  @@ -0,0 +1,1 @@
> +  +a
> +
> +
>   log -vf dir/b
>   
>     $ hg log -vf dir/b
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
Matt Mackall - July 15, 2014, 7:02 p.m.
On Sat, 2014-07-12 at 03:19 -0700, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0@fb.com>
> # Date 1405156997 25200
> #      Sat Jul 12 02:23:17 2014 -0700
> # Node ID 0541680b3ed0f7068efcd2baa7696d2d07740605
> # Parent  369ccce1dabdc8c1eed577c9f1b5cda673dfd2b3
> log: make --patch --follow work inside a subdirectory

Queued for stable, thanks.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1488,7 +1488,7 @@ 
 
     return iterate()
 
-def _makelogfilematcher(repo, pats, followfirst):
+def _makelogfilematcher(repo, files, followfirst):
     # When displaying a revision with --patch --follow FILE, we have
     # to know which file of the revision must be diffed. With
     # --follow, we want the names of the ancestors of FILE in the
@@ -1502,7 +1502,7 @@ 
     wctx = repo[None]
 
     def populate():
-        for fn in pats:
+        for fn in files:
             for i in ((pctx[fn],), pctx[fn].ancestors(followfirst=followfirst)):
                 for c in i:
                     fcache.setdefault(c.linkrev(), set()).add(c.path())
@@ -1627,7 +1627,9 @@ 
     filematcher = None
     if opts.get('patch') or opts.get('stat'):
         if follow:
-            filematcher = _makelogfilematcher(repo, pats, followfirst)
+            # _makelogfilematcher expects its files argument to be relative to
+            # the repo root, so use match.files(), not pats.
+            filematcher = _makelogfilematcher(repo, match.files(), followfirst)
         else:
             filematcher = lambda rev: match
 
diff --git a/tests/test-log.t b/tests/test-log.t
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -223,6 +223,43 @@ 
   +a
   
 
+log -pf b inside dir
+
+  $ hg --cwd=dir log -pf b
+  changeset:   2:f8954cd4dc1f
+  user:        test
+  date:        Thu Jan 01 00:00:03 1970 +0000
+  summary:     c
+  
+  diff -r d89b0a12d229 -r f8954cd4dc1f dir/b
+  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/dir/b	Thu Jan 01 00:00:03 1970 +0000
+  @@ -0,0 +1,1 @@
+  +a
+  
+  changeset:   1:d89b0a12d229
+  user:        test
+  date:        Thu Jan 01 00:00:02 1970 +0000
+  summary:     b
+  
+  diff -r 9161b9aeaf16 -r d89b0a12d229 b
+  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/b	Thu Jan 01 00:00:02 1970 +0000
+  @@ -0,0 +1,1 @@
+  +a
+  
+  changeset:   0:9161b9aeaf16
+  user:        test
+  date:        Thu Jan 01 00:00:01 1970 +0000
+  summary:     a
+  
+  diff -r 000000000000 -r 9161b9aeaf16 a
+  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/a	Thu Jan 01 00:00:01 1970 +0000
+  @@ -0,0 +1,1 @@
+  +a
+  
+
 log -vf dir/b
 
   $ hg log -vf dir/b