comparison 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
comparison
equal deleted inserted replaced
28829:65fb87479792 28830:a5009789960c
844 updating bookmark Y 844 updating bookmark Y
845 $ hg -R ../cloned-bookmarks-update parents -T "{rev}:{node|short}\n" 845 $ hg -R ../cloned-bookmarks-update parents -T "{rev}:{node|short}\n"
846 6:81dcce76aa0b 846 6:81dcce76aa0b
847 $ hg -R ../cloned-bookmarks-update bookmarks | grep ' Y ' 847 $ hg -R ../cloned-bookmarks-update bookmarks | grep ' Y '
848 * Y 6:81dcce76aa0b 848 * Y 6:81dcce76aa0b
849
850 $ cd ..
851
852 ensure changelog is written before bookmarks
853 $ hg init orderrepo
854 $ cd orderrepo
855 $ touch a
856 $ hg commit -Aqm one
857 $ hg book mybook
858 $ echo a > a
859
860 $ cat > $TESTTMP/pausefinalize.py <<EOF
861 > from mercurial import extensions, localrepo
862 > import os, time
863 > def transaction(orig, self, desc, report=None):
864 > tr = orig(self, desc, report)
865 > def sleep(*args, **kwargs):
866 > retry = 20
867 > while retry > 0 and not os.path.exists("$TESTTMP/unpause"):
868 > retry -= 1
869 > time.sleep(0.5)
870 > if os.path.exists("$TESTTMP/unpause"):
871 > os.remove("$TESTTMP/unpause")
872 > # It is important that this finalizer start with 'a', so it runs before
873 > # the changelog finalizer appends to the changelog.
874 > tr.addfinalize('a-sleep', sleep)
875 > return tr
876 >
877 > def extsetup(ui):
878 > # This extension inserts an artifical pause during the transaction
879 > # finalizer, so we can run commands mid-transaction-close.
880 > extensions.wrapfunction(localrepo.localrepository, 'transaction',
881 > transaction)
882 > EOF
883 $ hg commit -qm two --config extensions.pausefinalize=$TESTTMP/pausefinalize.py &
884 $ sleep 2
885 $ hg log -r .
886 changeset: 0:867bc5792c8c
887 bookmark: mybook
888 tag: tip
889 user: test
890 date: Thu Jan 01 00:00:00 1970 +0000
891 summary: one
892
893 $ hg bookmarks
894 * mybook 0:867bc5792c8c
895 $ touch $TESTTMP/unpause
896
897 $ cd ..