diff --git a/modules/git/repo_compare.go b/modules/git/repo_compare.go index ec8bacb5ec..5d7fbe6df6 100644 --- a/modules/git/repo_compare.go +++ b/modules/git/repo_compare.go @@ -233,17 +233,6 @@ func parseDiffStat(stdout string) (numFiles, totalAdditions, totalDeletions int, return numFiles, totalAdditions, totalDeletions, err } -// GetDiffOrPatch generates either diff or formatted patch data between given revisions -func (repo *Repository) GetDiffOrPatch(compareString string, w io.Writer, patch, binary bool) error { - if patch { - return repo.GetPatch(compareString, w) - } - if binary { - return repo.GetDiffBinary(compareString, w) - } - return repo.GetDiff(compareString, w) -} - func parseCompareArgs(compareArgs string) (args []string) { parts := strings.Split(compareArgs, "...") if len(parts) == 2 { diff --git a/services/pull/patch.go b/services/pull/patch.go index 192a67739e..c5befe39d6 100644 --- a/services/pull/patch.go +++ b/services/pull/patch.go @@ -29,6 +29,17 @@ import ( "github.com/gobwas/glob" ) +// getDiffOrPatch generates either diff or formatted patch data between given revisions +func getDiffOrPatch(repo *git.Repository, compareString string, w io.Writer, patch, binary bool) error { + if patch { + return repo.GetPatch(compareString, w) + } + if binary { + return repo.GetDiffBinary(compareString, w) + } + return repo.GetDiff(compareString, w) +} + // DownloadDiffOrPatch will write the patch for the pr to the writer func DownloadDiffOrPatch(ctx context.Context, pr *issues_model.PullRequest, w io.Writer, patch, binary bool) error { if err := pr.LoadBaseRepo(ctx); err != nil { @@ -42,7 +53,7 @@ func DownloadDiffOrPatch(ctx context.Context, pr *issues_model.PullRequest, w io } defer closer.Close() - if err := gitRepo.GetDiffOrPatch(pr.MergeBase+".."+pr.GetGitRefName(), w, patch, binary); err != nil { + if err := getDiffOrPatch(gitRepo, pr.MergeBase+"..."+pr.GetGitRefName(), w, patch, binary); err != nil { log.Error("unable to get patch file from %s to %s in %s Error: %v", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err) return fmt.Errorf("unable to get patch file from %s to %s in %s Error: %w", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err) }