diff options
author | Norwin <noerw@users.noreply.github.com> | 2021-09-27 23:09:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-27 17:09:49 -0400 |
commit | f48dce3176649916c262ab080d5f38a0433f38c0 (patch) | |
tree | d009bc163d78577666dc462d376d697f600ef2d1 /modules/git/repo_compare.go | |
parent | e8574f2f7d4648b5b3fda48f3e31599a6b9dd40b (diff) | |
download | gitea-f48dce3176649916c262ab080d5f38a0433f38c0.tar.gz gitea-f48dce3176649916c262ab080d5f38a0433f38c0.zip |
Don't return binary file changes in raw PR diffs by default (#17158)
* return diffs without binary file content change
* ?binary=true option to restore old behaviour
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'modules/git/repo_compare.go')
-rw-r--r-- | modules/git/repo_compare.go | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/modules/git/repo_compare.go b/modules/git/repo_compare.go index 866b3d9133..50e9005511 100644 --- a/modules/git/repo_compare.go +++ b/modules/git/repo_compare.go @@ -215,20 +215,29 @@ func parseDiffStat(stdout string) (numFiles, totalAdditions, totalDeletions int, } // GetDiffOrPatch generates either diff or formatted patch data between given revisions -func (repo *Repository) GetDiffOrPatch(base, head string, w io.Writer, formatted bool) error { - if formatted { +func (repo *Repository) GetDiffOrPatch(base, head string, w io.Writer, patch, binary bool) error { + if patch { return repo.GetPatch(base, head, w) } + if binary { + return repo.GetDiffBinary(base, head, w) + } return repo.GetDiff(base, head, w) } -// GetDiff generates and returns patch data between given revisions. +// GetDiff generates and returns patch data between given revisions, optimized for human readability func (repo *Repository) GetDiff(base, head string, w io.Writer) error { + return NewCommand("diff", "-p", base, head). + RunInDirPipeline(repo.Path, w, nil) +} + +// GetDiffBinary generates and returns patch data between given revisions, including binary diffs. +func (repo *Repository) GetDiffBinary(base, head string, w io.Writer) error { return NewCommand("diff", "-p", "--binary", base, head). RunInDirPipeline(repo.Path, w, nil) } -// GetPatch generates and returns format-patch data between given revisions. +// GetPatch generates and returns format-patch data between given revisions, able to be used with `git apply` func (repo *Repository) GetPatch(base, head string, w io.Writer) error { stderr := new(bytes.Buffer) err := NewCommand("format-patch", "--binary", "--stdout", base+"..."+head). @@ -246,8 +255,7 @@ func (repo *Repository) GetDiffFromMergeBase(base, head string, w io.Writer) err err := NewCommand("diff", "-p", "--binary", base+"..."+head). RunInDirPipeline(repo.Path, w, stderr) if err != nil && bytes.Contains(stderr.Bytes(), []byte("no merge base")) { - return NewCommand("diff", "-p", "--binary", base, head). - RunInDirPipeline(repo.Path, w, nil) + return repo.GetDiffBinary(base, head, w) } return err } |