Skip to content

Commit f59c6e6

Browse files
committed
Merge branch 'jk/reflog-date' into maint
The reflog output format is documented better, and a new format --date=unix to report the seconds-since-epoch (without timezone) has been added. * jk/reflog-date: date: clarify --date=raw description date: add "unix" format date: document and test "raw-local" mode doc/pretty-formats: explain shortening of %gd doc/pretty-formats: describe index/time formats for %gd doc/rev-list-options: explain "-g" output formats doc/rev-list-options: clarify "commit@{Nth}" for "-g" option
2 parents 7f5885a + 442f6fd commit f59c6e6

File tree

6 files changed

+57
-10
lines changed

6 files changed

+57
-10
lines changed

Documentation/pretty-formats.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,14 @@ endif::git-rev-list[]
147147
"U" for a good signature with unknown validity and "N" for no signature
148148
- '%GS': show the name of the signer for a signed commit
149149
- '%GK': show the key used to sign a signed commit
150-
- '%gD': reflog selector, e.g., `refs/stash@{1}`
151-
- '%gd': shortened reflog selector, e.g., `stash@{1}`
150+
- '%gD': reflog selector, e.g., `refs/stash@{1}` or
151+
`refs/stash@{2 minutes ago`}; the format follows the rules described
152+
for the `-g` option. The portion before the `@` is the refname as
153+
given on the command line (so `git log -g refs/heads/master` would
154+
yield `refs/heads/master@{0}`).
155+
- '%gd': shortened reflog selector; same as `%gD`, but the refname
156+
portion is shortened for human readability (so `refs/heads/master`
157+
becomes just `master`).
152158
- '%gn': reflog identity name
153159
- '%gN': reflog identity name (respecting .mailmap, see
154160
linkgit:git-shortlog[1] or linkgit:git-blame[1])

Documentation/rev-list-options.txt

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,25 @@ list.
252252
+
253253
With `--pretty` format other than `oneline` (for obvious reasons),
254254
this causes the output to have two extra lines of information
255-
taken from the reflog. By default, 'commit@\{Nth}' notation is
256-
used in the output. When the starting commit is specified as
257-
'commit@\{now}', output also uses 'commit@\{timestamp}' notation
258-
instead. Under `--pretty=oneline`, the commit message is
255+
taken from the reflog. The reflog designator in the output may be shown
256+
as `ref@{Nth}` (where `Nth` is the reverse-chronological index in the
257+
reflog) or as `ref@{timestamp}` (with the timestamp for that entry),
258+
depending on a few rules:
259+
+
260+
--
261+
1. If the starting point is specified as `ref@{Nth}`, show the index
262+
format.
263+
+
264+
2. If the starting point was specified as `ref@{now}`, show the
265+
timestamp format.
266+
+
267+
3. If neither was used, but `--date` was given on the command line, show
268+
the timestamp in the format requested by `--date`.
269+
+
270+
4. Otherwise, show the index format.
271+
--
272+
+
273+
Under `--pretty=oneline`, the commit message is
259274
prefixed with this information on the same line.
260275
This option cannot be combined with `--reverse`.
261276
See also linkgit:git-reflog[1].
@@ -710,8 +725,8 @@ include::pretty-options.txt[]
710725
`iso-local`), the user's local time zone is used instead.
711726
+
712727
`--date=relative` shows dates relative to the current time,
713-
e.g. ``2 hours ago''. The `-local` option cannot be used with
714-
`--raw` or `--relative`.
728+
e.g. ``2 hours ago''. The `-local` option has no effect for
729+
`--date=relative`.
715730
+
716731
`--date=local` is an alias for `--date=default-local`.
717732
+
@@ -731,7 +746,18 @@ format, often found in email messages.
731746
+
732747
`--date=short` shows only the date, but not the time, in `YYYY-MM-DD` format.
733748
+
734-
`--date=raw` shows the date in the internal raw Git format `%s %z` format.
749+
`--date=raw` shows the date as seconds since the epoch (1970-01-01
750+
00:00:00 UTC), followed by a space, and then the timezone as an offset
751+
from UTC (a `+` or `-` with four digits; the first two are hours, and
752+
the second two are minutes). I.e., as if the timestamp were formatted
753+
with `strftime("%s %z")`).
754+
Note that the `-local` option does not affect the seconds-since-epoch
755+
value (which is always measured in UTC), but does switch the accompanying
756+
timezone value.
757+
+
758+
`--date=unix` shows the date as a Unix epoch timestamp (seconds since
759+
1970). As with `--raw`, this is always in UTC and therefore `-local`
760+
has no effect.
735761
+
736762
`--date=format:...` feeds the format `...` to your system `strftime`.
737763
Use `--date=format:%c` to show the date in your system locale's

builtin/blame.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2633,6 +2633,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
26332633
case DATE_RAW:
26342634
blame_date_width = sizeof("1161298804 -0700");
26352635
break;
2636+
case DATE_UNIX:
2637+
blame_date_width = sizeof("1161298804");
2638+
break;
26362639
case DATE_SHORT:
26372640
blame_date_width = sizeof("2006-10-19");
26382641
break;

cache.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,8 @@ struct date_mode {
12241224
DATE_ISO8601_STRICT,
12251225
DATE_RFC2822,
12261226
DATE_STRFTIME,
1227-
DATE_RAW
1227+
DATE_RAW,
1228+
DATE_UNIX
12281229
} type;
12291230
const char *strftime_fmt;
12301231
int local;

date.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ const char *show_date(unsigned long time, int tz, const struct date_mode *mode)
177177
struct tm *tm;
178178
static struct strbuf timebuf = STRBUF_INIT;
179179

180+
if (mode->type == DATE_UNIX) {
181+
strbuf_reset(&timebuf);
182+
strbuf_addf(&timebuf, "%lu", time);
183+
return timebuf.buf;
184+
}
185+
180186
if (mode->local)
181187
tz = local_tzoffset(time);
182188

@@ -792,6 +798,8 @@ static enum date_mode_type parse_date_type(const char *format, const char **end)
792798
return DATE_NORMAL;
793799
if (skip_prefix(format, "raw", end))
794800
return DATE_RAW;
801+
if (skip_prefix(format, "unix", end))
802+
return DATE_UNIX;
795803
if (skip_prefix(format, "format", end))
796804
return DATE_STRFTIME;
797805

t/t0006-date.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ check_show rfc2822 "$TIME" 'Wed, 15 Jun 2016 16:13:20 +0200'
4646
check_show short "$TIME" '2016-06-15'
4747
check_show default "$TIME" 'Wed Jun 15 16:13:20 2016 +0200'
4848
check_show raw "$TIME" '1466000000 +0200'
49+
check_show unix "$TIME" '1466000000'
4950
check_show iso-local "$TIME" '2016-06-15 14:13:20 +0000'
51+
check_show raw-local "$TIME" '1466000000 +0000'
52+
check_show unix-local "$TIME" '1466000000'
5053

5154
# arbitrary time absurdly far in the future
5255
FUTURE="5758122296 -0400"

0 commit comments

Comments
 (0)