changeset 35400:8a0cac20a1ad

memfilectx: make changectx argument mandatory in constructor (API) committablefilectx has three subclasses: workingfilectx, memfilectx, and overlayfilectx. committablefilectx takes an optional (change) ctx instance to its constructor. If it's provided, it's set on the instance as self._changectx. If not, that property is supposed to be defined by the class. However, only workingfilectx does that. The other two will have the property undefined if it's not passed in the constructor. That seems bad to me. This patch makes the changectx argument to the memfilectx constructor mandatory because that fixes the failure I ran into. It seems like we should also fix the overlayfilectx case. Differential Revision: https://phab.mercurial-scm.org/D1658
author Martin von Zweigbergk <martinvonz@google.com>
date Mon, 11 Dec 2017 09:27:40 -0800
parents dffc35a5be9f
children cd3392cb5818
files contrib/synthrepo.py hgext/convert/hg.py hgext/histedit.py hgext/largefiles/lfcommands.py hgext/uncommit.py mercurial/cmdutil.py mercurial/context.py mercurial/debugcommands.py tests/test-commit.t tests/test-context.py
diffstat 10 files changed, 29 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/synthrepo.py	Sat Dec 09 14:22:12 2017 -0800
+++ b/contrib/synthrepo.py	Mon Dec 11 09:27:40 2017 -0800
@@ -376,7 +376,7 @@
                 dir = os.path.dirname(dir)
 
         def filectxfn(repo, memctx, path):
-            return context.memfilectx(repo, path, files[path])
+            return context.memfilectx(repo, memctx, path, files[path])
 
         ui.progress(_synthesizing, None)
         message = 'synthesized wide repo with %d files' % (len(files),)
@@ -468,7 +468,7 @@
         def filectxfn(repo, memctx, path):
             if path not in changes:
                 return None
-            return context.memfilectx(repo, path, changes[path])
+            return context.memfilectx(repo, memctx, path, changes[path])
         if not changes:
             continue
         if revs:
--- a/hgext/convert/hg.py	Sat Dec 09 14:22:12 2017 -0800
+++ b/hgext/convert/hg.py	Mon Dec 11 09:27:40 2017 -0800
@@ -253,7 +253,7 @@
                 data = self._rewritetags(source, revmap, data)
             if f == '.hgsubstate':
                 data = self._rewritesubstate(source, data)
