|
4 | 4 | # This module is part of GitPython and is released under
|
5 | 5 | # the BSD License: http://www.opensource.org/licenses/bsd-license.php
|
6 | 6 | """Module for general utility functions"""
|
7 |
| -from git.util import IterableList |
| 7 | +from git.util import ( |
| 8 | + IterableList, |
| 9 | + Actor |
| 10 | + ) |
8 | 11 |
|
9 | 12 | import re
|
10 | 13 | from collections import deque as Deque
|
11 |
| -import platform |
12 | 14 |
|
13 | 15 | from string import digits
|
14 | 16 | import time
|
15 | 17 | import os
|
16 | 18 |
|
17 |
| -__all__ = ('get_object_type_by_name', 'get_user_id', 'parse_date', 'parse_actor_and_date', |
| 19 | +__all__ = ('get_object_type_by_name', 'parse_date', 'parse_actor_and_date', |
18 | 20 | 'ProcessStreamAdapter', 'Traversable', 'altz_to_utctz_str', 'utctz_to_altz',
|
19 |
| - 'verify_utctz') |
| 21 | + 'verify_utctz', 'Actor') |
20 | 22 |
|
21 | 23 | #{ Functions
|
22 | 24 |
|
@@ -57,21 +59,9 @@ def get_object_type_by_name(object_type_name):
|
57 | 59 | else:
|
58 | 60 | raise ValueError("Cannot handle unknown object type: %s" % object_type_name)
|
59 | 61 |
|
60 |
| - |
61 |
| -def get_user_id(): |
62 |
| - """:return: string identifying the currently active system user as name@node |
63 |
| - :note: user can be set with the 'USER' environment variable, usually set on windows""" |
64 |
| - ukn = 'UNKNOWN' |
65 |
| - username = os.environ.get('USER', os.environ.get('USERNAME', ukn)) |
66 |
| - if username == ukn and hasattr(os, 'getlogin'): |
67 |
| - username = os.getlogin() |
68 |
| - # END get username from login |
69 |
| - return "%s@%s" % (username, platform.node()) |
70 |
| - |
71 |
| - |
72 | 62 | def utctz_to_altz(utctz):
|
73 | 63 | """we convert utctz to the timezone in seconds, it is the format time.altzone
|
74 |
| - returns. Git stores it as UTC timezon which has the opposite sign as well, |
| 64 | + returns. Git stores it as UTC timezone which has the opposite sign as well, |
75 | 65 | which explains the -1 * ( that was made explicit here )
|
76 | 66 | :param utctz: git utc timezone string, i.e. +0200"""
|
77 | 67 | return -1 * int(float(utctz)/100*3600)
|
@@ -193,56 +183,6 @@ def parse_actor_and_date(line):
|
193 | 183 |
|
194 | 184 |
|
195 | 185 | #{ Classes
|
196 |
| - |
197 |
| -class Actor(object): |
198 |
| - """Actors hold information about a person acting on the repository. They |
199 |
| - can be committers and authors or anything with a name and an email as |
200 |
| - mentioned in the git log entries.""" |
201 |
| - # precompiled regex |
202 |
| - name_only_regex = re.compile( r'<(.+)>' ) |
203 |
| - name_email_regex = re.compile( r'(.*) <(.+?)>' ) |
204 |
| - |
205 |
| - def __init__(self, name, email): |
206 |
| - self.name = name |
207 |
| - self.email = email |
208 |
| - |
209 |
| - def __eq__(self, other): |
210 |
| - return self.name == other.name and self.email == other.email |
211 |
| - |
212 |
| - def __ne__(self, other): |
213 |
| - return not (self == other) |
214 |
| - |
215 |
| - def __hash__(self): |
216 |
| - return hash((self.name, self.email)) |
217 |
| - |
218 |
| - def __str__(self): |
219 |
| - return self.name |
220 |
| - |
221 |
| - def __repr__(self): |
222 |
| - return '<git.Actor "%s <%s>">' % (self.name, self.email) |
223 |
| - |
224 |
| - @classmethod |
225 |
| - def _from_string(cls, string): |
226 |
| - """Create an Actor from a string. |
227 |
| - :param string: is the string, which is expected to be in regular git format |
228 |
| -
|
229 |
| - John Doe <jdoe@example.com> |
230 |
| - |
231 |
| - :return: Actor """ |
232 |
| - m = cls.name_email_regex.search(string) |
233 |
| - if m: |
234 |
| - name, email = m.groups() |
235 |
| - return Actor(name, email) |
236 |
| - else: |
237 |
| - m = cls.name_only_regex.search(string) |
238 |
| - if m: |
239 |
| - return Actor(m.group(1), None) |
240 |
| - else: |
241 |
| - # assume best and use the whole string as name |
242 |
| - return Actor(string, None) |
243 |
| - # END special case name |
244 |
| - # END handle name/email matching |
245 |
| - |
246 | 186 |
|
247 | 187 | class ProcessStreamAdapter(object):
|
248 | 188 | """Class wireing all calls to the contained Process instance.
|
@@ -359,6 +299,7 @@ def addToStack( stack, item, branch_first, depth ):
|
359 | 299 |
|
360 | 300 | class Serializable(object):
|
361 | 301 | """Defines methods to serialize and deserialize objects from and into a data stream"""
|
| 302 | + __slots__ = tuple() |
362 | 303 |
|
363 | 304 | def _serialize(self, stream):
|
364 | 305 | """Serialize the data of this object into the given data stream
|
|
0 commit comments