summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-10-15 10:33:13 +0200
committerSebastian Thiel <byronimo@gmail.com>2009-10-15 10:33:13 +0200
commit58d692e2a1d7e3894dbed68efbcf7166d6ec3fb7 (patch)
tree1f357dfaec33d1f808b74214771ea2bd78ac50c2
parent4186a2dbbd48fd67ff88075c63bbd3e6c1d8a2df (diff)
downloadgitpython-58d692e2a1d7e3894dbed68efbcf7166d6ec3fb7.tar.gz
All times are not stored as time_struct, but as simple int to consume less memory
time imports cleaned up and mostly removed as they were not required (anymore)
-rw-r--r--CHANGES3
-rw-r--r--lib/git/objects/commit.py31
-rw-r--r--lib/git/objects/tag.py12
-rw-r--r--lib/git/objects/utils.py19
-rw-r--r--lib/git/repo.py11
-rw-r--r--test/git/test_base.py1
-rw-r--r--test/git/test_blob.py1
-rw-r--r--test/git/test_repo.py9
-rw-r--r--test/git/test_tag.py3
9 files changed, 48 insertions, 42 deletions
diff --git a/CHANGES b/CHANGES
index c4ea13b0..456423d4 100644
--- a/CHANGES
+++ b/CHANGES
@@ -20,6 +20,9 @@ General
may change without prior notice.
* Renamed all find_all methods to list_items - this method is part of the Iterable interface
that also provides a more efficients and more responsive iter_items method
+* All dates, like authored_date and committer_date, are stored as seconds since epoc
+ to consume less memory - they can be converted using time.gmtime in a more suitable
+ presentation format if needed.
Item Iteration
--------------
diff --git a/lib/git/objects/commit.py b/lib/git/objects/commit.py
index 101014ab..edbe8ed7 100644
--- a/lib/git/objects/commit.py
+++ b/lib/git/objects/commit.py
@@ -4,14 +4,12 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
-import re
-import time
from git.utils import Iterable
-from git.actor import Actor
import git.diff as diff
import git.stats as stats
from tree import Tree
import base
+import utils
class Commit(base.Object, Iterable):
"""
@@ -20,8 +18,6 @@ class Commit(base.Object, Iterable):
This class will act lazily on some of its attributes and will query the
value on demand only if it involves calling the git binary.
"""
- # precompiled regex
- re_actor_epoch = re.compile(r'^.+? (.*) (\d+) .*$')
# object configuration
type = "commit"
@@ -48,14 +44,16 @@ class Commit(base.Object, Iterable):
``author`` : Actor
is the author string ( will be implicitly converted into an Actor object )
- ``authored_date`` : (tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst )
- is the authored DateTime
+ ``authored_date`` : int_seconds_since_epoch
+ is the authored DateTime - use time.gmtime() to convert it into a
+ different format
``committer`` : Actor
is the committer string
- ``committed_date`` : (tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst)
- is the committed DateTime
+ ``committed_date`` : int_seconds_since_epoch
+ is the committed DateTime - use time.gmtime() to convert it into a
+ different format
``message`` : string
is the commit message
@@ -185,8 +183,8 @@ class Commit(base.Object, Iterable):
parents.append(parent_line.split()[-1])
# END for each parent line
- author, authored_date = cls._actor(next_line)
- committer, committed_date = cls._actor(stream.next())
+ author, authored_date = utils.parse_actor_and_date(next_line)
+ committer, committed_date = utils.parse_actor_and_date(stream.next())
# empty line
stream.next()
@@ -286,14 +284,3 @@ class Commit(base.Object, Iterable):
def __repr__(self):
return '<git.Commit "%s">' % self.id
- @classmethod
- def _actor(cls, line):
- """
- Parse out the actor (author or committer) info
-
- Returns
- [Actor, gmtime(acted at time)]
- """
- m = cls.re_actor_epoch.search(line)
- actor, epoch = m.groups()
- return (Actor._from_string(actor), time.gmtime(int(epoch)))
diff --git a/lib/git/objects/tag.py b/lib/git/objects/tag.py
index ecf6349d..f54d4b64 100644
--- a/lib/git/objects/tag.py
+++ b/lib/git/objects/tag.py
@@ -7,8 +7,7 @@
Module containing all object based types.
"""
import base
-import commit
-from utils import get_object_type_by_name
+import utils
class TagObject(base.Object):
"""
@@ -38,8 +37,9 @@ class TagObject(base.Object):
``tagger``
Actor identifying the tagger
- ``tagged_date`` : (tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst)
- is the DateTime of the tag creation
+ ``tagged_date`` : int_seconds_since_epoch
+ is the DateTime of the tag creation - use time.gmtime to convert
+ it into a different format
"""
super(TagObject, self).__init__(repo, id )
self._set_self_from_args_(locals())
@@ -53,12 +53,12 @@ class TagObject(base.Object):
obj, hexsha = lines[0].split(" ") # object <hexsha>
type_token, type_name = lines[1].split(" ") # type <type_name>
- self.object = get_object_type_by_name(type_name)(self.repo, hexsha)
+ self.object = utils.get_object_type_by_name(type_name)(self.repo, hexsha)
self.tag = lines[2][4:] # tag <tag name>
tagger_info = lines[3][7:]# tagger <actor> <date>
- self.tagger, self.tagged_date = commit.Commit._actor(tagger_info)
+ self.tagger, self.tagged_date = utils.parse_actor_and_date(tagger_info)
# line 4 empty - check git source to figure out purpose
self.message = "\n".join(lines[5:])
diff --git a/lib/git/objects/utils.py b/lib/git/objects/utils.py
index 15c1d114..9b9e0c52 100644
--- a/lib/git/objects/utils.py
+++ b/lib/git/objects/utils.py
@@ -6,7 +6,9 @@
"""
Module for general utility functions
"""
+import re
import commit, tag, blob, tree
+from git.actor import Actor
def get_object_type_by_name(object_type_name):
"""
@@ -34,3 +36,20 @@ def get_object_type_by_name(object_type_name):
return tree.Tree
else:
raise ValueError("Cannot handle unknown object type: %s" % object_type_name)
+
+
+# precompiled regex
+_re_actor_epoch = re.compile(r'^.+? (.*) (\d+) .*$')
+
+def parse_actor_and_date(line):
+ """
+ Parse out the actor (author or committer) info from a line like::
+
+ author Tom Preston-Werner <tom@mojombo.com> 1191999972 -0700
+
+ Returns
+ [Actor, int_seconds_since_epoch]
+ """
+ m = _re_actor_epoch.search(line)
+ actor, epoch = m.groups()
+ return (Actor._from_string(actor), int(epoch))
diff --git a/lib/git/repo.py b/lib/git/repo.py
index c74c7e8d..1640fd32 100644
--- a/lib/git/repo.py
+++ b/lib/git/repo.py
@@ -8,7 +8,6 @@ import os
import re
import gzip
import StringIO
-import time
from errors import InvalidGitRepositoryError, NoSuchPathError
from utils import touch, is_git_dir
@@ -160,7 +159,7 @@ class Repo(object):
if firstpart.endswith('-mail'):
info["%s_email" % role] = parts[-1]
elif firstpart.endswith('-time'):
- info["%s_date" % role] = time.gmtime(int(parts[-1]))
+ info["%s_date" % role] = int(parts[-1])
elif role == firstpart:
info[role] = parts[-1]
# END distinguish mail,time,name
@@ -197,12 +196,13 @@ class Repo(object):
# END distinguish hexsha vs other information
return blames
- def commits(self, start='master', path='', max_count=None, skip=0):
+ def commits(self, start=None, path='', max_count=None, skip=0):
"""
A list of Commit objects representing the history of a given ref/commit
``start``
- is the branch/commit name (default 'master')
+ is a ref to start the commits from. If start is None,
+ the active branch will be used
``path``
is an optional path to limit the returned commits to
@@ -223,7 +223,8 @@ class Repo(object):
if max_count is None:
options.pop('max_count')
-
+ if start is None:
+ start = self.active_branch
return Commit.list_items(self, start, path, **options)
def commits_between(self, frm, to):
diff --git a/test/git/test_base.py b/test/git/test_base.py
index 402cdba3..48d628c3 100644
--- a/test/git/test_base.py
+++ b/test/git/test_base.py
@@ -4,7 +4,6 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
-import time
from test.testlib import *
from git import *
import git.objects.base as base
diff --git a/test/git/test_blob.py b/test/git/test_blob.py
index 266f3a23..e151b3c8 100644
--- a/test/git/test_blob.py
+++ b/test/git/test_blob.py
@@ -4,7 +4,6 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
-import time
from test.testlib import *
from git import *
diff --git a/test/git/test_repo.py b/test/git/test_repo.py
index e998ac6d..918e4769 100644
--- a/test/git/test_repo.py
+++ b/test/git/test_repo.py
@@ -5,7 +5,6 @@
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
import os, sys
-import time
from test.testlib import *
from git import *
@@ -51,10 +50,10 @@ class TestRepo(object):
assert_equal("672eca9b7f9e09c22dcb128c283e8c3c8d7697a4", c.tree.id)
assert_equal("Tom Preston-Werner", c.author.name)
assert_equal("tom@mojombo.com", c.author.email)
- assert_equal(time.gmtime(1191999972), c.authored_date)
+ assert_equal(1191999972, c.authored_date)
assert_equal("Tom Preston-Werner", c.committer.name)
assert_equal("tom@mojombo.com", c.committer.email)
- assert_equal(time.gmtime(1191999972), c.committed_date)
+ assert_equal(1191999972, c.committed_date)
assert_equal("implement Grit#heads", c.message)
c = commits[1]
@@ -233,10 +232,10 @@ class TestRepo(object):
assert_equal('634396b2f541a9f2d58b00be1a07f0c358b999b3', c.id)
assert_equal('Tom Preston-Werner', c.author.name)
assert_equal('tom@mojombo.com', c.author.email)
- assert_equal(time.gmtime(1191997100), c.authored_date)
+ assert_equal(1191997100, c.authored_date)
assert_equal('Tom Preston-Werner', c.committer.name)
assert_equal('tom@mojombo.com', c.committer.email)
- assert_equal(time.gmtime(1191997100), c.committed_date)
+ assert_equal(1191997100, c.committed_date)
assert_equal('initial grit setup', c.message)
# test the 'lines per commit' entries
diff --git a/test/git/test_tag.py b/test/git/test_tag.py
index 2ebb860a..8f12bf11 100644
--- a/test/git/test_tag.py
+++ b/test/git/test_tag.py
@@ -8,7 +8,6 @@ from mock import *
from test.testlib import *
from git import *
from git.objects.tag import TagObject
-import time
class TestTag(object):
def setup(self):
@@ -26,7 +25,7 @@ class TestTag(object):
assert isinstance( tagobj, TagObject )
assert tagobj.tag == tag.name
assert isinstance( tagobj.tagger, Actor )
- assert isinstance( tagobj.tagged_date, time.struct_time )
+ assert isinstance( tagobj.tagged_date, int )
assert tagobj.message
# END if we have a tag object
# END for tag in repo-tags