git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] apply: Recognize epoch timestamps with : in the timezone
@ 2010-09-29 20:49 Anders Kaseorg
  2010-09-29 21:41 ` Jonathan Nieder
  0 siblings, 1 reply; 7+ messages in thread
From: Anders Kaseorg @ 2010-09-29 20:49 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Some patches have a timezone formatted like ‘-08:00’ instead of
‘-0800’ (e.g. http://lwn.net/Articles/131729/), so git apply would
fail to recognize the epoch timestamp of deleted files and would
create empty files instead.  Teach it to support both formats, and add
a test case.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
---
 builtin/apply.c          |    6 ++++--
 t/t4132-apply-removal.sh |    2 ++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index 23c18c5..0fa9a8d 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -733,7 +733,7 @@ static int has_epoch_timestamp(const char *nameline)
 		" "
 		"[0-2][0-9]:[0-5][0-9]:00(\\.0+)?"
 		" "
-		"([-+][0-2][0-9][0-5][0-9])\n";
+		"([-+][0-2][0-9]):?([0-5][0-9])\n";
 	const char *timestamp = NULL, *cp;
 	static regex_t *stamp;
 	regmatch_t m[10];
@@ -765,7 +765,9 @@ static int has_epoch_timestamp(const char *nameline)
 	}
 
 	zoneoffset = strtol(timestamp + m[3].rm_so + 1, NULL, 10);
-	zoneoffset = (zoneoffset / 100) * 60 + (zoneoffset % 100);
+	if (m[4].rm_so == m[3].rm_so + 3)
+		zoneoffset /= 100;
+	zoneoffset = zoneoffset * 60 + strtol(timestamp + m[4].rm_so, NULL, 10);
 	if (timestamp[m[3].rm_so] == '-')
 		zoneoffset = -zoneoffset;
 
diff --git a/t/t4132-apply-removal.sh b/t/t4132-apply-removal.sh
index bb1ffe3..a2bc1cd 100755
--- a/t/t4132-apply-removal.sh
+++ b/t/t4132-apply-removal.sh
@@ -30,6 +30,7 @@ test_expect_success setup '
 	epocWest="1969-12-31 16:00:00.000000000 -0800" &&
 	 epocGMT="1970-01-01 00:00:00.000000000 +0000" &&
 	epocEast="1970-01-01 09:00:00.000000000 +0900" &&
+	epocWest2="1969-12-31 16:00:00 -08:00" &&
 
 	sed -e "s/TS0/$epocWest/" -e "s/TS1/$timeWest/" <c >createWest.patch &&
 	sed -e "s/TS0/$epocEast/" -e "s/TS1/$timeEast/" <c >createEast.patch &&
@@ -46,6 +47,7 @@ test_expect_success setup '
 	sed -e "s/TS0/$timeWest/" -e "s/TS1/$epocWest/" <d >removeWest.patch &&
 	sed -e "s/TS0/$timeEast/" -e "s/TS1/$epocEast/" <d >removeEast.patch &&
 	sed -e "s/TS0/$timeGMT/" -e "s/TS1/$epocGMT/" <d >removeGMT.patch &&
+	sed -e "s/TS0/$timeWest/" -e "s/TS1/$epocWest2/" <d >removeWest2.patch &&
 
 	echo something >something &&
 	>empty
-- 
1.7.3

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-10-13 23:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-29 20:49 [PATCH] apply: Recognize epoch timestamps with : in the timezone Anders Kaseorg
2010-09-29 21:41 ` Jonathan Nieder
2010-09-29 21:49   ` Jonathan Nieder
2010-10-13 18:59   ` Junio C Hamano
2010-10-13 19:31     ` Junio C Hamano
2010-10-13 22:50       ` Jonathan Nieder
2010-10-13 23:37         ` Junio C Hamano

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).