Skip to content

Commit

Permalink
Nicer git_log_oneline
Browse files Browse the repository at this point in the history
  • Loading branch information
robotdana committed Dec 4, 2023
1 parent 6ad7412 commit 3a03997
Show file tree
Hide file tree
Showing 20 changed files with 193 additions and 158 deletions.
4 changes: 3 additions & 1 deletion bin/gbf
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
# `gbf <filename>` git branch file

filename=$1;
git_log_oneline_new --follow --patch -- "$filename"
range=${2:-git_current_branch_range}
shift 2
git_log_oneline --follow --patch "$range" "$@" -- "$filename"
5 changes: 3 additions & 2 deletions bin/gbl
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
# `gbl [<base branch>]` git branch log
# list commits added to this branch since forked from <base branch> or main branch.

base_branch=${1:-"$(git_main_base_branch)"};
git_log_oneline "$base_branch" | more -eRSF
base_branch=${1:-"$(git_current_branch_range)"};
shift
git_log_oneline "$base_branch" "$@"
2 changes: 1 addition & 1 deletion bin/git_commit_during_rebase
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

echo git_commit_during_rebase;
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 )
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 )
7 changes: 7 additions & 0 deletions bin/git_current_branch_range
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

if [[ "$(git_branch_name)" == "$(git_main_branch)" ]]; then
echo HEAD
else
echo "$(git_main_base_branch)"..HEAD
fi
2 changes: 1 addition & 1 deletion bin/git_find_sha
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
commits=();
while IFS= read -r line; do
commits+=("$line");
done < <(git_log_oneline "$root" 2>/dev/null | grep -E -e '^([^\sm]+m)?'"$val" -e '\s.*'"$val");
done < <(git_log_oneline "$root"..HEAD 2>/dev/null | grep -E -e '^([^\sm]+m)?'"$val" -e '\s.*'"$val");
if (( ${#commits[@]} > 1 )); then
echoerr "Multiple possible commits found:";
for commit in "${commits[@]}";
Expand Down
37 changes: 6 additions & 31 deletions bin/git_log_oneline
Original file line number Diff line number Diff line change
@@ -1,33 +1,8 @@
#!/usr/bin/env bash





echo ${COLOR_GREY}git log --oneline $(git_log_range "$1")$COLOR_RESET 1>&2;
commits_in_origin=$(echo $(git log --format="%h" $(git merge-base --fork-point $(git_main_base_branch)) 2>/dev/null));
# local commits_in_origin=$(echo -e $(git log --format="%h" $(git_log_range "$1" HEAD) 2>/dev/null))
commit_in_origin_condition='index("'$commits_in_origin'", $2) > 0';
git log --reverse --format="%b%n§%h§%s§%cr" | awk -F'§' '{
if ($0 ~ "^$") {
# do nothing
} else if ($1 != "" ) {
body = body " " $1
} else {
if('"$commit_in_origin_condition"') {
printf "%s", "'$COLOR_AQUA'"
} else {
printf "%s", "'$COLOR_GREEN'"
}
printf "%s%s%s%s%s", $2, " '$COLOR_RESET'", $3, " '$COLOR_LOWLIGHT", $4
if (body != "") {
gsub("\r", "", body)
printf "%s%s", "'$COLOR_GREY''$COLOR_LOWLIGHT'", body
}
body=""
print "'$COLOR_RESET'"
}
}'
git --no-pager \
log \
--color \
--reverse \
--format='%h%Creset%Cred%Cgreen%Cblue%Creset%(decorate) %s %C(dim)%cr - %cn%Creset' \
"$@" | git_log_oneline_process
3 changes: 0 additions & 3 deletions bin/git_log_oneline_new

This file was deleted.

2 changes: 0 additions & 2 deletions bin/git_log_oneline_new_2

This file was deleted.

61 changes: 36 additions & 25 deletions bin/git_log_oneline_process
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#!/usr/bin/env ruby --disable-all

if ARGV.delete('--off')
while gets
puts $_
end
exit 0
end
# frozen_string_literal: true

# rubocop:disable Style/SpecialGlobalVars

def branch_exist?(branch)
(
Expand All @@ -27,38 +24,52 @@ def current_branch_main?
main_branch == current_branch
end

$forks = {
magenta: 'upstream/HEAD',
blue: (branch_exist?('origin/HEAD') ? 'origin/HEAD' : main_branch),
cyan: ('@{u}' unless current_branch_main?)
}
def forks
@forks ||= {
magenta: 'upstream/HEAD',
blue: (branch_exist?('origin/HEAD') ? 'origin/HEAD' : main_branch),
cyan: ('@{u}' unless current_branch_main?),
green: 'HEAD'
}.select { |_, v| branch_exist?(v) }
end

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

gets
exit 0 unless $_
sha, rest = $_.split("\e", 2)
line = $_
exit 0 unless line
sha, rest = next_line_split(line)
first = `git rev-parse --short #{sha}^ 2>/dev/null`.chomp
first = first.empty? ? '' : "#{first}.."
$forks.transform_values! do |v|
forks.transform_values! do |v|
`git log --format=%h #{first}#{v}`.chomp.split("\n").to_h { |k| [k, nil] }
end
def render(sha, rest)
color = if $forks[:magenta]&.key?(sha)

def render(sha, rest) # rubocop:disable Metrics
color = if forks[:magenta]&.key?(sha)
"\e[35m"
elsif $forks[:blue]&.key?(sha)
elsif forks[:blue]&.key?(sha)
"\e[34m"
elsif $forks[:cyan]&.key?(sha)
elsif forks[:cyan]&.key?(sha)
"\e[36m"
else
elsif forks[:green]&.key?(sha)
"\e[32m"
end
"#{color}#{sha}\e#{rest.chomp}\e[0m"
"#{color}#{sha}\e[m#{rest.chomp}\e[0m"
end
print "\x1b[?7l"
print render(sha, rest)

print "\e[?7l" # disable line wrap
print render(sha.chomp, rest)

while gets
puts
print render(*$_.split("\e", 2))
sha, rest = next_line_split($_)
print render(sha.chomp, rest.to_s)
end
puts "\x1b[?7h"

puts "\e[?7h" # reenable line wrap

# rubocop:enable Style/SpecialGlobalVars
2 changes: 1 addition & 1 deletion bin/git_rebase_onto
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

cat $(git rev-parse --git-path rebase-merge/onto) $(git rev-parse --git-path rebase-apply/onto) 2> /dev/null
cat $(git rev-parse --git-path rebase-merge/onto) $(git rev-parse --git-path rebase-apply/onto) 2> /dev/null
4 changes: 2 additions & 2 deletions bin/rtr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

rt --failure-exit-code 2 "$@";
[[ "$?" != "1" ]] && rtr "$@"
rt --failure-exit-code 2 "$@";
[[ "$?" != "1" ]] && rtr "$@"
4 changes: 3 additions & 1 deletion bin/strip_color
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env bash

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

0 comments on commit 3a03997

Please sign in to comment.