diff mercurial/subrepo.py @ 16430:6883c2363f44

revert: add support for reverting subrepos without --no-backup and/or --all When a subrepo is reverted but --no-backup is not set, call revert on the subrepo that is being reverted prior to updating it to the revision specified in the parent repo's .hgsubstate file. The --all flag is passed down to the subrepo when it is being reverted. If the --all flag is not set, all files that are modified on the subrepo will be reverted.
author Angel Ezquerra <angel.ezquerra@gmail.com>
date Wed, 28 Mar 2012 11:42:17 +0200
parents 71dcce391a44
children 9c431cfdca12
line wrap: on
line diff
--- a/mercurial/subrepo.py	Wed Mar 28 11:42:17 2012 +0200
+++ b/mercurial/subrepo.py	Wed Mar 28 11:42:17 2012 +0200
@@ -577,13 +577,37 @@
                               os.path.join(prefix, self._path), True)
 
     def revert(self, ui, substate, *pats, **opts):
-        # reverting a subrepo is done by updating it to the revision
-        # specified in the corresponding substate dictionary
+        # reverting a subrepo is a 2 step process:
+        # 1. if the no_backup is not set, revert all modified
+        #    files inside the subrepo
+        # 2. update the subrepo to the revision specified in
+        #    the corresponding substate dictionary
         ui.status(_('reverting subrepo %s\n') % substate[0])
+        if not opts.get('no_backup'):
+            # Revert all files on the subrepo, creating backups
+            # Note that this will not recursively revert subrepos
+            # We could do it if there was a set:subrepos() predicate
+            opts = opts.copy()
+            opts['date'] = None
+            opts['rev'] = substate[1]
+
+            pats = []
+            if not opts['all']:
+                pats = ['set:modified()']
+            self.filerevert(ui, *pats, **opts)
 
         # Update the repo to the revision specified in the given substate
         self.get(substate, overwrite=True)
 
+    def filerevert(self, ui, *pats, **opts):
+        ctx = self._repo[opts['rev']]
+        parents = self._repo.dirstate.parents()
+        if opts['all']:
+            pats = ['set:modified()']
+        else:
+            pats = []
+        cmdutil.revert(ui, self._repo, ctx, parents, *pats, **opts)
+
 class svnsubrepo(abstractsubrepo):
     def __init__(self, ctx, path, state):
         self._path = path