Patchwork [1,of,8,RFC] memctx: create a filectxfn if it is not callable

login
register
mail settings
Submitter Sean Farley
Date Aug. 7, 2014, 7:52 p.m.
Message ID <c19945ae6a620e9965bc.1407441128@laptop.att.net>
Download mbox | patch
Permalink /patch/5317/
State Accepted
Headers show

Comments

Sean Farley - Aug. 7, 2014, 7:52 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1406334961 18000
#      Fri Jul 25 19:36:01 2014 -0500
# Node ID c19945ae6a620e9965bc6f3b32562ef93f7d14d8
# Parent  ba5fc3f81f1588507a5a84ac2b43679705ceec7b
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.

Patch

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: