All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Eric Sunshine <sunshine@sunshineco.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Git Mailing List <git@vger.kernel.org>
Subject: [PATCH 1/2] parse_date_basic(): return early when given a bogus timestamp
Date: Wed, 15 Apr 2015 09:21:45 -0700	[thread overview]
Message-ID: <xmqqa8y9mkfa.fsf_-_@gitster.dls.corp.google.com> (raw)
In-Reply-To: <xmqqk2xdmp0e.fsf@gitster.dls.corp.google.com> (Junio C. Hamano's message of "Wed, 15 Apr 2015 07:42:41 -0700")

When the input does not have GMT timezone offset, the code computes
it by computing the local and GMT time for the given timestamp. But
there is no point doing so if the given timestamp is known to be a
bogus one.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

 * A simple preliminary clean-up while we are in the vicinity.  We
   may want to use time_t throughout the codepath and turn it into
   ulong at the very last, but that would be a separate topic.

 date.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/date.c b/date.c
index 782de95..01fd73f 100644
--- a/date.c
+++ b/date.c
@@ -696,6 +696,9 @@ int parse_date_basic(const char *date, unsigned long *timestamp, int *offset)
 
 	/* mktime uses local timezone */
 	*timestamp = tm_to_time_t(&tm);
+	if (*timestamp == -1)
+		return -1;
+
 	if (*offset == -1) {
 		time_t temp_time = mktime(&tm);
 		if ((time_t)*timestamp > temp_time) {
@@ -705,8 +708,6 @@ int parse_date_basic(const char *date, unsigned long *timestamp, int *offset)
 		}
 	}
 
-	if (*timestamp == -1)
-		return -1;
 
 	if (!tm_gmt)
 		*timestamp -= *offset * 60;
-- 
2.4.0-rc2-165-g862640d

  reply	other threads:[~2015-04-15 16:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-15  4:18 Odd broken "--date=now" behavior in current git Linus Torvalds
2015-04-15  4:47 ` Junio C Hamano
2015-04-15  7:22   ` Eric Sunshine
2015-04-15 14:42     ` Junio C Hamano
2015-04-15 16:21       ` Junio C Hamano [this message]
2015-04-15 16:24       ` [PATCH 2/2] parse_date_basic(): let the system handle DST conversion Junio C Hamano
2015-04-15 17:23         ` Eric Sunshine
2015-04-15 16:20     ` Odd broken "--date=now" behavior in current git Linus Torvalds
2015-04-15 17:04       ` Junio C Hamano
2015-04-15  7:07 ` Peter Krefting

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=xmqqa8y9mkfa.fsf_-_@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=sunshine@sunshineco.com \
    --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 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.