forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a page for comparing patchsets using 'git range-diff'. Fixes g…
…o-gitea#12800 Also add warnings if a '/compare/base...head' is y shaped and offer to show the raw difference (where the inverse of new commits on base are included in the diff) and also offer to compare the y shaped junction with range-diff. The rangediff page uses the interdiff tool to work out the changes between corresponding commits.
- Loading branch information
Showing
31 changed files
with
2,253 additions
and
469 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright 2020 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package git | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
|
||
"code.gitea.io/gitea/modules/process" | ||
) | ||
|
||
// GetInterdiff get the difference of two diffs. | ||
func GetInterdiff(diff1, diff2 string) (string, error) { | ||
f1 := "/dev/null" | ||
f2 := "/dev/null" | ||
|
||
if diff1 != "" { | ||
f, err := ioutil.TempFile("", "d1") | ||
if err != nil { | ||
return "", err | ||
} | ||
f1 = f.Name() | ||
defer os.Remove(f1) | ||
|
||
_, err = f.WriteString(diff1) | ||
|
||
if err != nil { | ||
return "", err | ||
} | ||
} | ||
|
||
if diff2 != "" { | ||
f, err := ioutil.TempFile("", "d2") | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
_, err = f.WriteString(diff2) | ||
|
||
if err != nil { | ||
return "", err | ||
} | ||
|
||
f2 = f.Name() | ||
defer os.Remove(f2) | ||
} | ||
|
||
ctx, cancel := context.WithCancel(DefaultContext) | ||
defer cancel() | ||
var cmd = exec.CommandContext(ctx, Interdiff, "-q", f1, f2) | ||
cmd.Stderr = os.Stderr | ||
|
||
stdout, err := cmd.StdoutPipe() | ||
if err != nil { | ||
return "", fmt.Errorf("StdoutPipe: %v", err) | ||
} | ||
|
||
if err = cmd.Start(); err != nil { | ||
return "", fmt.Errorf("Start: %v", err) | ||
} | ||
|
||
pid := process.GetManager().Add("GetInterdiff ", cancel) | ||
defer process.GetManager().Remove(pid) | ||
|
||
buf := new(strings.Builder) | ||
_, err = io.Copy(buf, stdout) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
if err = cmd.Wait(); err != nil { | ||
return "", fmt.Errorf("Wait: %v", err) | ||
} | ||
|
||
return buf.String(), nil | ||
} |
Oops, something went wrong.