Mercurial > public > mercurial-scm > hg
comparison contrib/synthrepo.py @ 35398:2123e7629ec0
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
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Sat, 09 Dec 2017 14:15:30 -0800 |
parents | ba479850c9c7 |
children | 8a0cac20a1ad |
comparison
equal
deleted
inserted
replaced
35397:a7ff4071c8aa | 35398:2123e7629ec0 |
---|---|
367 | 367 |
368 path = pickpath() | 368 path = pickpath() |
369 while not validpath(path): | 369 while not validpath(path): |
370 path = pickpath() | 370 path = pickpath() |
371 data = '%s contents\n' % path | 371 data = '%s contents\n' % path |
372 files[path] = context.memfilectx(repo, path, data) | 372 files[path] = data |
373 dir = os.path.dirname(path) | 373 dir = os.path.dirname(path) |
374 while dir and dir not in dirs: | 374 while dir and dir not in dirs: |
375 dirs.add(dir) | 375 dirs.add(dir) |
376 dir = os.path.dirname(dir) | 376 dir = os.path.dirname(dir) |
377 | 377 |
378 def filectxfn(repo, memctx, path): | 378 def filectxfn(repo, memctx, path): |
379 return files[path] | 379 return context.memfilectx(repo, path, files[path]) |
380 | 380 |
381 ui.progress(_synthesizing, None) | 381 ui.progress(_synthesizing, None) |
382 message = 'synthesized wide repo with %d files' % (len(files),) | 382 message = 'synthesized wide repo with %d files' % (len(files),) |
383 mc = context.memctx(repo, [pctx.node(), nullid], message, | 383 mc = context.memctx(repo, [pctx.node(), nullid], message, |
384 files.iterkeys(), filectxfn, ui.username(), | 384 files.iterkeys(), filectxfn, ui.username(), |
442 break | 442 break |
443 del lines[random.randrange(0, len(lines))] | 443 del lines[random.randrange(0, len(lines))] |
444 for __ in xrange(add): | 444 for __ in xrange(add): |
445 lines.insert(random.randint(0, len(lines)), makeline()) | 445 lines.insert(random.randint(0, len(lines)), makeline()) |
446 path = fctx.path() | 446 path = fctx.path() |
447 changes[path] = context.memfilectx(repo, path, | 447 changes[path] = '\n'.join(lines) + '\n' |
448 '\n'.join(lines) + '\n') | |
449 for __ in xrange(pick(filesremoved)): | 448 for __ in xrange(pick(filesremoved)): |
450 path = random.choice(mfk) | 449 path = random.choice(mfk) |
451 for __ in xrange(10): | 450 for __ in xrange(10): |
452 path = random.choice(mfk) | 451 path = random.choice(mfk) |
453 if path not in changes: | 452 if path not in changes: |
454 changes[path] = None | |
455 break | 453 break |
456 if filesadded: | 454 if filesadded: |
457 dirs = list(pctx.dirs()) | 455 dirs = list(pctx.dirs()) |
458 dirs.insert(0, '') | 456 dirs.insert(0, '') |
459 for __ in xrange(pick(filesadded)): | 457 for __ in xrange(pick(filesadded)): |
464 path.append(random.choice(words)) | 462 path.append(random.choice(words)) |
465 path.append(random.choice(words)) | 463 path.append(random.choice(words)) |
466 pathstr = '/'.join(filter(None, path)) | 464 pathstr = '/'.join(filter(None, path)) |
467 data = '\n'.join(makeline() | 465 data = '\n'.join(makeline() |
468 for __ in xrange(pick(linesinfilesadded))) + '\n' | 466 for __ in xrange(pick(linesinfilesadded))) + '\n' |
469 changes[pathstr] = context.memfilectx(repo, pathstr, data) | 467 changes[pathstr] = data |
470 def filectxfn(repo, memctx, path): | 468 def filectxfn(repo, memctx, path): |
471 return changes[path] | 469 if path not in changes: |
470 return None | |
471 return context.memfilectx(repo, path, changes[path]) | |
472 if not changes: | 472 if not changes: |
473 continue | 473 continue |
474 if revs: | 474 if revs: |
475 date = repo['tip'].date()[0] + pick(interarrival) | 475 date = repo['tip'].date()[0] + pick(interarrival) |
476 else: | 476 else: |