Skip to content

Commit b75c310

Browse files
committed
Merge commit 'refs/merge-requests/14' of git://gitorious.org/git-python/mainline into integration
2 parents 69361d9 + b48e4d3 commit b75c310

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

lib/git/objects/commit.py

+20-8
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ class Commit(base.Object, Iterable, diff.Diffable, utils.Traversable):
2323

2424
# object configuration
2525
type = "commit"
26-
__slots__ = ("tree", "author", "authored_date", "committer", "committed_date",
27-
"message", "parents")
26+
__slots__ = ("tree",
27+
"author", "authored_date", "author_tz_offset",
28+
"committer", "committed_date", "committer_tz_offset",
29+
"message", "parents")
2830
_id_attribute_ = "sha"
2931

30-
def __init__(self, repo, sha, tree=None, author=None, authored_date=None,
31-
committer=None, committed_date=None, message=None, parents=None):
32+
def __init__(self, repo, sha, tree=None, author=None, authored_date=None, author_tz_offset=None,
33+
committer=None, committed_date=None, committer_tz_offset=None, message=None, parents=None):
3234
"""
3335
Instantiate a new Commit. All keyword arguments taking None as default will
3436
be implicitly set if id names a valid sha.
@@ -51,13 +53,19 @@ def __init__(self, repo, sha, tree=None, author=None, authored_date=None,
5153
is the authored DateTime - use time.gmtime() to convert it into a
5254
different format
5355
56+
``author_tz_offset``: int_seconds_west_of_utc
57+
is the timezone that the authored_date is in
58+
5459
``committer`` : Actor
5560
is the committer string
5661
5762
``committed_date`` : int_seconds_since_epoch
5863
is the committed DateTime - use time.gmtime() to convert it into a
5964
different format
6065
66+
``committer_tz_offset``: int_seconds_west_of_utc
67+
is the timezone that the authored_date is in
68+
6169
``message`` : string
6270
is the commit message
6371
@@ -94,8 +102,10 @@ def _set_cache_(self, attr):
94102
self.tree = temp.tree
95103
self.author = temp.author
96104
self.authored_date = temp.authored_date
105+
self.author_tz_offset = temp.author_tz_offset
97106
self.committer = temp.committer
98107
self.committed_date = temp.committed_date
108+
self.committer_tz_offset = temp.committer_tz_offset
99109
self.message = temp.message
100110
else:
101111
super(Commit, self)._set_cache_(attr)
@@ -253,8 +263,8 @@ def _iter_from_process_or_stream(cls, repo, proc_or_stream, from_rev_list):
253263
parents.append(parent_line.split()[-1])
254264
# END for each parent line
255265

256-
author, authored_date = utils.parse_actor_and_date(next_line)
257-
committer, committed_date = utils.parse_actor_and_date(stream.next())
266+
author, authored_date, author_tz_offset = utils.parse_actor_and_date(next_line)
267+
committer, committed_date, committer_tz_offset = utils.parse_actor_and_date(stream.next())
258268

259269
# empty line
260270
stream.next()
@@ -276,8 +286,10 @@ def _iter_from_process_or_stream(cls, repo, proc_or_stream, from_rev_list):
276286
# END message parsing
277287
message = '\n'.join(message_lines)
278288

279-
yield Commit(repo, id, parents=tuple(parents), tree=tree, author=author, authored_date=authored_date,
280-
committer=committer, committed_date=committed_date, message=message)
289+
yield Commit(repo, id, parents=tuple(parents), tree=tree,
290+
author=author, authored_date=authored_date, author_tz_offset=author_tz_offset,
291+
committer=committer, committed_date=committed_date, committer_tz_offset=committer_tz_offset,
292+
message=message)
281293
# END for each line in stream
282294

283295

lib/git/objects/tag.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ class TagObject(base.Object):
1515
to.
1616
"""
1717
type = "tag"
18-
__slots__ = ( "object", "tag", "tagger", "tagged_date", "message" )
18+
__slots__ = ( "object", "tag", "tagger", "tagged_date", "tagger_tz_offset", "message" )
1919

2020
def __init__(self, repo, sha, object=None, tag=None,
21-
tagger=None, tagged_date=None, message=None):
21+
tagger=None, tagged_date=None, tagger_tz_offset=None, message=None):
2222
"""
2323
Initialize a tag object with additional data
2424
@@ -40,6 +40,10 @@ def __init__(self, repo, sha, object=None, tag=None,
4040
``tagged_date`` : int_seconds_since_epoch
4141
is the DateTime of the tag creation - use time.gmtime to convert
4242
it into a different format
43+
44+
``tagged_tz_offset``: int_seconds_west_of_utc
45+
is the timezone that the authored_date is in
46+
4347
"""
4448
super(TagObject, self).__init__(repo, sha )
4549
self._set_self_from_args_(locals())
@@ -58,7 +62,7 @@ def _set_cache_(self, attr):
5862
self.tag = lines[2][4:] # tag <tag name>
5963

6064
tagger_info = lines[3][7:]# tagger <actor> <date>
61-
self.tagger, self.tagged_date = utils.parse_actor_and_date(tagger_info)
65+
self.tagger, self.tagged_date, self.tagger_tz_offset = utils.parse_actor_and_date(tagger_info)
6266

6367
# line 4 empty - it could mark the beginning of the next header
6468
# in csse there really is no message, it would not exist. Otherwise

lib/git/objects/utils.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def get_object_type_by_name(object_type_name):
3939

4040

4141
# precompiled regex
42-
_re_actor_epoch = re.compile(r'^.+? (.*) (\d+) .*$')
42+
_re_actor_epoch = re.compile(r'^.+? (.*) (\d+) ([+-]\d+).*$')
4343

4444
def parse_actor_and_date(line):
4545
"""
@@ -48,11 +48,11 @@ def parse_actor_and_date(line):
4848
author Tom Preston-Werner <[email protected]> 1191999972 -0700
4949
5050
Returns
51-
[Actor, int_seconds_since_epoch]
51+
[Actor, int_seconds_since_epoch, int_timezone_offset]
5252
"""
5353
m = _re_actor_epoch.search(line)
54-
actor, epoch = m.groups()
55-
return (Actor._from_string(actor), int(epoch))
54+
actor, epoch, offset = m.groups()
55+
return (Actor._from_string(actor), int(epoch), -int(float(offset)/100*3600))
5656

5757

5858

test/git/test_commit.py

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def test_bake(self):
1818
assert_equal("[email protected]", commit.author.email)
1919
assert commit.author == commit.committer
2020
assert isinstance(commit.authored_date, int) and isinstance(commit.committed_date, int)
21+
assert isinstance(commit.author_tz_offset, int) and isinstance(commit.committer_tz_offset, int)
2122
assert commit.message == "Added missing information to docstrings of commit and stats module"
2223

2324

@@ -46,6 +47,8 @@ def check_entries(d):
4647
assert commit.committer == michael
4748
assert commit.authored_date == 1210193388
4849
assert commit.committed_date == 1210193388
50+
assert commit.author_tz_offset == 14400, commit.author_tz_offset
51+
assert commit.committer_tz_offset == 14400, commit.committer_tz_offset
4952
assert commit.message == "initial project"
5053

5154
def test_traversal(self):

0 commit comments

Comments
 (0)