[PATCH 1 of 3 RFC] revert: add support for reverting subrepos

Angel Ezquerra angel.ezquerra at gmail.com
Thu Mar 22 17:34:37 CDT 2012


# HG changeset patch
# User Angel Ezquerra <angel.ezquerra at gmail.com>
# Date 1332279907 -3600
# Node ID e45677da232ff46f043603fd232a07897f5fb6f2
# Parent  ba8b81caee4469a2e47c2d5074c2a59db8ac51ce
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:

- reverting added and revomed subrepos is not supported.

- 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 been changed. It now revers subrepos as well
Note that this may lead to data loss if the user has a dirty subrepo.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4826,8 +4826,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:
@@ -4841,6 +4839,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)
@@ -4969,6 +4974,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