[llvm] r347883 - git-llvm: Fix incremental population of svn tree.

James Y Knight via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 29 08:46:34 PST 2018


Author: jyknight
Date: Thu Nov 29 08:46:34 2018
New Revision: 347883

URL: http://llvm.org/viewvc/llvm-project?rev=347883&view=rev
Log:
git-llvm: Fix incremental population of svn tree.

"svn update --depth=..." is, annoyingly, not a specification of the
desired depth, but rather a _limit_ added on top of the "sticky" depth
in the working-directory. However, if the directory doesn't exist yet,
then it sets the sticky depth of the new directory entries.

Unfortunately, the svn command-line has no way of expanding the depth
of a directory from "empty" to "files", without also removing any
already-expanded subdirectories. The way you're supposed to increase
the depth of an existing directory is via --set-depth, but
--set-depth=files will also remove any subdirs which were already
requested.

This change avoids getting into the state of ever needing to increase
the depth of an existing directory from "empty" to "files" in the
first place, by:

1. Use svn update --depth=files, not --depth=immediates.

The latter has the effect of checking out the subdirectories and
marking them as depth=empty. The former excludes sub-directories from
the list of entries, which avoids the problem.

2. Explicitly populate missing parent directories.

Using --parents seemed nice and easy, but it marks the parent dirs as
depth=empty. Instead, check out parents explicitly if they're missing.

Modified:
    llvm/trunk/utils/git-svn/git-llvm

Modified: llvm/trunk/utils/git-svn/git-llvm
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/git-svn/git-llvm?rev=347883&r1=347882&r2=347883&view=diff
==============================================================================
--- llvm/trunk/utils/git-svn/git-llvm (original)
+++ llvm/trunk/utils/git-svn/git-llvm Thu Nov 29 08:46:34 2018
@@ -265,6 +265,14 @@ def split_subrepo(f):
     else:
         return '', f
 
+def get_all_parent_dirs(name):
+    parts = []
+    head, tail = os.path.split(name)
+    while head:
+        parts.append(head)
+        head, tail = os.path.split(head)
+    return parts
+
 def svn_push_one_rev(svn_repo, rev, dry_run):
     files = git('diff-tree', '--no-commit-id', '--name-only', '-r',
                 rev).split('\n')
@@ -289,9 +297,20 @@ def svn_push_one_rev(svn_repo, rev, dry_
             svn_dirs_to_update.add(
                 os.path.dirname(os.path.join(svn_sr_path, f)))
 
+    # We also need to svn update any parent directories which are not yet present
+    parent_dirs = set()
+    for dir in svn_dirs_to_update:
+        parent_dirs.update(get_all_parent_dirs(dir))
+    parent_dirs = set(dir for dir in parent_dirs
+                      if not os.path.exists(os.path.join(svn_repo, dir)))
+    svn_dirs_to_update.update(parent_dirs)
+
+    # Sort by length to ensure that the parent directories are passed to svn
+    # before child directories.
+    sorted_dirs_to_update = sorted(svn_dirs_to_update, key=len)
+
     # SVN update only in the affected directories.
-    svn(svn_repo, 'update', '--depth=immediates', '--parents',
-        *svn_dirs_to_update)
+    svn(svn_repo, 'update', '--depth=files', *sorted_dirs_to_update)
 
     for sr, files in iteritems(subrepo_files):
         svn_sr_path = os.path.join(svn_repo, GIT_TO_SVN_DIR[sr])




More information about the llvm-commits mailing list