summaryrefslogtreecommitdiff
path: root/rc/tools
diff options
context:
space:
mode:
authorJohannes Altmanninger <aclopte@gmail.com>2024-02-25 17:51:13 +0100
committerMaxime Coste <mawww@kakoune.org>2024-02-26 19:08:58 +1100
commit8a7641284cb6bbc614cd2088f78d6a7f03e49b99 (patch)
tree107aef01651f235fdba08f0079f4be754395fe1b /rc/tools
parent03bea7ced428beeda72186eecc50f9a8ce6f4f2b (diff)
rc git: hide blame and report error if git blame fails
Similar to the previous patch, when git blame fails it usually means that the blamed file is not tracked by Git. I don't know of other common failure scenarios. Since git blame runs in detached process, failure handling is a bit more involved. Let's forward stderr to the debug buffer and escalate the error. I'm not sure how to get the exit code from git blame in "git blame | perl" - we can't use $PIPESTATUS. As a workaround, interpret empty output as failure. In case of failure, also hide blame; this makes the UI more consistent I think.
Diffstat (limited to 'rc/tools')
-rw-r--r--rc/tools/git.kak26
1 files changed, 22 insertions, 4 deletions
diff --git a/rc/tools/git.kak b/rc/tools/git.kak
index 8c6808fa..ff8df616 100644
--- a/rc/tools/git.kak
+++ b/rc/tools/git.kak
@@ -289,7 +289,7 @@ define-command -params 1.. \
set-option buffer=$kak_bufname git_blame_index '$kak_timestamp'
set-option buffer=$kak_bufname git_blame ''
}" | kak -p ${kak_session}
- git blame --incremental "$@" <${contents_fifo} | perl -wne '
+ if ! stderr=$({ git blame --incremental "$@" <${contents_fifo} | perl -wne '
use POSIX qw(strftime);
sub quote {
my $SQ = "'\''";
@@ -298,8 +298,11 @@ define-command -params 1.. \
return "$SQ$token$SQ";
}
sub send_flags {
- my $flush = shift;
- if (not defined $line) { return; }
+ my $is_last_call = shift;
+ if (not defined $line) {
+ if ($is_last_call) { exit 1; }
+ return;
+ }
my $text = substr($sha,0,7) . " " . $dates{$sha} . " " . $authors{$sha};
$text =~ s/~/~~/g;
for ( my $i = 0; $i < $count; $i++ ) {
@@ -307,7 +310,7 @@ define-command -params 1.. \
}
$now = time();
# Send roughly one update per second, to avoid creating too many kak processes.
- if (!$flush && defined $last_sent && $now - $last_sent < 1) {
+ if (!$is_last_call && defined $last_sent && $now - $last_sent < 1) {
return
}
open CMD, "|-", "kak -p $ENV{kak_session}";
@@ -337,6 +340,21 @@ define-command -params 1.. \
}
if (m/^author-time ([0-9]*)/) { $dates{$sha} = strftime("%F %T", localtime $1) }
END { send_flags(1); }'
+ } 2>&1); then
+ escape2() { printf %s "$*" | sed "s/'/''''/g"; }
+ echo "evaluate-commands -client ${kak_client} '
+ evaluate-commands -draft %{
+ buffer %{${kak_buffile}}
+ git hide-blame
+ }
+ echo -debug failed to run git blame
+ echo -debug git stderr: <<<
+ echo -debug ''$(escape2 "$stderr")>>>''
+ hook -once buffer NormalIdle .* %{
+ echo -markup %{{Error}failed to run git blame, see *debug* buffer}
+ }
+ '" | kak -p ${kak_session}
+ fi
if [ "$contents_fifo" != /dev/null ]; then
rm -r $(dirname $contents_fifo)
fi