[PATCH] subrepo: avoids empty commit when .hgsubstate is dirty (issue2403)

Mads Kiilerich mads at kiilerich.com
Fri Nov 26 10:21:12 CST 2010


On 11/26/2010 04:54 PM, Erik Zielke wrote:
> # HG changeset patch
> # User Erik Zielke<ez at aragost.com>
> # Date 1290781536 -3600
> # Node ID dbd15e50463af413519d18eca2b662d4a1583f05
> # Parent  da69a1597285fe25eeedab1a45869487773b715b
> subrepo: avoids empty commit when .hgsubstate is dirty (issue2403)
>
> This patch avoids empty commit when .hgsubstate is dirty. Empty commit
> was caused by .hgsubstate being updated back to the state of the
> working copy parent when committing, if a user had changed it manually
> and not made any changes in subrepositories.
>
> The subrepository state from the working copies parent is compared
> with the state calculated as a result of trying to commit the
> subrepositories. If the two states are the same, then return None
> otherwise the commit is just done.
>
> The line: "committing subrepository x" will be written if there is
> nothing committed, but .hgsubstate is dirty for x subrepository.
>
> diff -r da69a1597285 -r dbd15e50463a mercurial/localrepo.py
> --- a/mercurial/localrepo.py	Sun Nov 21 13:16:59 2010 +0100
> +++ b/mercurial/localrepo.py	Fri Nov 26 15:25:36 2010 +0100
> @@ -939,6 +939,7 @@
>
>               # commit subs
>               if subs or removedsubs:
> +                pstate = subrepo.substate(self['.'])
>                   state = wctx.substate.copy()
>                   for s in sorted(subs):
>                       sub = wctx.sub(s)
> @@ -946,7 +947,18 @@
>                           subrepo.subrelpath(sub))
>                       sr = sub.commit(cctx._text, user, date)
>                       state[s] = (state[s][0], sr)
> -                subrepo.writestate(self, state)
> +
> +                changed = False
> +                if len(pstate) != len(state):
> +                    changed = True
> +                if not changed:
> +                    for newstate in state:
> +                        if state[newstate][1] != pstate[newstate]:
> +                            changed = True
> +                if changed:
> +                    subrepo.writestate(self, state)
> +                else:
> +                    return None
>

...

> +trying to do an empty commit:
> +
> +  $ hg commit -m1
> +  committing subrepository sub
> +  nothing changed
> +  [1]

That is fine, but just returning None will also ignore all other changes:

   $ touch f
   $ hg add f
   $ hg commit -m1
   committing subrepository sub
   nothing changed
   [1]

/Mads


More information about the Mercurial-devel mailing list