-            return context.memfilectx(self.repo, f, data, 'l' in mode,
+            return context.memfilectx(self.repo, memctx, f, data, 'l' in mode,
                                       'x' in mode, copies.get(f))
 
         pl = []
@@ -401,7 +401,7 @@
 
         data = "".join(newlines)
         def getfilectx(repo, memctx, f):
-            return context.memfilectx(repo, f, data, False, False, None)
+            return context.memfilectx(repo, memctx, f, data, False, False, None)
 
         self.ui.status(_("updating tags\n"))
         date = "%s 0" % int(time.mktime(time.gmtime()))
--- a/hgext/histedit.py	Sat Dec 09 14:22:12 2017 -0800
+++ b/hgext/histedit.py	Mon Dec 11 09:27:40 2017 -0800
@@ -602,7 +602,7 @@
         if path in headmf:
             fctx = last[path]
             flags = fctx.flags()
-            mctx = context.memfilectx(repo,
+            mctx = context.memfilectx(repo, ctx,
                                       fctx.path(), fctx.data(),
                                       islink='l' in flags,
                                       isexec='x' in flags,
--- a/hgext/largefiles/lfcommands.py	Sat Dec 09 14:22:12 2017 -0800
+++ b/hgext/largefiles/lfcommands.py	Mon Dec 11 09:27:40 2017 -0800
@@ -261,7 +261,8 @@
                 # doesn't change after rename or copy
                 renamed = lfutil.standin(renamed[0])
 
-            return context.memfilectx(repo, f, lfiletohash[srcfname] + '\n',
+            return context.memfilectx(repo, memctx, f,
+                                      lfiletohash[srcfname] + '\n',
                                       'l' in fctx.flags(), 'x' in fctx.flags(),
                                       renamed)
         else:
@@ -313,7 +314,7 @@
     data = fctx.data()
     if f == '.hgtags':
         data = _converttags (repo.ui, revmap, data)
-    return context.memfilectx(repo, f, data, 'l' in fctx.flags(),
+    return context.memfilectx(repo, ctx, f, data, 'l' in fctx.flags(),
                               'x' in fctx.flags(), renamed)
 
 # Remap tag data using a revision map
--- a/hgext/uncommit.py	Sat Dec 09 14:22:12 2017 -0800
+++ b/hgext/uncommit.py	Mon Dec 11 09:27:40 2017 -0800
@@ -77,7 +77,7 @@
         if path not in contentctx:
             return None
         fctx = contentctx[path]
-        mctx = context.memfilectx(repo, fctx.path(), fctx.data(),
+        mctx = context.memfilectx(repo, memctx, fctx.path(), fctx.data(),
                                   fctx.islink(),
                                   fctx.isexec(),
                                   copied=copied.get(path))
--- a/mercurial/cmdutil.py	Sat Dec 09 14:22:12 2017 -0800
+++ b/mercurial/cmdutil.py	Mon Dec 11 09:27:40 2017 -0800
@@ -3195,7 +3195,7 @@
 
                     fctx = wctx[path]
                     flags = fctx.flags()
-                    mctx = context.memfilectx(repo,
+                    mctx = context.memfilectx(repo, ctx_,
                                               fctx.path(), fctx.data(),
                                               islink='l' in flags,
                                               isexec='x' in flags,
--- a/mercurial/context.py	Sat Dec 09 14:22:12 2017 -0800
+++ b/mercurial/context.py	Mon Dec 11 09:27:40 2017 -0800
@@ -2204,12 +2204,11 @@
         files = self._cache.keys()
         def getfile(repo, memctx, path):
             if self._cache[path]['exists']:
-                return memfilectx(repo, path,
+                return memfilectx(repo, memctx, path,
                                   self._cache[path]['data'],
                                   'l' in self._cache[path]['flags'],
                                   'x' in self._cache[path]['flags'],
-                                  self._cache[path]['copied'],
-                                  memctx)
+                                  self._cache[path]['copied'])
             else:
                 # Returning None, but including the path in `files`, is
                 # necessary for memctx to register a deletion.
@@ -2389,9 +2388,9 @@
         copied = fctx.renamed()
         if copied:
             copied = copied[0]
-        return memfilectx(repo, path, fctx.data(),
+        return memfilectx(repo, memctx, path, fctx.data(),
                           islink=fctx.islink(), isexec=fctx.isexec(),
-                          copied=copied, memctx=memctx)
+                          copied=copied)
 
     return getfilectx
 
@@ -2405,9 +2404,8 @@
         if data is None:
             return None
         islink, isexec = mode
-        return memfilectx(repo, path, data, islink=islink,
-                          isexec=isexec, copied=copied,
-                          memctx=memctx)
+        return memfilectx(repo, memctx, path, data, islink=islink,
+                          isexec=isexec, copied=copied)
 
     return getfilectx
 
@@ -2539,8 +2537,8 @@
 
     See memctx and committablefilectx for more details.
     """
-    def __init__(self, repo, path, data, islink=False,
-                 isexec=False, copied=None, memctx=None):
+    def __init__(self, repo, changectx, path, data, islink=False,
+                 isexec=False, copied=None):
         """
         path is the normalized file path relative to repository root.
         data is the file content as a string.
@@ -2548,7 +2546,7 @@
         isexec is True if the file is executable.
         copied is the source file path if current file was copied in the
         revision being committed, or None."""
-        super(memfilectx, self).__init__(repo, path, None, memctx)
+        super(memfilectx, self).__init__(repo, path, None, changectx)
         self._data = data
         self._flags = (islink and 'l' or '') + (isexec and 'x' or '')
         self._copied = None
--- a/mercurial/debugcommands.py	Sat Dec 09 14:22:12 2017 -0800
+++ b/mercurial/debugcommands.py	Mon Dec 11 09:27:40 2017 -0800
@@ -225,7 +225,8 @@
 
                 def fctxfn(repo, cx, path):
                     if path in filecontent:
-                        return context.memfilectx(repo, path, filecontent[path])
+                        return context.memfilectx(repo, cx, path,
+                                                  filecontent[path])
                     return None
 
                 if len(ps) == 0 or ps[0] < 0:
--- a/tests/test-commit.t	Sat Dec 09 14:22:12 2017 -0800
+++ b/tests/test-commit.t	Mon Dec 11 09:27:40 2017 -0800
@@ -648,7 +648,8 @@
   > u = uimod.ui.load()
   > r = hg.repository(u, '.')
   > def filectxfn(repo, memctx, path):
-  >     return context.memfilectx(repo, path, '[hooks]\nupdate = echo owned')
+  >     return context.memfilectx(repo, memctx, path,
+  >         '[hooks]\nupdate = echo owned')
   > c = context.memctx(r, [r['tip'].node(), node.nullid],
   >                    'evil', [notrc], filectxfn, 0)
   > r.commitctx(c)
@@ -673,7 +674,8 @@
   > u = uimod.ui.load()
   > r = hg.repository(u, '.')
   > def filectxfn(repo, memctx, path):
-  >     return context.memfilectx(repo, path, '[hooks]\nupdate = echo owned')
+  >     return context.memfilectx(repo, memctx, path,
+  >         '[hooks]\nupdate = echo owned')
   > c = context.memctx(r, [r['tip'].node(), node.nullid],
   >                    'evil', [notrc], filectxfn, 0)
   > r.commitctx(c)
@@ -692,7 +694,8 @@
   > u = uimod.ui.load()
   > r = hg.repository(u, '.')
   > def filectxfn(repo, memctx, path):
-  >     return context.memfilectx(repo, path, '[hooks]\nupdate = echo owned')
+  >     return context.memfilectx(repo, memctx, path,
+  >         '[hooks]\nupdate = echo owned')
   > c = context.memctx(r, [r['tip'].node(), node.nullid],
   >                    'evil', [notrc], filectxfn, 0)
   > r.commitctx(c)
--- a/tests/test-context.py	Sat Dec 09 14:22:12 2017 -0800
+++ b/tests/test-context.py	Mon Dec 11 09:27:40 2017 -0800
@@ -32,7 +32,7 @@
 # test memctx with non-ASCII commit message
 
 def filectxfn(repo, memctx, path):
-    return context.memfilectx(repo, "foo", "")
+    return context.memfilectx(repo, memctx, "foo", "")
 
 ctx = context.memctx(repo, ['tip', None],
                      encoding.tolocal("Gr\xc3\xbcezi!"),
@@ -49,7 +49,7 @@
     data, flags = fctx.data(), fctx.flags()
     if f == 'foo':
         data += 'bar\n'
-    return context.memfilectx(repo, f, data, 'l' in flags, 'x' in flags)
+    return context.memfilectx(repo, memctx, f, data, 'l' in flags, 'x' in flags)
 
 ctxa = repo.changectx(0)
 ctxb = context.memctx(repo, [ctxa.node(), None], "test diff", ["foo"],