Patchwork revlog: move file writing to a separate function

login
register
mail settings
Submitter Durham Goode
Date Jan. 3, 2014, 4:44 p.m.
Message ID <9ebc0972b310ce028c06.1388767490@dev010.prn1.facebook.com>
Download mbox | patch
Permalink /patch/3258/
State Accepted
Commit 33394f2e331ea46d2eaa149a3f7a35f050281976
Headers show

Comments

Durham Goode - Jan. 3, 2014, 4:44 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1385499507 28800
#      Tue Nov 26 12:58:27 2013 -0800
# Node ID 9ebc0972b310ce028c0670133ece61afd0b5c910
# Parent  082b2930fe2ca9a003b08439524384e097acaa0a
revlog: move file writing to a separate function

Moves the code that actually writes to a file to a separate function in
revlog.py. This allows extensions to intercept and use the data being written to
disk. For example, an extension might want to replicate these writes elsewhere.

When cloning the Mercurial repo on /dev/shm with --pull, I see about a 0.3% perf change.
It goes from 28.2 to 28.3 seconds.
Matt Mackall - Jan. 3, 2014, 11:35 p.m.
On Fri, 2014-01-03 at 08:44 -0800, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1385499507 28800
> #      Tue Nov 26 12:58:27 2013 -0800
> # Node ID 9ebc0972b310ce028c0670133ece61afd0b5c910
> # Parent  082b2930fe2ca9a003b08439524384e097acaa0a
> revlog: move file writing to a separate function

Queued for default, thanks.

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1206,6 +1206,15 @@ 
         self.nodemap[node] = curr
 
         entry = self._io.packentry(e, self.node, self.version, curr)
+        self._writeentry(transaction, ifh, dfh, entry, data, link, offset)
+
+        if type(text) == str: # only accept immutable objects
+            self._cache = (node, curr, text)
+        self._basecache = (curr, chainbase)
+        return node
+
+    def _writeentry(self, transaction, ifh, dfh, entry, data, link, offset):
+        curr = len(self) - 1
         if not self._inline:
             transaction.add(self.datafile, offset)
             transaction.add(self.indexfile, curr * len(entry))
@@ -1222,11 +1231,6 @@ 
             ifh.write(data[1])
             self.checkinlinesize(transaction, ifh)
 
-        if type(text) == str: # only accept immutable objects
-            self._cache = (node, curr, text)
-        self._basecache = (curr, chainbase)
-        return node
-
     def addgroup(self, bundle, linkmapper, transaction):
         """
         add a delta group