diff -r 71dcce391a44 -r 6883c2363f44 mercurial/subrepo.py --- 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