def commit_diff(self, commit): from klaus.utils import guess_is_binary, force_unicode if commit.parents: parent_tree = self[commit.parents[0]].tree else: parent_tree = None changes = self.object_store.tree_changes(parent_tree, commit.tree) for (oldpath, newpath), (oldmode, newmode), (oldsha, newsha) in changes: try: if newsha and guess_is_binary(self[newsha]) or oldsha and guess_is_binary(self[oldsha]): yield { "is_binary": True, "old_filename": oldpath or "/dev/null", "new_filename": newpath or "/dev/null", "chunks": None, } continue except KeyError: # newsha/oldsha are probably related to submodules. # Dulwich will handle that. pass stringio = cStringIO.StringIO() dulwich.patch.write_object_diff( stringio, self.object_store, (oldpath, oldmode, oldsha), (newpath, newmode, newsha) ) files = prepare_udiff(force_unicode(stringio.getvalue()), want_header=False) if not files: # the diff module doesn't handle deletions/additions # of empty files correctly. yield {"old_filename": oldpath or "/dev/null", "new_filename": newpath or "/dev/null", "chunks": []} else: yield files[0]
def commit_diff(self, commit): """Return the list of changes introduced by `commit`.""" from klaus.utils import guess_is_binary if commit.parents: parent_tree = self[commit.parents[0]].tree else: parent_tree = None summary = {'nfiles': 0, 'nadditions': 0, 'ndeletions': 0} file_changes = [] # the changes in detail dulwich_changes = self.object_store.tree_changes( parent_tree, commit.tree) for (oldpath, newpath), (oldmode, newmode), (oldsha, newsha) in dulwich_changes: summary['nfiles'] += 1 try: # Check for binary files -- can't show diffs for these if newsha and guess_is_binary(self[newsha]) or \ oldsha and guess_is_binary(self[oldsha]): file_changes.append({ 'is_binary': True, 'old_filename': oldpath or '/dev/null', 'new_filename': newpath or '/dev/null', 'chunks': None }) continue except KeyError: # newsha/oldsha are probably related to submodules. # Dulwich will handle that. pass bytesio = io.BytesIO() dulwich.patch.write_object_diff(bytesio, self.object_store, (oldpath, oldmode, oldsha), (newpath, newmode, newsha)) files = prepare_udiff(decode_from_git(bytesio.getvalue()), want_header=False) if not files: # the diff module doesn't handle deletions/additions # of empty files correctly. file_changes.append({ 'old_filename': oldpath or '/dev/null', 'new_filename': newpath or '/dev/null', 'chunks': [], 'additions': 0, 'deletions': 0, }) else: change = files[0] summary['nadditions'] += change['additions'] summary['ndeletions'] += change['deletions'] file_changes.append(change) return summary, file_changes
def commit_diff(self, commit): from klaus.utils import guess_is_binary, force_unicode if commit.parents: parent_tree = self[commit.parents[0]].tree else: parent_tree = None summary = {'nfiles': 0, 'nadditions': 0, 'ndeletions': 0} file_changes = [] # the changes in detail dulwich_changes = self.object_store.tree_changes(parent_tree, commit.tree) for (oldpath, newpath), (oldmode, newmode), (oldsha, newsha) in dulwich_changes: summary['nfiles'] += 1 try: # Check for binary files -- can't show diffs for these if newsha and guess_is_binary(self[newsha]) or \ oldsha and guess_is_binary(self[oldsha]): file_changes.append({ 'is_binary': True, 'old_filename': oldpath or '/dev/null', 'new_filename': newpath or '/dev/null', 'chunks': None }) continue except KeyError: # newsha/oldsha are probably related to submodules. # Dulwich will handle that. pass stringio = cStringIO.StringIO() dulwich.patch.write_object_diff(stringio, self.object_store, (oldpath, oldmode, oldsha), (newpath, newmode, newsha)) files = prepare_udiff(force_unicode(stringio.getvalue()), want_header=False) if not files: # the diff module doesn't handle deletions/additions # of empty files correctly. file_changes.append({ 'old_filename': oldpath or '/dev/null', 'new_filename': newpath or '/dev/null', 'chunks': [], 'additions': 0, 'deletions': 0, }) else: change = files[0] summary['nadditions'] += change['additions'] summary['ndeletions'] += change['deletions'] file_changes.append(change) return summary, file_changes
def commit_diff(self, commit): from klaus.utils import guess_is_binary, force_unicode if commit.parents: parent_tree = self[commit.parents[0]].tree else: parent_tree = None changes = self.object_store.tree_changes(parent_tree, commit.tree) for (oldpath, newpath), (oldmode, newmode), (oldsha, newsha) in changes: try: if newsha and guess_is_binary(self[newsha]) or \ oldsha and guess_is_binary(self[oldsha]): yield { 'is_binary': True, 'old_filename': oldpath or '/dev/null', 'new_filename': newpath or '/dev/null', 'chunks': None } continue except KeyError: # newsha/oldsha are probably related to submodules. # Dulwich will handle that. pass stringio = StringIO.StringIO() dulwich.patch.write_object_diff(stringio, self.object_store, (oldpath, oldmode, oldsha), (newpath, newmode, newsha)) files = prepare_udiff(force_unicode(stringio.getvalue()), want_header=False) if not files: # the diff module doesn't handle deletions/additions # of empty files correctly. yield { 'old_filename': oldpath or '/dev/null', 'new_filename': newpath or '/dev/null', 'chunks': [] } else: yield files[0]