git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: "Stephen P. Smith" <ischis2@cox.net>
Cc: git@vger.kernel.org,
	"Linus Torvalds" <torvalds@linux-foundation.org>,
	"Junio C Hamano" <gitster@pobox.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: Re: [PATCH 1/3] Add 'human' date format
Date: Fri, 4 Jan 2019 02:50:35 -0500	[thread overview]
Message-ID: <20190104075034.GA26014@sigill.intra.peff.net> (raw)
In-Reply-To: <2637944.PqRbksyA0G@thunderbird>

On Thu, Jan 03, 2019 at 06:19:56AM -0700, Stephen P. Smith wrote:

> On Thursday, January 3, 2019 12:37:35 AM MST Jeff King wrote:
> > I like the idea of "human", and I like the idea of "auto", but it seems
> > to me that these are really two orthogonal things. E.g., might some
> > people not want to do something like:
> > 
> >   git config log.date auto:relative
> I didn't see anything in the code which would prohibit setting something like 
> that.

Yeah, I don't think supporting that is too hard. I was thinking
something like this:

diff --git a/date.c b/date.c
index 4486c028ac..f731803872 100644
--- a/date.c
+++ b/date.c
@@ -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))
@@ -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))
@@ -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";

That removes "auto" completely. We could still support it as an alias
for "auto:human" with something like:

  if (!strcmp(format, "auto"))
	format = "auto:human";

but IMHO it is a simpler interface to just have the user be explicit
(this is meant to be set once in config, after all).

> > I don't personally care about using this myself, but we already had to
> > deal with retrofitting "local" as a modifier. I'd prefer to avoid making
> > the same mistake again.
> Since I wasn't involved could you summarize the you are referring to?

The format "local" was a variant of "default" that would use the local
timezone instead of the author's. But there was no way to format, say,
iso8601 in the local timezone. So we had to invent a new syntax that was
compatible ("iso8601-local"), and keep "local" around forever for
backwards compatibility. Not the end of the world, but we can avoid it
in this case with a little preparation.

> > (I'd actually argue that "log.date" should basically _always_ have the
> > "auto" behavior, since it tends to get treated as plumbing anyway, and I
> > suspect that anybody who sets log.date now would see subtle breakage
> > from scripts. But maybe it's too late at this point?).
> If auto isn't added to the "log.date" file, then the date behaviour is not 
> changed from is currently in the code base.   Therefore, there shouldn't be 
> any breakage.

Right, this isn't a problem with your patches. I mean that the existing
"log.date" is arguably mis-designed, and we ought to have had something
like "auto" from day one (or even made it the default for log.date).

-Peff

  reply	other threads:[~2019-01-04  7:50 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-31  0:31 [PATCH 0/3] Add 'human' date format Stephen P. Smith
2018-12-31  0:31 ` [PATCH 1/3] " Stephen P. Smith
2019-01-03  7:37   ` Jeff King
2019-01-03 13:19     ` Stephen P. Smith
2019-01-04  7:50       ` Jeff King [this message]
2019-01-04 13:03         ` Stephen P Smith
2019-01-06  6:19           ` Jeff King
2018-12-31  0:31 ` [PATCH 2/3] Add 'human' date format documentation Stephen P. Smith
2018-12-31  0:31 ` [PATCH 3/3] t0006-date.sh: add `human` date format tests Stephen P. Smith
2019-01-02 18:15   ` Junio C Hamano
2019-01-03  2:36     ` Stephen & Linda Smith
2019-01-03  6:42       ` Junio C Hamano
2019-01-03 13:20         ` Stephen P. Smith
2019-01-03 21:14     ` Philip Oakley
2019-01-03 21:45       ` Junio C Hamano
2019-01-03 23:57         ` Stephen P. Smith
2019-01-03  7:44   ` Jeff King
2019-01-03 13:12     ` Stephen & Linda Smith
2019-01-08 21:27   ` Johannes Sixt
2019-01-09  0:44     ` Stephen P. Smith
2019-01-09  6:58       ` Johannes Sixt
2019-01-10  1:50         ` Stephen & Linda Smith
2019-01-18  6:18 ` [PATCH v2 0/5] Re-roll of 'human' date format patch set Stephen P. Smith
2019-01-18  6:18   ` [PATCH v2 1/5] Add 'human' date format Stephen P. Smith
2019-01-18  6:18   ` [PATCH v2 2/5] Remove the proposed use of auto as secondary way to specify human Stephen P. Smith
2019-01-18 18:35     ` Junio C Hamano
2019-01-19  3:44       ` Stephen & Linda Smith
2019-01-18  6:18   ` [PATCH v2 3/5] Add 'human' date format documentation Stephen P. Smith
2019-01-18 18:47     ` Junio C Hamano
2019-01-18  6:18   ` [PATCH v2 4/5] Add `human` format to test-tool Stephen P. Smith
2019-01-18 19:03     ` Junio C Hamano
2019-01-20 22:11       ` Stephen P. Smith
2019-01-22 18:29         ` Junio C Hamano
2019-01-18  6:18   ` [PATCH v2 5/5] Add `human` date format tests Stephen P. Smith
2019-01-18 19:24     ` Junio C Hamano
2019-01-21  5:31   ` [PATCH v3 0/5] Re-roll of 'human' date format patch set Stephen P. Smith
2019-01-21  5:31     ` [PATCH v3 1/5] Add 'human' date format Stephen P. Smith
2019-01-21  5:31     ` [PATCH v3 2/5] Replace the proposed 'auto' mode with 'auto:' Stephen P. Smith
2019-01-21  5:31     ` [PATCH v3 3/5] Add 'human' date format documentation Stephen P. Smith
2019-01-21  5:31     ` [PATCH v3 4/5] Add `human` format to test-tool Stephen P. Smith
2019-01-22 22:34       ` Junio C Hamano
2019-01-21  5:31     ` [PATCH v3 5/5] Add `human` date format tests Stephen P. Smith
2019-01-29  3:50     ` [PATCH v4 0/5] Re-roll of 'human' date format patch set Stephen P. Smith
2019-01-29  3:50       ` [PATCH v4 1/5] Add 'human' date format Stephen P. Smith
2019-01-29  3:50       ` [PATCH v4 2/5] Replace the proposed 'auto' mode with 'auto:' Stephen P. Smith
2019-01-29  3:50       ` [PATCH v4 3/5] Add 'human' date format documentation Stephen P. Smith
2019-01-29  3:50       ` [PATCH v4 4/5] Add `human` format to test-tool Stephen P. Smith
2019-01-29  3:50       ` [PATCH v4 5/5] Add `human` date format tests Stephen P. Smith
2019-01-21  5:16 ` [PATCH v3 0/5] Re-roll of 'human' date format patch set Stephen P. Smith
2019-01-21  5:16   ` [PATCH v3 1/5] Add 'human' date format Stephen P. Smith
2019-01-21  5:16   ` [PATCH v3 2/5] Replace the proposed 'auto' mode with 'auto:' Stephen P. Smith
2019-01-21  5:16   ` [PATCH v3 3/5] Add 'human' date format documentation Stephen P. Smith
2019-01-21  5:16   ` [PATCH v3 4/5] Add `human` format to test-tool Stephen P. Smith
2019-01-21  5:16   ` [PATCH v3 5/5] Add `human` date format tests Stephen P. Smith
2019-01-21 15:04     ` SZEDER Gábor
2019-01-22  0:53       ` Stephen & Linda Smith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190104075034.GA26014@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=ischis2@cox.net \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).