[PATCH 2 of 2 DEFAULT REVIEW] forget: support forgetting explicit paths in subrepos

David M. Carr david at carrclan.us
Sun Nov 6 20:48:30 UTC 2011


# HG changeset patch
# User David M. Carr  <david at carrclan.us>
# Date 1320523788 14400
# Node ID b9aaf2d6a0ba1ab55354d93e455ae8f7e4be5383
# Parent  f196387b7e519860554c9a0d24fa9d327d643e29
forget: support forgetting explicit paths in subrepos

Change the behavior of the forget command such that explicit paths in
subrepos are handled by forgetting the file in the subrepo. This eliminates the
previous behavior where if you called "hg forget" for an explicit path in a
subrepo, it would state that the file is already untracked.

diff -r f196387b7e51 -r b9aaf2d6a0ba mercurial/commands.py
--- a/mercurial/commands.py	Sat Nov 05 16:09:38 2011 -0400
+++ b/mercurial/commands.py	Sat Nov 05 16:09:48 2011 -0400
@@ -13,6 +13,7 @@
 import patch, help, url, encoding, templatekw, discovery
 import archival, changegroup, cmdutil, hbisect
 import sshserver, hgweb, hgweb.server, commandserver
+import match as matchmod
 import merge as mergemod
 import minirst, revset, fileset
 import dagparser, context, simplemerge
@@ -2432,23 +2433,45 @@
     if not pats:
         raise util.Abort(_('no files specified'))
 
-    m = scmutil.match(repo[None], pats, opts)
+    wctx = repo[None]
+    m = scmutil.match(wctx, pats, opts)
     s = repo.status(match=m, clean=True)
     forget = sorted(s[0] + s[1] + s[3] + s[6])
+    subforget = {}
     errs = 0
 
+    for subpath in wctx.substate:
+        sub = wctx.sub(subpath)
+        try:
+            submatch = matchmod.narrowmatcher(subpath, m)
+            for fsub in sub.walk(submatch):
+                if submatch.exact(fsub):
+                    subforget[os.path.join(subpath, fsub)] = (fsub, sub)
+        except error.LookupError:
+            ui.status(_("skipping missing subrepository: %s\n") % subpath)
+
     for f in m.files():
         if f not in repo.dirstate and not os.path.isdir(m.rel(f)):
-            if os.path.exists(m.rel(f)):
-                ui.warn(_('not removing %s: file is already untracked\n')
-                        % m.rel(f))
-            errs = 1
+            if f not in subforget:
+                if os.path.exists(m.rel(f)):
+                    ui.warn(_('not removing %s: file is already untracked\n')
+                            % m.rel(f))
+                errs = 1
 
     for f in forget:
         if ui.verbose or not m.exact(f):
             ui.status(_('removing %s\n') % m.rel(f))
 
-    repo[None].forget(forget)
+    if ui.verbose:
+        for f in sorted(subforget.keys()):
+            ui.status(_('removing %s\n') % m.rel(f))
+
+    wctx.forget(forget)
+
+    for f in sorted(subforget.keys()):
+        fsub, sub = subforget[f]
+        sub.forget([fsub])
+
     return errs
 
 @command(
diff -r f196387b7e51 -r b9aaf2d6a0ba mercurial/help/subrepos.txt
--- a/mercurial/help/subrepos.txt	Sat Nov 05 16:09:38 2011 -0400
+++ b/mercurial/help/subrepos.txt	Sat Nov 05 16:09:48 2011 -0400
@@ -94,6 +94,9 @@
     elements. Subversion subrepositories are currently silently
     ignored.
 
+:forget: forget currently only handles exact file matches in subrepos.
+    Git and Subversion subrepositories are currently silently ignored.
+
 :incoming: incoming does not recurse in subrepos unless -S/--subrepos
     is specified. Subversion subrepositories are currently silently
     ignored.
diff -r f196387b7e51 -r b9aaf2d6a0ba mercurial/subrepo.py
--- a/mercurial/subrepo.py	Sat Nov 05 16:09:38 2011 -0400
+++ b/mercurial/subrepo.py	Sat Nov 05 16:09:48 2011 -0400
@@ -360,6 +360,9 @@
         '''
         pass
 
+    def forget(self, files):
+        pass
+
 class hgsubrepo(abstractsubrepo):
     def __init__(self, ctx, path, state):
         self._path = path
@@ -553,6 +556,10 @@
         ctx = self._repo[None]
         return ctx.walk(match)
 
+    def forget(self, files):
+        ctx = self._repo[None]
+        ctx.forget(files)
+
 class svnsubrepo(abstractsubrepo):
     def __init__(self, ctx, path, state):
         self._path = path
diff -r f196387b7e51 -r b9aaf2d6a0ba tests/test-subrepo.t
--- a/tests/test-subrepo.t	Sat Nov 05 16:09:38 2011 -0400
+++ b/tests/test-subrepo.t	Sat Nov 05 16:09:48 2011 -0400
@@ -1006,12 +1006,12 @@
   committing subrepository s
 
 Test behavior of forget for explicit path in subrepo:
-Forgetting an explicit path in a subrepo currently gives a file untracked warn
+Forgetting an explicit path in a subrepo untracks the file
   $ echo c19 > s/f19
   $ hg add s/f19
   $ hg st -S
   A s/f19
   $ hg forget s/f19
-  not removing s/f19: file is already untracked
-  [1]
+  $ hg st -S
+  ? s/f19
   $ rm s/f19



More information about the Mercurial-devel mailing list