contrib/synthrepo.py
changeset 43004 c07812bdd568
parent 41398 2ff8994ac71d
child 43076 2372284d9457
equal deleted inserted replaced
43003:bbf77341a956 43004:c07812bdd568
    56     context,
    56     context,
    57     diffutil,
    57     diffutil,
    58     error,
    58     error,
    59     hg,
    59     hg,
    60     patch,
    60     patch,
       
    61     pycompat,
    61     registrar,
    62     registrar,
    62     scmutil,
    63     scmutil,
    63 )
    64 )
    64 from mercurial.utils import (
    65 from mercurial.utils import (
    65     dateutil,
    66     dateutil,
   363                     return False
   364                     return False
   364                 path = os.path.dirname(path)
   365                 path = os.path.dirname(path)
   365             return True
   366             return True
   366 
   367 
   367         progress = ui.makeprogress(_synthesizing, unit=_files, total=initcount)
   368         progress = ui.makeprogress(_synthesizing, unit=_files, total=initcount)
   368         for i in xrange(0, initcount):
   369         for i in pycompat.xrange(0, initcount):
   369             progress.update(i)
   370             progress.update(i)
   370 
   371 
   371             path = pickpath()
   372             path = pickpath()
   372             while not validpath(path):
   373             while not validpath(path):
   373                 path = pickpath()
   374                 path = pickpath()
   396 
   397 
   397     # Synthesize incremental revisions to the repository, adding repo depth.
   398     # Synthesize incremental revisions to the repository, adding repo depth.
   398     count = int(opts['count'])
   399     count = int(opts['count'])
   399     heads = set(map(repo.changelog.rev, repo.heads()))
   400     heads = set(map(repo.changelog.rev, repo.heads()))
   400     progress = ui.makeprogress(_synthesizing, unit=_changesets, total=count)
   401     progress = ui.makeprogress(_synthesizing, unit=_changesets, total=count)
   401     for i in xrange(count):
   402     for i in pycompat.xrange(count):
   402         progress.update(i)
   403         progress.update(i)
   403 
   404 
   404         node = repo.changelog.node
   405         node = repo.changelog.node
   405         revs = len(repo)
   406         revs = len(repo)
   406 
   407 
   430         pctx = repo[r1]
   431         pctx = repo[r1]
   431         mf = pctx.manifest()
   432         mf = pctx.manifest()
   432         mfk = mf.keys()
   433         mfk = mf.keys()
   433         changes = {}
   434         changes = {}
   434         if mfk:
   435         if mfk:
   435             for __ in xrange(pick(fileschanged)):
   436             for __ in pycompat.xrange(pick(fileschanged)):
   436                 for __ in xrange(10):
   437                 for __ in pycompat.xrange(10):
   437                     fctx = pctx.filectx(random.choice(mfk))
   438                     fctx = pctx.filectx(random.choice(mfk))
   438                     path = fctx.path()
   439                     path = fctx.path()
   439                     if not (path in nevertouch or fctx.isbinary() or
   440                     if not (path in nevertouch or fctx.isbinary() or
   440                             'l' in fctx.flags()):
   441                             'l' in fctx.flags()):
   441                         break
   442                         break
   442                 lines = fctx.data().splitlines()
   443                 lines = fctx.data().splitlines()
   443                 add, remove = pick(lineschanged)
   444                 add, remove = pick(lineschanged)
   444                 for __ in xrange(remove):
   445                 for __ in pycompat.xrange(remove):
   445                     if not lines:
   446                     if not lines:
   446                         break
   447                         break
   447                     del lines[random.randrange(0, len(lines))]
   448                     del lines[random.randrange(0, len(lines))]
   448                 for __ in xrange(add):
   449                 for __ in pycompat.xrange(add):
   449                     lines.insert(random.randint(0, len(lines)), makeline())
   450                     lines.insert(random.randint(0, len(lines)), makeline())
   450                 path = fctx.path()
   451                 path = fctx.path()
   451                 changes[path] = '\n'.join(lines) + '\n'
   452                 changes[path] = '\n'.join(lines) + '\n'
   452             for __ in xrange(pick(filesremoved)):
   453             for __ in pycompat.xrange(pick(filesremoved)):
   453                 for __ in xrange(10):
   454                 for __ in pycompat.xrange(10):
   454                     path = random.choice(mfk)
   455                     path = random.choice(mfk)
   455                     if path not in changes:
   456                     if path not in changes:
   456                         break
   457                         break
   457         if filesadded:
   458         if filesadded:
   458             dirs = list(pctx.dirs())
   459             dirs = list(pctx.dirs())
   459             dirs.insert(0, '')
   460             dirs.insert(0, '')
   460         for __ in xrange(pick(filesadded)):
   461         for __ in pycompat.xrange(pick(filesadded)):
   461             pathstr = ''
   462             pathstr = ''
   462             while pathstr in dirs:
   463             while pathstr in dirs:
   463                 path = [random.choice(dirs)]
   464                 path = [random.choice(dirs)]
   464                 if pick(dirsadded):
   465                 if pick(dirsadded):
   465                     path.append(random.choice(words))
   466                     path.append(random.choice(words))
   466                 path.append(random.choice(words))
   467                 path.append(random.choice(words))
   467                 pathstr = '/'.join(filter(None, path))
   468                 pathstr = '/'.join(filter(None, path))
   468             data = '\n'.join(makeline()
   469             data = '\n'.join(
   469                              for __ in xrange(pick(linesinfilesadded))) + '\n'
   470                 makeline()
       
   471                 for __ in pycompat.xrange(pick(linesinfilesadded))) + '\n'
   470             changes[pathstr] = data
   472             changes[pathstr] = data
   471         def filectxfn(repo, memctx, path):
   473         def filectxfn(repo, memctx, path):
   472             if path not in changes:
   474             if path not in changes:
   473                 return None
   475                 return None
   474             return context.memfilectx(repo, memctx, path, changes[path])
   476             return context.memfilectx(repo, memctx, path, changes[path])