示例#1
0
 def GetSource(self, path, revision):
   """Returns source code of the file at ``path`` of the given revision."""
   # Check whether the requested file exist or not.
   command = 'git show %s:%s' % (ConvertRemoteCommitToLocal(
       revision, self.real_repo_path), path)
   output = script_util.GetCommandOutput(self._GetFinalCommand(command))
   return output
示例#2
0
 def GetChangeDiff(self, revision, path=None):  # pylint: disable=W
   """Returns the diff of the given revision."""
   command = ('git log --format="" --max-count=1 %s' %
              ConvertRemoteCommitToLocal(revision, self.real_repo_path))
   if path:
     command += ' -p %s' % path
   output = script_util.GetCommandOutput(self._GetFinalCommand(command))
   return self.diff_parser(output)
示例#3
0
 def GetChangeLog(self, revision):
   """Returns the change log of the given revision."""
   command = ('git log --pretty=format:"%s" --max-count=1 --raw '
              '--no-abbrev %s' % (_CHANGELOG_FORMAT_STRING,
                                  ConvertRemoteCommitToLocal(
                                      revision, self.real_repo_path)))
   output = script_util.GetCommandOutput(self._GetFinalCommand(command, True))
   return self.changelog_parser(output, self.repo_url, self._ref)
 def GetChangeLogs(self, start_revision, end_revision):  # pylint: disable=W
     """Returns change log list in (start_revision, end_revision]."""
     command = ('git log --pretty=format:"%s" --raw --no-abbrev %s' %
                (_CHANGELOGS_FORMAT_STRING, '%s..%s' %
                 (ConvertRemoteCommitToLocal(start_revision),
                  ConvertRemoteCommitToLocal(end_revision))))
     output = script_util.GetCommandOutput(
         self._GetFinalCommand(command, True))
     return self.changelogs_parser(output, self.repo_url)
示例#5
0
  def GetChangeLogs(self, start_revision, end_revision):  # pylint: disable=W
    """Returns change log list in (start_revision, end_revision].

    Note that, unlike GitilesRepository, LocalGitRepository does allow getting
    changelogs from (None, None], which means from start of time to the current
    time.
    """
    revision_range = GetRevisionRangeForGitCommand(start_revision, end_revision,
                                                   self.real_repo_path)
    command = 'git log %s --pretty=format:"%s" --raw --no-abbrev' % (
        revision_range, _CHANGELOGS_FORMAT_STRING)

    output = script_util.GetCommandOutput(self._GetFinalCommand(command, True))
    return self.changelogs_parser(output, self.repo_url, self._ref)
  def testGetLocalGitCommandOutput(self):
    class _MockProcess(object):
      def __init__(self, command, *_):
        self.command = command

      def communicate(self, *_):
        return self.command, 'error'

      @property
      def returncode(self):
        return 1 if self.command == 'dummy' else 0

    self.mock(subprocess, 'Popen', lambda command, **_: _MockProcess(command))
    output = script_util.GetCommandOutput('command')
    self.assertEqual(output, 'command')

    self.assertRaisesRegexp(Exception, 'Error running command dummy: error',
                            script_util.GetCommandOutput, 'dummy')
示例#7
0
  def GetCommitsBetweenRevisions(self, start_revision, end_revision):
    """Gets a list of commit hashes between start_revision and end_revision.

    Note that, unlike GitilesRepository, LocalGitRepository does allow getting
    changelogs from (None, None], which means from start of time to the current
    time.

    Args:
      start_revision: The oldest revision in the range.
      end_revision: The latest revision in the range.

    Returns:
      A list of commit hashes made since start_revision through and including
      end_revision in order from most-recent to least-recent. This includes
      end_revision, but not start_revision.
    """
    revision_range = GetRevisionRangeForGitCommand(start_revision, end_revision,
                                                   self.real_repo_path)

    command = 'git log --pretty=oneline %s' % revision_range
    output = script_util.GetCommandOutput(self._GetFinalCommand(command))
    return self.commits_parser(output)
示例#8
0
 def GetBlame(self, path, revision):
   """Returns blame of the file at ``path`` of the given revision."""
   command = 'git blame --incremental %s -- %s' % (ConvertRemoteCommitToLocal(
       revision, self.real_repo_path), path)
   output = script_util.GetCommandOutput(self._GetFinalCommand(command))
   return self.blame_parser(output, path, revision)