Patchwork [8,of,8] addremove: support addremove with explicit paths in subrepos

login
register
mail settings
Submitter Matt Harbison
Date Nov. 27, 2014, 1:12 a.m.
Message ID <d7617993a40e96f45a66.1417050741@Envy>
Download mbox | patch
Permalink /patch/6876/
State Superseded
Headers show

Comments

Matt Harbison - Nov. 27, 2014, 1:12 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1415594785 18000
#      Sun Nov 09 23:46:25 2014 -0500
# Node ID d7617993a40e96f45a6695177eb6c553962a4bf1
# Parent  a7e140b57517bc271f29c8874bd356dc85c026a6
addremove: support addremove with explicit paths in subrepos

Git and svn subrepos are currently not supported.
Augie Fackler - Dec. 2, 2014, 3:59 p.m.
On Wed, Nov 26, 2014 at 08:12:21PM -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1415594785 18000
> #      Sun Nov 09 23:46:25 2014 -0500
> # Node ID d7617993a40e96f45a6695177eb6c553962a4bf1
> # Parent  a7e140b57517bc271f29c8874bd356dc85c026a6
> addremove: support addremove with explicit paths in subrepos

Rest of the series looks reasonable to me, FYI.

>
> Git and svn subrepos are currently not supported.
>
> diff --git a/mercurial/help/subrepos.txt b/mercurial/help/subrepos.txt
> --- a/mercurial/help/subrepos.txt
> +++ b/mercurial/help/subrepos.txt
> @@ -82,8 +82,10 @@
>      ignored.
>
>  :addremove: addremove does not recurse into subrepos unless
> -    -S/--subrepos is specified.  Git and Subversion subrepositories
> -    will print a warning and continue.
> +    -S/--subrepos is specified.  However, if you specify the full
> +    path of a directory in a subrepo, addremove will be performed on
> +    it even without -S/--subrepos being specified.  Git and
> +    Subversion subrepositories will print a warning and continue.
>
>  :archive: archive does not recurse in subrepositories unless
>      -S/--subrepos is specified.
> diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
> --- a/mercurial/scmutil.py
> +++ b/mercurial/scmutil.py
> @@ -722,9 +722,17 @@
>      ret = 0
>      join = lambda f: os.path.join(prefix, f)
>
> +    def matchessubrepo(matcher, subpath):
> +        if matcher.exact(subpath):
> +            return True
> +        for f in matcher.files():
> +            if f.startswith(subpath):
> +                return True
> +        return False
> +
>      wctx = repo[None]
>      for subpath in sorted(wctx.substate):
> -        if opts.get('subrepos'):
> +        if opts.get('subrepos') or matchessubrepo(m, subpath):
>              sub = wctx.sub(subpath)
>              try:
>                  submatch = matchmod.narrowmatcher(subpath, m)
> diff --git a/tests/test-subrepo-deep-nested-change.t b/tests/test-subrepo-deep-nested-change.t
> --- a/tests/test-subrepo-deep-nested-change.t
> +++ b/tests/test-subrepo-deep-nested-change.t
> @@ -139,9 +139,17 @@
>    A sub1/foo
>    R sub1/sub2/test.txt
>    $ hg update -Cq
> +  $ touch sub1/sub2/folder/bar
> +  $ hg addremove sub1/sub2
> +  adding sub1/sub2/folder/bar (glob)
> +  $ hg status -S
> +  A sub1/sub2/folder/bar
> +  ? sub1/foo
> +  $ hg update -Cq
>    $ rm sub1/sub2/folder/test.txt
>    $ rm sub1/sub2/test.txt
>    $ hg ci -ASm "remove test.txt"
> +  adding sub1/sub2/folder/bar (glob)
>    removing sub1/sub2/folder/test.txt (glob)
>    removing sub1/sub2/test.txt (glob)
>    adding sub1/foo (glob)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/help/subrepos.txt b/mercurial/help/subrepos.txt
--- a/mercurial/help/subrepos.txt
+++ b/mercurial/help/subrepos.txt
@@ -82,8 +82,10 @@ 
     ignored.
 
 :addremove: addremove does not recurse into subrepos unless
-    -S/--subrepos is specified.  Git and Subversion subrepositories
-    will print a warning and continue.
+    -S/--subrepos is specified.  However, if you specify the full
+    path of a directory in a subrepo, addremove will be performed on
+    it even without -S/--subrepos being specified.  Git and
+    Subversion subrepositories will print a warning and continue.
 
 :archive: archive does not recurse in subrepositories unless
     -S/--subrepos is specified.
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -722,9 +722,17 @@ 
     ret = 0
     join = lambda f: os.path.join(prefix, f)
 
+    def matchessubrepo(matcher, subpath):
+        if matcher.exact(subpath):
+            return True
+        for f in matcher.files():
+            if f.startswith(subpath):
+                return True
+        return False
+
     wctx = repo[None]
     for subpath in sorted(wctx.substate):
-        if opts.get('subrepos'):
+        if opts.get('subrepos') or matchessubrepo(m, subpath):
             sub = wctx.sub(subpath)
             try:
                 submatch = matchmod.narrowmatcher(subpath, m)
diff --git a/tests/test-subrepo-deep-nested-change.t b/tests/test-subrepo-deep-nested-change.t
--- a/tests/test-subrepo-deep-nested-change.t
+++ b/tests/test-subrepo-deep-nested-change.t
@@ -139,9 +139,17 @@ 
   A sub1/foo
   R sub1/sub2/test.txt
   $ hg update -Cq
+  $ touch sub1/sub2/folder/bar
+  $ hg addremove sub1/sub2
+  adding sub1/sub2/folder/bar (glob)
+  $ hg status -S
+  A sub1/sub2/folder/bar
+  ? sub1/foo
+  $ hg update -Cq
   $ rm sub1/sub2/folder/test.txt
   $ rm sub1/sub2/test.txt
   $ hg ci -ASm "remove test.txt"
+  adding sub1/sub2/folder/bar (glob)
   removing sub1/sub2/folder/test.txt (glob)
   removing sub1/sub2/test.txt (glob)
   adding sub1/foo (glob)