Patchwork subrepo: add include/exclude support for diffing git subrepos

login
register
mail settings
Submitter Mathias De Maré
Date April 14, 2015, 6:31 p.m.
Message ID <dadecab56ef1982b56cf.1429036271@waste.org>
Download mbox | patch
Permalink /patch/8657/
State Accepted
Commit a48b65ab428d16c45bae970b8477a3731613875a
Delegated to: Kevin Bullock
Headers show

Comments

Mathias De Maré - April 14, 2015, 6:31 p.m.
# HG changeset patch
# User Mathias De Maré <mathias.demare@gmail.com>
# Date 1429034996 -7200
#      Tue Apr 14 20:09:56 2015 +0200
# Node ID dadecab56ef1982b56cf1bb25c14a8133634c0bc
# Parent  c560d8c687916cb70a6d54c2c9ddcb5c9e457be2
subrepo: add include/exclude support for diffing git subrepos

Previously, git subrepos were ignored if any type of path selection
was done.
This can be solved by using subrepo status and filtering matching files.
Pierre-Yves David - April 15, 2015, 4:40 a.m.
On 04/14/2015 02:31 PM, Mathias De Maré wrote:
> # HG changeset patch
> # User Mathias De Maré <mathias.demare@gmail.com>
> # Date 1429034996 -7200
> #      Tue Apr 14 20:09:56 2015 +0200
> # Node ID dadecab56ef1982b56cf1bb25c14a8133634c0bc
> # Parent  c560d8c687916cb70a6d54c2c9ddcb5c9e457be2
> subrepo: add include/exclude support for diffing git subrepos

Looks good to me.

I would like someone else to look at it though, my git and subrepo foo 
are low.
Matt Mackall - April 16, 2015, 10:48 p.m.
On Tue, 2015-04-14 at 13:31 -0500, Mathias De Maré wrote:
> # HG changeset patch
> # User Mathias De Maré <mathias.demare@gmail.com>
> # Date 1429034996 -7200
> #      Tue Apr 14 20:09:56 2015 +0200
> # Node ID dadecab56ef1982b56cf1bb25c14a8133634c0bc
> # Parent  c560d8c687916cb70a6d54c2c9ddcb5c9e457be2
> subrepo: add include/exclude support for diffing git subrepos
>
> Previously, git subrepos were ignored if any type of path selection
> was done.
> This can be solved by using subrepo status and filtering matching files.

Looks appropriately awful. Queued for default, thanks.

Patch

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -1779,17 +1779,15 @@ 
         if node2:
             cmd.append(node2)
 
-        if match.anypats():
-            return #No support for include/exclude yet
-
         output = ""
         if match.always():
             output += self._gitcommand(cmd) + '\n'
-        elif match.files():
-            for f in match.files():
-                output += self._gitcommand(cmd + [f]) + '\n'
-        elif match(gitprefix): #Subrepo is matched
-            output += self._gitcommand(cmd) + '\n'
+        else:
+            st = self.status(node2)[:3]
+            files = [f for sublist in st for f in sublist]
+            for f in files:
+                if match(f):
+                    output += self._gitcommand(cmd + ['--', f]) + '\n'
 
         if output.strip():
             ui.write(output)
diff --git a/tests/test-subrepo-git.t b/tests/test-subrepo-git.t
--- a/tests/test-subrepo-git.t
+++ b/tests/test-subrepo-git.t
@@ -785,9 +785,57 @@ 
   \s*foobar |\s*2 +- (re)
    2 files changed, 2 insertions\(\+\), 1 deletions?\(-\) (re)
 
-ensure adding include/exclude ignores the subrepo
+adding an include should ignore the other elements
   $ hg diff --subrepos -I s/foobar
+  diff --git a/s/foobar b/s/foobar
+  index 8a5a5e2..bd5812a 100644
+  --- a/s/foobar
+  +++ b/s/foobar
+  @@ -1,4 +1,4 @@
+  -woopwoop
+  +woop    woop
+   
+   foo
+   bar
+
+adding an exclude should ignore this element
   $ hg diff --subrepos -X s/foobar
+  diff --git a/s/barfoo b/s/barfoo
+  new file mode 100644
+  index 0000000..257cc56
+  --- /dev/null
+  +++ b/s/barfoo
+  @@ -0,0 +1 @@
+  +foo
+
+moving a file should show a removal and an add
+  $ hg revert --all
+  reverting subrepo ../gitroot
+  $ cd s
+  $ git mv foobar woop
+  $ cd ..
+  $ hg diff --subrepos
+  diff --git a/s/foobar b/s/foobar
+  deleted file mode 100644
+  index 8a5a5e2..0000000
+  --- a/s/foobar
+  +++ /dev/null
+  @@ -1,4 +0,0 @@
+  -woopwoop
+  -
+  -foo
+  -bar
+  diff --git a/s/woop b/s/woop
+  new file mode 100644
+  index 0000000..8a5a5e2
+  --- /dev/null
+  +++ b/s/woop
+  @@ -0,0 +1,4 @@
+  +woopwoop
+  +
+  +foo
+  +bar
+  $ rm s/woop
 
 revert the subrepository
   $ hg revert --all