Exemple #1
0
 def add_commit(self, commit):
     """Adds the commit to the commits array if it doesn't already exist,
     and returns the commit's index in the array.
     """
     sha1 = commit.hex
     if sha1 in self._commits:
         return self._commits[sha1]
     title, separator, body = commit.message.partition("\n")
     commit = {
         'explored': False,
         'sha1': sha1,
         'name': GitUtils.abbreviate_sha1(sha1),
         'describe': GitUtils.describe(sha1),
         'refs': GitUtils.refs_to(sha1, self.repo()),
         'author_name': commit.author.name,
         'author_mail': commit.author.email,
         'author_time': commit.author.time,
         'author_offset': commit.author.offset,
         'committer_name': commit.committer.name,
         'committer_mail': commit.committer.email,
         'committer_time': commit.committer.time,
         'committer_offset': commit.committer.offset,
         # 'message': commit.message,
         'title': title,
         'separator': separator,
         'body': body.lstrip("\n"),
     }
     self._json['commits'].append(commit)
     self._commits[sha1] = len(self._json['commits']) - 1
     return self._commits[sha1]
Exemple #2
0
    def deps(revspec):
        detector = DependencyDetector(options)
        listener = JSONDependencyListener(options)
        detector.add_listener(listener)

        if '..' in revspec:
            try:
                revisions = GitUtils.rev_list(revspec)
            except subprocess.CalledProcessError:
                return json_error(422,
                                  'Invalid revision range',
                                  "Could not resolve revision range '%s'" %
                                  revspec,
                                  revspec=revspec)
        else:
            revisions = [revspec]

        for rev in revisions:
            try:
                detector.get_commit(rev)
            except InvalidCommitish:
                return json_error(422,
                                  'Invalid revision',
                                  "Could not resolve revision '%s'" % rev,
                                  rev=rev)

            detector.find_dependencies(rev)

        tip_commit = detector.get_commit(revisions[0])
        tip_sha1 = tip_commit.hex

        json = listener.json()
        json['query'] = {
            'revspec': revspec,
            'revisions': revisions,
            'tip_sha1': tip_sha1,
            'tip_abbrev': GitUtils.abbreviate_sha1(tip_sha1),
        }
        return jsonify(json)
Exemple #3
0
def test_abbreviate_sha1():
    sha1 = GitUtils.abbreviate_sha1("HEAD")
    assert len(sha1) == 7