contrib/synthrepo.py
changeset 23778 a5dbec255f14
parent 23235 4cdc3e2810b9
child 24306 6ddc86eedc3b
equal deleted inserted replaced
23777:a4951adebfb0 23778:a5dbec255f14
   321     # Synthesize a single initial revision adding files to the repo according
   321     # Synthesize a single initial revision adding files to the repo according
   322     # to the modeled directory structure.
   322     # to the modeled directory structure.
   323     initcount = int(opts['initfiles'])
   323     initcount = int(opts['initfiles'])
   324     if initcount and initdirs:
   324     if initcount and initdirs:
   325         pctx = repo[None].parents()[0]
   325         pctx = repo[None].parents()[0]
       
   326         dirs = set(pctx.dirs())
   326         files = {}
   327         files = {}
       
   328 
       
   329         def validpath(path):
       
   330             # Don't pick filenames which are already directory names.
       
   331             if path in dirs:
       
   332                 return False
       
   333             # Don't pick directories which were used as file names.
       
   334             while path:
       
   335                 if path in files:
       
   336                     return False
       
   337                 path = os.path.dirname(path)
       
   338             return True
       
   339 
   327         for i in xrange(0, initcount):
   340         for i in xrange(0, initcount):
   328             ui.progress(_synthesizing, i, unit=_files, total=initcount)
   341             ui.progress(_synthesizing, i, unit=_files, total=initcount)
   329 
   342 
   330             path = pickpath()
   343             path = pickpath()
   331             while path in pctx.dirs():
   344             while not validpath(path):
   332                 path = pickpath()
   345                 path = pickpath()
   333             data = '%s contents\n' % path
   346             data = '%s contents\n' % path
   334             files[path] = context.memfilectx(repo, path, data)
   347             files[path] = context.memfilectx(repo, path, data)
       
   348             dir = os.path.dirname(path)
       
   349             while dir and dir not in dirs:
       
   350                 dirs.add(dir)
       
   351                 dir = os.path.dirname(dir)
   335 
   352 
   336         def filectxfn(repo, memctx, path):
   353         def filectxfn(repo, memctx, path):
   337             return files[path]
   354             return files[path]
   338 
   355 
   339         ui.progress(_synthesizing, None)
   356         ui.progress(_synthesizing, None)