summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2023-04-07 19:28:31 +0200
committerStefan Haller <stefan@haller-berlin.de>2023-04-15 08:36:03 +0200
commita0d179b6dcb1dc27690c447dd55f264bcc9cbcb0 (patch)
tree853f2dd4dc39a6a66bdb0192e179880117975eda /pkg/commands
parentc53c5e47efc36c1b9bf9fa51f4840caf70ceba28 (diff)
Make getHydratedRebasingCommits more robust
So far the algorithm worked on the assumption that the output of the "git show" command corresponds one-to-one to the lines of the rebase-todo file. This assumption doesn't hold once we start to include todo lines that don't have a sha (like update-ref), or when the todo file contains multiple entries for the same sha. This should never happen normally, but it can if users manually edit the todo file and duplicate a line.
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/git_commands/commit_loader.go24
1 files changed, 15 insertions, 9 deletions
diff --git a/pkg/commands/git_commands/commit_loader.go b/pkg/commands/git_commands/commit_loader.go
index 3b2e52ec4..6e409d717 100644
--- a/pkg/commands/git_commands/commit_loader.go
+++ b/pkg/commands/git_commands/commit_loader.go
@@ -194,8 +194,8 @@ func (self *CommitLoader) getHydratedRebasingCommits(rebaseMode enums.RebaseMode
return nil, nil
}
- commitShas := slices.Map(commits, func(commit *models.Commit) string {
- return commit.Sha
+ commitShas := slices.FilterMap(commits, func(commit *models.Commit) (string, bool) {
+ return commit.Sha, commit.Sha != ""
})
// note that we're not filtering these as we do non-rebasing commits just because
@@ -209,20 +209,26 @@ func (self *CommitLoader) getHydratedRebasingCommits(rebaseMode enums.RebaseMode
),
).DontLog()
- hydratedCommits := make([]*models.Commit, 0, len(commits))
- i := 0
+ fullCommits := map[string]*models.Commit{}
err = cmdObj.RunAndProcessLines(func(line string) (bool, error) {
commit := self.extractCommitFromLine(line)
- matchingCommit := commits[i]
- commit.Action = matchingCommit.Action
- commit.Status = matchingCommit.Status
- hydratedCommits = append(hydratedCommits, commit)
- i++
+ fullCommits[commit.Sha] = commit
return false, nil
})
if err != nil {
return nil, err
}
+
+ hydratedCommits := make([]*models.Commit, 0, len(commits))
+ for _, rebasingCommit := range commits {
+ if rebasingCommit.Sha == "" {
+ hydratedCommits = append(hydratedCommits, rebasingCommit)
+ } else if commit := fullCommits[rebasingCommit.Sha]; commit != nil {
+ commit.Action = rebasingCommit.Action
+ commit.Status = rebasingCommit.Status
+ hydratedCommits = append(hydratedCommits, commit)
+ }
+ }
return hydratedCommits, nil
}