From 5650bf33fa924f90ba5ac076cd763452315bc6b5 Mon Sep 17 00:00:00 2001 From: Qeole Date: Thu, 27 Jan 2022 23:06:00 +0000 Subject: [PATCH] rc git: Batch flags when passing commit info for "git blame" The wrapper for "git blame" creates flags for each line of the buffer. It parses the output from git and would send a flag (or a series of flags) each time the commit to blame for a line differs from the previous one. For files that were touched by a large number of commits, this results in a high number of kakoune processes being launched, and may take some time. This is visible in the session through the flags for the different commits appearing on the lines one by one, possibly during several seconds. To speed up the process, batch flags before passing them to the kak session. One solution could be to send all flags at once, but this might delay the appearance of commit info for too long if "git blame" really takes a long time. The alternative solution retained for this commit consists in grouping as many flags as we can during one second (roughly), to pass them to kakoune, and then to move on to the next flags. This way, a new batch of commit information flags appears every second or so in the client, until all information is added. This should be much faster than lauching a kakoune process for each commit reported by "git blame": tests have shown that blaming a large file in the Linux repository goes 4.5 times faster when batching flags. Co-authored-by: Johannes Altmanninger --- rc/tools/git.kak | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/rc/tools/git.kak b/rc/tools/git.kak index 0cd505d0..b7c82d96 100644 --- a/rc/tools/git.kak +++ b/rc/tools/git.kak @@ -109,21 +109,27 @@ define-command -params 1.. \ set-option buffer=$kak_bufname git_blame_flags '$kak_timestamp' }" | kak -p ${kak_session} git blame "$@" --incremental ${kak_buffile} | awk ' - function send_flags(text, flag, i) { + function send_flags(flush, text, i) { if (line == "") { return; } text=substr(sha,1,8) " " dates[sha] " " authors[sha] # gsub("|", "\\|", text) gsub("~", "~~", text) - flag="%~" line "|" text "~" - for ( i=1; i < count; i++ ) { - flag=flag " %~" line+i "|" text "~" + for ( i=0; i < count; i++ ) { + flags = flags " %~" line+i "|" text "~" + } + now = systime() + # Send roughly one update per second, to avoid creating too many kak processes. + if (!flush && now - last_sent < 1) { + return } cmd = "kak -p " ENVIRON["kak_session"] - print "set-option -add buffer=" ENVIRON["kak_bufname"] " git_blame_flags " flag | cmd + print "set-option -add buffer=" ENVIRON["kak_bufname"] " git_blame_flags " flags | cmd close(cmd) + flags = "" + last_sent = now } /^([0-9a-f]+) ([0-9]+) ([0-9]+) ([0-9]+)/ { - send_flags() + send_flags(0) sha=$1 line=$3 count=$4 @@ -134,7 +140,7 @@ define-command -params 1.. \ cmd | getline dates[sha] close(cmd) } - END { send_flags(); }' + END { send_flags(1); }' ) > /dev/null 2>&1 < /dev/null & }