This repository was archived by the owner on Dec 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimportant-roots.py
More file actions
55 lines (44 loc) · 1.54 KB
/
important-roots.py
File metadata and controls
55 lines (44 loc) · 1.54 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from __future__ import annotations
import os
import subprocess
import sys
def main() -> int:
os.chdir(sys.argv[1])
merges = []
for cid in subprocess.check_output((
'git', 'log', '--merges', '--format=%h',
)).decode().splitlines():
if subprocess.call(
('git', 'merge-base', f'{cid}^1', f'{cid}^2'),
stdout=subprocess.DEVNULL,
):
merges.append(cid)
def _roots_n(parent: str) -> tuple[str, int]:
out = subprocess.check_output((
'git', 'log', parent, '--max-parents=0', '--format=%h',
)).decode().strip()
n_out = subprocess.check_output((
'git', 'rev-list', '--count', parent,
)).decode()
n = int(n_out) - 1
return out, n
indent = 0
print('|')
for merge in merges:
left, leftn = _roots_n(f'{merge}^1')
right, rightn = _roots_n(f'{merge}^2')
if len(left.splitlines()) == 1 and len(right.splitlines()) == 1:
print(
f'{' ' * indent}{left} <=> {leftn: 4} commits <=> {merge} '
f'<=> {rightn: 4} commits <=> {right}',
)
elif len(left.splitlines()) == 1:
print(f'{' ' * indent}{left} <=> {leftn: 4} commits <=> {merge} ')
indent += 20
print(f'{' ' * indent}|')
elif len(right.splitlines()) == 1:
print(f'{' ' * indent}{merge} <=> {rightn: 4} commits <=> {right}')
print(f'{' ' * indent}|')
return 0
if __name__ == '__main__':
raise SystemExit(main())