[PATCH 4 of 5] localrepo: do not write dirstate if it's not in transaction scope

Martin von Zweigbergk martinvonz at google.com
Tue Feb 28 16:15:17 EST 2017


On Mon, Feb 27, 2017 at 9:35 AM, Jun Wu <quark at fb.com> wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1488189479 28800
> #      Mon Feb 27 01:57:59 2017 -0800
> # Node ID f88c37484782ae7fede3c7a2a27a5f5d9b12bc9a
> # Parent  89793c9bfdc93896fd308ad9f4c400710ff2bde2
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r f88c37484782
> localrepo: do not write dirstate if it's not in transaction scope
>
> See the previous patch for why.
>
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -1077,14 +1077,16 @@ class localrepository(object):
>              repo = reporef()
>              if success:
> -                # this should be explicitly invoked here, because
> -                # in-memory changes aren't written out at closing
> -                # transaction, if tr.addfilegenerator (via
> -                # dirstate.write or so) isn't invoked while
> -                # transaction running
> -                repo.dirstate.write(None)
> +                if 'dirstate' in tr.scope():
> +                    # this should be explicitly invoked here, because
> +                    # in-memory changes aren't written out at closing
> +                    # transaction, if tr.addfilegenerator (via
> +                    # dirstate.write or so) isn't invoked while
> +                    # transaction running
> +                    repo.dirstate.write(None)

Can we check that the dirstate has not been modified since the start
of the transaction and fail if it has? Otherwise it seems like we may
easily forgot to add e.g. "dirstate" to the scope one day when "hg
bookmarks" starts modifying it. I suspect the answer is that that
won't be easy, but how much work it be? The same thing of course
applies to the journal files in the other patch.

>              else:
> -                # discard all changes (including ones already written
> -                # out) in this transaction
> -                repo.dirstate.restorebackup(None, prefix='journal.')
> +                if 'dirstate' in tr.scope():
> +                    # discard all changes (including ones already written
> +                    # out) in this transaction
> +                    repo.dirstate.restorebackup(None, prefix='journal.')
>
>                  repo.invalidate(clearfilecache=True)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list