def print_commit(commit, with_diff=False):
t = time.strftime("%a, %d %b %Y %H:%M", time.gmtime(commit.authored_date))
print(commit.hexsha, commit.author.name, t, commit.message)
print("stats:", commit.stats.total)
print()
if with_diff and len(commit.parents):
diffs = commit.diff(commit.parents[0])
for d in diffs:
print(d)
b_lines = str(d.b_blob.data_stream.read()).split()
a_lines = str(d.a_blob.data_stream.read()).split()
differ = difflib.Differ()
delta = differ.compare(b_lines, a_lines)
for i in delta:
print(i)
line_number = 0
for line in delta:
# split off the code
code = line[:2]
# if the line is in both files or just a, increment the
# line number.
if code in (" ", "+ "):
line_number += 1
# if this line is only in a, print the line number and
# the text on the line
if code == "+ ":
print("%d: %s" % (line_number, line[2:].strip()))
# print(b_lines)
# print(a_lines)
# dcont = list(difflib.unified_diff(
# b_lines, a_lines, d.b_path, d.a_path))
# for l in dcont:
# print(l)
print("------------------------")
print("+++++++++++++++++++++++++++++++++++++++++++++++++++++++")
print()
评论列表
文章目录