-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathgit_log_format.py
38 lines (34 loc) · 1.08 KB
/
git_log_format.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
import sys
import subprocess
def get_log_process(path, last_commit=None):
SEPARATOR="%x1F"
GIT_COMMIT_FLAG="%x1E"
command = [
"git",
"-C",
path,
"log",
f"--pretty=format:\"%n{GIT_COMMIT_FLAG}%H{SEPARATOR}%aN{SEPARATOR}%aE{SEPARATOR}%aI{SEPARATOR}%cN{SEPARATOR}%cE{SEPARATOR}%cI{SEPARATOR}%(trailers:key=Co-authored-by,valueonly=true,separator={SEPARATOR}){SEPARATOR}{SEPARATOR}%e\"",
"--reverse",
"--use-mailmap",
"--numstat",
"-z",
"--compact-summary",
"--stat-width=1024",
"--stat-name-width=1024",
"--stat-graph-width=1"
]
if last_commit:
command.insert(4, f"{last_commit}..HEAD")
return subprocess.Popen(command, stdout=subprocess.PIPE)
def main():
argc = len(sys.argv)
if argc <= 1:
print("No repo supplied")
return
last_commit = None if argc < 3 else sys.argv[2]
log_process = get_log_process(sys.argv[1], last_commit)
while line := log_process.stdout.readline():
print(line)
if __name__ == "__main__":
main()