Skip to content

Commit

Permalink
Merge branch 'jk/date-local'
Browse files Browse the repository at this point in the history
"git log --date=local" used to only show the normal (default)
format in the local timezone.  The command learned to take 'local'
as an instruction to use the local timezone with other formats,
e.g. "git show --date=rfc-local".

* jk/date-local:
  t6300: add tests for "-local" date formats
  t6300: make UTC and local dates different
  date: make "local" orthogonal to date format
  date: check for "local" before anything else
  t6300: add test for "raw" date format
  t6300: introduce test_date() helper
  fast-import: switch crash-report date to iso8601
  Documentation/rev-list: don't list date formats
  Documentation/git-for-each-ref: don't list date formats
  Documentation/config: don't list date formats
  Documentation/blame-options: don't list date formats
  • Loading branch information
Junio C Hamano committed Oct 5, 2015
2 parents 297ae71 + 99264e9 commit 7b09c45
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 114 deletions.
5 changes: 2 additions & 3 deletions Documentation/blame-options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ include::line-range-format.txt[]
`-` to make the command read from the standard input).

--date <format>::
The value is one of the following alternatives:
{relative,local,default,iso,rfc,short}. If --date is not
Specifies the format used to output dates. If --date is not
provided, the value of the blame.date config variable is
used. If the blame.date config variable is also not set, the
iso format is used. For more information, See the discussion
iso format is used. For supported values, see the discussion
of the --date option at linkgit:git-log[1].

-M|<num>|::
Expand Down
4 changes: 1 addition & 3 deletions Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1829,9 +1829,7 @@ log.abbrevCommit::
log.date::
Set the default date-time mode for the 'log' command.
Setting a value for log.date is similar to using 'git log''s
`--date` option. Possible values are `relative`, `local`,
`default`, `iso`, `rfc`, and `short`; see linkgit:git-log[1]
for details.
`--date` option. See linkgit:git-log[1] for details.

log.decorate::
Print out the ref names of any commits that are shown by the log
Expand Down
5 changes: 2 additions & 3 deletions Documentation/git-for-each-ref.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,8 @@ the object referred by the ref does not cause an error. It
returns an empty string instead.

As a special case for the date-type fields, you may specify a format for
the date by adding one of `:default`, `:relative`, `:short`, `:local`,
`:iso8601`, `:rfc2822` or `:raw` to the end of the fieldname; e.g.
`%(taggerdate:relative)`.
the date by adding `:` followed by date format name (see the
values the `--date` option to linkgit::git-rev-list[1] takes).


EXAMPLES
Expand Down
2 changes: 1 addition & 1 deletion Documentation/git-rev-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ SYNOPSIS
[ --regexp-ignore-case | -i ]
[ --extended-regexp | -E ]
[ --fixed-strings | -F ]
[ --date=(local|relative|default|iso|iso-strict|rfc|short) ]
[ --date=<format>]
[ [ --objects | --objects-edge | --objects-edge-aggressive ]
[ --unpacked ] ]
[ --pretty | --header ]
Expand Down
23 changes: 16 additions & 7 deletions Documentation/rev-list-options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -701,15 +701,19 @@ include::pretty-options.txt[]
--relative-date::
Synonym for `--date=relative`.

