##// END OF EJS Templates
transaction: allow running file generators after finalizers...
Durham Goode -
r28830:a5009789 default
parent child Browse files
Show More
@@ -23,6 +23,19 b' from . import ('
23
23
24 version = 2
24 version = 2
25
25
26 # These are the file generators that should only be executed after the
27 # finalizers are done, since they rely on the output of the finalizers (like
28 # the changelog having been written).
29 postfinalizegenerators = set([
30 'bookmarks',
31 'dirstate'
32 ])
33
34 class GenerationGroup(object):
35 ALL='all'
36 PREFINALIZE='prefinalize'
37 POSTFINALIZE='postfinalize'
38
26 def active(func):
39 def active(func):
27 def _active(self, *args, **kwds):
40 def _active(self, *args, **kwds):
28 if self.count == 0:
41 if self.count == 0:
@@ -276,12 +289,19 b' class transaction(object):'
276 # but for bookmarks that are handled outside this mechanism.
289 # but for bookmarks that are handled outside this mechanism.
277 self._filegenerators[genid] = (order, filenames, genfunc, location)
290 self._filegenerators[genid] = (order, filenames, genfunc, location)
278
291
279 def _generatefiles(self, suffix=''):
292 def _generatefiles(self, suffix='', group=GenerationGroup.ALL):
280 # write files registered for generation
293 # write files registered for generation
281 any = False
294 any = False
282 for entry in sorted(self._filegenerators.values()):
295 for id, entry in sorted(self._filegenerators.iteritems()):
283 any = True
296 any = True
284 order, filenames, genfunc, location = entry
297 order, filenames, genfunc, location = entry
298
299 # for generation at closing, check if it's before or after finalize
300 postfinalize = group == GenerationGroup.POSTFINALIZE
301 if (group != GenerationGroup.ALL and
302 (id in postfinalizegenerators) != (postfinalize)):
303 continue
304
285 vfs = self._vfsmap[location]
305 vfs = self._vfsmap[location]
286 files = []
306 files = []
287 try:
307 try:
@@ -407,10 +427,11 b' class transaction(object):'
407 '''commit the transaction'''
427 '''commit the transaction'''
408 if self.count == 1:
428 if self.count == 1:
409 self.validator(self) # will raise exception if needed
429 self.validator(self) # will raise exception if needed
410 self._generatefiles()
430 self._generatefiles(group=GenerationGroup.PREFINALIZE)
411 categories = sorted(self._finalizecallback)
431 categories = sorted(self._finalizecallback)
412 for cat in categories:
432 for cat in categories:
413 self._finalizecallback[cat](self)
433 self._finalizecallback[cat](self)
434 self._generatefiles(group=GenerationGroup.POSTFINALIZE)
414
435
415 self.count -= 1
436 self.count -= 1
416 if self.count != 0:
437 if self.count != 0:
@@ -846,3 +846,52 b' updates the working directory and curren'
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 ..
General Comments 0
You need to be logged in to leave comments. Login now