Skip to content

Commit

Permalink
Replace the proposed 'auto' mode with 'auto:'
Browse files Browse the repository at this point in the history
In addition to adding the 'human' format, the patch added the auto
keyword which could be used in the config file as an alternate way to
specify the human format.  Removing 'auto' cleans up the 'human'
format interface.

Added the ability to specify mode 'foo' if the pager is being used by
using auto:foo syntax.  Therefore, 'auto:human' date mode defaults to
human if we're using the pager.  So you can do

	git config --add log.date auto:human

and your "git log" commands will show the human-legible format unless
you're scripting things.

Signed-off-by: Stephen P. Smith <ischis2@cox.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Stephen P. Smith authored and gitster committed Jan 22, 2019
1 parent acdd377 commit 2fd7c22
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions date.c
Original file line number Diff line number Diff line change
Expand Up @@ -883,11 +883,6 @@ int parse_date(const char *date, struct strbuf *result)
return 0;
}

static int auto_date_style(void)
{
return (isatty(1) || pager_in_use()) ? DATE_HUMAN : DATE_NORMAL;
}

static enum date_mode_type parse_date_type(const char *format, const char **end)
{
if (skip_prefix(format, "relative", end))
Expand All @@ -907,8 +902,6 @@ static enum date_mode_type parse_date_type(const char *format, const char **end)
return DATE_NORMAL;
if (skip_prefix(format, "human", end))
return DATE_HUMAN;
if (skip_prefix(format, "auto", end))
return auto_date_style();
if (skip_prefix(format, "raw", end))
return DATE_RAW;
if (skip_prefix(format, "unix", end))
Expand All @@ -923,6 +916,14 @@ void parse_date_format(const char *format, struct date_mode *mode)
{
const char *p;

/* "auto:foo" is "if tty/pager, then foo, otherwise normal" */
if (skip_prefix(format, "auto:", &p)) {
if (isatty(1) || pager_in_use())
format = p;
else
format = "default";
}

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

0 comments on commit 2fd7c22

Please sign in to comment.