-
Notifications
You must be signed in to change notification settings - Fork 0
/
.githelpers
153 lines (135 loc) · 4.51 KB
/
.githelpers
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
# Log output:
#
# * 51c333e (12 days) <Gary Bernhardt> add vim-eunuch
#
# The time massaging regexes start with ^[^<]* because that ensures that they
# only operate before the first "<". That "<" will be the beginning of the
# author name, ensuring that we don't destroy anything in the commit message
# that looks like time.
#
# The log format uses } characters between each field, and `column` is later
# used to split on them. A } in the commit subject or any other field will
# break this.
PLAINHASH="%h"
HASH="%C(yellow)%h%Creset"
RELATIVE_TIME="%Cgreen(%ai)%Creset"
AUTHOR="%C(bold blue)<%an>%Creset"
REFS="%C(red)%d%Creset"
SUBJECT="%s"
FORMAT="$HASH}}}}$RELATIVE_TIME}}}}$AUTHOR}}}}$REFS $SUBJECT"
FORMAT_NO_REFS="$HASH}}}}$RELATIVE_TIME}}}}$AUTHOR}}}}$SUBJECT"
FORMAT2="$HASH}}}}$RELATIVE_TIME}}}}XXX<$PLAINHASH>XXX}}}}$AUTHOR}}}}$REFS $SUBJECT"
show_git_head() {
pretty_git_log -1
git show -p --pretty="tformat:"
}
pretty_git_topo_log() {
git log --pretty="tformat:${FORMAT}" $* |
# Replace (2 years ago) with (2 years)
sed -Ee 's/(^[^<]*) ago\)/\1)/' |
# Replace (2 years, 5 months) with (2 years)
sed -Ee 's/(^[^<]*), [[:digit:]]+ .*months?\)/\1)/' |
# Replace }}}}s with daggers
sed -Ee 's/}}}}/†/g' |
# Line columns up based on dagger
column -s '†' -t |
# Page only if we need to
less -FXRS
}
pretty_git_topo_log_no_branch_names() {
git log --pretty="tformat:${FORMAT_NO_REFS}" $* |
# Replace (2 years ago) with (2 years)
sed -Ee 's/(^[^<]*) ago\)/\1)/' |
# Replace (2 years, 5 months) with (2 years)
sed -Ee 's/(^[^<]*), [[:digit:]]+ .*months?\)/\1)/' |
# Replace }}}}s with daggers
sed -Ee 's/}}}}/†/g' |
# Line columns up based on dagger
column -s '†' -t
}
pretty_git_log() {
git log --graph --pretty="tformat:${FORMAT}" $* |
# Replace (2 years ago) with (2 years)
sed -Ee 's/(^[^<]*) ago\)/\1)/' |
# Replace (2 years, 5 months) with (2 years)
sed -Ee 's/(^[^<]*), [[:digit:]]+ .*months?\)/\1)/' |
# Replace }}}}s with daggers
sed -Ee 's/}}}}/†/g' |
# Line columns up based on dagger
column -s '†' -t |
# Page only if we need to
less -FXRS
}
pretty_git_branches() {
git for-each-ref \
--sort=-committerdate refs/heads/ refs/remotes/ \
--format='%(color:red)%(objectname:short)%(color:reset)}}}}(%(color:green)%(committerdate:iso8601)%(color:reset))}}}}%(authorname)}}}}%(color:yellow)%(refname:short)%(color:reset)}}}}%(contents:subject)' \
$* |
# Replace (2 years ago) with (2 years)
sed -Ee 's/(^[^<]*) ago\)/\1)/' |
# Replace (2 years, 5 months) with (2 years)
sed -Ee 's/(^[^<]*), [[:digit:]]+ .*months?\)/\1)/' |
# Replace }}}}s with daggers
sed -Ee 's/}}}}/†/g' |
# Line columns up based on dagger
column -s '†' -t |
# Page only if we need to
less -FXRS
}
commits_range_from_head() {
local branch="$1"
local head="${2:-HEAD}"
echo "$(git merge-base "$branch" "$head")".."$branch"
}
branch_commits_range_from_head() {
(
set -eu
branch="$1"
head="${2:-HEAD}"
pretty_git_topo_log_no_branch_names "$(commits_range_from_head "$branch" "$head")"
)
}
files_in_branch() {
(
set -eu
branch="$1"
head="${2:-HEAD}"
files_in_range "$(commits_range_from_head "$branch" "$head")"
)
}
files_in_range() {
# git diff-tree --no-commit-id --name-only -r "$(. ~/.githelpers && commits_range_from_head HEAD develop)"
(
set -eu
git diff-tree --no-commit-id --name-only -r "$1"
)
}
filestats() {
while read entry; do
line="$(printf "%s" "$entry" | sed -e 's/XXX<.*>XXX//g')"
hash="$(printf "%s" "$entry" | sed -E 's/.*XXX\<([0-9a-f]+)\>XXX.*/\1/')"
printf "%s" "$line"
if ! [ "$hash" = "$entry" ]; then
stat="$(
git diff-tree --no-commit-id -r --dirstat=lines $hash | tail -1 | cut -d'/' -f1-3 | sed -E 's/^ +//g')"
echo " [$stat]"
else
echo ""
fi
done
}
pretty_git_log2() {
git log --graph --pretty="tformat:${FORMAT2}" $* |
# Replace (2 years ago) with (2 years)
sed -Ee 's/(^[^<]*) ago\)/\1)/' |
# Replace (2 years, 5 months) with (2 years)
sed -Ee 's/(^[^<]*), [[:digit:]]+ .*months?\)/\1)/' |
# Replace }}}}s with daggers
sed -Ee 's/}}}}/†/g' |
# Line columns up based on } delimiter
column -s '†' -t |
# Page only if we need to
filestats |
less -FXRS
}