From 9374a916588d9fe7169937ba262c86ad710cfa74 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 11 Oct 2009 16:49:05 +0200 Subject: converted all spaces to tabs ( 4 spaces = 1 tab ) just to allow me and my editor to work with the files properly. Can convert it back for releaes --- lib/git/diff.py | 140 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 70 insertions(+), 70 deletions(-) (limited to 'lib/git/diff.py') diff --git a/lib/git/diff.py b/lib/git/diff.py index 75450d70..ef58cb0e 100644 --- a/lib/git/diff.py +++ b/lib/git/diff.py @@ -8,30 +8,30 @@ import re import blob class Diff(object): - """ - A Diff contains diff information between two commits. - - It contains two sides a and b of the diff, members are prefixed with - "a" and "b" respectively to inidcate that. - - Diffs keep information about the changed blob objects, the file mode, renames, - deletions and new files. - - There are a few cases where None has to be expected as member variable value: - - ``New File``:: - - a_mode is None - a_blob is None - - ``Deleted File``:: - - b_mode is None - b_blob is NOne - """ - - # precompiled regex - re_header = re.compile(r""" + """ + A Diff contains diff information between two commits. + + It contains two sides a and b of the diff, members are prefixed with + "a" and "b" respectively to inidcate that. + + Diffs keep information about the changed blob objects, the file mode, renames, + deletions and new files. + + There are a few cases where None has to be expected as member variable value: + + ``New File``:: + + a_mode is None + a_blob is None + + ``Deleted File``:: + + b_mode is None + b_blob is NOne + """ + + # precompiled regex + re_header = re.compile(r""" #^diff[ ]--git [ ]a/(?P\S+)[ ]b/(?P\S+)\n (?:^similarity[ ]index[ ](?P\d+)%\n @@ -44,58 +44,58 @@ class Diff(object): (?:^index[ ](?P[0-9A-Fa-f]+) \.\.(?P[0-9A-Fa-f]+)[ ]?(?P.+)?(?:\n|$))? """, re.VERBOSE | re.MULTILINE) - re_is_null_hexsha = re.compile( r'^0{40}$' ) + re_is_null_hexsha = re.compile( r'^0{40}$' ) - 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 + 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: - self.a_blob = blob.Blob(repo, id=a_blob_id, mode=a_mode, path=a_path) - if not b_blob_id or self.re_is_null_hexsha.search(b_blob_id): - self.b_blob = None - else: - self.b_blob = blob.Blob(repo, id=b_blob_id, mode=b_mode, path=b_path) + if not a_blob_id or self.re_is_null_hexsha.search(a_blob_id): + self.a_blob = None + else: + self.a_blob = blob.Blob(repo, id=a_blob_id, mode=a_mode, path=a_path) + if not b_blob_id or self.re_is_null_hexsha.search(b_blob_id): + self.b_blob = None + else: + self.b_blob = blob.Blob(repo, id=b_blob_id, mode=b_mode, path=b_path) - self.a_mode = a_mode - self.b_mode = b_mode - self.new_file = new_file - self.deleted_file = deleted_file - self.rename_from = rename_from - self.rename_to = rename_to - self.renamed = rename_from != rename_to - self.diff = diff + self.a_mode = a_mode + self.b_mode = b_mode + self.new_file = new_file + self.deleted_file = deleted_file + self.rename_from = rename_from + self.rename_to = rename_to + self.renamed = rename_from != rename_to + self.diff = diff - @classmethod - def list_from_string(cls, repo, text): - """ - Create a new diff object from the given text - ``repo`` - is the repository we are operating on - it is required - - ``text`` - result of 'git diff' between two commits or one commit and the index - - Returns - git.Diff[] - """ - diffs = [] + @classmethod + def list_from_string(cls, repo, text): + """ + Create a new diff object from the given text + ``repo`` + is the repository we are operating on - it is required + + ``text`` + result of 'git diff' between two commits or one commit and the index + + Returns + git.Diff[] + """ + diffs = [] - diff_header = cls.re_header.match - for diff in ('\n' + text).split('\ndiff --git')[1:]: - header = diff_header(diff) + diff_header = cls.re_header.match + for diff in ('\n' + text).split('\ndiff --git')[1:]: + header = diff_header(diff) - a_path, b_path, similarity_index, rename_from, rename_to, \ - old_mode, new_mode, new_file_mode, deleted_file_mode, \ - a_blob_id, b_blob_id, b_mode = header.groups() - new_file, deleted_file = bool(new_file_mode), bool(deleted_file_mode) + a_path, b_path, similarity_index, rename_from, rename_to, \ + old_mode, new_mode, new_file_mode, deleted_file_mode, \ + a_blob_id, b_blob_id, b_mode = header.groups() + new_file, deleted_file = bool(new_file_mode), bool(deleted_file_mode) - diffs.append(Diff(repo, a_path, b_path, a_blob_id, b_blob_id, - old_mode or deleted_file_mode, new_mode or new_file_mode or b_mode, - new_file, deleted_file, rename_from, rename_to, diff[header.end():])) + diffs.append(Diff(repo, a_path, b_path, a_blob_id, b_blob_id, + old_mode or deleted_file_mode, new_mode or new_file_mode or b_mode, + new_file, deleted_file, rename_from, rename_to, diff[header.end():])) - return diffs + return diffs -- cgit v1.2.1 From 708b8dda8e7b87841a5f39c60b799c514e75a9c7 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 11 Oct 2009 21:17:59 +0200 Subject: 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 --- lib/git/diff.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/git/diff.py') 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[0-9A-Fa-f]+)[ ]?(?P.+)?(?:\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: -- cgit v1.2.1 From b01824b1aecf8aadae4501e22feb45c20fb26bce Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 11 Oct 2009 22:22:28 +0200 Subject: Fixed remaining tests to deal with the changes mode is now generally an int compatible to the stat module --- lib/git/diff.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/git/diff.py') diff --git a/lib/git/diff.py b/lib/git/diff.py index 7200b7e3..943fb08a 100644 --- a/lib/git/diff.py +++ b/lib/git/diff.py @@ -62,6 +62,10 @@ class Diff(object): self.a_mode = a_mode self.b_mode = b_mode + if self.a_mode: + self.a_mode = blob.Blob._mode_str_to_int( self.a_mode ) + if self.b_mode: + self.b_mode = blob.Blob._mode_str_to_int( self.b_mode ) self.new_file = new_file self.deleted_file = deleted_file self.rename_from = rename_from -- cgit v1.2.1