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:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2020-09-24 13:01:09 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2020-10-15 14:48:12 +0300
commit658eaa2e301fad2a244301d5fcf268f32e7f4e17 (patch)
treeef50753c7561f1a08031c7a4d89ddecc7fa72176
parent831cb43987a98e817ce88d5c0b26ad345c07418b (diff)
git2go: Store conflict contents as bytes
When conflicts occur, it's not necessarily the case that the conflict's contents are valid UTF-8, as conflicting files may have different encodings. But as we're serializing and deserializing those contents as strings, any such encoding issues may get stripped away and cause us to end up with conflict contents which don't really represent the actual conflict. Fix this by using a byte array for conflict contents instead of a string.
-rw-r--r--cmd/gitaly-git2go/conflicts.go8
-rw-r--r--cmd/gitaly-git2go/conflicts_test.go15
-rw-r--r--internal/git2go/conflicts.go2
-rw-r--r--internal/git2go/conflicts_test.go4
4 files changed, 15 insertions, 14 deletions
diff --git a/cmd/gitaly-git2go/conflicts.go b/cmd/gitaly-git2go/conflicts.go
index adce23d60..ba892067e 100644
--- a/cmd/gitaly-git2go/conflicts.go
+++ b/cmd/gitaly-git2go/conflicts.go
@@ -32,7 +32,7 @@ func conflictEntryFromIndex(entry *git.IndexEntry) git2go.ConflictEntry {
}
}
-func conflictContent(repo *git.Repository, conflict git.IndexConflict) (string, error) {
+func conflictContent(repo *git.Repository, conflict git.IndexConflict) ([]byte, error) {
var ancestor, our, their git.MergeFileInput
for entry, input := range map[*git.IndexEntry]*git.MergeFileInput{
@@ -46,7 +46,7 @@ func conflictContent(repo *git.Repository, conflict git.IndexConflict) (string,
blob, err := repo.LookupBlob(entry.Id)
if err != nil {
- return "", fmt.Errorf("could not get conflicting blob: %w", err)
+ return nil, fmt.Errorf("could not get conflicting blob: %w", err)
}
input.Path = entry.Path
@@ -56,10 +56,10 @@ func conflictContent(repo *git.Repository, conflict git.IndexConflict) (string,
merge, err := git.MergeFile(ancestor, our, their, nil)
if err != nil {
- return "", fmt.Errorf("could not compute conflicts: %w", err)
+ return nil, fmt.Errorf("could not compute conflicts: %w", err)
}
- return string(merge.Contents), nil
+ return merge.Contents, nil
}
// Run performs a merge and prints resulting conflicts to stdout.
diff --git a/cmd/gitaly-git2go/conflicts_test.go b/cmd/gitaly-git2go/conflicts_test.go
index 36d49bddc..4cef16c12 100644
--- a/cmd/gitaly-git2go/conflicts_test.go
+++ b/cmd/gitaly-git2go/conflicts_test.go
@@ -48,7 +48,7 @@ func TestConflicts(t *testing.T) {
Ancestor: git2go.ConflictEntry{Path: "file", Mode: 0100644},
Our: git2go.ConflictEntry{Path: "file", Mode: 0100644},
Their: git2go.ConflictEntry{Path: "file", Mode: 0100644},
- Content: "<<<<<<< file\nb\n=======\nc\n>>>>>>> file\n",
+ Content: []byte("<<<<<<< file\nb\n=======\nc\n>>>>>>> file\n"),
},
},
},
@@ -71,7 +71,7 @@ func TestConflicts(t *testing.T) {
Ancestor: git2go.ConflictEntry{Path: "file-2", Mode: 0100644},
Our: git2go.ConflictEntry{Path: "file-2", Mode: 0100644},
Their: git2go.ConflictEntry{Path: "file-2", Mode: 0100644},
- Content: "<<<<<<< file-2\nb\n=======\nc\n>>>>>>> file-2\n",
+ Content: []byte("<<<<<<< file-2\nb\n=======\nc\n>>>>>>> file-2\n"),
},
},
},
@@ -94,13 +94,13 @@ func TestConflicts(t *testing.T) {
Ancestor: git2go.ConflictEntry{Path: "file-1", Mode: 0100644},
Our: git2go.ConflictEntry{Path: "file-1", Mode: 0100644},
Their: git2go.ConflictEntry{Path: "file-1", Mode: 0100644},
- Content: "<<<<<<< file-1\nb\n=======\nc\n>>>>>>> file-1\n",
+ Content: []byte("<<<<<<< file-1\nb\n=======\nc\n>>>>>>> file-1\n"),
},
{
Ancestor: git2go.ConflictEntry{Path: "file-2", Mode: 0100644},
Our: git2go.ConflictEntry{Path: "file-2", Mode: 0100644},
Their: git2go.ConflictEntry{Path: "file-2", Mode: 0100644},
- Content: "<<<<<<< file-2\nb\n=======\nc\n>>>>>>> file-2\n",
+ Content: []byte("<<<<<<< file-2\nb\n=======\nc\n>>>>>>> file-2\n"),
},
},
},
@@ -120,7 +120,7 @@ func TestConflicts(t *testing.T) {
Ancestor: git2go.ConflictEntry{Path: "file", Mode: 0100644},
Our: git2go.ConflictEntry{Path: "file", Mode: 0100644},
Their: git2go.ConflictEntry{},
- Content: "<<<<<<< file\nchanged\n=======\n>>>>>>> \n",
+ Content: []byte("<<<<<<< file\nchanged\n=======\n>>>>>>> \n"),
},
},
},
@@ -143,18 +143,19 @@ func TestConflicts(t *testing.T) {
Ancestor: git2go.ConflictEntry{Path: "file", Mode: 0100644},
Our: git2go.ConflictEntry{},
Their: git2go.ConflictEntry{},
+ Content: []byte{},
},
{
Ancestor: git2go.ConflictEntry{},
Our: git2go.ConflictEntry{Path: "renamed-1", Mode: 0100644},
Their: git2go.ConflictEntry{},
- Content: "a\nb\nc\nd\ne\nf\ng\n",
+ Content: []byte("a\nb\nc\nd\ne\nf\ng\n"),
},
{
Ancestor: git2go.ConflictEntry{},
Our: git2go.ConflictEntry{},
Their: git2go.ConflictEntry{Path: "renamed-2", Mode: 0100644},
- Content: "a\nb\nc\nd\ne\nf\ng\n",
+ Content: []byte("a\nb\nc\nd\ne\nf\ng\n"),
},
},
},
diff --git a/internal/git2go/conflicts.go b/internal/git2go/conflicts.go
index 1b2d2658b..79f732be5 100644
--- a/internal/git2go/conflicts.go
+++ b/internal/git2go/conflicts.go
@@ -36,7 +36,7 @@ type Conflict struct {
// Their is the conflict entry of theirs.
Their ConflictEntry `json:"their"`
// Content contains the conflicting merge results.
- Content string `json:"content"`
+ Content []byte `json:"content"`
}
// ConflictsResult contains all conflicts resulting from a merge.
diff --git a/internal/git2go/conflicts_test.go b/internal/git2go/conflicts_test.go
index fe1268445..4061598bf 100644
--- a/internal/git2go/conflicts_test.go
+++ b/internal/git2go/conflicts_test.go
@@ -89,7 +89,7 @@ func TestConflictsResult_Serialization(t *testing.T) {
Ancestor: ConflictEntry{Path: "dir/ancestor", Mode: 0100644},
Our: ConflictEntry{Path: "dir/our", Mode: 0100644},
Their: ConflictEntry{Path: "dir/their", Mode: 0100644},
- Content: "content",
+ Content: []byte("content"),
},
},
}),
@@ -99,7 +99,7 @@ func TestConflictsResult_Serialization(t *testing.T) {
Ancestor: ConflictEntry{Path: "dir/ancestor", Mode: 0100644},
Our: ConflictEntry{Path: "dir/our", Mode: 0100644},
Their: ConflictEntry{Path: "dir/their", Mode: 0100644},
- Content: "content",
+ Content: []byte("content"),
},
},
},