[PATCH] journal: use a more compatible way to wrap dirstate

Jun Wu quark at fb.com
Fri May 26 02:56:41 UTC 2017


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1495767385 25200
#      Thu May 25 19:56:25 2017 -0700
# Node ID 27b3fcbc4fd5125d86a4f4f2cb3e9accdae71265
# Parent  2b5953a49f1407f825d65b45986d213cb5c79203
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 27b3fcbc4fd5
journal: use a more compatible way to wrap dirstate

Previously journal uses

  extensions.wrapfunction(localrepo.localrepository.dirstate, 'func', wrap)

in extsetup to change dirstate. That assumes the dirstate filecache is not
touched by others, and is incompatible with bf3af0eced.

This patch moves the dirstate change to reposetup and does not assume
filecache internal implementation. It is more compatible with other code.

This fixes "--extra-config-opt=extensions.fsmonitor= test-journal.t" test.

diff --git a/hgext/journal.py b/hgext/journal.py
--- a/hgext/journal.py
+++ b/hgext/journal.py
@@ -62,6 +62,4 @@ def extsetup(ui):
     extensions.wrapfunction(dispatch, 'runcommand', runcommand)
     extensions.wrapfunction(bookmarks.bmstore, '_write', recordbookmarks)
-    extensions.wrapfunction(
-        localrepo.localrepository.dirstate, 'func', wrapdirstate)
     extensions.wrapfunction(hg, 'postshare', wrappostshare)
     extensions.wrapfunction(hg, 'copystore', unsharejournal)
@@ -70,4 +68,6 @@ def reposetup(ui, repo):
     if repo.local():
         repo.journal = journalstorage(repo)
+        repo.dirstate.journalstorage = repo.journal
+        repo.dirstate.addparentchangecallback('journal', recorddirstateparents)
 
 def runcommand(orig, lui, repo, cmd, fullargs, *args):
@@ -76,13 +76,4 @@ def runcommand(orig, lui, repo, cmd, ful
     return orig(lui, repo, cmd, fullargs, *args)
 
-# 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)
-    return dirstate
-
 def recorddirstateparents(dirstate, old, new):
     """Records all dirstate parent changes in the journal."""


More information about the Mercurial-devel mailing list