diff options
author | Karthik Nayak <knayak@gitlab.com> | 2023-05-31 14:20:46 +0300 |
---|---|---|
committer | Karthik Nayak <knayak@gitlab.com> | 2023-05-31 14:56:47 +0300 |
commit | 6c6be4c5f5f7158698dd5d143a6f6b7457c853f8 (patch) | |
tree | ea9386fc2e8ee2b50df583fc3e3a147150b5994f | |
parent | 933db61fb6cd67139730d83ff2170624986d30e5 (diff) |
git2go: Use struct slice instead of map in `conflicts`
The `Merge()` function iterates over a map and does a lookup on blobs.
This works, but iterating over a map doesn't guarantee the order of
iteration. Matter of fact, go randomizes map iteration to avoid sloppy
programming.
The iteration order doesn't really matter for the functionality of the
function. The only problem is it makes testing non-deterministic. Since
we're about to rid this code with time and to make the upcoming tests
deterministic, lets replace the map with a struct slice.
-rw-r--r-- | cmd/gitaly-git2go/conflicts.go | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/cmd/gitaly-git2go/conflicts.go b/cmd/gitaly-git2go/conflicts.go index adb77843c..ed52086f9 100644 --- a/cmd/gitaly-git2go/conflicts.go +++ b/cmd/gitaly-git2go/conflicts.go @@ -103,23 +103,26 @@ func (*conflictsSubcommand) conflicts(request git2go.ConflictsCommand) git2go.Co func Merge(repo *git.Repository, conflict git.IndexConflict) (*git.MergeFileResult, error) { var ancestor, our, their git.MergeFileInput - for entry, input := range map[*git.IndexEntry]*git.MergeFileInput{ - conflict.Ancestor: &ancestor, - conflict.Our: &our, - conflict.Their: &their, + for _, val := range []struct { + entry *git.IndexEntry + input *git.MergeFileInput + }{ + {conflict.Ancestor, &ancestor}, + {conflict.Our, &our}, + {conflict.Their, &their}, } { - if entry == nil { + if val.entry == nil { continue } - blob, err := repo.LookupBlob(entry.Id) + blob, err := repo.LookupBlob(val.entry.Id) if err != nil { return nil, structerr.NewFailedPrecondition("could not get conflicting blob: %w", err) } - input.Path = entry.Path - input.Mode = uint(entry.Mode) - input.Contents = blob.Contents() + val.input.Path = val.entry.Path + val.input.Mode = uint(val.entry.Mode) + val.input.Contents = blob.Contents() } merge, err := git.MergeFile(ancestor, our, their, nil) |