All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Miles Bader <miles@gnu.org>
Cc: git@vger.kernel.org
Subject: Re: orthogonal cases of log --date option
Date: Tue, 03 Mar 2009 00:45:37 -0800	[thread overview]
Message-ID: <7vtz6bdmfi.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <buo8wnnrpcf.fsf@dhlpc061.dev.necel.com> (Miles Bader's message of "Tue, 03 Mar 2009 17:18:56 +0900")

Miles Bader <miles@gnu.org> writes:

> I can use "git log --date=iso" to get YYYY-MM-DD format for dates, or
> "git log --date=local" to force the dates to use my local time zone, but
> if I use _both_ of these options together, it uses only the last one,
> and ignores any preceding --date (even those in this case, the two
> --date options affect orthogonal properties of dates).  Is there a way
> to get YYYY-MM-DD format dates, but in my local time-zone?

No, there isn't.

But this patch may help you get started.

Just like any other patches I send out to only show a way to competent
people I can trust to carry it forward, it is not even compile tested,
though.

---
 builtin-for-each-ref.c |    2 +-
 builtin-log.c          |    2 +-
 cache.h                |   15 ++++++++-------
 date.c                 |   27 +++++++++++++++------------
 revision.c             |    2 +-
 5 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
index e46b7ad..3a9f64b 100644
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
@@ -361,7 +361,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam
 	formatp = strchr(atomname, ':');
 	if (formatp != NULL) {
 		formatp++;
-		date_mode = parse_date_format(formatp);
+		date_mode = parse_date_format(formatp, 0);
 	}
 
 	if (!eoemail)
diff --git a/builtin-log.c b/builtin-log.c
index 2ae39af..618922a 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -41,7 +41,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
 	DIFF_OPT_SET(&rev->diffopt, ALLOW_TEXTCONV);
 
 	if (default_date_mode)
-		rev->date_mode = parse_date_format(default_date_mode);
+		rev->date_mode = parse_date_format(default_date_mode, 0);
 
 	argc = setup_revisions(argc, argv, rev, "HEAD");
 
diff --git a/cache.h b/cache.h
index 189151d..a3ecf63 100644
--- a/cache.h
+++ b/cache.h
@@ -692,19 +692,20 @@ extern struct object *peel_to_type(const char *name, int namelen,
 
 enum date_mode {
 	DATE_NORMAL = 0,
-	DATE_RELATIVE,
-	DATE_SHORT,
-	DATE_LOCAL,
-	DATE_ISO8601,
-	DATE_RFC2822,
-	DATE_RAW
+	DATE_RELATIVE = 1,
+	DATE_SHORT = 2,
+	DATE_ISO8601 = 3,
+	DATE_RFC2822 = 4,
+	DATE_RAW = 5,
+
+	DATE_LOCAL = 16, /* OR'ed in to others */
 };
 
 const char *show_date(unsigned long time, int timezone, enum date_mode mode);
 int parse_date(const char *date, char *buf, int bufsize);
 void datestamp(char *buf, int bufsize);
 unsigned long approxidate(const char *);
-enum date_mode parse_date_format(const char *format);
+enum date_mode parse_date_format(const char *format, enum date_mode so_far);
 
 #define IDENT_WARN_ON_NO_NAME  1
 #define IDENT_ERROR_ON_NO_NAME 2
diff --git a/date.c b/date.c
index d75dff4..8d04418 100644
--- a/date.c
+++ b/date.c
@@ -89,6 +89,10 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
 	struct tm *tm;
 	static char timebuf[200];
 
+	if (mode & DATE_LOCAL)
+		tz = local_tzoffset(time);
+	mode &= ~DATE_LOCAL;
+
 	if (mode == DATE_RAW) {
 		snprintf(timebuf, sizeof(timebuf), "%lu %+05d", time, tz);
 		return timebuf;
@@ -136,9 +140,6 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
 		/* Else fall back on absolute format.. */
 	}
 
-	if (mode == DATE_LOCAL)
-		tz = local_tzoffset(time);
-
 	tm = time_to_tm(time, tz);
 	if (!tm)
 		return NULL;
@@ -604,24 +605,26 @@ int parse_date(const char *date, char *result, int maxlen)
 	return date_string(then, offset, result, maxlen);
 }
 
-enum date_mode parse_date_format(const char *format)
+enum date_mode parse_date_format(const char *format, enum date_mode so_far)
 {
+	int or_in_local = so_far & DATE_LOCAL;
+
 	if (!strcmp(format, "relative"))
-		return DATE_RELATIVE;
+		return DATE_RELATIVE | or_in_local;
 	else if (!strcmp(format, "iso8601") ||
 		 !strcmp(format, "iso"))
-		return DATE_ISO8601;
+		return DATE_ISO8601 | or_in_local;
 	else if (!strcmp(format, "rfc2822") ||
 		 !strcmp(format, "rfc"))
-		return DATE_RFC2822;
+		return DATE_RFC2822 | or_in_local;
 	else if (!strcmp(format, "short"))
-		return DATE_SHORT;
-	else if (!strcmp(format, "local"))
-		return DATE_LOCAL;
+		return DATE_SHORT | or_in_local;
 	else if (!strcmp(format, "default"))
-		return DATE_NORMAL;
+		return DATE_NORMAL | or_in_local;
 	else if (!strcmp(format, "raw"))
-		return DATE_RAW;
+		return DATE_RAW | or_in_local;
+	else if (!strcmp(format, "local"))
+		return DATE_LOCAL | so_far;
 	else
 		die("unknown date format %s", format);
 }
diff --git a/revision.c b/revision.c
index 286e416..be9bbc4 100644
--- a/revision.c
+++ b/revision.c
@@ -1177,7 +1177,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 	} else if (!strcmp(arg, "--relative-date")) {
 		revs->date_mode = DATE_RELATIVE;
 	} else if (!strncmp(arg, "--date=", 7)) {
-		revs->date_mode = parse_date_format(arg + 7);
+		revs->date_mode = parse_date_format(arg + 7, revs->date_mode);
 	} else if (!strcmp(arg, "--log-size")) {
 		revs->show_log_size = 1;
 	}

  parent reply	other threads:[~2009-03-03  8:47 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-03  8:18 orthogonal cases of log --date option Miles Bader
2009-03-03  8:34 ` Jeff King
2009-03-03  8:45 ` Junio C Hamano [this message]
2009-03-05 10:43   ` Jeff King
2009-03-05 21:04     ` Jay Soffian
2009-03-05 21:11       ` Jeff King
2009-03-05 22:21         ` Junio C Hamano
2009-03-06  5:23           ` Jeff King
2009-03-06  6:50             ` Junio C Hamano
2009-03-06  6:58               ` Jay Soffian
2009-03-06  8:02                 ` Junio C Hamano
2009-03-06  8:31                   ` Jay Soffian
2009-03-06  8:58                     ` Junio C Hamano
2009-03-06 12:12                       ` Jeff King
2009-03-06 12:10                 ` Jeff King
2009-03-06 12:09               ` Jeff King
2009-03-06  1:47     ` Miles Bader

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=7vtz6bdmfi.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=miles@gnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.