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

Unified Diff: deps2git/git_tools.py

Issue 11085027: Add --workspace option, so deps2git.py may be run in a (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/
Patch Set: Created 8 years, 2 months 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 | « deps2git/deps2git.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: deps2git/git_tools.py
===================================================================
--- deps2git/git_tools.py (revision 160870)
+++ deps2git/git_tools.py (working copy)
@@ -4,6 +4,7 @@
# found in the LICENSE file.
+import os
import re
import subprocess
@@ -12,12 +13,12 @@
VERBOSE = False
-def GetStatusOutput(cmd):
+def GetStatusOutput(cmd, cwd=None):
"""Return (status, output) of executing cmd in a shell."""
if VERBOSE:
print ''
print '[DEBUG] Running "%s"' % cmd
- proc = subprocess.Popen(cmd, shell=True, universal_newlines=True,
+ proc = subprocess.Popen(cmd, shell=True, universal_newlines=True, cwd=cwd,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = ''.join(proc.stdout.readlines())
status = proc.wait()
@@ -32,24 +33,32 @@
return (status, output)
-def Git(git_repo, command):
+def Git(git_repo, command, is_mirror=False):
"""Execute a git command within a local git repo."""
- cmd = 'git --git-dir=%s %s' % (git_repo, command)
- (status, output) = GetStatusOutput(cmd)
+ if is_mirror:
+ cmd = 'git --git-dir=%s %s' % (git_repo, command)
+ cwd = None
+ else:
+ cmd = 'git %s' % command
+ cwd = git_repo
+ (status, output) = GetStatusOutput(cmd, cwd)
if status != 0:
raise Exception('Failed to run %s. error %d. output %s' % (cmd, status,
output))
return (status, output)
-def Clone(git_url, git_repo):
+def Clone(git_url, git_repo, is_mirror):
"""Clone a repository."""
- Git(git_repo, 'clone --mirror %s %s' % (git_url, git_repo))
+ cmd = 'clone%s %s %s' % (' --mirror' if is_mirror else '', git_url, git_repo)
+ if not is_mirror and not os.path.exists(git_repo):
+ os.mkdir(git_repo)
+ return Git(git_repo, cmd, is_mirror)
-def Fetch(git_repo):
+def Fetch(git_repo, is_mirror):
"""Fetch the latest objects for a given git repository."""
- Git(git_repo, 'fetch')
+ Git(git_repo, 'fetch', is_mirror)
def Ping(git_repo):
@@ -123,11 +132,12 @@
return regex
-def Search(git_repo, svn_rev):
+def Search(git_repo, svn_rev, is_mirror):
"""Return the Git commit id matching the given SVN revision."""
regex = CreateLessThanOrEqualRegex(svn_rev)
(status, output) = Git(git_repo, ('log -E --grep=".*git-svn-id:.*@%s " '
- '-1 --format=%%H FETCH_HEAD') % regex)
+ '-1 --format=%%H FETCH_HEAD') % regex,
+ is_mirror)
if output != '':
output = output.splitlines()[0]
« no previous file with comments | « deps2git/deps2git.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698