[PATCH 3 of 3 remove-makememctx V2] context: inline makememctx (API)

Sean Farley sean at farley.io
Fri Jun 9 17:20:26 EDT 2017


# HG changeset patch
# User Sean Farley <sean at farley.io>
# Date 1494536055 25200
#      Thu May 11 13:54:15 2017 -0700
# Branch remove-makememctx
# Node ID 05e45093fb0bff79c5107d89365666859cc93c00
# Parent  06fb38543b73062f9f6b5190e98ca000e2a34636
context: inline makememctx (API)

I have always thought it weird that we have a helper method instead of
just using __init__. So, I ripped it out.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
index 501a9f8..9f47d19 100644
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1106,15 +1106,17 @@ def tryimportone(ui, repo, hunk, parents
                     raise error.Abort(str(e))
                 if opts.get('exact'):
                     editor = None
                 else:
                     editor = getcommiteditor(editform='import.bypass')
-                memctx = context.makememctx(repo, (p1.node(), p2.node()),
+                memctx = context.memctx(repo, (p1.node(), p2.node()),
                                             message,
-                                            user,
-                                            date,
-                                            branch, files, store,
+                                            files=files,
+                                            filectxfn=store,
+                                            user=user,
+                                            date=date,
+                                            branch=branch,
                                             editor=editor)
                 n = memctx.commit()
             finally:
                 store.close()
         if opts.get('exact') and nocommit:
diff --git a/mercurial/context.py b/mercurial/context.py
index 7d37c23..7ce34af 100644
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -383,28 +383,10 @@ class basectx(object):
         for l in r:
             l.sort()
 
         return r
 
-
-def makememctx(repo, parents, text, user, date, branch, files, store,
-               editor=None, extra=None):
-    def getfilectx(repo, memctx, path):
-        data, mode, copied = store.getfile(path)
-        if data is None:
-            return None
-        islink, isexec = mode
-        return memfilectx(repo, path, data, islink=islink, isexec=isexec,
-                                  copied=copied, memctx=memctx)
-    if extra is None:
-        extra = {}
-    if branch:
-        extra['branch'] = encoding.fromlocal(branch)
-    ctx = memctx(repo, parents, text, files, getfilectx, user,
-                 date, extra, editor)
-    return ctx
-
 def _filterederror(repo, changeid):
     """build an exception to be raised about a filtered changeid
 
     This is extracted in a function to help extensions (eg: evolve) to
     experiment with various message variants."""
@@ -2108,23 +2090,27 @@ class memctx(committablectx):
     # Extensions that need to retain compatibility across Mercurial 3.1 can use
     # this field to determine what to do in filectxfn.
     _returnnoneformissingfiles = True
 
     def __init__(self, repo, parents, text, files, filectxfn, user=None,
-                 date=None, extra=None, editor=False):
+                 date=None, extra=None, branch=None, editor=False):
         super(memctx, self).__init__(repo, text, user, date, extra)
         self._rev = None
         self._node = None
         parents = [(p or nullid) for p in parents]
         p1, p2 = parents
         self._parents = [changectx(self._repo, p) for p in (p1, p2)]
         files = sorted(set(files))
         self._files = files
+        if branch is not None:
+            self._extra['branch'] = encoding.fromlocal(branch)
         self.substate = {}
 
-        # if store is not callable, wrap it in a function
-        if not callable(filectxfn):
+        if isinstance(filectxfn, patch.filestore):
+            self._filectxfn = memfilefrompatch(filectxfn)
+        elif not callable(filectxfn):
+            # if store is not callable, wrap it in a function
             self._filectxfn = memfilefromctx(filectxfn)
         else:
             # memoizing increases performance for e.g. vcs convert scenarios.
             self._filectxfn = makecachingfilectxfn(filectxfn)
 


More information about the Mercurial-devel mailing list