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
This commit is contained in:
Junio C Hamano 2016-09-08 21:35:52 -07:00
Родитель 7f5885ad2a 442f6fd3d6
Коммит f59c6e6ccb
6 изменённых файлов: 57 добавлений и 10 удалений

Просмотреть файл

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

Просмотреть файл

@ -252,10 +252,25 @@ list.
+
With `--pretty` format other than `oneline` (for obvious reasons),
this causes the output to have two extra lines of information
taken from the reflog. By default, 'commit@\{Nth}' notation is
used in the output. When the starting commit is specified as
'commit@\{now}', output also uses 'commit@\{timestamp}' notation
instead. Under `--pretty=oneline`, the commit message is
taken from the reflog. The reflog designator in the output may be shown
as `ref@{Nth}` (where `Nth` is the reverse-chronological index in the
reflog) or as `ref@{timestamp}` (with the timestamp for that entry),
depending on a few rules:
+
--
1. If the starting point is specified as `ref@{Nth}`, show the index
format.
+
2. If the starting point was specified as `ref@{now}`, show the
timestamp format.
+
3. If neither was used, but `--date` was given on the command line, show
the timestamp in the format requested by `--date`.
+
4. Otherwise, show the index format.
--
+
Under `--pretty=oneline`, the commit message is
prefixed with this information on the same line.
This option cannot be combined with `--reverse`.
See also linkgit:git-reflog[1].
@ -710,8 +725,8 @@ include::pretty-options.txt[]
`iso-local`), the user's local time zone is used instead.
+
`--date=relative` shows dates relative to the current time,
e.g. ``2 hours ago''. The `-local` option cannot be used with
`--raw` or `--relative`.
e.g. ``2 hours ago''. The `-local` option has no effect for
`--date=relative`.
+
`--date=local` is an alias for `--date=default-local`.
+
@ -731,7 +746,18 @@ format, often found in email messages.
+
`--date=short` shows only the date, but not the time, in `YYYY-MM-DD` format.
+
`--date=raw` shows the date in the internal raw Git format `%s %z` format.
`--date=raw` shows the date as seconds since the epoch (1970-01-01
00:00:00 UTC), followed by a space, and then the timezone as an offset
from UTC (a `+` or `-` with four digits; the first two are hours, and
the second two are minutes). I.e., as if the timestamp were formatted
with `strftime("%s %z")`).
Note that the `-local` option does not affect the seconds-since-epoch
value (which is always measured in UTC), but does switch the accompanying
timezone value.
+
`--date=unix` shows the date as a Unix epoch timestamp (seconds since
1970). As with `--raw`, this is always in UTC and therefore `-local`
has no effect.
+
`--date=format:...` feeds the format `...` to your system `strftime`.
Use `--date=format:%c` to show the date in your system locale's

Просмотреть файл

@ -2633,6 +2633,9 @@ parse_done:
case DATE_RAW:
blame_date_width = sizeof("1161298804 -0700");
break;
case DATE_UNIX:
blame_date_width = sizeof("1161298804");
break;
case DATE_SHORT:
blame_date_width = sizeof("2006-10-19");
break;

Просмотреть файл

@ -1224,7 +1224,8 @@ struct date_mode {
DATE_ISO8601_STRICT,
DATE_RFC2822,
DATE_STRFTIME,
DATE_RAW
DATE_RAW,
DATE_UNIX
} type;
const char *strftime_fmt;
int local;

8
date.c
Просмотреть файл

@ -177,6 +177,12 @@ const char *show_date(unsigned long time, int tz, const struct date_mode *mode)
struct tm *tm;
static struct strbuf timebuf = STRBUF_INIT;
if (mode->type == DATE_UNIX) {
strbuf_reset(&timebuf);
strbuf_addf(&timebuf, "%lu", time);
return timebuf.buf;
}
if (mode->local)
tz = local_tzoffset(time);
@ -792,6 +798,8 @@ static enum date_mode_type parse_date_type(const char *format, const char **end)
return DATE_NORMAL;
if (skip_prefix(format, "raw", end))
return DATE_RAW;
if (skip_prefix(format, "unix", end))
return DATE_UNIX;
if (skip_prefix(format, "format", end))
return DATE_STRFTIME;

Просмотреть файл

@ -46,7 +46,10 @@ check_show rfc2822 "$TIME" 'Wed, 15 Jun 2016 16:13:20 +0200'
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 iso-local "$TIME" '2016-06-15 14:13:20 +0000'
check_show raw-local "$TIME" '1466000000 +0000'
check_show unix-local "$TIME" '1466000000'
# arbitrary time absurdly far in the future
FUTURE="5758122296 -0400"