summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2015-08-17 22:32:15 +0200
committerSebastian Thiel <byronimo@gmail.com>2015-08-17 22:33:02 +0200
commita8f7e3772f68c8e6350b9ff5ac981ba3223f2d43 (patch)
treece01004c2f928cc71265e8a3b832c03bc111da11
parent039e265819cc6e5241907f1be30d2510bfa5ca6c (diff)
downloadgitpython-a8f7e3772f68c8e6350b9ff5ac981ba3223f2d43.tar.gz
fix(commit): serialization timezone handling
Previously timezones which were not divisable by 3600s would be parsed correctly, but would serialize into a full hour, rounded up. Now floating point computation is used which fixes the issue. Related to #336
-rw-r--r--doc/source/changes.rst7
-rw-r--r--git/objects/util.py2
-rw-r--r--git/test/performance/test_commit.py2
3 files changed, 9 insertions, 2 deletions
diff --git a/doc/source/changes.rst b/doc/source/changes.rst
index e6d7b09b..970ba195 100644
--- a/doc/source/changes.rst
+++ b/doc/source/changes.rst
@@ -2,6 +2,13 @@
Changelog
=========
+1.0.2 - Fixes
+=============
+
+* CRITICAL: fixed incorrect `Commit` object serialization when authored or commit date had timezones which were not
+ divisable by 3600 seconds. This would happen if the timezone was something like `+0530` for instance.
+* A list of all additional fixes can be found `on github <https://github.com/gitpython-developers/GitPython/issues?q=milestone%3A%22v1.0.2+-+Fixes%22+is%3Aclosed>`_
+
1.0.1 - Fixes
=============
diff --git a/git/objects/util.py b/git/objects/util.py
index 567b1d5b..8fd92a0a 100644
--- a/git/objects/util.py
+++ b/git/objects/util.py
@@ -73,7 +73,7 @@ def utctz_to_altz(utctz):
def altz_to_utctz_str(altz):
"""As above, but inverses the operation, returning a string that can be used
in commit objects"""
- utci = -1 * int((altz / 3600) * 100)
+ utci = -1 * int((float(altz) / 3600) * 100)
utcs = str(abs(utci))
utcs = "0" * (4 - len(utcs)) + utcs
prefix = (utci < 0 and '-') or '+'
diff --git a/git/test/performance/test_commit.py b/git/test/performance/test_commit.py
index 7d3e87c4..b59c747e 100644
--- a/git/test/performance/test_commit.py
+++ b/git/test/performance/test_commit.py
@@ -76,7 +76,7 @@ class TestPerformance(TestBigRepoRW):
% (nc, elapsed_time, nc / elapsed_time), file=sys.stderr)
def test_commit_serialization(self):
- assert_commit_serialization(self.gitrwrepo, self.gitrwrepo.head, True)
+ assert_commit_serialization(self.gitrwrepo, '58c78e6', True)
rwrepo = self.gitrwrepo
make_object = rwrepo.odb.store