示例#1
0
def read_commit(rev):
    obj = git.cat_file(rev, wd=path)
    commit = {}
    commit['parent'] = []
    inCommitMsg = False
    for line in obj:
        if inCommitMsg:
          commit['message'].append(line)
          continue
        if not line:
          inCommitMsg = True
          commit['message'] = []
          continue
        match = re.search("^(tree|parent|author|committer) (.+)$", line)
        if not match:
          raise Exception('Line in commit record is odd: %s' % line)
        if match.group(1) not in commit:
          commit[match.group(1)] = []
        commit[match.group(1)].append(match.group(2))

    if len(commit['tree']) == 0:
        commit['tree'] = None
    elif len(commit['tree']) == 1:
        commit['tree'] = commit['tree'][0]
    else:
        raise Exception('Malformed commit in %s' % rev)

    if verbose:
      if len(commit['parent']) > 1:
          print '    merge commit'
          for h in commit['parent']:
              print '        parent', h

    return commit
示例#2
0
def import_rev(rev):
    print "importing", rev
    commit = read_commit(rev)
    subtree = commit['tree']
    subtrees = [subtree]
    while subtrees:
        subtree = subtrees.pop(0)
        if subtree in thirdparty:
          print '    thirdparty', subtree
          continue
        if subtree in trees:
          print '    already seen', subtree
          continue
        print '    ' + subtree
        trees.add(subtree)
        output = git.cat_file(subtree, wd=path)