Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / tools / auto_bisect / source_control.py
index 66b7e73..10b9780 100644 (file)
@@ -6,7 +6,7 @@
 
 import os
 
-from . import bisect_utils
+import bisect_utils
 
 CROS_VERSION_PATTERN = 'new version number from %s'
 
@@ -27,6 +27,9 @@ def DetermineAndCreateSourceControl(opts):
   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."""
 
@@ -36,10 +39,10 @@ class SourceControl(object):
   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.
@@ -48,11 +51,11 @@ class SourceControl(object):
         '--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.
@@ -114,7 +117,7 @@ class GitSourceControl(SourceControl):
 
   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
@@ -151,8 +154,9 @@ class GitSourceControl(SourceControl):
 
       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)
 
@@ -201,23 +205,25 @@ class GitSourceControl(SourceControl):
 
     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
 
@@ -227,6 +233,7 @@ class GitSourceControl(SourceControl):
 
     Args:
       revision: Revision you want to gather information on.
+
     Returns:
       A dict in the following format:
       {
@@ -239,7 +246,7 @@ class GitSourceControl(SourceControl):
     """
     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)):
@@ -259,7 +266,7 @@ class GitSourceControl(SourceControl):
         ['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.
@@ -281,7 +288,7 @@ class GitSourceControl(SourceControl):
         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]