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

login
register
mail settings
Submitter Sean Farley
Date Aug. 6, 2014, 8:42 p.m.
Message ID <afeff43a1849fae47073.1407357730@178.1.168.192.in-addr.arpa>
Download mbox | patch
Permalink /patch/5299/
State Superseded
Commit 443ef664fb557b850e8ad21d647c992dd8f6f855
Headers show

Comments

Sean Farley - Aug. 6, 2014, 8:42 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 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.

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: