Beispiel #1
0
def RevertFileToHead(file_name):
    """Un-stages a file and resets the file's state to HEAD.

  Returns:
    True if successful.
  """
    # Reset doesn't seem to return 0 on success.
    bisect_utils.RunGit(['reset', 'HEAD', file_name])
    _, return_code = bisect_utils.RunGit(
        ['checkout', bisect_utils.FILE_DEPS_GIT])
    return not return_code
Beispiel #2
0
    def CheckoutFileAtRevision(self, file_name, revision, cwd=None):
        """Performs a checkout on a file at the given revision.

    Returns:
      True if successful.
    """
        return not bisect_utils.RunGit(['checkout', revision, file_name],
                                       cwd=cwd)[1]
Beispiel #3
0
def CheckoutFileAtRevision(file_name, revision, cwd=None):
    """Performs a checkout on a file at the given revision.

  Returns:
    True if successful.
  """
    command = ['checkout', revision, file_name]
    _, return_code = bisect_utils.RunGit(command, cwd=cwd)
    return not return_code
Beispiel #4
0
def SyncToRevision(revision, sync_client=None):
    if not sync_client:
        _, return_code = bisect_utils.RunGit(['checkout', revision])
    elif sync_client == 'gclient':
        return_code = SyncToRevisionWithGClient(revision)
    else:
        raise NotImplementedError('Unsupported sync_client: "%s"' %
                                  sync_client)

    return not return_code
Beispiel #5
0
def DetermineAndCreateSourceControl(opts):
    """Attempts to determine the underlying source control workflow and returns
  a SourceControl object.

  Returns:
    An instance of a SourceControl object, or None if the current workflow
    is unsupported.
  """
    (output, _) = bisect_utils.RunGit(['rev-parse', '--is-inside-work-tree'])

    if output.strip() == 'true':
        return GitSourceControl(opts)

    return None
Beispiel #6
0
    def SyncToRevision(self, revision, sync_client=None):
        """Syncs to the specified revision.

    Args:
      revision: The revision to sync to.
      use_gclient: Specifies whether or not we should sync using gclient or
        just use source control directly.

    Returns:
      True if successful.
    """

        if not sync_client:
            results = bisect_utils.RunGit(['checkout', revision])[1]
        elif sync_client == 'gclient':
            results = self.SyncToRevisionWithGClient(revision)
        elif sync_client == 'repo':
            results = self.SyncToRevisionWithRepo(revision)

        return not results
Beispiel #7
0
def SyncToRevision(revision, sync_client=None):
    """Syncs or checks out a revision based on sync_client argument.

  Args:
    revision: Git hash for the solutions with the format <repo>@rev.
        E.g., "src@2ae43f...", "src/third_party/webkit@asr1234" etc.
    sync_client: Syncs to revision when this is True otherwise checks out
        the revision.

  Returns:
    True if sync or checkout is successful, False otherwise.
  """
    if not sync_client:
        _, return_code = bisect_utils.RunGit(['checkout', revision])
    elif sync_client == 'gclient':
        return_code = bisect_utils.RunGClientAndSync([revision])
    else:
        raise NotImplementedError('Unsupported sync_client: "%s"' %
                                  sync_client)

    return not return_code
Beispiel #8
0
def GetCommitPosition(git_revision, cwd=None):
    """Finds git commit position for the given git hash.

  This function executes "git footer --position-num <git hash>" command to get
  commit position the given revision.

  Args:
    git_revision: The git SHA1 to use.
    cwd: Working directory to run the command from.

  Returns:
    Git commit position as integer or None.
  """
    # Some of the repositories are pure git based, unlike other repositories
    # they doesn't have commit position. e.g., skia, angle.
    cmd = ['footers', '--position-num', git_revision]
    output, return_code = bisect_utils.RunGit(cmd, cwd)
    if not return_code:
        commit_position = output.strip()
        if bisect_utils.IsStringInt(commit_position):
            return int(commit_position)
    return None
Beispiel #9
0
def IsInGitRepository():
    output, _ = bisect_utils.RunGit(['rev-parse', '--is-inside-work-tree'])
    return output.strip() == 'true'
Beispiel #10
0
    def ResolveToRevision(self,
                          revision_to_check,
                          depot,
                          depot_deps_dict,
                          search,
                          cwd=None):
        """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
        resolved to a git SHA1.
      depot: The depot the revision_to_check is from.
      depot_deps_dict: A dictionary with information about different depots.
      search: The number of changelists to try if the first fails to resolve
        to a git hash. If the value is negative, the function will search
        backwards chronologically, otherwise it will search forward.

    Returns:
      A string containing a git SHA1 hash, otherwise None.
    """
        # Android-chrome is git only, so no need to resolve this to anything else.
        if depot == 'android-chrome':
            return revision_to_check

        if depot != 'cros':
            if not bisect_utils.IsStringInt(revision_to_check):
                return revision_to_check

            depot_svn = 'svn://svn.chromium.org/chrome/trunk/src'

            if depot != 'chromium':
                depot_svn = depot_deps_dict[depot]['svn']

            svn_revision = int(revision_to_check)
            git_revision = None

            if search > 0:
                search_range = xrange(svn_revision, svn_revision + search, 1)
            else:
                search_range = xrange(svn_revision, svn_revision + search, -1)

            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,
                    '--grep', commit_position_pattern, 'origin/master'
                ]

                (log_output, return_code) = bisect_utils.RunGit(cmd, cwd=cwd)

                assert not return_code, 'An error occurred while running'\
                                        ' "git %s"' % ' '.join(cmd)

                if not return_code:
                    log_output = log_output.strip()

                    if log_output:
                        git_revision = log_output

                        break

            return git_revision
        else:
            if bisect_utils.IsStringInt(revision_to_check):
                return int(revision_to_check)
            else:
                cwd = os.getcwd()
                os.chdir(
                    os.path.join(os.getcwd(), 'src', 'third_party',
                                 'chromiumos-overlay'))
                pattern = CROS_VERSION_PATTERN % revision_to_check
                cmd = ['log', '--format=%ct', '-1', '--grep', pattern]

                git_revision = None

                log_output = bisect_utils.CheckRunGit(cmd, cwd=cwd)
                if log_output:
                    git_revision = log_output
                    git_revision = int(log_output.strip())
                os.chdir(cwd)

                return git_revision