mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-29 10:02:57 +03:00
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.
This commit is contained in:
parent
03bea7ced4
commit
8a7641284c
@ -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_index '$kak_timestamp'
|
||||||
set-option buffer=$kak_bufname git_blame ''
|
set-option buffer=$kak_bufname git_blame ''
|
||||||
}" | kak -p ${kak_session}
|
}" | kak -p ${kak_session}
|
||||||
git blame --incremental "$@" <${contents_fifo} | perl -wne '
|
if ! stderr=$({ git blame --incremental "$@" <${contents_fifo} | perl -wne '
|
||||||
use POSIX qw(strftime);
|
use POSIX qw(strftime);
|
||||||
sub quote {
|
sub quote {
|
||||||
my $SQ = "'\''";
|
my $SQ = "'\''";
|
||||||
@ -298,8 +298,11 @@ define-command -params 1.. \
|
|||||||
return "$SQ$token$SQ";
|
return "$SQ$token$SQ";
|
||||||
}
|
}
|
||||||
sub send_flags {
|
sub send_flags {
|
||||||
my $flush = shift;
|
my $is_last_call = shift;
|
||||||
if (not defined $line) { return; }
|
if (not defined $line) {
|
||||||
|
if ($is_last_call) { exit 1; }
|
||||||
|
return;
|
||||||
|
}
|
||||||
my $text = substr($sha,0,7) . " " . $dates{$sha} . " " . $authors{$sha};
|
my $text = substr($sha,0,7) . " " . $dates{$sha} . " " . $authors{$sha};
|
||||||
$text =~ s/~/~~/g;
|
$text =~ s/~/~~/g;
|
||||||
for ( my $i = 0; $i < $count; $i++ ) {
|
for ( my $i = 0; $i < $count; $i++ ) {
|
||||||
@ -307,7 +310,7 @@ define-command -params 1.. \
|
|||||||
}
|
}
|
||||||
$now = time();
|
$now = time();
|
||||||
# Send roughly one update per second, to avoid creating too many kak processes.
|
# 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
|
return
|
||||||
}
|
}
|
||||||
open CMD, "|-", "kak -p $ENV{kak_session}";
|
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) }
|
if (m/^author-time ([0-9]*)/) { $dates{$sha} = strftime("%F %T", localtime $1) }
|
||||||
END { send_flags(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
|
if [ "$contents_fifo" != /dev/null ]; then
|
||||||
rm -r $(dirname $contents_fifo)
|
rm -r $(dirname $contents_fifo)
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user