[PATCH 2 of 2 V3] revert: add support for reverting subrepos

Angel Ezquerra angel.ezquerra at gmail.com
Fri Oct 14 18:10:14 CDT 2011


# HG changeset patch
# User Angel Ezquerra <angel.ezquerra at gmail.com>
# Date 1318633615 -7200
# Node ID f4d050e992a90bdc386498c201dbab5b9a7ddde2
# Parent  adb7eb4d36eaa4a67b586357e1ec6de6435ab587
revert: add support for reverting subrepos

Reverting a subrepo is done by updating it to the revision that is selected on
the parent repo .hgsubstate file.

* ISSUES/TODO:
- Added and removed subrepos are not handled (that is left for another patch).

- This version of this patch only allows reverting a subrepo if the --no-backup
flag is used, since no backups are performed on the contents of the subrepo. It
could be possible to add support for backing up the subrepo contents by first
performing a "revert --all" on the subrepo, and then updating the subrepo to
the proper revision.

- The behavior of the --all flag has not been changed: The --all flag will not
revert the state of the subrepos. In order to support the --all flag we must
also support not using the --no-backup flag. Otherwise it will not be possible
to use --all without the --no-backup flag.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4653,8 +4653,6 @@
             if path in names:
                 return
             if path in repo[node].substate:
-                ui.warn("%s: %s\n" % (m.rel(path),
-                    'reverting subrepos is unsupported'))
                 return
             path_ = path + '/'
             for f in names:
@@ -4668,6 +4666,13 @@
             if abs not in names:
                 names[abs] = m.rel(abs), m.exact(abs)
 
+        targetsubs = [s for s in repo[node].substate if m(s)]
+        if targetsubs and not opts.get('no_backup'):
+            msg = _("cannot revert subrepos unless the no-backup flag is set")
+            hint = _("there are subrepos on the revert list, "
+                "use --no-backup to revert them")
+            raise util.Abort(msg, hint=hint)
+
         m = scmutil.matchfiles(repo, names)
         changes = repo.status(match=m)[:4]
         modified, added, removed, deleted = map(set, changes)
@@ -4797,6 +4802,13 @@
                 checkout(f)
                 normal(f)
 
+            if targetsubs:
+                # Revert the subrepos on the revert list
+                # reverting a subrepo is done by updating it to the revision
+                # specified in the corresponding substate dictionary
+                for sname in targetsubs:
+                    ui.status(_('reverting subrepo %s\n') % sname)
+                    ctx.sub(sname).get(ctx.substate[sname], overwrite=True)
     finally:
         wlock.release()
 


More information about the Mercurial-devel mailing list