# HG changeset patch # User Martin von Zweigbergk # Date 1512857730 28800 # Node ID 2123e7629ec03152d79855735360c59396b7f747 # Parent a7ff4071c8aa2a03636c2c8bb588e97f26e4e717 synthrepo: create filectx instance in 'filectxfn' callback I would like to pass the memctx to the memfilectx constructor, but it's not available where we currently create the memfilectx. It is available in the 'filectxfn' callback, so let's create the memfilectx there instead. A later patch will start actually passing the memctx. Differential Revision: https://phab.mercurial-scm.org/D1669 diff -r a7ff4071c8aa -r 2123e7629ec0 contrib/synthrepo.py --- a/contrib/synthrepo.py Tue Dec 12 20:28:38 2017 -0500 +++ b/contrib/synthrepo.py Sat Dec 09 14:15:30 2017 -0800 @@ -369,14 +369,14 @@ while not validpath(path): path = pickpath() data = '%s contents\n' % path - files[path] = context.memfilectx(repo, path, data) + files[path] = data dir = os.path.dirname(path) while dir and dir not in dirs: dirs.add(dir) dir = os.path.dirname(dir) def filectxfn(repo, memctx, path): - return files[path] + return context.memfilectx(repo, path, files[path]) ui.progress(_synthesizing, None) message = 'synthesized wide repo with %d files' % (len(files),) @@ -444,14 +444,12 @@ for __ in xrange(add): lines.insert(random.randint(0, len(lines)), makeline()) path = fctx.path() - changes[path] = context.memfilectx(repo, path, - '\n'.join(lines) + '\n') + changes[path] = '\n'.join(lines) + '\n' for __ in xrange(pick(filesremoved)): path = random.choice(mfk) for __ in xrange(10): path = random.choice(mfk) if path not in changes: - changes[path] = None break if filesadded: dirs = list(pctx.dirs()) @@ -466,9 +464,11 @@ pathstr = '/'.join(filter(None, path)) data = '\n'.join(makeline() for __ in xrange(pick(linesinfilesadded))) + '\n' - changes[pathstr] = context.memfilectx(repo, pathstr, data) + changes[pathstr] = data def filectxfn(repo, memctx, path): - return changes[path] + if path not in changes: + return None + return context.memfilectx(repo, path, changes[path]) if not changes: continue if revs: