Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Unified Diff: gclient-new-workdir.py

Issue 52663008: Add a new gclient-new-workdir script which clones an existing gclient working directory much like g… (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Fix according to comments Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gclient-new-workdir.py
diff --git a/gclient-new-workdir.py b/gclient-new-workdir.py
new file mode 100755
index 0000000000000000000000000000000000000000..2e2435de20aa69c0e79dab0f640bf1f6f71d66e0
--- /dev/null
+++ b/gclient-new-workdir.py
@@ -0,0 +1,88 @@
+#!/usr/bin/env python
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# Usage:
+# gclient-new-workdir.py <repository> <new_workdir> [<branch>]
+#
+
+import os
+import shutil
+import subprocess
+import sys
+
+def parse_options(argv):
iannucci 2013/11/04 22:30:43 style nit: 2 lines between top-level statements
+ if len(argv) != 3:
+ usage()
+ return False, "", ""
iannucci 2013/11/04 22:30:43 I think sys.exit(1) is clearer, instead of passing
+
+ success = True
+ repository = argv[1]
+ new_workdir = argv[2]
+
+ if not os.path.exists(repository):
+ print("Repository does not exist: " + repository)
+ success = False
+
+ if os.path.exists(new_workdir):
+ print("New workdir already exists: " + new_workdir)
+ success = False
+
+ return success, repository, new_workdir
+
+def main(argv):
+ assert not sys.platform.startswith("win")
iannucci 2013/11/04 22:30:43 nit: I would move this into parse_options, but up
+
+ success, repository, new_workdir = parse_options(argv)
+ if not success:
+ return 1
+
+ gclient = os.path.join(repository, ".gclient")
+ if not os.path.exists(gclient):
+ print("No .gclient file: " + gclient)
+
+ gclient_entries = os.path.join(repository, ".gclient_entries")
+ if not os.path.exists(gclient_entries):
+ print("No .gclient_entries file: " + gclient_entries)
+
+ os.mkdir(new_workdir)
+ os.symlink(gclient, os.path.join(new_workdir, ".gclient"))
+ os.symlink(gclient_entries, os.path.join(new_workdir, ".gclient_entries"))
+
+ for root, dirs, files in os.walk(repository):
+ for name in dirs:
+ if name == ".git":
iannucci 2013/11/04 22:30:43 Why not just: if '.git' in dirs: # do stuff wit
+ workdir = root.replace(repository, new_workdir, 1)
+ make_workdir(os.path.join(root, name), os.path.join(workdir, name))
iannucci 2013/11/04 22:30:43 What happens if something breaks half-way through?
atreat 2013/11/04 22:51:35 We aren't touching the original workdir. The only
+
+ return 0
+
+def make_workdir(repository, new_workdir):
+ print("Creating: " + new_workdir)
+ os.makedirs(new_workdir)
+ make_symlink(repository, new_workdir, "config")
+ make_symlink(repository, new_workdir, "refs")
+ if os.path.exists(repository + os.sep + "logs"):
+ os.makedirs(new_workdir + os.sep + "logs")
iannucci 2013/11/04 22:30:43 os.path.join
+ make_symlink(repository, new_workdir, "logs" + os.sep + "refs")
+ make_symlink(repository, new_workdir, "objects")
+ make_symlink(repository, new_workdir, "info")
+ make_symlink(repository, new_workdir, "hooks")
+ make_symlink(repository, new_workdir, "packed-refs")
+ make_symlink(repository, new_workdir, "remotes")
+ make_symlink(repository, new_workdir, "rr-cache")
+ make_symlink(repository, new_workdir, "svn")
iannucci 2013/11/04 22:30:43 I wonder if a blacklist would be more correct than
atreat 2013/11/04 22:51:35 The whitelist was explicitly taken from git-new-wo
atreat 2013/11/04 22:51:35 Hmm, I am not sure that a list would make it any m
iannucci 2013/11/04 22:54:51 I'm thinking like: GIT_DIRECTORY_WHITELIST = ['co
+ shutil.copy2(repository + os.sep + "HEAD", new_workdir + os.sep + "HEAD")
iannucci 2013/11/04 22:30:43 os.path.join
+ subprocess.check_call(["git", "checkout", "-f"], cwd=new_workdir.rstrip(".git"))
+
+def make_symlink(repository, new_workdir, link):
+ if not os.path.exists(os.path.join(repository, link)):
+ return
+ os.symlink(os.path.join(repository, link), os.path.join(new_workdir, link))
+
+def usage():
+ print("usage: gclient-new-workdir.py <repository> <new_workdir>")
iannucci 2013/11/04 22:30:43 Maybe since this is used in exactly 1 place, just
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698