Skip to content

Commit 3a03997

Browse files
committed
Nicer git_log_oneline
1 parent 6ad7412 commit 3a03997

20 files changed

+193
-158
lines changed

bin/gbf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
# `gbf <filename>` git branch file
44

55
filename=$1;
6-
git_log_oneline_new --follow --patch -- "$filename"
6+
range=${2:-git_current_branch_range}
7+
shift 2
8+
git_log_oneline --follow --patch "$range" "$@" -- "$filename"

bin/gbl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
# `gbl [<base branch>]` git branch log
44
# list commits added to this branch since forked from <base branch> or main branch.
55

6-
base_branch=${1:-"$(git_main_base_branch)"};
7-
git_log_oneline "$base_branch" | more -eRSF
6+
base_branch=${1:-"$(git_current_branch_range)"};
7+
shift
8+
git_log_oneline "$base_branch" "$@"

bin/git_commit_during_rebase

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env bash
22

33
echo git_commit_during_rebase;
4-
git_add_p && ( git_status_clean || git commit --no-edit --no-verify 2> /dev/null || ( git commit --amend --no-edit --no-verify ) ) && ( git_status_clean || git_stash )
4+
git_add_p && ( git_status_clean || git commit --no-edit --no-verify 2> /dev/null || ( ! git merge-base --is-ancestor HEAD "$(git_main_base_branch)" && git commit --amend --no-edit --no-verify || git commit -m "Auto lint" --no-verify ) ) && ( git_status_clean || git_stash )

bin/git_current_branch_range

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ "$(git_branch_name)" == "$(git_main_branch)" ]]; then
4+
echo HEAD
5+
else
6+
echo "$(git_main_base_branch)"..HEAD
7+
fi

