feat(third_party/git): Support dottime as log date format
This commit is contained in:
parent
1ea6dcabbb
commit
dce1112842
3 changed files with 121 additions and 2 deletions
3
third_party/default.nix
vendored
3
third_party/default.nix
vendored
|
@ -41,7 +41,6 @@ let
|
||||||
fira-code
|
fira-code
|
||||||
fira-mono
|
fira-mono
|
||||||
gettext
|
gettext
|
||||||
git
|
|
||||||
glibc
|
glibc
|
||||||
gnutar
|
gnutar
|
||||||
go
|
go
|
||||||
|
@ -103,6 +102,6 @@ in exposed // {
|
||||||
|
|
||||||
# Packages to be overridden
|
# Packages to be overridden
|
||||||
originals = {
|
originals = {
|
||||||
inherit (nixpkgs) notmuch;
|
inherit (nixpkgs) git notmuch;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
6
third_party/git/default.nix
vendored
Normal file
6
third_party/git/default.nix
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{ pkgs, ... }:
|
||||||
|
|
||||||
|
pkgs.third_party.originals.git.overrideAttrs(old: {
|
||||||
|
doCheck = false;
|
||||||
|
patches = [ ./dottime.patch ] ++ (if old ? patches then old.patches else []);
|
||||||
|
})
|
114
third_party/git/dottime.patch
vendored
Normal file
114
third_party/git/dottime.patch
vendored
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
From 37628ffd977d8233ad02d482c5d70a0cf9719dce Mon Sep 17 00:00:00 2001
|
||||||
|
From: Vincent Ambo <tazjin@google.com>
|
||||||
|
Date: Sat, 28 Dec 2019 01:20:00 +0100
|
||||||
|
Subject: [PATCH] date: add "dottime" format
|
||||||
|
|
||||||
|
Adds dottime (as defined on https://dotti.me) as a timestamp format.
|
||||||
|
|
||||||
|
This format is designed to simplify working with timestamps across
|
||||||
|
many different timezones by keeping the timestamp format itself in
|
||||||
|
UTC (and indicating this with a dot), but appending the local offset.
|
||||||
|
---
|
||||||
|
Documentation/rev-list-options.txt | 3 +++
|
||||||
|
builtin/blame.c | 3 +++
|
||||||
|
cache.h | 3 ++-
|
||||||
|
date.c | 17 +++++++++++++++++
|
||||||
|
t/t0006-date.sh | 2 ++
|
||||||
|
5 files changed, 27 insertions(+), 1 deletion(-)
|
||||||
|
|
||||||
|
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
|
||||||
|
index bb1251c036..fa4e70f511 100644
|
||||||
|
--- a/Documentation/rev-list-options.txt
|
||||||
|
+++ b/Documentation/rev-list-options.txt
|
||||||
|
@@ -866,6 +866,9 @@ omitted.
|
||||||
|
1970). As with `--raw`, this is always in UTC and therefore `-local`
|
||||||
|
has no effect.
|
||||||
|
|
||||||
|
+`--date=dottime` shows the date in dottime format (rendered as UTC,
|
||||||
|
+but suffixed with the local timezone offset if given)
|
||||||
|
+
|
||||||
|
`--date=format:...` feeds the format `...` to your system `strftime`,
|
||||||
|
except for %z and %Z, which are handled internally.
|
||||||
|
Use `--date=format:%c` to show the date in your system locale's
|
||||||
|
diff --git a/builtin/blame.c b/builtin/blame.c
|
||||||
|
index b6534d4dea..7ebd51ae4d 100644
|
||||||
|
--- a/builtin/blame.c
|
||||||
|
+++ b/builtin/blame.c
|
||||||
|
@@ -989,6 +989,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
|
||||||
|
case DATE_STRFTIME:
|
||||||
|
blame_date_width = strlen(show_date(0, 0, &blame_date_mode)) + 1; /* add the null */
|
||||||
|
break;
|
||||||
|
+ case DATE_DOTTIME:
|
||||||
|
+ blame_date_width = sizeof("2006-10-19T15·00-0700");
|
||||||
|
+ break;
|
||||||
|
}
|
||||||
|
blame_date_width -= 1; /* strip the null */
|
||||||
|
|
||||||
|
diff --git a/cache.h b/cache.h
|
||||||
|
index b1da1ab08f..5695ec6439 100644
|
||||||
|
--- a/cache.h
|
||||||
|
+++ b/cache.h
|
||||||
|
@@ -1498,7 +1498,8 @@ enum date_mode_type {
|
||||||
|
DATE_RFC2822,
|
||||||
|
DATE_STRFTIME,
|
||||||
|
DATE_RAW,
|
||||||
|
- DATE_UNIX
|
||||||
|
+ DATE_UNIX,
|
||||||
|
+ DATE_DOTTIME
|
||||||
|
};
|
||||||
|
|
||||||
|
struct date_mode {
|
||||||
|
diff --git a/date.c b/date.c
|
||||||
|
index 8126146c50..6b7e18a75b 100644
|
||||||
|
--- a/date.c
|
||||||
|
+++ b/date.c
|
||||||
|
@@ -350,6 +350,21 @@ const char *show_date(timestamp_t time, int tz, const struct date_mode *mode)
|
||||||
|
tm->tm_mday,
|
||||||
|
tm->tm_hour, tm->tm_min, tm->tm_sec,
|
||||||
|
sign, tz / 100, tz % 100);
|
||||||
|
+ } else if (mode->type == DATE_DOTTIME) {
|
||||||
|
+ char sign = (tz >= 0) ? '+' : '-';
|
||||||
|
+ tz = abs(tz);
|
||||||
|
+
|
||||||
|
+ // Time is converted again without the timezone as the
|
||||||
|
+ // dottime format includes the zone only in offset
|
||||||
|
+ // position.
|
||||||
|
+ time_t t = gm_time_t(time, 0);
|
||||||
|
+ tm = gmtime(&t);
|
||||||
|
+ strbuf_addf(&timebuf, "%04d-%02d-%02dT%02d·%02d%c%02d%02d",
|
||||||
|
+ tm->tm_year + 1900,
|
||||||
|
+ tm->tm_mon + 1,
|
||||||
|
+ tm->tm_mday,
|
||||||
|
+ tm->tm_hour, tm->tm_min,
|
||||||
|
+ sign, tz / 100, tz % 100);
|
||||||
|
} else if (mode->type == DATE_RFC2822)
|
||||||
|
strbuf_addf(&timebuf, "%.3s, %d %.3s %d %02d:%02d:%02d %+05d",
|
||||||
|
weekday_names[tm->tm_wday], tm->tm_mday,
|
||||||
|
@@ -921,6 +936,8 @@ static enum date_mode_type parse_date_type(const char *format, const char **end)
|
||||||
|
return DATE_UNIX;
|
||||||
|
if (skip_prefix(format, "format", end))
|
||||||
|
return DATE_STRFTIME;
|
||||||
|
+ if (skip_prefix(format, "dottime", end))
|
||||||
|
+ return DATE_DOTTIME;
|
||||||
|
/*
|
||||||
|
* Please update $__git_log_date_formats in
|
||||||
|
* git-completion.bash when you add new formats.
|
||||||
|
diff --git a/t/t0006-date.sh b/t/t0006-date.sh
|
||||||
|
index d9fcc829a9..b723db1f76 100755
|
||||||
|
--- a/t/t0006-date.sh
|
||||||
|
+++ b/t/t0006-date.sh
|
||||||
|
@@ -49,9 +49,11 @@ check_show short "$TIME" '2016-06-15'
|
||||||
|
check_show default "$TIME" 'Wed Jun 15 16:13:20 2016 +0200'
|
||||||
|
check_show raw "$TIME" '1466000000 +0200'
|
||||||
|
check_show unix "$TIME" '1466000000'
|
||||||
|
+check_show dottime "$TIME" '2016-06-15T14·13+0200'
|
||||||
|
check_show iso-local "$TIME" '2016-06-15 14:13:20 +0000'
|
||||||
|
check_show raw-local "$TIME" '1466000000 +0000'
|
||||||
|
check_show unix-local "$TIME" '1466000000'
|
||||||
|
+check_show dottime-local "$TIME" '2016-06-15T14·13+0000'
|
||||||
|
|
||||||
|
check_show 'format:%z' "$TIME" '+0200'
|
||||||
|
check_show 'format-local:%z' "$TIME" '+0000'
|
||||||
|
--
|
||||||
|
2.24.1.735.g03f4e72817-goog
|
||||||
|
|
Loading…
Reference in a new issue