This repository has been archived by the owner on Nov 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 98
/
u_log_gen.py
42 lines (37 loc) · 1.64 KB
/
u_log_gen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Simple git tool that will filter out duplicated commits caused by cherry-picks
# This is mainly intended for release notes generation
import argparse
import time
from git import Repo, Commit
parser = argparse.ArgumentParser(description='Script for generating change log from a tag without duplicated commits. This is mainly intended for release notes generation')
parser.add_argument('rev', help='Starting tag, branch or SHA')
parser.add_argument('--oneline', action='store_true', help='Only print out the first line of the commit message for each listed commit')
parser.add_argument('--branchmerge', action='store_true', help='Merges between branches are hidden by default. Set this flag to show them.')
args = parser.parse_args()
repo = Repo(".")
assert not repo.bare
def filter_commit(commit: Commit, msg_list):
# If the commit is alread in the msg_list we return True
if commit.message in msg_list:
return True
else:
msg_list.append(commit.message)
return False
commits = repo.iter_commits(f"{args.rev}..HEAD")
msg_list = []
commits = [c for c in commits if not filter_commit(c, msg_list)]
for commit in commits:
if not args.branchmerge:
if commit.message.upper().startswith("MERGE BRANCH"):
continue
if args.oneline:
print(commit.message.split('\n')[0])
else:
print(f"commit {commit.hexsha}")
print(f"Author: {commit.author}")
committed_date = time.strftime("%a, %d %b %Y %H:%M", time.gmtime(commit.committed_date))
print(f"Date: {committed_date}")
print()
msg = ' ' + commit.message.replace('\n','\n ')
print(msg)
print()