bin/git_find_sha

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
commits=();
1313
while IFS= read -r line; do
1414
commits+=("$line");
15-
done < <(git_log_oneline "$root" 2>/dev/null | grep -E -e '^([^\sm]+m)?'"$val" -e '\s.*'"$val");
15+
done < <(git_log_oneline "$root"..HEAD 2>/dev/null | grep -E -e '^([^\sm]+m)?'"$val" -e '\s.*'"$val");
1616
if (( ${#commits[@]} > 1 )); then
1717
echoerr "Multiple possible commits found:";
1818
for commit in "${commits[@]}";

bin/git_log_oneline

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,8 @@
11
#!/usr/bin/env bash
22

3-
4-
5-
6-
7-
echo ${COLOR_GREY}git log --oneline $(git_log_range "$1")$COLOR_RESET 1>&2;
8-
commits_in_origin=$(echo $(git log --format="%h" $(git merge-base --fork-point $(git_main_base_branch)) 2>/dev/null));
9-
# local commits_in_origin=$(echo -e $(git log --format="%h" $(git_log_range "$1" HEAD) 2>/dev/null))
10-
commit_in_origin_condition='index("'$commits_in_origin'", $2) > 0';
11-
git log --reverse --format="%b%n§%h§%s§%cr" | awk -F'§' '{
12-
if ($0 ~ "^$") {
13-
# do nothing
14-
} else if ($1 != "" ) {
15-
body = body " " $1
16-
} else {
17-
if('"$commit_in_origin_condition"') {
18-
printf "%s", "'$COLOR_AQUA'"
19-
} else {
20-
printf "%s", "'$COLOR_GREEN'"
21-
}
22-
printf "%s%s%s%s%s", $2, " '$COLOR_RESET'", $3, " '$COLOR_LOWLIGHT", $4
23-
24-
if (body != "") {
25-
gsub("\r", "", body)
26-
printf "%s%s", "'$COLOR_GREY''$COLOR_LOWLIGHT'", body
27-
}
28-
29-
body=""
30-
31-
print "'$COLOR_RESET'"
32-
}
33-
}'
3+
git --no-pager \
4+
log \
5+
--color \
6+
--reverse \
7+
--format='%h%Creset%Cred%Cgreen%Cblue%Creset%(decorate) %s %C(dim)%cr - %cn%Creset' \
8+
"$@" | git_log_oneline_process

bin/git_log_oneline_new

Lines changed: 0 additions & 3 deletions
This file was deleted.

bin/git_log_oneline_new_2

Lines changed: 0 additions & 2 deletions
This file was deleted.

bin/git_log_oneline_process

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
#!/usr/bin/env ruby --disable-all
22

3-
if ARGV.delete('--off')
4-
while gets
5-
puts $_
6-
end
7-
exit 0
8-
end
3+
# frozen_string_literal: true
4+
5+
# rubocop:disable Style/SpecialGlobalVars
96

107
def branch_exist?(branch)
118
(
@@ -27,38 +24,52 @@ def current_branch_main?
2724
main_branch == current_branch
2825
end
2926

30-
$forks = {
31-
magenta: 'upstream/HEAD',
32-
blue: (branch_exist?('origin/HEAD') ? 'origin/HEAD' : main_branch),
33-
cyan: ('@{u}' unless current_branch_main?)
34-
}
27+
def forks
28+
@forks ||= {
29+
magenta: 'upstream/HEAD',
30+
blue: (branch_exist?('origin/HEAD') ? 'origin/HEAD' : main_branch),
31+
cyan: ('@{u}' unless current_branch_main?),
32+
green: 'HEAD'
33+
}.select { |_, v| branch_exist?(v) }
34+
end
3535

36-
$forks.select! { |k, v| branch_exist?(v) }
36+
# this is split on the magic sigil in git_log_oneline
37+
def next_line_split(line)
38+
line.split("\e[m\e[31m\e[32m\e[34m\e[m", 2)
39+
end
3740

3841
gets
39-
exit 0 unless $_
40-
sha, rest = $_.split("\e", 2)
42+
line = $_
43+
exit 0 unless line
44+
sha, rest = next_line_split(line)
4145
first = `git rev-parse --short #{sha}^ 2>/dev/null`.chomp
4246
first = first.empty? ? '' : "#{first}.."
43-
$forks.transform_values! do |v|
47+
forks.transform_values! do |v|
4448
`git log --format=%h #{first}#{v}`.chomp.split("\n").to_h { |k| [k, nil] }
4549
end
46-
def render(sha, rest)
47-
color = if $forks[:magenta]&.key?(sha)
50+
51+
def render(sha, rest) # rubocop:disable Metrics
52+
color = if forks[:magenta]&.key?(sha)
4853
"\e[35m"
49-
elsif $forks[:blue]&.key?(sha)
54+
elsif forks[:blue]&.key?(sha)
5055
"\e[34m"
51-
elsif $forks[:cyan]&.key?(sha)
56+
elsif forks[:cyan]&.key?(sha)
5257
"\e[36m"
53-
else
58+
elsif forks[:green]&.key?(sha)
5459
"\e[32m"
5560
end
56-
"#{color}#{sha}\e#{rest.chomp}\e[0m"
61+
"#{color}#{sha}\e[m#{rest.chomp}\e[0m"
5762
end
58-
print "\x1b[?7l"
59-
print render(sha, rest)
63+
64+
print "\e[?7l" # disable line wrap
65+
print render(sha.chomp, rest)
66+
6067
while gets
6168
puts
62-
print render(*$_.split("\e", 2))
69+
sha, rest = next_line_split($_)
70+
print render(sha.chomp, rest.to_s)
6371
end
64-
puts "\x1b[?7h"
72+
73+
puts "\e[?7h" # reenable line wrap
74+
75+
# rubocop:enable Style/SpecialGlobalVars

bin/git_rebase_onto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env bash
22

3-
cat $(git rev-parse --git-path rebase-merge/onto) $(git rev-parse --git-path rebase-apply/onto) 2> /dev/null
3+
cat $(git rev-parse --git-path rebase-merge/onto) $(git rev-parse --git-path rebase-apply/onto) 2> /dev/null

bin/rtr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env bash
22

3-
rt --failure-exit-code 2 "$@";
4-
[[ "$?" != "1" ]] && rtr "$@"
3+
rt --failure-exit-code 2 "$@";
4+
[[ "$?" != "1" ]] && rtr "$@"

bin/strip_color

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/env bash
22

3+
# also strip the disabling of line wrap
4+
# that gets added by git_log_oneline_process
35
if (( $# == 0 )); then
4-
sed -E "/^[[:cntrl:]]\\[1;90m.*[[:cntrl:]]\\[0m$/d;s/([[:cntrl:]]\\[[0-9]{1,3}(;[0-9]{1,3})*m)//g"
6+
sed -E 's/(\x1b\[[0-9;]*m|\x1b\[\?7[lh])//g'
57
else
68
echo -e "$@" | "$BASH_SOURCE"
79
fi

0 commit comments

Comments
 (0)