Patchwork [2,of,6,V2] journal: execute setup procedures for already instantiated dirstate

mail settings
Submitter Katsunori FUJIWARA
Date July 10, 2017, 2:18 p.m.
Message ID <7ae6b72cb5da75670c00.1499696295@speaknoevil>
Download mbox | patch
Permalink /patch/22202/
State Accepted
Headers show


Katsunori FUJIWARA - July 10, 2017, 2:18 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <>
# Date 1499695791 -32400
#      Mon Jul 10 23:09:51 2017 +0900
# Node ID 7ae6b72cb5da75670c00b00fe096cec22e0de731
# Parent  d5ba581532af80641a881860c1dc718773892a40
journal: execute setup procedures for already instantiated dirstate

If dirstate is instantiated before reposetup() of journal extension,
it doesn't have "journalstorage" property, even if it is instantiated
via wrapdirstate() wrapping repo.dirstate(), because wrapdirstate()
works as same as original one before marking repo as "journal"-ing in

This issue can be reproduced by running test-journal.t or
test-journal-share.t with

On the other hand, just discarding already instantiated dirstate in
reposetup() prevents chg from filling dirstate before reposetup() (see
bf3af0eced44 for detail).

Therefore, this patch executes setup procedures for already
instantiated dirstate explicitly in reposetup().

To centralize setup procedures for dirstate, this patch also factors
them out from wrapdirstate().


diff --git a/hgext/ b/hgext/
--- a/hgext/
+++ b/hgext/
@@ -70,18 +70,28 @@  def reposetup(ui, repo):
     if repo.local():
         repo.journal = journalstorage(repo)
+        dirstate, cached = localrepo.isfilecached(repo, 'dirstate')
+        if cached:
+            # already instantiated dirstate isn't yet marked as
+            # "journal"-ing, even though repo.dirstate() was already
+            # wrapped by own wrapdirstate()
+            _setupdirstate(repo, dirstate)
 def runcommand(orig, lui, repo, cmd, fullargs, *args):
     """Track the command line options for recording in the journal"""
     return orig(lui, repo, cmd, fullargs, *args)
+def _setupdirstate(repo, dirstate):
+    dirstate.journalstorage = repo.journal
+    dirstate.addparentchangecallback('journal', recorddirstateparents)
 # hooks to record dirstate changes
 def wrapdirstate(orig, repo):
     """Make journal storage available to the dirstate object"""
     dirstate = orig(repo)
     if util.safehasattr(repo, 'journal'):
-        dirstate.journalstorage = repo.journal
-        dirstate.addparentchangecallback('journal', recorddirstateparents)
+        _setupdirstate(repo, dirstate)
     return dirstate
 def recorddirstateparents(dirstate, old, new):