[PATCH 4 of 6] memctx: create a filectxfn if it is not callable

Sean Farley sean.michael.farley at gmail.com
Wed Aug 6 15:42:10 CDT 2014


# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1406334961 18000
#      Fri Jul 25 19:36:01 2014 -0500
# Node ID afeff43a1849fae470730880a7c949d28fc25750
# Parent  ccdd920b71df87e4cdc9c14dfe3698f18bd91bc0
memctx: create a filectxfn if it is not callable

This will allow future patches to construct a memctx based on another context
or any other store-type object.

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1594,10 +1594,24 @@ class memctx(committablectx):
         files = sorted(set(files))
         self._status = [files, [], [], [], []]
         self._filectxfn = filectxfn
         self.substate = {}
 
+        # if store is not callable, wrap it in a function
+        if not callable(filectxfn):
+            def getfilectx(repo, memctx, path):
+                fctx = filectxfn[path]
+                # this is weird but apparently we only keep track of one parent
+                # (why not only store that instead of a tuple?)
+                copied = fctx.renamed()
+                if copied:
+                    copied = copied[0]
+                return memfilectx(repo, path, fctx.data(),
+                                  islink=fctx.islink(), isexec=fctx.isexec(),
+                                  copied=copied, memctx=memctx)
+            self._filectxfn = getfilectx
+
         self._extra = extra and extra.copy() or {}
         if self._extra.get('branch', '') == '':
             self._extra['branch'] = 'default'
 
         if editor:


More information about the Mercurial-devel mailing list