diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-10-11 21:17:59 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-10-11 21:17:59 +0200 |
commit | 708b8dda8e7b87841a5f39c60b799c514e75a9c7 (patch) | |
tree | 0726d95c0ad6270278c6695381522e8a5f8a2b76 /lib/git | |
parent | ccde80b7a3037a004a7807a6b79916ce2a1e9729 (diff) | |
download | gitpython-708b8dda8e7b87841a5f39c60b799c514e75a9c7.tar.gz |
commit: fixed failing commit tests as the mocked git command would always return the same thing which does not work anymore - re-implemented it in a more dynamic manner, but in the end tests will have to be revised anyway
Added slots to Diff and Stats type respectively
Diffstat (limited to 'lib/git')
-rw-r--r-- | lib/git/blob.py | 2 | ||||
-rw-r--r-- | lib/git/commit.py | 15 | ||||
-rw-r--r-- | lib/git/diff.py | 4 | ||||
-rw-r--r-- | lib/git/stats.py | 7 |
4 files changed, 16 insertions, 12 deletions
diff --git a/lib/git/blob.py b/lib/git/blob.py index b0e47a3c..1fafb128 100644 --- a/lib/git/blob.py +++ b/lib/git/blob.py @@ -57,7 +57,7 @@ class Blob(base.IndexObject): blames = [] info = None - for line in data.splitlines(): + for line in data.splitlines(False): parts = cls.re_whitespace.split(line, 1) firstpart = parts[0] if cls.re_hexsha_only.search(firstpart): diff --git a/lib/git/commit.py b/lib/git/commit.py index 5d494621..9bf753e0 100644 --- a/lib/git/commit.py +++ b/lib/git/commit.py @@ -162,8 +162,7 @@ class Commit(base.Object): Returns git.Commit[] """ - lines = [l for l in text.splitlines() if l.strip('\r\n')] - + lines =text.splitlines(False) commits = [] while lines: @@ -173,18 +172,22 @@ class Commit(base.Object): parents = [] while lines and lines[0].startswith('parent'): parents.append(lines.pop(0).split()[-1]) + # END while there are parent lines author, authored_date = cls._actor(lines.pop(0)) committer, committed_date = cls._actor(lines.pop(0)) - + + # free line + lines.pop(0) + messages = [] - while lines and lines[0].startswith(' '): + while lines and not lines[0].startswith('commit'): messages.append(lines.pop(0).strip()) - + # END while there are message lines message = '\n'.join(messages) commits.append(Commit(repo, id=id, parents=parents, tree=tree, author=author, authored_date=authored_date, committer=committer, committed_date=committed_date, message=message)) - + # END while lines return commits @classmethod diff --git a/lib/git/diff.py b/lib/git/diff.py index ef58cb0e..7200b7e3 100644 --- a/lib/git/diff.py +++ b/lib/git/diff.py @@ -45,12 +45,12 @@ class Diff(object): \.\.(?P<b_blob_id>[0-9A-Fa-f]+)[ ]?(?P<b_mode>.+)?(?:\n|$))? """, re.VERBOSE | re.MULTILINE) re_is_null_hexsha = re.compile( r'^0{40}$' ) + __slots__ = ("a_blob", "b_blob", "a_mode", "b_mode", "new_file", "deleted_file", + "rename_from", "rename_to", "renamed", "diff") def __init__(self, repo, a_path, b_path, a_blob_id, b_blob_id, a_mode, b_mode, new_file, deleted_file, rename_from, rename_to, diff): - self.repo = repo - if not a_blob_id or self.re_is_null_hexsha.search(a_blob_id): self.a_blob = None else: diff --git a/lib/git/stats.py b/lib/git/stats.py index a39d1dab..19b1591f 100644 --- a/lib/git/stats.py +++ b/lib/git/stats.py @@ -31,8 +31,9 @@ class Stats(object): files = number of changed files as int """ - def __init__(self, repo, total, files): - self.repo = repo + __slots__ = ("total", "files") + + def __init__(self, total, files): self.total = total self.files = files @@ -56,4 +57,4 @@ class Stats(object): hsh['files'][filename.strip()] = {'insertions': insertions, 'deletions': deletions, 'lines': insertions + deletions} - return Stats(repo, hsh['total'], hsh['files']) + return Stats(hsh['total'], hsh['files']) |