import os
-from . import bisect_utils
+import bisect_utils
CROS_VERSION_PATTERN = 'new version number from %s'
return None
+# TODO(qyearsley): Almost all of the methods below could be top-level functions
+# (or class methods). Refactoring may make this simpler.
+# pylint: disable=R0201
class SourceControl(object):
"""SourceControl is an abstraction over the source control system."""
def SyncToRevisionWithGClient(self, revision):
"""Uses gclient to sync to the specified revision.
- ie. gclient sync --revision <revision>
+ This is like running gclient sync --revision <revision>.
Args:
- revision: The git SHA1 or svn CL (depending on workflow).
+ revision: A git SHA1 hash or SVN revision number (depending on workflow).
Returns:
The return code of the call.
'--delete_unversioned_trees', '--nohooks', '--revision', revision])
def SyncToRevisionWithRepo(self, timestamp):
- """Uses repo to sync all the underlying git depots to the specified
- time.
+ """Uses the repo command to sync all the underlying git depots to the
+ specified time.
Args:
- timestamp: The unix timestamp to sync to.
+ timestamp: The Unix timestamp to sync to.
Returns:
The return code of the call.
def ResolveToRevision(self, revision_to_check, depot, depot_deps_dict,
search, cwd=None):
- """If an SVN revision is supplied, try to resolve it to a git SHA1.
+ """Tries to resolve an SVN revision or commit position to a git SHA1.
Args:
revision_to_check: The user supplied revision string that may need to be
for i in search_range:
svn_pattern = 'git-svn-id: %s@%d' % (depot_svn, i)
+ commit_position_pattern = '^Cr-Commit-Position: .*@{#%d}' % i
cmd = ['log', '--format=%H', '-1', '--grep', svn_pattern,
- 'origin/master']
+ '--grep', commit_position_pattern, 'origin/master']
(log_output, return_code) = bisect_utils.RunGit(cmd, cwd=cwd)
return log_output == "master"
- def SVNFindRev(self, revision, cwd=None):
- """Maps directly to the 'git svn find-rev' command.
+ def GetCommitPosition(self, git_revision, cwd=None):
+ """Finds git commit postion for the given git hash.
+
+ This function executes "git footer --position-num <git hash>" command to get
+ commit position the given revision.
Args:
- revision: The git SHA1 to use.
+ git_revision: The git SHA1 to use.
+ cwd: Working directory to run the command from.
Returns:
- An integer changelist #, otherwise None.
+ Git commit position as integer or None.
"""
-
- cmd = ['svn', 'find-rev', revision]
-
+ cmd = ['footers', '--position-num', git_revision]
output = bisect_utils.CheckRunGit(cmd, cwd)
- svn_revision = output.strip()
+ commit_position = output.strip()
- if bisect_utils.IsStringInt(svn_revision):
- return int(svn_revision)
+ if bisect_utils.IsStringInt(commit_position):
+ return int(commit_position)
return None
Args:
revision: Revision you want to gather information on.
+
Returns:
A dict in the following format:
{
"""
commit_info = {}
- formats = ['%cN', '%cE', '%s', '%cD', '%b']
+ formats = ['%aN', '%aE', '%s', '%cD', '%b']
targets = ['author', 'email', 'subject', 'date', 'body']
for i in xrange(len(formats)):
['checkout', revision, file_name], cwd=cwd)[1]
def RevertFileToHead(self, file_name):
- """Unstages a file and returns it to HEAD.
+ """Un-stages a file and resets the file's state to HEAD.
Returns:
True if successful.
Returns a list of commits that touched this file.
"""
cmd = ['log', '--format=%H', '%s~1..%s' % (revision_start, revision_end),
- filename]
+ '--', filename]
output = bisect_utils.CheckRunGit(cmd)
return [o for o in output.split('\n') if o]