Skip to content

Commit c9dbf20

Browse files
committed
Moved small types that had their own module into the utils module
1 parent 38b3cfb commit c9dbf20

File tree

8 files changed

+482
-488
lines changed

8 files changed

+482
-488
lines changed

lib/git/__init__.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ def _init_externals():
2727
from git.config import GitConfigParser
2828
from git.objects import *
2929
from git.refs import *
30-
from git.actor import Actor
3130
from git.diff import *
3231
from git.errors import InvalidGitRepositoryError, NoSuchPathError, GitCommandError
3332
from git.cmd import Git
3433
from git.repo import Repo
35-
from git.stats import Stats
3634
from git.remote import *
3735
from git.index import *
38-
from git.utils import LockFile, BlockingLockFile
36+
from git.utils import (
37+
LockFile,
38+
BlockingLockFile,
39+
Stats
40+
)
3941

4042
#} END imports
4143

lib/git/actor.py

-62
This file was deleted.

lib/git/objects/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from tree import *
99
from commit import *
1010
from submodule import *
11+
from utils import Actor
1112

1213
__all__ = [ name for name, obj in locals().items()
1314
if not (name.startswith('_') or inspect.ismodule(obj)) ]

lib/git/objects/commit.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
# This module is part of GitPython and is released under
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66

7-
from git.utils import Iterable
7+
from git.utils import (
8+
Iterable,
9+
Stats,
10+
)
11+
812
import git.diff as diff
9-
import git.stats as stats
10-
from git.actor import Actor
1113
from tree import Tree
1214
from gitdb import IStream
1315
from cStringIO import StringIO
@@ -223,7 +225,7 @@ def stats(self):
223225
text = text2
224226
else:
225227
text = self.repo.git.diff(self.parents[0].sha, self.sha, '--', numstat=True)
226-
return stats.Stats._list_from_string(self.repo, text)
228+
return Stats._list_from_string(self.repo, text)
227229

228230
@classmethod
229231
def _iter_from_process_or_stream(cls, repo, proc_or_stream):
@@ -332,8 +334,8 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False):
332334
enc_section, enc_option = cls.conf_encoding.split('.')
333335
conf_encoding = cr.get_value(enc_section, enc_option, cls.default_encoding)
334336

335-
author = Actor(author_name, author_email)
336-
committer = Actor(committer_name, committer_email)
337+
author = utils.Actor(author_name, author_email)
338+
committer = utils.Actor(committer_name, committer_email)
337339

338340

339341
# CREATE NEW COMMIT

lib/git/objects/utils.py

+56-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"""
99
import re
1010
from collections import deque as Deque
11-
from git.actor import Actor
1211
import platform
1312

1413
from string import digits
@@ -19,6 +18,8 @@
1918
'ProcessStreamAdapter', 'Traversable', 'altz_to_utctz_str', 'utctz_to_altz',
2019
'verify_utctz')
2120

21+
#{ Functions
22+
2223
def get_object_type_by_name(object_type_name):
2324
"""
2425
Returns
@@ -180,6 +181,60 @@ def parse_actor_and_date(line):
180181
actor, epoch, offset = m.groups()
181182
return (Actor._from_string(actor), int(epoch), utctz_to_altz(offset))
182183

184+
185+
#} END functions
186+
187+
188+
#{ Classes
189+
190+
class Actor(object):
191+
"""Actors hold information about a person acting on the repository. They
192+
can be committers and authors or anything with a name and an email as
193+
mentioned in the git log entries."""
194+
# precompiled regex
195+
name_only_regex = re.compile( r'<(.+)>' )
196+
name_email_regex = re.compile( r'(.*) <(.+?)>' )
197+
198+
def __init__(self, name, email):
199+
self.name = name
200+
self.email = email
201+
202+
def __eq__(self, other):
203+
return self.name == other.name and self.email == other.email
204+
205+
def __ne__(self, other):
206+
return not (self == other)
207+
208+
def __hash__(self):
209+
return hash((self.name, self.email))
210+
211+
def __str__(self):
212+
return self.name
213+
214+
def __repr__(self):
215+
return '<git.Actor "%s <%s>">' % (self.name, self.email)
216+
217+
@classmethod
218+
def _from_string(cls, string):
219+
"""Create an Actor from a string.
220+
:param string: is the string, which is expected to be in regular git format
221+
222+
John Doe <jdoe@example.com>
223+
224+
:return: Actor """
225+
m = cls.name_email_regex.search(string)
226+
if m:
227+
name, email = m.groups()
228+
return Actor(name, email)
229+
else:
230+
m = cls.name_only_regex.search(string)
231+
if m:
232+
return Actor(m.group(1), None)
233+
else:
234+
# assume best and use the whole string as name
235+
return Actor(string, None)
236+
# END special case name
237+
# END handle name/email matching
183238

184239

185240
class ProcessStreamAdapter(object):

lib/git/repo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from errors import InvalidGitRepositoryError, NoSuchPathError
88
from cmd import Git
9-
from actor import Actor
9+
from objects import Actor
1010
from refs import *
1111
from index import IndexFile
1212
from objects import *

lib/git/stats.py

-60
This file was deleted.

0 commit comments

Comments
 (0)