Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md5
-rw-r--r--internal/diff/diff.go6
-rw-r--r--internal/service/diff/commit_test.go12
-rw-r--r--internal/service/diff/testdata/file-with-pluses-chunks.txt6
4 files changed, 27 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 47ad62a26..289e296dd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,10 @@
# Gitaly changelog
+UNRELEASED
+
+- Fix incorrect parsing of diff chunks starting with ++ or --
+ https://gitlab.com/gitlab-org/gitaly/merge_requests/385
+
v0.43.0
- Pass details of Gitaly-Ruby's Ruby exceptions back to
diff --git a/internal/diff/diff.go b/internal/diff/diff.go
index e6b68b9ab..9365ef1ac 100644
--- a/internal/diff/diff.go
+++ b/internal/diff/diff.go
@@ -136,7 +136,7 @@ func (parser *Parser) Parse() bool {
break
} else if bytes.HasPrefix(line, []byte("@@")) {
parser.consumeChunkLine()
- } else if helper.ByteSliceHasAnyPrefix(line, "---", "+++") {
+ } else if helper.ByteSliceHasAnyPrefix(line, "---", "+++") && !parser.isParsingChunkLines() {
parser.consumeLine(true)
} else if helper.ByteSliceHasAnyPrefix(line, "-", "+", " ", "\\", "Binary") {
parser.consumeChunkLine()
@@ -361,6 +361,10 @@ func (parser *Parser) consumeLine(updateStats bool) {
}
}
+func (parser *Parser) isParsingChunkLines() bool {
+ return len(parser.currentDiff.Patch) > 0
+}
+
// unescape unescapes the escape codes used by 'git diff'
func unescape(s []byte) []byte {
var unescaped []byte
diff --git a/internal/service/diff/commit_test.go b/internal/service/diff/commit_test.go
index 3817ff3f6..7239cca78 100644
--- a/internal/service/diff/commit_test.go
+++ b/internal/service/diff/commit_test.go
@@ -21,7 +21,7 @@ func TestSuccessfulCommitDiffRequest(t *testing.T) {
client, conn := newDiffClient(t)
defer conn.Close()
- rightCommit := "e395f646b1499e8e0279445fc99a0596a65fab7e"
+ rightCommit := "ab2c9622c02288a2bbaaf35d96088cfdff31d9d9"
leftCommit := "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab"
rpcRequest := &pb.CommitDiffRequest{Repository: testRepo, RightCommitId: rightCommit, LeftCommitId: leftCommit, IgnoreWhitespaceChange: false}
@@ -65,6 +65,16 @@ func TestSuccessfulCommitDiffRequest(t *testing.T) {
},
{
FromID: "0000000000000000000000000000000000000000",
+ ToID: "389c7a36a6e133268b0d36b00e7ffc0f3a5b6651",
+ OldMode: 0,
+ NewMode: 0100644,
+ FromPath: []byte("gitaly/file-with-pluses.txt"),
+ ToPath: []byte("gitaly/file-with-pluses.txt"),
+ Binary: false,
+ Patch: testhelper.MustReadFile(t, "testdata/file-with-pluses-chunks.txt"),
+ },
+ {
+ FromID: "0000000000000000000000000000000000000000",
ToID: "bc2ef601a538d69ef99d5bdafa605e63f902e8e4",
OldMode: 0,
NewMode: 0100644,
diff --git a/internal/service/diff/testdata/file-with-pluses-chunks.txt b/internal/service/diff/testdata/file-with-pluses-chunks.txt
new file mode 100644
index 000000000..d36fcf375
--- /dev/null
+++ b/internal/service/diff/testdata/file-with-pluses-chunks.txt
@@ -0,0 +1,6 @@
+@@ -0,0 +1,5 @@
+++
++++
+++++
++++++
+++++++