##// END OF EJS Templates
memfilectx: call super.__init__ instead of duplicating code...
Sean Farley -
r21689:503bb3af default
parent child Browse files
Show More
@@ -334,7 +334,7 b' def synthesize(ui, repo, descpath, **opt'
334 334 for __ in xrange(add):
335 335 lines.insert(random.randint(0, len(lines)), makeline())
336 336 path = fctx.path()
337 changes[path] = context.memfilectx(path,
337 changes[path] = context.memfilectx(repo, path,
338 338 '\n'.join(lines) + '\n')
339 339 for __ in xrange(pick(filesremoved)):
340 340 path = random.choice(mfk)
@@ -354,7 +354,7 b' def synthesize(ui, repo, descpath, **opt'
354 354 path = '/'.join(filter(None, path))
355 355 data = '\n'.join(makeline()
356 356 for __ in xrange(pick(linesinfilesadded))) + '\n'
357 changes[path] = context.memfilectx(path, data)
357 changes[path] = context.memfilectx(repo, path, data)
358 358 def filectxfn(repo, memctx, path):
359 359 data = changes[path]
360 360 if data is None:
@@ -136,8 +136,8 b' class mercurial_sink(converter_sink):'
136 136 data, mode = source.getfile(f, v)
137 137 if f == '.hgtags':
138 138 data = self._rewritetags(source, revmap, data)
139 return context.memfilectx(f, data, 'l' in mode, 'x' in mode,
140 copies.get(f))
139 return context.memfilectx(self.repo, f, data, 'l' in mode,
140 'x' in mode, copies.get(f))
141 141
142 142 pl = []
143 143 for p in parents:
@@ -229,7 +229,7 b' class mercurial_sink(converter_sink):'
229 229
230 230 data = "".join(newlines)
231 231 def getfilectx(repo, memctx, f):
232 return context.memfilectx(f, data, False, False, None)
232 return context.memfilectx(repo, f, data, False, False, None)
233 233
234 234 self.ui.status(_("updating tags\n"))
235 235 date = "%s 0" % int(time.mktime(time.gmtime()))
@@ -275,7 +275,8 b' def collapse(repo, first, last, commitop'
275 275 if path in headmf:
276 276 fctx = last[path]
277 277 flags = fctx.flags()
278 mctx = context.memfilectx(fctx.path(), fctx.data(),
278 mctx = context.memfilectx(repo,
279 fctx.path(), fctx.data(),
279 280 islink='l' in flags,
280 281 isexec='x' in flags,
281 282 copied=copied.get(path))
@@ -172,10 +172,10 b' def _addchangeset(ui, rsrc, rdst, ctx, r'
172 172 finally:
173 173 if fd:
174 174 fd.close()
175 return context.memfilectx(f, data, 'l' in fctx.flags(),
175 return context.memfilectx(repo, f, data, 'l' in fctx.flags(),
176 176 'x' in fctx.flags(), renamed)
177 177 else:
178 return _getnormalcontext(repo.ui, ctx, f, revmap)
178 return _getnormalcontext(repo, ctx, f, revmap)
179 179
180 180 dstfiles = []
181 181 for file in files:
@@ -255,10 +255,11 b' def _lfconvert_addchangeset(rsrc, rdst, '
255 255 # doesn't change after rename or copy
256 256 renamed = lfutil.standin(renamed[0])
257 257
258 return context.memfilectx(f, lfiletohash[srcfname] + '\n', 'l' in
259 fctx.flags(), 'x' in fctx.flags(), renamed)
258 return context.memfilectx(repo, f, lfiletohash[srcfname] + '\n',
259 'l' in fctx.flags(), 'x' in fctx.flags(),
260 renamed)
260 261 else:
261 return _getnormalcontext(repo.ui, ctx, f, revmap)
262 return _getnormalcontext(repo, ctx, f, revmap)
262 263
263 264 # Commit
264 265 _commitcontext(rdst, parents, ctx, dstfiles, getfilectx, revmap)
@@ -293,7 +294,7 b' def _convertparents(ctx, revmap):'
293 294 return parents
294 295
295 296 # Get memfilectx for a normal file
296 def _getnormalcontext(ui, ctx, f, revmap):
297 def _getnormalcontext(repo, ctx, f, revmap):
297 298 try:
298 299 fctx = ctx.filectx(f)
299 300 except error.LookupError:
@@ -304,8 +305,8 b' def _getnormalcontext(ui, ctx, f, revmap'
304 305
305 306 data = fctx.data()
306 307 if f == '.hgtags':
307 data = _converttags (ui, revmap, data)
308 return context.memfilectx(f, data, 'l' in fctx.flags(),
308 data = _converttags (repo.ui, revmap, data)
309 return context.memfilectx(repo, f, data, 'l' in fctx.flags(),
309 310 'x' in fctx.flags(), renamed)
310 311
311 312 # Remap tag data using a revision map
@@ -2057,7 +2057,8 b' def amend(ui, repo, commitfunc, old, ext'
2057 2057 try:
2058 2058 fctx = ctx[path]
2059 2059 flags = fctx.flags()
2060 mctx = context.memfilectx(fctx.path(), fctx.data(),
2060 mctx = context.memfilectx(repo,
2061 fctx.path(), fctx.data(),
2061 2062 islink='l' in flags,
2062 2063 isexec='x' in flags,
2063 2064 copied=copied.get(path))
@@ -1681,17 +1681,17 b' def debugbuilddag(ui, repo, text=None,'
1681 1681 ml[id * linesperrev] += " r%i" % id
1682 1682 mergedtext = "\n".join(ml)
1683 1683 files.append(fn)
1684 fctxs[fn] = context.memfilectx(fn, mergedtext)
1684 fctxs[fn] = context.memfilectx(repo, fn, mergedtext)
1685 1685
1686 1686 if overwritten_file:
1687 1687 fn = "of"
1688 1688 files.append(fn)
1689 fctxs[fn] = context.memfilectx(fn, "r%i\n" % id)
1689 fctxs[fn] = context.memfilectx(repo, fn, "r%i\n" % id)
1690 1690
1691 1691 if new_file:
1692 1692 fn = "nf%i" % id
1693 1693 files.append(fn)
1694 fctxs[fn] = context.memfilectx(fn, "r%i\n" % id)
1694 fctxs[fn] = context.memfilectx(repo, fn, "r%i\n" % id)
1695 1695 if len(ps) > 1:
1696 1696 if not p2:
1697 1697 p2 = repo[ps[1]]
@@ -335,8 +335,8 b' def makememctx(repo, parents, text, user'
335 335 editor=None):
336 336 def getfilectx(repo, memctx, path):
337 337 data, (islink, isexec), copied = store.getfile(path)
338 return memfilectx(path, data, islink=islink, isexec=isexec,
339 copied=copied)
338 return memfilectx(repo, path, data, islink=islink, isexec=isexec,
339 copied=copied, memctx=memctx)
340 340 extra = {}
341 341 if branch:
342 342 extra['branch'] = encoding.fromlocal(branch)
@@ -1589,9 +1589,10 b' class memctx(committablectx):'
1589 1589 class memfilectx(committablefilectx):
1590 1590 """memfilectx represents an in-memory file to commit.
1591 1591
1592 See memctx for more details.
1592 See memctx and commitablefilectx for more details.
1593 1593 """
1594 def __init__(self, path, data, islink=False, isexec=False, copied=None):
1594 def __init__(self, repo, path, data, islink=False,
1595 isexec=False, copied=None, memctx=None):
1595 1596 """
1596 1597 path is the normalized file path relative to repository root.
1597 1598 data is the file content as a string.
@@ -1599,7 +1600,7 b' class memfilectx(committablefilectx):'
1599 1600 isexec is True if the file is executable.
1600 1601 copied is the source file path if current file was copied in the
1601 1602 revision being committed, or None."""
1602 self._path = path
1603 super(memfilectx, self).__init__(repo, path, None, memctx)
1603 1604 self._data = data
1604 1605 self._flags = (islink and 'l' or '') + (isexec and 'x' or '')
1605 1606 self._copied = None
@@ -21,7 +21,7 b' print "workingfilectx.date =", repo[None'
21 21 # test memctx with non-ASCII commit message
22 22
23 23 def filectxfn(repo, memctx, path):
24 return context.memfilectx("foo", "")
24 return context.memfilectx(repo, "foo", "")
25 25
26 26 ctx = context.memctx(repo, ['tip', None],
27 27 encoding.tolocal("Gr\xc3\xbcezi!"),
General Comments 0
You need to be logged in to leave comments. Login now