--date=(relative|local|default|iso|iso-strict|rfc|short|raw)::
--date=<format>::
Only takes effect for dates shown in human-readable format, such
as when using `--pretty`. `log.date` config variable sets a default
value for the log command's `--date` option.
value for the log command's `--date` option. By default, dates
are shown in the original time zone (either committer's or
author's). If `-local` is appended to the format (e.g.,
`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''.
e.g. ``2 hours ago''. The `-local` option cannot be used with
`--raw` or `--relative`.
+
`--date=local` shows timestamps in user's local time zone.
`--date=local` is an alias for `--date=default-local`.
+
`--date=iso` (or `--date=iso8601`) shows timestamps in a ISO 8601-like format.
The differences to the strict ISO 8601 format are:
Expand All @@ -732,10 +736,15 @@ format, often found in email messages.
`--date=format:...` feeds the format `...` to your system `strftime`.
Use `--date=format:%c` to show the date in your system locale's
preferred format. See the `strftime` manual for a complete list of
format placeholders.
format placeholders. When using `-local`, the correct syntax is
`--date=format-local:...`.
+
`--date=default` shows timestamps in the original time zone
(either committer's or author's).
`--date=default` is the default format, and is similar to
`--date=rfc2822`, with a few exceptions:

- there is no comma after the day-of-week

- the time zone is omitted when the local time zone is used

ifdef::git-rev-list[]
--header::
Expand Down
1 change: 0 additions & 1 deletion builtin/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -2600,7 +2600,6 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
fewer display columns. */
blame_date_width = utf8_strwidth(_("4 years, 11 months ago")) + 1; /* add the null */
break;
case DATE_LOCAL:
case DATE_NORMAL:
blame_date_width = sizeof("Thu Oct 19 16:00:04 2006 -0700");
break;
Expand Down
2 changes: 1 addition & 1 deletion cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -1091,14 +1091,14 @@ struct date_mode {
DATE_NORMAL = 0,
DATE_RELATIVE,
DATE_SHORT,
DATE_LOCAL,
DATE_ISO8601,
DATE_ISO8601_STRICT,
DATE_RFC2822,
DATE_STRFTIME,
DATE_RAW
} type;
const char *strftime_fmt;
int local;
};

/*
Expand Down
74 changes: 47 additions & 27 deletions date.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ struct date_mode *date_mode_from_type(enum date_mode_type type)
if (type == DATE_STRFTIME)
die("BUG: cannot create anonymous strftime date_mode struct");
mode.type = type;
mode.local = 0;
return &mode;
}

Expand All @@ -174,6 +175,9 @@ 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->local)
tz = local_tzoffset(time);

if (mode->type == DATE_RAW) {
strbuf_reset(&timebuf);
strbuf_addf(&timebuf, "%lu %+05d", time, tz);
Expand All @@ -189,9 +193,6 @@ const char *show_date(unsigned long time, int tz, const struct date_mode *mode)
return timebuf.buf;
}

if (mode->type == DATE_LOCAL)
tz = local_tzoffset(time);

tm = time_to_tm(time, tz);
if (!tm) {
tm = time_to_tm(0, 0);
Expand Down Expand Up @@ -232,7 +233,7 @@ const char *show_date(unsigned long time, int tz, const struct date_mode *mode)
tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec,
tm->tm_year + 1900,
(mode->type == DATE_LOCAL) ? 0 : ' ',
mode->local ? 0 : ' ',
tz);
return timebuf.buf;
}
Expand Down Expand Up @@ -770,31 +771,50 @@ int parse_date(const char *date, struct strbuf *result)
return 0;
}

static enum date_mode_type parse_date_type(const char *format, const char **end)
{
if (skip_prefix(format, "relative", end))
return DATE_RELATIVE;
if (skip_prefix(format, "iso8601-strict", end) ||
skip_prefix(format, "iso-strict", end))
return DATE_ISO8601_STRICT;
if (skip_prefix(format, "iso8601", end) ||
skip_prefix(format, "iso", end))
return DATE_ISO8601;
if (skip_prefix(format, "rfc2822", end) ||
skip_prefix(format, "rfc", end))
return DATE_RFC2822;
if (skip_prefix(format, "short", end))
return DATE_SHORT;
if (skip_prefix(format, "default", end))
return DATE_NORMAL;
if (skip_prefix(format, "raw", end))
return DATE_RAW;
if (skip_prefix(format, "format", end))
return DATE_STRFTIME;

die("unknown date format %s", format);
}

void parse_date_format(const char *format, struct date_mode *mode)
{
if (!strcmp(format, "relative"))
mode->type = DATE_RELATIVE;
else if (!strcmp(format, "iso8601") ||
!strcmp(format, "iso"))
mode->type = DATE_ISO8601;
else if (!strcmp(format, "iso8601-strict") ||
!strcmp(format, "iso-strict"))
mode->type = DATE_ISO8601_STRICT;
else if (!strcmp(format, "rfc2822") ||
!strcmp(format, "rfc"))
mode->type = DATE_RFC2822;
else if (!strcmp(format, "short"))
mode->type = DATE_SHORT;
else if (!strcmp(format, "local"))
mode->type = DATE_LOCAL;
else if (!strcmp(format, "default"))
mode->type = DATE_NORMAL;
else if (!strcmp(format, "raw"))
mode->type = DATE_RAW;
else if (skip_prefix(format, "format:", &format)) {
mode->type = DATE_STRFTIME;
mode->strftime_fmt = xstrdup(format);
} else
const char *p;

/* historical alias */
if (!strcmp(format, "local"))
format = "default-local";

mode->type = parse_date_type(format, &p);
mode->local = 0;

if (skip_prefix(p, "-local", &p))
mode->local = 1;

if (mode->type == DATE_STRFTIME) {
if (!skip_prefix(p, ":", &p))
die("date format missing colon separator: %s", format);
mode->strftime_fmt = xstrdup(p);
} else if (*p)
die("unknown date format %s", format);
}

Expand Down
2 changes: 1 addition & 1 deletion fast-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ static void write_crash_report(const char *err)
fprintf(rpt, "fast-import crash report:\n");
fprintf(rpt, " fast-import process: %"PRIuMAX"\n", (uintmax_t) getpid());
fprintf(rpt, " parent process : %"PRIuMAX"\n", (uintmax_t) getppid());
fprintf(rpt, " at %s\n", show_date(time(NULL), 0, DATE_MODE(LOCAL)));
fprintf(rpt, " at %s\n", show_date(time(NULL), 0, DATE_MODE(ISO8601)));
fputc('\n', rpt);

fputs("fatal: ", rpt);
Expand Down
Loading

0 comments on commit 7b09c45

Please sign in to comment.