summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-12-13 22:21:06 +0000
committerAntoine GIRARD <sapk@users.noreply.github.com>2019-12-13 23:21:06 +0100
commit74179d1b5e739b3fa0d0915bb35d6b7596fd13af (patch)
treefd8eb776c254b716a4e2d416bb6903f1c4c90ea7 /modules
parent8f16a2c37b4f2650f5e9623a92eb368db9564c6f (diff)
downloadgitea-74179d1b5e739b3fa0d0915bb35d6b7596fd13af.tar.gz
gitea-74179d1b5e739b3fa0d0915bb35d6b7596fd13af.zip
Remove SavePatch and generate patches on the fly (#9302)
* Save patches to temporary files * Remove SavePatch and generate patches on the fly * Use ioutil.TempDir * fixup! Use ioutil.TempDir * fixup! fixup! Use ioutil.TempDir * RemoveAll LocalCopyPath() in initIntergrationTest * Default to status checking on PR creation * Remove unnecessary set to StatusChecking * Protect against unable to load repo * Handle conflicts * Restore original conflict setting * In TestPullRequests update status to StatusChecking before running TestPatch
Diffstat (limited to 'modules')
-rw-r--r--modules/git/repo_compare.go28
-rw-r--r--modules/git/repo_compare_test.go4
2 files changed, 18 insertions, 14 deletions
diff --git a/modules/git/repo_compare.go b/modules/git/repo_compare.go
index 677201c5e0..53b8af4bb4 100644
--- a/modules/git/repo_compare.go
+++ b/modules/git/repo_compare.go
@@ -6,7 +6,6 @@
package git
import (
- "bytes"
"container/list"
"fmt"
"io"
@@ -94,19 +93,22 @@ func (repo *Repository) GetCompareInfo(basePath, baseBranch, headBranch string)
return compareInfo, nil
}
-// GetPatch generates and returns patch data between given revisions.
-func (repo *Repository) GetPatch(base, head string) ([]byte, error) {
- return NewCommand("diff", "-p", "--binary", base, head).RunInDirBytes(repo.Path)
+// 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 {
+ return repo.GetPatch(base, head, w)
+ }
+ return repo.GetDiff(base, head, w)
}
-// GetFormatPatch generates and returns format-patch data between given revisions.
-func (repo *Repository) GetFormatPatch(base, head string) (io.Reader, error) {
- stdout := new(bytes.Buffer)
- stderr := new(bytes.Buffer)
+// GetDiff generates and returns patch data between given revisions.
+func (repo *Repository) GetDiff(base, head string, w io.Writer) error {
+ return NewCommand("diff", "-p", "--binary", base, head).
+ RunInDirPipeline(repo.Path, w, nil)
+}
- if err := NewCommand("format-patch", "--binary", "--stdout", base+"..."+head).
- RunInDirPipeline(repo.Path, stdout, stderr); err != nil {
- return nil, concatenateError(err, stderr.String())
- }
- return stdout, nil
+// GetPatch generates and returns format-patch data between given revisions.
+func (repo *Repository) GetPatch(base, head string, w io.Writer) error {
+ return NewCommand("format-patch", "--binary", "--stdout", base+"..."+head).
+ RunInDirPipeline(repo.Path, w, nil)
}
diff --git a/modules/git/repo_compare_test.go b/modules/git/repo_compare_test.go
index def67fa87b..bf4631d853 100644
--- a/modules/git/repo_compare_test.go
+++ b/modules/git/repo_compare_test.go
@@ -5,6 +5,7 @@
package git
import (
+ "bytes"
"io/ioutil"
"os"
"path/filepath"
@@ -21,7 +22,8 @@ func TestGetFormatPatch(t *testing.T) {
repo, err := OpenRepository(clonedPath)
assert.NoError(t, err)
defer repo.Close()
- rd, err := repo.GetFormatPatch("8d92fc95^", "8d92fc95")
+ rd := &bytes.Buffer{}
+ err = repo.GetPatch("8d92fc95^", "8d92fc95", rd)
assert.NoError(t, err)
patchb, err := ioutil.ReadAll(rd)
assert.NoError(t, err)