summaryrefslogtreecommitdiff
path: root/lib/git
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-10-08 23:41:21 +0200
committerSebastian Thiel <byronimo@gmail.com>2009-10-08 23:41:21 +0200
commit88cc927ff2f8560cb2f224c313a5e5e8d64aa414 (patch)
tree819051315aa6c0fa8aac7cde5f5e57396a5c44b0 /lib/git
parent07eaa4ce2696a88ec0db6e91f191af1e48226aca (diff)
parentac13dbce276f81b5839987140cdd8db3d15d42a1 (diff)
downloadgitpython-88cc927ff2f8560cb2f224c313a5e5e8d64aa414.tar.gz
Merge branches 'doc_enhancements' and 'fixes_for_mainline' into improvements_for_mainline
* doc_enhancements: improved repo documentation Improved head and tag object documentation slightly Added docs for the error module Added missing information to docstrings of commit and stats module improved git.cmd documentation Improved documentation on Actor and Blob * fixes_for_mainline: repo_tests: fixed duplicate test-method name which would redefine the previous one which never ran Fixed Diff class which used Commits instead of Blobs - as Blobs contain the path ( in the 'name' member variable ), the a|b_path members of Diff have been removed. Tests were adjusted and run git.git.Git.__init__ takes None as default argument as the execute method handles this correctly Fixed git.blob.Blob.blame function which would return the text-per-commit as individual characters Conflicts: lib/git/cmd.py test/git/test_repo.py
Diffstat (limited to 'lib/git')
-rw-r--r--lib/git/blob.py2
-rw-r--r--lib/git/cmd.py2
-rw-r--r--lib/git/diff.py55
3 files changed, 43 insertions, 16 deletions
diff --git a/lib/git/blob.py b/lib/git/blob.py
index eea04490..82a41f73 100644
--- a/lib/git/blob.py
+++ b/lib/git/blob.py
@@ -152,7 +152,7 @@ class Blob(object):
m = re.search(r'^\t(.*)$', line)
text, = m.groups()
blames[-1][0] = c
- blames[-1][1] += text
+ blames[-1][1].append( text )
info = None
return blames
diff --git a/lib/git/cmd.py b/lib/git/cmd.py
index 796928b3..aef53350 100644
--- a/lib/git/cmd.py
+++ b/lib/git/cmd.py
@@ -35,7 +35,7 @@ class Git(object):
of the command to stdout.
Set its value to 'full' to see details about the returned values.
"""
- def __init__(self, git_dir):
+ def __init__(self, git_dir=None):
"""
Initialize this instance with:
diff --git a/lib/git/diff.py b/lib/git/diff.py
index 0216e061..44f55602 100644
--- a/lib/git/diff.py
+++ b/lib/git/diff.py
@@ -5,28 +5,44 @@
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
import re
-import commit
+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
"""
- def __init__(self, repo, a_path, b_path, a_commit, b_commit, a_mode,
+ def __init__(self, repo, a_path, b_path, a_blob, b_blob, a_mode,
b_mode, new_file, deleted_file, rename_from,
rename_to, diff):
self.repo = repo
- self.a_path = a_path
- self.b_path = b_path
- if not a_commit or re.search(r'^0{40}$', a_commit):
- self.a_commit = None
+ if not a_blob or re.search(r'^0{40}$', a_blob):
+ self.a_blob = None
else:
- self.a_commit = commit.Commit(repo, id=a_commit)
- if not b_commit or re.search(r'^0{40}$', b_commit):
- self.b_commit = None
+ self.a_blob = blob.Blob(repo, id=a_blob, mode=a_mode, name=a_path)
+ if not b_blob or re.search(r'^0{40}$', b_blob):
+ self.b_blob = None
else:
- self.b_commit = commit.Commit(repo, id=b_commit)
+ self.b_blob = blob.Blob(repo, id=b_blob, mode=b_mode, name=b_path)
self.a_mode = a_mode
self.b_mode = b_mode
@@ -39,6 +55,17 @@ class Diff(object):
@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 = re.compile(r"""
@@ -51,8 +78,8 @@ class Diff(object):
^new[ ]mode[ ](?P<new_mode>\d+)(?:\n|$))?
(?:^new[ ]file[ ]mode[ ](?P<new_file_mode>.+)(?:\n|$))?
(?:^deleted[ ]file[ ]mode[ ](?P<deleted_file_mode>.+)(?:\n|$))?
- (?:^index[ ](?P<a_commit>[0-9A-Fa-f]+)
- \.\.(?P<b_commit>[0-9A-Fa-f]+)[ ]?(?P<b_mode>.+)?(?:\n|$))?
+ (?:^index[ ](?P<a_blob>[0-9A-Fa-f]+)
+ \.\.(?P<b_blob>[0-9A-Fa-f]+)[ ]?(?P<b_mode>.+)?(?:\n|$))?
""", re.VERBOSE | re.MULTILINE).match
for diff in ('\n' + text).split('\ndiff --git')[1:]:
@@ -60,10 +87,10 @@ class Diff(object):
a_path, b_path, similarity_index, rename_from, rename_to, \
old_mode, new_mode, new_file_mode, deleted_file_mode, \
- a_commit, b_commit, b_mode = header.groups()
+ a_blob, b_blob, 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_commit, b_commit,
+ diffs.append(Diff(repo, a_path, b_path, a_blob, b_blob,
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():]))