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

Side by Side Diff: scm.py

Issue 8382030: depot_tools: Add git svn find-rev for safesync_url parsing (commonly LKGR link). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: changing more occurrences of SVN to Svn Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2011 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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 short_sha = GIT.Capture(['rev-parse', '--short=4', 'HEAD'], cwd=cwd).strip() 373 short_sha = GIT.Capture(['rev-parse', '--short=4', 'HEAD'], cwd=cwd).strip()
374 return "%s#%s" % (GIT.GetBranch(cwd), short_sha) 374 return "%s#%s" % (GIT.GetBranch(cwd), short_sha)
375 375
376 @staticmethod 376 @staticmethod
377 def GetCheckoutRoot(cwd): 377 def GetCheckoutRoot(cwd):
378 """Returns the top level directory of a git checkout as an absolute path. 378 """Returns the top level directory of a git checkout as an absolute path.
379 """ 379 """
380 root = GIT.Capture(['rev-parse', '--show-cdup'], cwd=cwd).strip() 380 root = GIT.Capture(['rev-parse', '--show-cdup'], cwd=cwd).strip()
381 return os.path.abspath(os.path.join(cwd, root)) 381 return os.path.abspath(os.path.join(cwd, root))
382 382
383 @staticmethod
384 def GetGitSvnHeadRev(cwd):
385 """Gets the most recently pulled git-svn revision."""
386 try:
387 output = GIT.Capture(['svn', 'info'], cwd=cwd)
388 match = re.search(r'^Revision: ([0-9]+)$', output, re.MULTILINE)
389 return int(match.group(1)) if match else None
390 except (subprocess2.CalledProcessError, ValueError):
391 return None
392
393 @staticmethod
394 def GetSha1ForSvnRev(cwd, rev):
395 """Returns a corresponding git sha1 for a SVN revision."""
396 if not GIT.IsGitSvn(cwd=cwd):
397 return None
398 try:
399 lines = GIT.Capture(
400 ['svn', 'find-rev', 'r' + str(rev)], cwd=cwd).splitlines()
401 return lines[-1].strip() if lines else None
402 except subprocess2.CalledProcessError:
403 return None
404
405 @staticmethod
406 def IsValidRevision(cwd, rev):
407 """Verifies the revision is a proper git revision."""
408 try:
409 GIT.Capture(['rev-parse', rev], cwd=cwd)
410 return True
411 except subprocess2.CalledProcessError:
412 return False
413
383 @classmethod 414 @classmethod
384 def AssertVersion(cls, min_version): 415 def AssertVersion(cls, min_version):
385 """Asserts git's version is at least min_version.""" 416 """Asserts git's version is at least min_version."""
386 if cls.current_version is None: 417 if cls.current_version is None:
387 cls.current_version = cls.Capture(['--version'], '.').split()[-1] 418 cls.current_version = cls.Capture(['--version'], '.').split()[-1]
388 current_version_list = map(only_int, cls.current_version.split('.')) 419 current_version_list = map(only_int, cls.current_version.split('.'))
389 for min_ver in map(int, min_version.split('.')): 420 for min_ver in map(int, min_version.split('.')):
390 ver = current_version_list.pop(0) 421 ver = current_version_list.pop(0)
391 if ver < min_ver: 422 if ver < min_ver:
392 return (False, cls.current_version) 423 return (False, cls.current_version)
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 info = SVN.CaptureLocalInfo([], parent) 970 info = SVN.CaptureLocalInfo([], parent)
940 if (info['Repository Root'] != cur_dir_repo_root or 971 if (info['Repository Root'] != cur_dir_repo_root or
941 info['URL'] != os.path.dirname(url)): 972 info['URL'] != os.path.dirname(url)):
942 break 973 break
943 url = info['URL'] 974 url = info['URL']
944 except subprocess2.CalledProcessError: 975 except subprocess2.CalledProcessError:
945 break 976 break
946 cwd = parent 977 cwd = parent
947 return GetCasedPath(cwd) 978 return GetCasedPath(cwd)
948 979
980 @staticmethod
981 def IsValidRevision(url):
982 """Verifies the revision looks like an SVN revision."""
983 try:
984 SVN.Capture(['info', url], cwd=None)
985 return True
986 except subprocess2.CalledProcessError:
987 return False
988
949 @classmethod 989 @classmethod
950 def AssertVersion(cls, min_version): 990 def AssertVersion(cls, min_version):
951 """Asserts svn's version is at least min_version.""" 991 """Asserts svn's version is at least min_version."""
952 if cls.current_version is None: 992 if cls.current_version is None:
953 cls.current_version = cls.Capture(['--version'], None).split()[2] 993 cls.current_version = cls.Capture(['--version'], None).split()[2]
954 current_version_list = map(only_int, cls.current_version.split('.')) 994 current_version_list = map(only_int, cls.current_version.split('.'))
955 for min_ver in map(int, min_version.split('.')): 995 for min_ver in map(int, min_version.split('.')):
956 ver = current_version_list.pop(0) 996 ver = current_version_list.pop(0)
957 if ver < min_ver: 997 if ver < min_ver:
958 return (False, cls.current_version) 998 return (False, cls.current_version)
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 # revert, like for properties. 1044 # revert, like for properties.
1005 if not os.path.isdir(cwd): 1045 if not os.path.isdir(cwd):
1006 # '.' was deleted. It's not worth continuing. 1046 # '.' was deleted. It's not worth continuing.
1007 return 1047 return
1008 try: 1048 try:
1009 SVN.Capture(['revert', file_status[1]], cwd=cwd) 1049 SVN.Capture(['revert', file_status[1]], cwd=cwd)
1010 except subprocess2.CalledProcessError: 1050 except subprocess2.CalledProcessError:
1011 if not os.path.exists(file_path): 1051 if not os.path.exists(file_path):
1012 continue 1052 continue
1013 raise 1053 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