From 37ef8f1859a191c35340dacea848f282f9a6b727 Mon Sep 17 00:00:00 2001 From: Peter Grayson Date: Mon, 13 Sep 2021 18:36:24 -0400 Subject: [PATCH] Do not show binary diffs when editing patch Nobody is going to edit the base85-encoded content of binary diffs. N.B. in order for diffs containing "Binary files ... differ" notations to apply, the full sha1 must be present in the diff indexes. Thus --full-index is now used with `git diff-tree`. Signed-off-by: Peter Grayson --- stgit/lib/edit.py | 4 +++- stgit/lib/git/repository.py | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/stgit/lib/edit.py b/stgit/lib/edit.py index 4f56899..c7c4144 100644 --- a/stgit/lib/edit.py +++ b/stgit/lib/edit.py @@ -76,7 +76,9 @@ def get_patch_description(repo, cd, patch_name, append_diff, diff_flags): ).encode(commit_encoding) if append_diff: parts = [desc.rstrip(), b'---', b''] - diff = repo.diff_tree(cd.parent.data.tree, cd.tree, diff_flags) + diff = repo.diff_tree( + cd.parent.data.tree, cd.tree, diff_flags, binary=False, full_index=True + ) if diff: diffstat = repo.default_iw.diffstat(diff).encode(commit_encoding) parts.extend([diffstat, diff]) diff --git a/stgit/lib/git/repository.py b/stgit/lib/git/repository.py index f89e37f..fff3441 100644 --- a/stgit/lib/git/repository.py +++ b/stgit/lib/git/repository.py @@ -404,7 +404,16 @@ class Repository: # Then extract the paths of any submodules return set(m.group(1) for m in map(regex.match, files) if m) - def diff_tree(self, t1, t2, diff_opts=(), pathlimits=(), binary=True, stat=False): + def diff_tree( + self, + t1, + t2, + diff_opts=(), + pathlimits=(), + binary=True, + stat=False, + full_index=False, + ): """Produce patch (diff) between two trees. Given two :class:`Tree`s ``t1`` and ``t2``, return the patch that takes @@ -420,6 +429,8 @@ class Repository: args = ['--patch'] if binary and '--binary' not in diff_opts: args.append('--binary') + if full_index: + args.append('--full-index') args.extend(diff_opts) if pathlimits: args.append('--') -- 2.11.4.GIT