summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/git/diff.go18
-rw-r--r--modules/structs/repo_file.go8
2 files changed, 24 insertions, 2 deletions
diff --git a/modules/git/diff.go b/modules/git/diff.go
index d71b0b2471..2d85db4753 100644
--- a/modules/git/diff.go
+++ b/modules/git/diff.go
@@ -32,6 +32,21 @@ func GetRawDiff(ctx context.Context, repoPath, commitID string, diffType RawDiff
return GetRawDiffForFile(ctx, repoPath, "", commitID, diffType, "", writer)
}
+// GetReverseRawDiff dumps the reverse diff results of repository in given commit ID to io.Writer.
+func GetReverseRawDiff(ctx context.Context, repoPath, commitID string, writer io.Writer) error {
+ stderr := new(bytes.Buffer)
+ cmd := NewCommand(ctx, "show", "--pretty=format:revert %H%n", "-R", commitID)
+ if err := cmd.RunWithContext(&RunContext{
+ Timeout: -1,
+ Dir: repoPath,
+ Stdout: writer,
+ Stderr: stderr,
+ }); err != nil {
+ return fmt.Errorf("Run: %v - %s", err, stderr)
+ }
+ return nil
+}
+
// GetRawDiffForFile dumps diff results of file in given commit ID to io.Writer.
func GetRawDiffForFile(ctx context.Context, repoPath, startCommit, endCommit string, diffType RawDiffType, file string, writer io.Writer) error {
repo, closer, err := RepositoryFromContextOrOpen(ctx, repoPath)
@@ -221,8 +236,7 @@ func CutDiffAroundLine(originalDiff io.Reader, line int64, old bool, numbersOfLi
}
}
}
- err := scanner.Err()
- if err != nil {
+ if err := scanner.Err(); err != nil {
return "", err
}
diff --git a/modules/structs/repo_file.go b/modules/structs/repo_file.go
index 71733c90e7..e2947bf7ac 100644
--- a/modules/structs/repo_file.go
+++ b/modules/structs/repo_file.go
@@ -50,6 +50,14 @@ type UpdateFileOptions struct {
FromPath string `json:"from_path" binding:"MaxSize(500)"`
}
+// ApplyDiffPatchFileOptions options for applying a diff patch
+// Note: `author` and `committer` are optional (if only one is given, it will be used for the other, otherwise the authenticated user will be used)
+type ApplyDiffPatchFileOptions struct {
+ DeleteFileOptions
+ // required: true
+ Content string `json:"content"`
+}
+
// FileLinksResponse contains the links for a repo's file
type FileLinksResponse struct {
Self *string `json:"self"`