diff options
| author | Johannes Altmanninger <aclopte@gmail.com> | 2025-01-26 08:37:12 +0100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2025-02-10 11:58:42 +1100 |
| commit | 0a4bea856fe6ddd6420d6d7141b20eed8fe0bd25 (patch) | |
| tree | 585fbf970486fc9a3f70b83516b274089dc9dc73 | |
| parent | 22b461c3a0b22dd4501943230f0774c34f0b4b35 (diff) | |
Format blamed commit timestamps using the original time zone
Surprisingly, these two commands show different commit times:
git blame README.asciidoc
kak -e 'git blame' README.asciidoc
This is because git shows times as of the original time zone (of the
author/committer). Our blame integration uses the current local time.
- blame-jump displays the date in the status line of a git-show buffer
This date may be inconsistent with the buffer's "Date:" header,
so this seems surprising. Fix that. This fixes a test in some
time zones.
- Unlike "git blame", our ":git blame" does not display time zone
info by default. So, the conversion to localtime might make sense.
I don't really have an opinion on this. Change it too I guess,
since the current behavior might not have been intended.
Fixes #5285
| -rw-r--r-- | rc/tools/git.kak | 16 | ||||
| -rw-r--r-- | test/tools/git/blame-jump-message/script | 2 |
2 files changed, 15 insertions, 3 deletions
diff --git a/rc/tools/git.kak b/rc/tools/git.kak index cf2f7319..5b46d2d8 100644 --- a/rc/tools/git.kak +++ b/rc/tools/git.kak @@ -308,6 +308,7 @@ define-command -params 1.. \ set-option buffer=$kak_bufname git_blame '' }" | kak -p ${kak_session} if ! stderr=$({ git blame --incremental "$@" <${blame_stdin} | perl -wne ' + BEGIN { use POSIX qw(strftime); sub quote { my $SQ = "'\''"; @@ -341,6 +342,7 @@ define-command -params 1.. \ $raw_blame = ""; $last_sent = $now; } + } $raw_blame .= $_; chomp; if (m/^([0-9a-f]+) ([0-9]+) ([0-9]+) ([0-9]+)/) { @@ -356,7 +358,12 @@ define-command -params 1.. \ $authors{$sha} = substr($_,7); $authors{$sha} = "Not Committed Yet" if $authors{$sha} eq "External file (--contents)"; } - if (m/^author-time ([0-9]*)/) { $dates{$sha} = strftime("%F %T", localtime $1) } + if (m/^author-time ([0-9]*)/) { $author_time = $1; } + if (m/^author-tz ([+-])(\d\d)/) { + my $sign = $1 eq "+" ? "-" : "+"; + local $ENV{"TZ"} = "UTC${sign}$2"; + $dates{$sha} = strftime("%F %T", localtime $author_time); + } END { send_flags(1); }' } 2>&1); then escape2() { printf %s "$*" | sed "s/'/''''/g"; } @@ -683,7 +690,12 @@ define-command -params 1.. \ } if (m/^filename /) { $old_filenames{$sha} = substr($_,9) } if (m/^author /) { $authors{$sha} = substr($_,7) } - if (m/^author-time ([0-9]*)/) { $dates{$sha} = strftime("%F", localtime $1) } + if (m/^author-time ([0-9]*)/) { $author_time = $1; } + if (m/^author-tz ([+-])(\d\d)/) { + my $sign = $1 eq "+" ? "-" : "+"; + local $ENV{"TZ"} = "UTC${sign}$2"; + $dates{$sha} = strftime("%F", localtime $author_time); + } if (m/^summary /) { $summaries{$sha} = substr($_,8) } END { if (@blame_index and not defined $target_in_blame) { diff --git a/test/tools/git/blame-jump-message/script b/test/tools/git/blame-jump-message/script index 92b1f670..daf5e48c 100644 --- a/test/tools/git/blame-jump-message/script +++ b/test/tools/git/blame-jump-message/script @@ -1,5 +1,5 @@ expected_subject=$(cat <<'EOF' -2017-07-14 A U Thor "Don't break on single quotes or unbalanced {" +2017-07-13 A U Thor "Don't break on single quotes or unbalanced {" EOF ) expected_subject_json=\"$(printf '%s' "$expected_subject" | sed 's/"/\\"/g')\" |
