Patchwork [3,of,5,V2] memctx: create a filectxfn if it is not callable

login
register
mail settings
Submitter Sean Farley
Date Aug. 6, 2014, 11:20 p.m.
Message ID <e0a761486fd816bb7baa.1407367224@laptop.local>
Download mbox | patch
Permalink /patch/5304/
State Superseded
Commit 443ef664fb557b850e8ad21d647c992dd8f6f855
Headers show

Comments

Sean Farley - Aug. 6, 2014, 11:20 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 e0a761486fd816bb7baab8645f6c44c64e0489ef
# Parent  28eed68e6f02e5a7ac85e8bab0fbcaf59f8a2408
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
@@ -1596,10 +1596,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: