Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 short_sha = GIT.Capture(['rev-parse', '--short=4', 'HEAD'], cwd=cwd).strip() | 372 short_sha = GIT.Capture(['rev-parse', '--short=4', 'HEAD'], cwd=cwd).strip() |
| 373 return "%s#%s" % (GIT.GetBranch(cwd), short_sha) | 373 return "%s#%s" % (GIT.GetBranch(cwd), short_sha) |
| 374 | 374 |
| 375 @staticmethod | 375 @staticmethod |
| 376 def GetCheckoutRoot(cwd): | 376 def GetCheckoutRoot(cwd): |
| 377 """Returns the top level directory of a git checkout as an absolute path. | 377 """Returns the top level directory of a git checkout as an absolute path. |
| 378 """ | 378 """ |
| 379 root = GIT.Capture(['rev-parse', '--show-cdup'], cwd=cwd).strip() | 379 root = GIT.Capture(['rev-parse', '--show-cdup'], cwd=cwd).strip() |
| 380 return os.path.abspath(os.path.join(cwd, root)) | 380 return os.path.abspath(os.path.join(cwd, root)) |
| 381 | 381 |
| 382 @staticmethod | |
| 383 def GetSha1ForSvnRev(cwd, rev): | |
| 384 """Returns a git sha1 for a corresponding Subversion revision from a git-svn | |
| 385 remote. If that Subversion revision isn't found, an empty string is | |
| 386 returned.""" | |
| 387 # This probably won't work if not git-svn. There's a warning in | |
| 388 # gclient_scm.py that gives a user an error message and a URL to how to set | |
| 389 # up a git-svn remote, so we'll probably never get here but it doesn't hurt. | |
| 390 if not GIT.IsGitSvn(cwd=cwd): | |
| 391 return '' | |
|
M-A Ruel
2011/10/31 13:46:51
return None in case of failure.
Dan Beam
2011/11/06 07:34:08
Done.
| |
| 392 try: | |
| 393 GIT.Capture(['svn', 'rebase', '--local'], cwd=cwd) | |
|
M-A Ruel
2011/10/31 13:46:51
rebase (!) You need to use svn fetch instead, then
Dan Beam
2011/10/31 18:32:28
Yeah, I guess this isn't a good idea, but it's the
M-A Ruel
2011/10/31 19:17:50
Ah I see. I just dislike that a function like that
Dan Beam
2011/11/06 07:34:08
Done.
| |
| 394 # Currently works by just grabbing last line of output from git svn | |
| 395 # find-rev after rebuilding the index. This seems to currently always be | |
| 396 # what we want (either a sha1 or empty) even if there is error output. | |
| 397 lines = GIT.Capture( | |
| 398 ['svn', 'find-rev', 'r' + rev], cwd=cwd).splitlines(True) | |
| 399 return lines[-1].strip() if len(lines) else '' | |
| 400 except subprocess2.CalledProcessError: | |
| 401 return '' | |
| 402 | |
| 382 @classmethod | 403 @classmethod |
| 383 def AssertVersion(cls, min_version): | 404 def AssertVersion(cls, min_version): |
| 384 """Asserts git's version is at least min_version.""" | 405 """Asserts git's version is at least min_version.""" |
| 385 if cls.current_version is None: | 406 if cls.current_version is None: |
| 386 cls.current_version = cls.Capture(['--version']).split()[-1] | 407 cls.current_version = cls.Capture(['--version']).split()[-1] |
| 387 current_version_list = map(only_int, cls.current_version.split('.')) | 408 current_version_list = map(only_int, cls.current_version.split('.')) |
| 388 for min_ver in map(int, min_version.split('.')): | 409 for min_ver in map(int, min_version.split('.')): |
| 389 ver = current_version_list.pop(0) | 410 ver = current_version_list.pop(0) |
| 390 if ver < min_ver: | 411 if ver < min_ver: |
| 391 return (False, cls.current_version) | 412 return (False, cls.current_version) |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 984 if (file_status[0][0] in ('D', 'A', '!') or | 1005 if (file_status[0][0] in ('D', 'A', '!') or |
| 985 not file_status[0][1:].isspace()): | 1006 not file_status[0][1:].isspace()): |
| 986 # Added, deleted file requires manual intervention and require calling | 1007 # Added, deleted file requires manual intervention and require calling |
| 987 # revert, like for properties. | 1008 # revert, like for properties. |
| 988 try: | 1009 try: |
| 989 SVN.Capture(['revert', file_status[1]], cwd=repo_root) | 1010 SVN.Capture(['revert', file_status[1]], cwd=repo_root) |
| 990 except subprocess2.CalledProcessError: | 1011 except subprocess2.CalledProcessError: |
| 991 if not os.path.exists(file_path): | 1012 if not os.path.exists(file_path): |
| 992 continue | 1013 continue |
| 993 raise | 1014 raise |
| OLD | NEW |