[PATCH [RFC][V2]] revert: add support for reverting subrepos

Angel Ezquerra angel.ezquerra at gmail.com
Thu Jan 12 17:40:12 CST 2012


On Thu, Jan 12, 2012 at 9:48 PM, Angel Ezquerra
<angel.ezquerra at gmail.com> wrote:
> # HG changeset patch
> # User Angel Ezquerra <angel.ezquerra at gmail.com>
> # Date 1326364670 -3600
> # Node ID 747979cca1c541b84d2a15b3e037c63388db1c59
> # Parent  c47d69ce5208d5b5cfd2fb2f0f1d7a2b4795fbf5
> 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 removed subrepos is not supported (yet).
>
> - This patch only allows reverting subrepos 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 changed. It now reverts subrepos as well.
> Note that this may lead to data loss if the user has a dirty subrepo. Since this
> only works with the --no-backup flag it seems reasonable.
>
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -4791,8 +4791,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:
> @@ -4806,6 +4804,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)
> @@ -4934,6 +4939,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()
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

This is a patch that I sent before the mercurial 2.0 code freeze,
rebased to the tip of the default branch.

The patch adds support for reverting modified subrepos (but it does
not work for added or removed subrepos).

I got another patch that applies on top of this one which detects
which subrepos have been added or removed. However I am not certain of
what is the best way to "forget" subrepo that has been added to the
.hgsub file (but not committed). I tried using subrepo.remove() but
that did not work.

I could always manually edit the .hgsub file, but it does not seem the
right way to go... Any ideas?

Cheers,

Angel


More information about the Mercurial-devel mailing list