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-23 12:36:31 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2020-10-15 14:48:12 +0300
commit957f36666b8207882754a675ed9919dad7c2bb01 (patch)
tree53955aac5d8064662c7be4569029f8abd500f32e
parentedc556107506a698e6bf95110d458e9eb07d311f (diff)
git2go: Make conflict entry's modes available
When listing merge conflicts via Git2Go, we currently only pass along information about conflict paths and contents. In order to implement ListConflictFiles, we also require the mode of each of the sides. Add the mode to the conflicts response to cater to this need. In order to avoid code duplication, this commit also does some refactoring and sets up a separate structure for conflict entries.
-rw-r--r--cmd/gitaly-git2go/conflicts.go17
-rw-r--r--cmd/gitaly-git2go/conflicts_test.go62
-rw-r--r--internal/git2go/conflicts.go20
-rw-r--r--internal/git2go/conflicts_test.go16
4 files changed, 63 insertions, 52 deletions
diff --git a/cmd/gitaly-git2go/conflicts.go b/cmd/gitaly-git2go/conflicts.go
index 2a96c34a7..adce23d60 100644
--- a/cmd/gitaly-git2go/conflicts.go
+++ b/cmd/gitaly-git2go/conflicts.go
@@ -22,11 +22,14 @@ func (cmd *conflictsSubcommand) Flags() *flag.FlagSet {
return flags
}
-func indexEntryPath(entry *git.IndexEntry) string {
+func conflictEntryFromIndex(entry *git.IndexEntry) git2go.ConflictEntry {
if entry == nil {
- return ""
+ return git2go.ConflictEntry{}
+ }
+ return git2go.ConflictEntry{
+ Path: entry.Path,
+ Mode: int32(entry.Mode),
}
- return entry.Path
}
func conflictContent(repo *git.Repository, conflict git.IndexConflict) (string, error) {
@@ -108,10 +111,10 @@ func (cmd *conflictsSubcommand) Run() error {
}
result.Conflicts = append(result.Conflicts, git2go.Conflict{
- AncestorPath: indexEntryPath(conflict.Ancestor),
- OurPath: indexEntryPath(conflict.Our),
- TheirPath: indexEntryPath(conflict.Their),
- Content: content,
+ Ancestor: conflictEntryFromIndex(conflict.Ancestor),
+ Our: conflictEntryFromIndex(conflict.Our),
+ Their: conflictEntryFromIndex(conflict.Their),
+ Content: content,
})
}
diff --git a/cmd/gitaly-git2go/conflicts_test.go b/cmd/gitaly-git2go/conflicts_test.go
index e1310bc1e..36d49bddc 100644
--- a/cmd/gitaly-git2go/conflicts_test.go
+++ b/cmd/gitaly-git2go/conflicts_test.go
@@ -45,10 +45,10 @@ func TestConflicts(t *testing.T) {
},
conflicts: []git2go.Conflict{
{
- AncestorPath: "file",
- OurPath: "file",
- TheirPath: "file",
- Content: "<<<<<<< file\nb\n=======\nc\n>>>>>>> file\n",
+ 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",
},
},
},
@@ -68,10 +68,10 @@ func TestConflicts(t *testing.T) {
},
conflicts: []git2go.Conflict{
{
- AncestorPath: "file-2",
- OurPath: "file-2",
- TheirPath: "file-2",
- Content: "<<<<<<< file-2\nb\n=======\nc\n>>>>>>> file-2\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",
},
},
},
@@ -91,16 +91,16 @@ func TestConflicts(t *testing.T) {
},
conflicts: []git2go.Conflict{
{
- AncestorPath: "file-1",
- OurPath: "file-1",
- TheirPath: "file-1",
- Content: "<<<<<<< file-1\nb\n=======\nc\n>>>>>>> file-1\n",
+ 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",
},
{
- AncestorPath: "file-2",
- OurPath: "file-2",
- TheirPath: "file-2",
- Content: "<<<<<<< file-2\nb\n=======\nc\n>>>>>>> file-2\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",
},
},
},
@@ -117,10 +117,10 @@ func TestConflicts(t *testing.T) {
},
conflicts: []git2go.Conflict{
{
- AncestorPath: "file",
- OurPath: "file",
- TheirPath: "",
- Content: "<<<<<<< file\nchanged\n=======\n>>>>>>> \n",
+ Ancestor: git2go.ConflictEntry{Path: "file", Mode: 0100644},
+ Our: git2go.ConflictEntry{Path: "file", Mode: 0100644},
+ Their: git2go.ConflictEntry{},
+ Content: "<<<<<<< file\nchanged\n=======\n>>>>>>> \n",
},
},
},
@@ -140,21 +140,21 @@ func TestConflicts(t *testing.T) {
},
conflicts: []git2go.Conflict{
{
- AncestorPath: "file",
- OurPath: "",
- TheirPath: "",
+ Ancestor: git2go.ConflictEntry{Path: "file", Mode: 0100644},
+ Our: git2go.ConflictEntry{},
+ Their: git2go.ConflictEntry{},
},
{
- AncestorPath: "",
- OurPath: "renamed-1",
- TheirPath: "",
- Content: "a\nb\nc\nd\ne\nf\ng\n",
+ Ancestor: git2go.ConflictEntry{},
+ Our: git2go.ConflictEntry{Path: "renamed-1", Mode: 0100644},
+ Their: git2go.ConflictEntry{},
+ Content: "a\nb\nc\nd\ne\nf\ng\n",
},
{
- AncestorPath: "",
- OurPath: "",
- TheirPath: "renamed-2",
- Content: "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",
},
},
},
diff --git a/internal/git2go/conflicts.go b/internal/git2go/conflicts.go
index 101c260ae..1b2d2658b 100644
--- a/internal/git2go/conflicts.go
+++ b/internal/git2go/conflicts.go
@@ -19,14 +19,22 @@ type ConflictsCommand struct {
Theirs string `json:"theirs"`
}
+// ConflictEntry represents a conflict entry which is one of the sides of a conflict.
+type ConflictEntry struct {
+ // Path is the path of the conflicting file.
+ Path string `json:"path"`
+ // Mode is the mode of the conflicting file.
+ Mode int32 `json:"mode"`
+}
+
// Conflict represents a merge conflict for a single file.
type Conflict struct {
- // AncestorPath is the path of the ancestor.
- AncestorPath string `json:"ancestor_path"`
- // OurPath is the path of ours.
- OurPath string `json:"our_path"`
- // TheirPath is the path of theirs.
- TheirPath string `json:"their_path"`
+ // Ancestor is the conflict entry of the merge-base.
+ Ancestor ConflictEntry `json:"ancestor"`
+ // Our is the conflict entry of ours.
+ Our ConflictEntry `json:"our"`
+ // Their is the conflict entry of theirs.
+ Their ConflictEntry `json:"their"`
// Content contains the conflicting merge results.
Content string `json:"content"`
}
diff --git a/internal/git2go/conflicts_test.go b/internal/git2go/conflicts_test.go
index 6aeeb2903..fe1268445 100644
--- a/internal/git2go/conflicts_test.go
+++ b/internal/git2go/conflicts_test.go
@@ -86,20 +86,20 @@ func TestConflictsResult_Serialization(t *testing.T) {
serialized: serializeResult(t, ConflictsResult{
Conflicts: []Conflict{
{
- AncestorPath: "dir/ancestor",
- OurPath: "dir/our",
- TheirPath: "dir/their",
- Content: "content",
+ Ancestor: ConflictEntry{Path: "dir/ancestor", Mode: 0100644},
+ Our: ConflictEntry{Path: "dir/our", Mode: 0100644},
+ Their: ConflictEntry{Path: "dir/their", Mode: 0100644},
+ Content: "content",
},
},
}),
expected: ConflictsResult{
Conflicts: []Conflict{
{
- AncestorPath: "dir/ancestor",
- OurPath: "dir/our",
- TheirPath: "dir/their",
- Content: "content",
+ Ancestor: ConflictEntry{Path: "dir/ancestor", Mode: 0100644},
+ Our: ConflictEntry{Path: "dir/our", Mode: 0100644},
+ Their: ConflictEntry{Path: "dir/their", Mode: 0100644},
+ Content: "content",
},
},
},