Patchwork [2,of,2] synthrepo: when adding files, ensure new path is not a directory

login
register
mail settings
Submitter adgar@google.com
Date Nov. 6, 2014, 10:27 p.m.
Message ID <0cc67632e6c98aecc1ac.1415312866@adgar.nyc.corp.google.com>
Download mbox | patch
Permalink /patch/6615/
State Superseded
Headers show

Comments

adgar@google.com - Nov. 6, 2014, 10:27 p.m.
# HG changeset patch
# User Mike Edgar <adgar@google.com>
# Date 1413829243 14400
#      Mon Oct 20 14:20:43 2014 -0400
# Node ID 0cc67632e6c98aecc1acea4ab31cfd9e0c096881
# Parent  f917db22b2b3dcedfc16877254e3a8314936e3e2
synthrepo: when adding files, ensure new path is not a directory

Patch

diff -r f917db22b2b3 -r 0cc67632e6c9 contrib/synthrepo.py
--- a/contrib/synthrepo.py	Mon Oct 20 13:59:13 2014 -0400
+++ b/contrib/synthrepo.py	Mon Oct 20 14:20:43 2014 -0400
@@ -410,16 +410,18 @@ 
                         break
         if filesadded:
             dirs = list(pctx.dirs())
-            dirs.append('')
+            dirs.insert(0, '')
         for __ in xrange(pick(filesadded)):
-            path = [random.choice(dirs)]
-            if pick(dirsadded):
+            pathstr = ''
+            while pathstr in dirs:
+                path = [random.choice(dirs)]
+                if pick(dirsadded):
+                    path.append(random.choice(words))
                 path.append(random.choice(words))
-            path.append(random.choice(words))
-            path = '/'.join(filter(None, path))
+                pathstr = '/'.join(filter(None, path))
             data = '\n'.join(makeline()
                              for __ in xrange(pick(linesinfilesadded))) + '\n'
-            changes[path] = context.memfilectx(repo, path, data)
+            changes[pathstr] = context.memfilectx(repo, pathstr, data)
         def filectxfn(repo, memctx, path):
             return changes[path]
         if not changes: