changeset 21689:503bb3af70fe

memfilectx: call super.__init__ instead of duplicating code This patch changes the calling signature of memfilectx's __init__ to fall in line with the other file contexts. Calling code and tests have been updated accordingly.
author Sean Farley <sean.michael.farley@gmail.com>
date Thu, 15 Aug 2013 16:49:27 -0500
parents cc677803bad4
children da352312fa18
files contrib/synthrepo.py hgext/convert/hg.py hgext/histedit.py hgext/largefiles/lfcommands.py mercurial/cmdutil.py mercurial/commands.py mercurial/context.py tests/test-context.py
diffstat 8 files changed, 28 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/synthrepo.py	Thu Aug 15 15:23:36 2013 -0500
+++ b/contrib/synthrepo.py	Thu Aug 15 16:49:27 2013 -0500
@@ -334,7 +334,7 @@
                 for __ in xrange(add):
                     lines.insert(random.randint(0, len(lines)), makeline())
                 path = fctx.path()
-                changes[path] = context.memfilectx(path,
+                changes[path] = context.memfilectx(repo, path,
                                                    '\n'.join(lines) + '\n')
             for __ in xrange(pick(filesremoved)):
                 path = random.choice(mfk)
@@ -354,7 +354,7 @@
             path = '/'.join(filter(None, path))
             data = '\n'.join(makeline()
                              for __ in xrange(pick(linesinfilesadded))) + '\n'
-            changes[path] = context.memfilectx(path, data)
+            changes[path] = context.memfilectx(repo, path, data)
         def filectxfn(repo, memctx, path):
             data = changes[path]
             if data is None:
--- a/hgext/convert/hg.py	Thu Aug 15 15:23:36 2013 -0500
+++ b/hgext/convert/hg.py	Thu Aug 15 16:49:27 2013 -0500
@@ -136,8 +136,8 @@
             data, mode = source.getfile(f, v)
             if f == '.hgtags':
                 data = self._rewritetags(source, revmap, data)
-            return context.memfilectx(f, data, 'l' in mode, 'x' in mode,
-                                      copies.get(f))
+            return context.memfilectx(self.repo, f, data, 'l' in mode,
+                                      'x' in mode, copies.get(f))
 
         pl = []
         for p in parents:
@@ -229,7 +229,7 @@
 
         data = "".join(newlines)
         def getfilectx(repo, memctx, f):
-            return context.memfilectx(f, data, False, False, None)
+            return context.memfilectx(repo, f, data, False, False, None)
 
         self.ui.status(_("updating tags\n"))
         date = "%s 0" % int(time.mktime(time.gmtime()))
--- a/hgext/histedit.py	Thu Aug 15 15:23:36 2013 -0500
+++ b/hgext/histedit.py	Thu Aug 15 16:49:27 2013 -0500
@@ -275,7 +275,8 @@
         if path in headmf:
             fctx = last[path]
             flags = fctx.flags()
-            mctx = context.memfilectx(fctx.path(), fctx.data(),
+            mctx = context.memfilectx(repo,
+                                      fctx.path(), fctx.data(),
                                       islink='l' in flags,
                                       isexec='x' in flags,
                                       copied=copied.get(path))
--- a/hgext/largefiles/lfcommands.py	Thu Aug 15 15:23:36 2013 -0500
+++ b/hgext/largefiles/lfcommands.py	Thu Aug 15 16:49:27 2013 -0500
@@ -172,10 +172,10 @@
             finally:
                 if fd:
                     fd.close()
-            return context.memfilectx(f, data, 'l' in fctx.flags(),
+            return context.memfilectx(repo, f, data, 'l' in fctx.flags(),
                                       'x' in fctx.flags(), renamed)
         else:
-            return _getnormalcontext(repo.ui, ctx, f, revmap)
+            return _getnormalcontext(repo, ctx, f, revmap)
 
     dstfiles = []
     for file in files:
@@ -255,10 +255,11 @@
                 # doesn't change after rename or copy
                 renamed = lfutil.standin(renamed[0])
 
-            return context.memfilectx(f, lfiletohash[srcfname] + '\n', 'l' in
-                fctx.flags(), 'x' in fctx.flags(), renamed)
+            return context.memfilectx(repo, f, lfiletohash[srcfname] + '\n',
+                                      'l' in fctx.flags(), 'x' in fctx.flags(),
+                                      renamed)
         else:
-            return _getnormalcontext(repo.ui, ctx, f, revmap)
+            return _getnormalcontext(repo, ctx, f, revmap)
 
     # Commit
     _commitcontext(rdst, parents, ctx, dstfiles, getfilectx, revmap)
@@ -293,7 +294,7 @@
     return parents
 
 # Get memfilectx for a normal file
-def _getnormalcontext(ui, ctx, f, revmap):
+def _getnormalcontext(repo, ctx, f, revmap):
     try:
         fctx = ctx.filectx(f)
     except error.LookupError:
@@ -304,8 +305,8 @@
 
     data = fctx.data()
     if f == '.hgtags':
-        data = _converttags (ui, revmap, data)
-    return context.memfilectx(f, data, 'l' in fctx.flags(),
+        data = _converttags (repo.ui, revmap, data)
+    return context.memfilectx(repo, f, data, 'l' in fctx.flags(),
                               'x' in fctx.flags(), renamed)
 
 # Remap tag data using a revision map
--- a/mercurial/cmdutil.py	Thu Aug 15 15:23:36 2013 -0500
+++ b/mercurial/cmdutil.py	Thu Aug 15 16:49:27 2013 -0500
@@ -2057,7 +2057,8 @@
                     try:
                         fctx = ctx[path]
                         flags = fctx.flags()
-                        mctx = context.memfilectx(fctx.path(), fctx.data(),
+                        mctx = context.memfilectx(repo,
+                                                  fctx.path(), fctx.data(),
                                                   islink='l' in flags,
                                                   isexec='x' in flags,
                                                   copied=copied.get(path))
--- a/mercurial/commands.py	Thu Aug 15 15:23:36 2013 -0500
+++ b/mercurial/commands.py	Thu Aug 15 16:49:27 2013 -0500
@@ -1681,17 +1681,17 @@
                     ml[id * linesperrev] += " r%i" % id
                     mergedtext = "\n".join(ml)
                     files.append(fn)
-                    fctxs[fn] = context.memfilectx(fn, mergedtext)
+                    fctxs[fn] = context.memfilectx(repo, fn, mergedtext)
 
                 if overwritten_file:
                     fn = "of"
                     files.append(fn)
-                    fctxs[fn] = context.memfilectx(fn, "r%i\n" % id)
+                    fctxs[fn] = context.memfilectx(repo, fn, "r%i\n" % id)
 
                 if new_file:
                     fn = "nf%i" % id
                     files.append(fn)
-                    fctxs[fn] = context.memfilectx(fn, "r%i\n" % id)
+                    fctxs[fn] = context.memfilectx(repo, fn, "r%i\n" % id)
                     if len(ps) > 1:
                         if not p2:
                             p2 = repo[ps[1]]
--- a/mercurial/context.py	Thu Aug 15 15:23:36 2013 -0500
+++ b/mercurial/context.py	Thu Aug 15 16:49:27 2013 -0500
@@ -335,8 +335,8 @@
                editor=None):
     def getfilectx(repo, memctx, path):
         data, (islink, isexec), copied = store.getfile(path)
-        return memfilectx(path, data, islink=islink, isexec=isexec,
-                                  copied=copied)
+        return memfilectx(repo, path, data, islink=islink, isexec=isexec,
+                                  copied=copied, memctx=memctx)
     extra = {}
     if branch:
         extra['branch'] = encoding.fromlocal(branch)
@@ -1589,9 +1589,10 @@
 class memfilectx(committablefilectx):
     """memfilectx represents an in-memory file to commit.
 
-    See memctx for more details.
+    See memctx and commitablefilectx for more details.
     """
-    def __init__(self, path, data, islink=False, isexec=False, copied=None):
+    def __init__(self, repo, path, data, islink=False,
+                 isexec=False, copied=None, memctx=None):
         """
         path is the normalized file path relative to repository root.
         data is the file content as a string.
@@ -1599,7 +1600,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."""
-        self._path = path
+        super(memfilectx, self).__init__(repo, path, None, memctx)
         self._data = data
         self._flags = (islink and 'l' or '') + (isexec and 'x' or '')
         self._copied = None
--- a/tests/test-context.py	Thu Aug 15 15:23:36 2013 -0500
+++ b/tests/test-context.py	Thu Aug 15 16:49:27 2013 -0500
@@ -21,7 +21,7 @@
 # test memctx with non-ASCII commit message
 
 def filectxfn(repo, memctx, path):
-    return context.memfilectx("foo", "")
+    return context.memfilectx(repo, "foo", "")
 
 ctx = context.memctx(repo, ['tip', None],
                      encoding.tolocal("Gr\xc3\xbcezi!"),