diff tests/test-bookmarks.t @ 28830:a5009789960c

transaction: allow running file generators after finalizers Previously, transaction.close would run the file generators before running the finalizers (see the list below for what is in each). Since file generators contain the bookmarks and the dirstate, this meant we made the dirstate and bookmarks visible to external readers before we actually wrote the commits into the changelog, which could result in missing bookmarks and missing working copy parents (especially on servers with high commit throughput, since pulls might fail to see certain bookmarks in this situation). By moving the changelog writing to be before the bookmark/dirstate writing, we ensure the commits are present before they are referenced. This implementation allows certain file generators to be after the finalizers. We didn't want to move all of the generators, since it's important that things like phases actually run before the finalizers (otherwise you could expose commits as public when they really shouldn't be). For reference, file generators currently consist of: bookmarks, dirstate, and phases. Finalizers currently consist of: changelog, revbranchcache, and fncache.
author Durham Goode <durham@fb.com>
date Thu, 07 Apr 2016 14:10:49 -0700
parents 2e1bceeea520
children 318a24b52eeb
line wrap: on
line diff
--- a/tests/test-bookmarks.t	Thu Apr 07 11:11:55 2016 +0000
+++ b/tests/test-bookmarks.t	Thu Apr 07 14:10:49 2016 -0700
@@ -846,3 +846,52 @@
   6:81dcce76aa0b
   $ hg -R ../cloned-bookmarks-update bookmarks | grep ' Y '
    * Y                         6:81dcce76aa0b
+
+  $ cd ..
+
+ensure changelog is written before bookmarks
+  $ hg init orderrepo
+  $ cd orderrepo
+  $ touch a
+  $ hg commit -Aqm one
+  $ hg book mybook
+  $ echo a > a
+
+  $ cat > $TESTTMP/pausefinalize.py <<EOF
+  > from mercurial import extensions, localrepo
+  > import os, time
+  > def transaction(orig, self, desc, report=None):
+  >    tr = orig(self, desc, report)
+  >    def sleep(*args, **kwargs):
+  >        retry = 20
+  >        while retry > 0 and not os.path.exists("$TESTTMP/unpause"):
+  >            retry -= 1
+  >            time.sleep(0.5)
+  >        if os.path.exists("$TESTTMP/unpause"):
+  >            os.remove("$TESTTMP/unpause")
+  >    # It is important that this finalizer start with 'a', so it runs before
+  >    # the changelog finalizer appends to the changelog.
+  >    tr.addfinalize('a-sleep', sleep)
+  >    return tr
+  > 
+  > def extsetup(ui):
+  >    # This extension inserts an artifical pause during the transaction
+  >    # finalizer, so we can run commands mid-transaction-close.
+  >    extensions.wrapfunction(localrepo.localrepository, 'transaction',
+  >                            transaction)
+  > EOF
+  $ hg commit -qm two --config extensions.pausefinalize=$TESTTMP/pausefinalize.py &
+  $ sleep 2
+  $ hg log -r .
+  changeset:   0:867bc5792c8c
+  bookmark:    mybook
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     one
+  
+  $ hg bookmarks
+   * mybook                    0:867bc5792c8c
+  $ touch $TESTTMP/unpause
+
+  $ cd ..