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

Side by Side Diff: scm.py

Issue 133073015: Re-reland r245404 ("If the destination directory doesn't contain the desired repo, delete it") (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Clean up check_output call, print hostname on bots Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gclient_scm.py ('k') | tests/gclient_scm_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """SCM-specific utility classes.""" 5 """SCM-specific utility classes."""
6 6
7 import cStringIO 7 import cStringIO
8 import glob 8 import glob
9 import logging 9 import logging
10 import os 10 import os
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 def GetBranchRef(cwd): 159 def GetBranchRef(cwd):
160 """Returns the full branch reference, e.g. 'refs/heads/master'.""" 160 """Returns the full branch reference, e.g. 'refs/heads/master'."""
161 return GIT.Capture(['symbolic-ref', 'HEAD'], cwd=cwd) 161 return GIT.Capture(['symbolic-ref', 'HEAD'], cwd=cwd)
162 162
163 @staticmethod 163 @staticmethod
164 def GetBranch(cwd): 164 def GetBranch(cwd):
165 """Returns the short branch name, e.g. 'master'.""" 165 """Returns the short branch name, e.g. 'master'."""
166 return GIT.ShortBranchName(GIT.GetBranchRef(cwd)) 166 return GIT.ShortBranchName(GIT.GetBranchRef(cwd))
167 167
168 @staticmethod 168 @staticmethod
169 def IsGitSvn(cwd): 169 def IsGitSvn(checkout_root):
170 """Returns true if this repo looks like it's using git-svn.""" 170 """Returns true if this repo looks like it's using git-svn."""
171 # A git-svn checkout has a .git directory.
172 if not os.path.isdir(os.path.join(checkout_root, '.git')):
173 return False
171 # If you have any "svn-remote.*" config keys, we think you're using svn. 174 # If you have any "svn-remote.*" config keys, we think you're using svn.
172 try: 175 try:
173 GIT.Capture(['config', '--local', '--get-regexp', r'^svn-remote\.'], 176 GIT.Capture(['config', '--local', '--get-regexp', r'^svn-remote\.'],
174 cwd=cwd) 177 cwd=checkout_root)
175 return True 178 return True
176 except subprocess2.CalledProcessError: 179 except subprocess2.CalledProcessError:
177 return False 180 return False
178 181
179 @staticmethod 182 @staticmethod
180 def MatchSvnGlob(url, base_url, glob_spec, allow_wildcards): 183 def MatchSvnGlob(url, base_url, glob_spec, allow_wildcards):
181 """Return the corresponding git ref if |base_url| together with |glob_spec| 184 """Return the corresponding git ref if |base_url| together with |glob_spec|
182 matches the full |url|. 185 matches the full |url|.
183 186
184 If |allow_wildcards| is true, |glob_spec| can contain wildcards (see below). 187 If |allow_wildcards| is true, |glob_spec| can contain wildcards (see below).
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 404
402 @staticmethod 405 @staticmethod
403 def ParseGitSvnSha1(output): 406 def ParseGitSvnSha1(output):
404 """Parses git-svn output for the first sha1.""" 407 """Parses git-svn output for the first sha1."""
405 match = re.search(r'[0-9a-fA-F]{40}', output) 408 match = re.search(r'[0-9a-fA-F]{40}', output)
406 return match.group(0) if match else None 409 return match.group(0) if match else None
407 410
408 @staticmethod 411 @staticmethod
409 def GetSha1ForSvnRev(cwd, rev): 412 def GetSha1ForSvnRev(cwd, rev):
410 """Returns a corresponding git sha1 for a SVN revision.""" 413 """Returns a corresponding git sha1 for a SVN revision."""
411 if not GIT.IsGitSvn(cwd=cwd): 414 if not GIT.IsGitSvn(cwd):
412 return None 415 return None
413 try: 416 try:
414 output = GIT.Capture(['svn', 'find-rev', 'r' + str(rev)], cwd=cwd) 417 output = GIT.Capture(['svn', 'find-rev', 'r' + str(rev)], cwd=cwd)
415 return GIT.ParseGitSvnSha1(output) 418 return GIT.ParseGitSvnSha1(output)
416 except subprocess2.CalledProcessError: 419 except subprocess2.CalledProcessError:
417 return None 420 return None
418 421
419 @staticmethod 422 @staticmethod
420 def GetBlessedSha1ForSvnRev(cwd, rev): 423 def GetBlessedSha1ForSvnRev(cwd, rev):
421 """Returns a git commit hash from the master branch history that has 424 """Returns a git commit hash from the master branch history that has
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 # revert, like for properties. 1110 # revert, like for properties.
1108 if not os.path.isdir(cwd): 1111 if not os.path.isdir(cwd):
1109 # '.' was deleted. It's not worth continuing. 1112 # '.' was deleted. It's not worth continuing.
1110 return 1113 return
1111 try: 1114 try:
1112 SVN.Capture(['revert', file_status[1]], cwd=cwd) 1115 SVN.Capture(['revert', file_status[1]], cwd=cwd)
1113 except subprocess2.CalledProcessError: 1116 except subprocess2.CalledProcessError:
1114 if not os.path.exists(file_path): 1117 if not os.path.exists(file_path):
1115 continue 1118 continue
1116 raise 1119 raise
OLDNEW
« no previous file with comments | « gclient_scm.py ('k') | tests/gclient_scm_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698