summaryrefslogtreecommitdiff
path: root/lib/git
diff options
context:
space:
mode:
Diffstat (limited to 'lib/git')
-rw-r--r--lib/git/diff.py41
-rw-r--r--lib/git/objects/base.py8
2 files changed, 45 insertions, 4 deletions
diff --git a/lib/git/diff.py b/lib/git/diff.py
index dfeb7064..38430827 100644
--- a/lib/git/diff.py
+++ b/lib/git/diff.py
@@ -208,7 +208,7 @@ class Diff(object):
self.a_blob = None
else:
self.a_blob = blob.Blob(repo, a_blob_id, mode=a_mode, path=a_path)
- if not b_blob_id:
+ if b_blob_id is None:
self.b_blob = None
else:
self.b_blob = blob.Blob(repo, b_blob_id, mode=b_mode, path=b_path)
@@ -244,6 +244,45 @@ class Diff(object):
def __hash__(self):
return hash(tuple(getattr(self,n) for n in self.__slots__))
+ def __str__(self):
+ h = "%s"
+ if self.a_blob:
+ h %= self.a_blob.path
+ if self.b_blob:
+ h %= self.b_blob.path
+
+ msg = ''
+ l = None # temp line
+ ll = 0 # line length
+ for b,n in zip((self.a_blob, self.b_blob), ('lhs', 'rhs')):
+ if b:
+ l = "\n%s: %o | %s" % (n, b.mode, b.sha)
+ else:
+ l = "\n%s: None" % n
+ # END if blob is not None
+ ll = max(len(l), ll)
+ msg += l
+ # END for each blob
+
+ # add headline
+ h += '\n' + '='*ll
+
+ if self.deleted_file:
+ msg += '\nfile deleted in rhs'
+ if self.new_file:
+ msg += '\nfile added in rhs'
+ if self.rename_from:
+ msg += '\nfile renamed from %r' % self.rename_from
+ if self.rename_to:
+ msg += '\nfile renamed to %r' % self.rename_to
+ if self.diff:
+ msg += '\n---'
+ msg += self.diff
+ msg += '\n---'
+ # END diff info
+
+ return h + msg
+
@property
def renamed(self):
"""
diff --git a/lib/git/objects/base.py b/lib/git/objects/base.py
index c66263c0..c7bf5bf2 100644
--- a/lib/git/objects/base.py
+++ b/lib/git/objects/base.py
@@ -184,14 +184,16 @@ class IndexObject(Object):
def _mode_str_to_int(cls, modestr):
"""
``modestr``
- string like 755 or 644 or 100644 - only the last 3 chars will be used
+ string like 755 or 644 or 100644 - only the last 6 chars will be used
Returns
String identifying a mode compatible to the mode methods ids of the
- stat module regarding the rwx permissions for user, group and other
+ stat module regarding the rwx permissions for user, group and other,
+ special flags and file system flags, i.e. whether it is a symlink
+ for example.
"""
mode = 0
- for iteration,char in enumerate(reversed(modestr[-3:])):
+ for iteration,char in enumerate(reversed(modestr[-6:])):
mode += int(char) << iteration*3
# END for each char
return mode