diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-10-22 22:22:00 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-10-22 22:22:00 +0200 |
commit | b2a14e4b96a0ffc5353733b50266b477539ef899 (patch) | |
tree | ce48feb6d2da2bed92240c0fbd2350e05f7b7519 /lib/git/diff.py | |
parent | 20c34a929a8b2871edd4fd44a38688e8977a4be6 (diff) | |
parent | ea33fe8b21d2b02f902b131aba0d14389f2f8715 (diff) | |
download | gitpython-b2a14e4b96a0ffc5353733b50266b477539ef899.tar.gz |
Merge branch 'index' into improvements
* index:
Index: Is now diffable and appears to properly implement diffing against other items as well as the working tree
default index writing now writes the index of the current repository in a fashion comparable to the native implementation
Added test for ConcurrentWriteOperation
utils: Added LockFile including test
Index now behaves more like the default index if no explicit stream is given. It will lazily read its data on first access
Diffstat (limited to 'lib/git/diff.py')
-rw-r--r-- | lib/git/diff.py | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/lib/git/diff.py b/lib/git/diff.py index 9b884502..03e6709c 100644 --- a/lib/git/diff.py +++ b/lib/git/diff.py @@ -18,13 +18,18 @@ class Diffable(object): """ __slots__ = tuple() - # subclasses provide additional arguments to the git-diff comamnd by supplynig - # them in this tuple - _diff_args = tuple() - - # Temporary standin for Index type until we have a real index type + # standin indicating you want to diff against the index class Index(object): pass + + def _process_diff_args(self, args): + """ + Returns + possibly altered version of the given args list. + Method is called right before git command execution. + Subclasses can use it to alter the behaviour of the superclass + """ + return args def diff(self, other=Index, paths=None, create_patch=False, **kwargs): """ @@ -60,13 +65,13 @@ class Diffable(object): On a bare repository, 'other' needs to be provided as Index or as as Tree/Commit, or a git command error will occour """ - args = list(self._diff_args[:]) + args = list() args.append( "--abbrev=40" ) # we need full shas args.append( "--full-index" ) # get full index paths, not only filenames if create_patch: args.append("-p") - args.append("-M") # check for renames + args.append("-M") # check for renames else: args.append("--raw") @@ -87,7 +92,7 @@ class Diffable(object): # END paths handling kwargs['as_process'] = True - proc = self.repo.git.diff(*args, **kwargs) + proc = self.repo.git.diff(*self._process_diff_args(args), **kwargs) diff_method = Diff._index_from_raw_format if create_patch: @@ -96,7 +101,7 @@ class Diffable(object): status = proc.wait() if status != 0: - raise GitCommandError("git-diff", status, proc.stderr ) + raise GitCommandError(("git diff",)+tuple(args), status, proc.stderr.read()) return index @@ -207,6 +212,20 @@ class Diff(object): self.diff = diff + + def __eq__(self, other): + for name in self.__slots__: + if getattr(self, name) != getattr(other, name): + return False + # END for each name + return True + + def __ne__(self, other): + return not ( self == other ) + + def __hash__(self): + return hash(tuple(getattr(self,n) for n in self.__slots__)) + @property def renamed(self): """ |