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:
authorKarthik Nayak <knayak@gitlab.com>2023-06-21 16:59:39 +0300
committerKarthik Nayak <knayak@gitlab.com>2023-06-26 11:20:25 +0300
commitc504e05b0d2a06156c67a87ce03bd5f7454b1ff8 (patch)
treeb3108ec0bd5ee7f20fc3307f8cfca001b0406684
parentf84ec4a43183ef8dd207015fa0969eb519097920 (diff)
conflict: Move constants to new file `resolve.go`
The conflicts package defines two functions on the `File` structure, i.e. `Parse` and `Resolve`. The two functions are tied to the `File` structure which is tied to the Git2Go implementation. In the upcoming commits we'll introduce a new standalone `Resolve` function which is not tied to `File` structure, this allows us to deprecate the `File` structure along with Git2Go:ResolveConflict deprecation. Let's move some of the variables which will be common to a new file `resolve.go`, which would make it easier to deprecate the entire `parser.go` file in the future.
-rw-r--r--internal/git/conflict/parser.go44
-rw-r--r--internal/git/conflict/resolve.go73
2 files changed, 73 insertions, 44 deletions
diff --git a/internal/git/conflict/parser.go b/internal/git/conflict/parser.go
index 9a8997afd..b106f8599 100644
--- a/internal/git/conflict/parser.go
+++ b/internal/git/conflict/parser.go
@@ -14,33 +14,6 @@ import (
"strings"
)
-// Errors that can occur during parsing of a merge conflict file
-var (
- ErrUnmergeableFile = errors.New("merging is not supported for file")
- ErrUnexpectedDelimiter = errors.New("unexpected conflict delimiter")
- ErrMissingEndDelimiter = errors.New("missing last delimiter")
-)
-
-type section uint
-
-const (
- sectionNone = section(iota)
- sectionOld
- sectionNew
- sectionNoNewline
-)
-
-const fileLimit = 200 * (1 << 10) // 200k
-
-type line struct {
- objIndex uint // where are we in the object?
- oldIndex uint // where are we in the old file?
- newIndex uint // where are we in the new file?
-
- payload string // actual line contents (minus the newline)
- section section
-}
-
// File contains an ordered list of lines with metadata about potential
// conflicts.
type File struct {
@@ -54,23 +27,6 @@ func (f File) sectionID(l line) string {
return fmt.Sprintf("%x_%d_%d", pathSHA1, l.oldIndex, l.newIndex)
}
-// Resolution indicates how to resolve a conflict
-type Resolution struct {
- OldPath string `json:"old_path"`
- NewPath string `json:"new_path"`
-
- // key is a sectionID, value is "head" or "origin"
- Sections map[string]string `json:"sections"`
-
- // Content is used when no sections are defined
- Content string `json:"content"`
-}
-
-const (
- head = "head"
- origin = "origin"
-)
-
// Resolve will iterate through each conflict line and replace it with the
// specified resolution
func (f File) Resolve(resolution Resolution) ([]byte, error) {
diff --git a/internal/git/conflict/resolve.go b/internal/git/conflict/resolve.go
new file mode 100644
index 000000000..db380fad8
--- /dev/null
+++ b/internal/git/conflict/resolve.go
@@ -0,0 +1,73 @@
+package conflict
+
+import (
+ "errors"
+)
+
+// section denotes the various conflict sections
+type section uint
+
+const (
+ // Resolutions for conflict is done by clients providing selections for
+ // the different conflict sections. "head"/"origin" is used to denote the
+ // selection for ours/their trees respectively.
+ head = "head"
+ origin = "origin"
+
+ // fileLimit is used to set the limit on the buffer size for bufio.Scanner,
+ // we don't support conflict resolution for files which require bigger buffers.
+ fileLimit = 200 * (1 << 10)
+)
+
+const (
+ // The sections are used to define various lines of the conflicted file.
+ // Here Old/New is used to denote ours/their respectively.
+ sectionNone = section(iota)
+ sectionOld
+ sectionNew
+ sectionNoNewline
+)
+
+// Errors that can occur during parsing of a merge conflict file
+var (
+ // ErrUnmergeableFile is returned when the either the file exceeds the
+ // fileLimit or no data was read from the file (in case of a binary file).
+ ErrUnmergeableFile = errors.New("merging is not supported for file")
+ // ErrUnexpectedDelimiter is returned when the previous section doesn't
+ // match the expected flow of sections.
+ ErrUnexpectedDelimiter = errors.New("unexpected conflict delimiter")
+ // ErrMissingEndDelimiter is returned when the final section parsed doesn't
+ // match the expected end state.
+ ErrMissingEndDelimiter = errors.New("missing last delimiter")
+)
+
+// line is a structure used to denote individual lines in the conflicted blob,
+// with information around how that line maps to ours/theirs blobs.
+type line struct {
+ // objIndex states the cursor position in the conflicted blob
+ objIndex uint
+ // oldIndex states the cursor position in the 'ours' blob
+ oldIndex uint
+ // oldIndex states the cursor position in the 'theirs' blob
+ newIndex uint
+ // payload denotes the content of line (sans the newline)
+ payload string
+ // section denotes which section this line belongs to.
+ section section
+}
+
+// Resolution indicates how to resolve a conflict
+type Resolution struct {
+ // OldPath is the mapping of the path wrt to 'ours' OID
+ OldPath string `json:"old_path"`
+ // OldPath is the mapping of the path wrt to 'their' OID
+ NewPath string `json:"new_path"`
+
+ // Sections is a map which is used to denote which section to select
+ // for each conflict. Key is the sectionID, while the value is either
+ // "head" or "origin", which denotes the ours/theirs OIDs respectively.
+ Sections map[string]string `json:"sections"`
+
+ // Content is used when no sections are defined
+ Content string `json:"content"`
+}