From 69147fe1209af176e77c458ef38b38200dff221d Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Mon, 17 Dec 2018 17:41:04 -0800 Subject: [PATCH] filter-repo: fix crazy timezone issues Oh, boy, timezone +051800 exists in the wild. Is that 0518 hours and 00 minutes? Or 05 hours and 1800 minutes? Or 051 hours and 800 minutes? Attempt to do something sane with these broken commits that fast-import barfs on. Also, fix an old bug in the handling of ahead-of-UTC timezones. Signed-off-by: Elijah Newren --- git-filter-repo | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/git-filter-repo b/git-filter-repo index bea4a00..2f05a4a 100755 --- a/git-filter-repo +++ b/git-filter-repo @@ -53,9 +53,23 @@ class FixedTimeZone(tzinfo): def __init__(self, offset_string): tzinfo.__init__(self) - minus, hh, mm = re.match(r'^([-+]?)(\d\d)(\d\d)$', offset_string).groups() - sign = minus and -1 or 1 - self._offset = timedelta(minutes = sign*(60*int(hh) + int(mm))) + try: + sign, hh, mm = re.match(r'^([-+]?)(\d\d)(\d\d)$', offset_string).groups() + except AttributeError: + # TimeZone idiocy; IST is any of four timezones, so someone translated + # it to something that was totally invalid...and it got recorded that + # way. Others have suggested just using an invalid timezone that + # fast-import will not choke on. Let's do that. Note that +051800 + # seems to be the only weird timezone found in the wild, by me or some + # other posts google returned on the subject... + if offset_string == '+051800': + sign, hh, mm = '+', '02', '61' + offset_string = offset_string.replace('+051800', '+0261') + else: + raise AttributeError("Could not parse {} as timezone" + .format(offset_string)) + factor = -1 if (sign and sign == '-') else 1 + self._offset = timedelta(minutes = factor*(60*int(hh) + int(mm))) self._offset_string = offset_string def utcoffset(self, dt):