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

Side by Side Diff: scm.py

Issue 184343003: Now trychange can store patches in a Git repo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: branch -> ref Created 6 years, 8 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 | « no previous file | tests/scm_unittest.py » ('j') | trychange.py » ('J')
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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 # these 2 branches instead diffing to upstream. 134 # these 2 branches instead diffing to upstream.
135 m = re.match('^(\w)+\t(.+)$', statusline) 135 m = re.match('^(\w)+\t(.+)$', statusline)
136 if not m: 136 if not m:
137 raise gclient_utils.Error( 137 raise gclient_utils.Error(
138 'status currently unsupported: %s' % statusline) 138 'status currently unsupported: %s' % statusline)
139 # Only grab the first letter. 139 # Only grab the first letter.
140 results.append(('%s ' % m.group(1)[0], m.group(2))) 140 results.append(('%s ' % m.group(1)[0], m.group(2)))
141 return results 141 return results
142 142
143 @staticmethod 143 @staticmethod
144 def IsWorkTreeDirty(cwd):
145 return GIT.Capture(['status', '-s'], cwd=cwd) != ''
146
147 @staticmethod
144 def GetEmail(cwd): 148 def GetEmail(cwd):
145 """Retrieves the user email address if known.""" 149 """Retrieves the user email address if known."""
146 # We could want to look at the svn cred when it has a svn remote but it 150 # We could want to look at the svn cred when it has a svn remote but it
147 # should be fine for now, users should simply configure their git settings. 151 # should be fine for now, users should simply configure their git settings.
148 try: 152 try:
149 return GIT.Capture(['config', 'user.email'], cwd=cwd) 153 return GIT.Capture(['config', 'user.email'], cwd=cwd)
150 except subprocess2.CalledProcessError: 154 except subprocess2.CalledProcessError:
151 return '' 155 return ''
152 156
153 @staticmethod 157 @staticmethod
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 return "%s#%s" % (GIT.GetBranch(cwd), short_sha) 387 return "%s#%s" % (GIT.GetBranch(cwd), short_sha)
384 388
385 @staticmethod 389 @staticmethod
386 def GetCheckoutRoot(cwd): 390 def GetCheckoutRoot(cwd):
387 """Returns the top level directory of a git checkout as an absolute path. 391 """Returns the top level directory of a git checkout as an absolute path.
388 """ 392 """
389 root = GIT.Capture(['rev-parse', '--show-cdup'], cwd=cwd) 393 root = GIT.Capture(['rev-parse', '--show-cdup'], cwd=cwd)
390 return os.path.abspath(os.path.join(cwd, root)) 394 return os.path.abspath(os.path.join(cwd, root))
391 395
392 @staticmethod 396 @staticmethod
397 def GetGitDir(cwd):
398 return os.path.abspath(GIT.Capture(['rev-parse', '--git-dir'], cwd=cwd))
399
400 @staticmethod
401 def IsInsideWorkTree(cwd):
402 try:
403 return GIT.Capture(['rev-parse', '--is-inside-work-tree'], cwd=cwd)
404 except (OSError, subprocess2.CalledProcessError):
405 return False
406
407 @staticmethod
393 def GetGitSvnHeadRev(cwd): 408 def GetGitSvnHeadRev(cwd):
394 """Gets the most recently pulled git-svn revision.""" 409 """Gets the most recently pulled git-svn revision."""
395 try: 410 try:
396 output = GIT.Capture(['svn', 'info'], cwd=cwd) 411 output = GIT.Capture(['svn', 'info'], cwd=cwd)
397 match = re.search(r'^Revision: ([0-9]+)$', output, re.MULTILINE) 412 match = re.search(r'^Revision: ([0-9]+)$', output, re.MULTILINE)
398 return int(match.group(1)) if match else None 413 return int(match.group(1)) if match else None
399 except (subprocess2.CalledProcessError, ValueError): 414 except (subprocess2.CalledProcessError, ValueError):
400 return None 415 return None
401 416
402 @staticmethod 417 @staticmethod
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 # revert, like for properties. 1122 # revert, like for properties.
1108 if not os.path.isdir(cwd): 1123 if not os.path.isdir(cwd):
1109 # '.' was deleted. It's not worth continuing. 1124 # '.' was deleted. It's not worth continuing.
1110 return 1125 return
1111 try: 1126 try:
1112 SVN.Capture(['revert', file_status[1]], cwd=cwd) 1127 SVN.Capture(['revert', file_status[1]], cwd=cwd)
1113 except subprocess2.CalledProcessError: 1128 except subprocess2.CalledProcessError:
1114 if not os.path.exists(file_path): 1129 if not os.path.exists(file_path):
1115 continue 1130 continue
1116 raise 1131 raise
OLDNEW
« no previous file with comments | « no previous file | tests/scm_unittest.py » ('j') | trychange.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698