[PATCH 1 of 2] commit: ignore subrepos completely if the '.hgsub' is excluded via -X

Matt Mackall mpm at selenic.com
Thu Jan 26 15:31:21 CST 2012


On Thu, 2012-01-26 at 12:31 +0100, Jason Harris wrote:
> # HG changeset patch
> # User Jason Harris <jason at jasonfharris.com>
> # Date 1327576926 -3600
> # Branch stable
> # Node ID 410354c0ee27ac8afd192f138aa9c205d1d17898
> # Parent  c2e6c5ef45555ff98dd12bef335c40a91eccc390
> commit: ignore subrepos completely if the '.hgsub' is excluded via -X
> 
> As a way for users to make sure that their sub repository state is not
> committed, make it so that -X .hgsub actually obeys the exclusion.

Use case, please. Bear in mind that "create a consistent snapshot of the
whole project state" is a core Mercurial principle, and including
subrepos in that snapshot is the obvious manifestation of that
principle.

This change strikes me as way too involved, especially at this date in
the cycle. It's also definitely not how we normally do pattern matching.

Also, it seems the file to ignore is actually .hgsubstate.

> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -1190,6 +1190,11 @@
>          # Let --subrepos on the command line overide config setting.
>          ui.setconfig('ui', 'commitsubrepos', True)
>  
> +    # if -X .hgsub is specified then ignore subrepos completely
> +    excluded = opts.get('exclude')
> +    if excluded and ('.hgsub' in excluded):
> +            ui.setconfig('ui', 'excludesubrepos', True)
> +
>      extra = {}
>      if opts.get('close_branch'):
>          if repo['.'].node() not in repo.branchheads():
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -1097,35 +1097,37 @@
>              # check subrepos
>              subs = []
>              removedsubs = set()
> -            if '.hgsub' in wctx:
> -                # only manage subrepos and .hgsubstate if .hgsub is present
> -                for p in wctx.parents():
> -                    removedsubs.update(s for s in p.substate if match(s))
> -                for s in wctx.substate:
> -                    removedsubs.discard(s)
> -                    if match(s) and wctx.sub(s).dirty():
> -                        subs.append(s)
> -                if (subs or removedsubs):
> -                    if (not match('.hgsub') and
> -                        '.hgsub' in (wctx.modified() + wctx.added())):
> -                        raise util.Abort(
> -                            _("can't commit subrepos without .hgsub"))
> -                    if '.hgsubstate' not in changes[0]:
> -                        changes[0].insert(0, '.hgsubstate')
> -                        if '.hgsubstate' in changes[2]:
> -                            changes[2].remove('.hgsubstate')
> -            elif '.hgsub' in changes[2]:
> -                # clean up .hgsubstate when .hgsub is removed
> -                if ('.hgsubstate' in wctx and
> -                    '.hgsubstate' not in changes[0] + changes[1] + changes[2]):
> -                    changes[2].insert(0, '.hgsubstate')
> +            if not self.ui.configbool('ui', 'excludesubrepos'):
> +                if '.hgsub' in wctx:
> +                    # only manage subrepos and .hgsubstate if .hgsub is present
> +                    for p in wctx.parents():
> +                        removedsubs.update(s for s in p.substate if match(s))
> +                    for s in wctx.substate:
> +                        removedsubs.discard(s)
> +                        if match(s) and wctx.sub(s).dirty():
> +                            subs.append(s)
> +                    if (subs or removedsubs):
> +                        if (not match('.hgsub') and
> +                            '.hgsub' in (wctx.modified() + wctx.added())):
> +                            raise util.Abort(
> +                                _("can't commit subrepos without .hgsub"))
> +                        if '.hgsubstate' not in changes[0]:
> +                            changes[0].insert(0, '.hgsubstate')
> +                            if '.hgsubstate' in changes[2]:
> +                                changes[2].remove('.hgsubstate')
> +                elif '.hgsub' in changes[2]:
> +                    # clean up .hgsubstate when .hgsub is removed
> +                    if ('.hgsubstate' in wctx and '.hgsubstate' not in
> +                                changes[0] + changes[1] + changes[2]):
> +                        changes[2].insert(0, '.hgsubstate')
>  
> -            if subs and not self.ui.configbool('ui', 'commitsubrepos', False):
> -                changedsubs = [s for s in subs if wctx.sub(s).dirty(True)]
> -                if changedsubs:
> -                    raise util.Abort(_("uncommitted changes in subrepo %s")
> -                                     % changedsubs[0],
> -                                     hint=_("use --subrepos for recursive commit"))
> +                if subs and not self.ui.configbool('ui', 'commitsubrepos',
> +                                                                     False):
> +                    changedsubs = [s for s in subs if wctx.sub(s).dirty(True)]
> +                    if changedsubs:
> +                        raise util.Abort(_("uncommitted changes in subrepo %s")
> +                                 % changedsubs[0],
> +                                 hint=_("use --subrepos for recursive commit"))
>  
>              # make sure all explicit patterns are matched
>              if not force and match.files():
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel


-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list