Skip to content

Commit

Permalink
rename sha to hash 9, case: Sha
Browse files Browse the repository at this point in the history
  • Loading branch information
pikomonde authored and stefanhaller committed Apr 12, 2024
1 parent de1c495 commit 170c4ec
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 90 deletions.
6 changes: 3 additions & 3 deletions pkg/app/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ type MoveFixupCommitDownInstruction struct {
FixupHash string
}

func NewMoveFixupCommitDownInstruction(originalSha string, fixupSha string) Instruction {
func NewMoveFixupCommitDownInstruction(originalHash string, fixupHash string) Instruction {
return &MoveFixupCommitDownInstruction{
OriginalHash: originalSha,
FixupHash: fixupSha,
OriginalHash: originalHash,
FixupHash: fixupHash,
}
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/commands/git_commands/bisect.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ func (self *BisectCommands) GetInfoForGitDir(gitDir string) *BisectInfo {
self.Log.Infof("error getting git bisect info: %s", err.Error())
return info
}
currentSha := strings.TrimSpace(string(currentContent))
info.current = currentSha
currentHash := strings.TrimSpace(string(currentContent))
info.current = currentHash

return info
}
Expand Down Expand Up @@ -143,8 +143,8 @@ func (self *BisectCommands) IsDone() (bool, []string, error) {
return false, nil, nil
}

newSha := info.GetNewHash()
if newSha == "" {
newHash := info.GetNewHash()
if newHash == "" {
return false, nil, nil
}

Expand All @@ -153,7 +153,7 @@ func (self *BisectCommands) IsDone() (bool, []string, error) {
done := false
candidates := []string{}

cmdArgs := NewGitCmd("rev-list").Arg(newSha).ToArgv()
cmdArgs := NewGitCmd("rev-list").Arg(newHash).ToArgv()
err := self.cmd.New(cmdArgs).RunAndProcessLines(func(line string) (bool, error) {
hash := strings.TrimSpace(line)

Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/git_commands/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (self *PatchCommands) MovePatchToSelectedCommit(commits []*models.Commit, s
self.os.LogCommand(logTodoChanges(changes), false)

err := self.rebase.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: commits[baseIndex].Hash,
baseHashOrRoot: commits[baseIndex].Hash,
overrideEditor: true,
instruction: daemon.NewChangeTodoActionsInstruction(changes),
}).Run()
Expand Down
50 changes: 25 additions & 25 deletions pkg/commands/git_commands/rebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func (self *RebaseCommands) RewordCommitInEditor(commits []*models.Commit, index
self.os.LogCommand(logTodoChanges(changes), false)

return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: getBaseShaOrRoot(commits, index+1),
instruction: daemon.NewChangeTodoActionsInstruction(changes),
baseHashOrRoot: getBaseHashOrRoot(commits, index+1),
instruction: daemon.NewChangeTodoActionsInstruction(changes),
}), nil
}

Expand Down Expand Up @@ -106,28 +106,28 @@ func (self *RebaseCommands) GenericAmend(commits []*models.Commit, index int, f
}

func (self *RebaseCommands) MoveCommitsDown(commits []*models.Commit, startIdx int, endIdx int) error {
baseShaOrRoot := getBaseShaOrRoot(commits, endIdx+2)
baseHashOrRoot := getBaseHashOrRoot(commits, endIdx+2)

shas := lo.Map(commits[startIdx:endIdx+1], func(commit *models.Commit, _ int) string {
return commit.Hash
})

return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: baseShaOrRoot,
baseHashOrRoot: baseHashOrRoot,
instruction: daemon.NewMoveTodosDownInstruction(shas),
overrideEditor: true,
}).Run()
}

func (self *RebaseCommands) MoveCommitsUp(commits []*models.Commit, startIdx int, endIdx int) error {
baseShaOrRoot := getBaseShaOrRoot(commits, endIdx+1)
baseHashOrRoot := getBaseHashOrRoot(commits, endIdx+1)

shas := lo.Map(commits[startIdx:endIdx+1], func(commit *models.Commit, _ int) string {
return commit.Hash
})

return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: baseShaOrRoot,
baseHashOrRoot: baseHashOrRoot,
instruction: daemon.NewMoveTodosUpInstruction(shas),
overrideEditor: true,
}).Run()
Expand All @@ -139,7 +139,7 @@ func (self *RebaseCommands) InteractiveRebase(commits []*models.Commit, startIdx
baseIndex++
}

baseShaOrRoot := getBaseShaOrRoot(commits, baseIndex)
baseHashOrRoot := getBaseHashOrRoot(commits, baseIndex)

changes := lo.Map(commits[startIdx:endIdx+1], func(commit *models.Commit, _ int) daemon.ChangeTodoAction {
return daemon.ChangeTodoAction{
Expand All @@ -151,7 +151,7 @@ func (self *RebaseCommands) InteractiveRebase(commits []*models.Commit, startIdx
self.os.LogCommand(logTodoChanges(changes), false)

return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: baseShaOrRoot,
baseHashOrRoot: baseHashOrRoot,
overrideEditor: true,
instruction: daemon.NewChangeTodoActionsInstruction(changes),
}).Run()
Expand All @@ -166,8 +166,8 @@ func (self *RebaseCommands) EditRebase(branchRef string) error {
)
self.os.LogCommand(msg, false)
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: branchRef,
instruction: daemon.NewInsertBreakInstruction(),
baseHashOrRoot: branchRef,
instruction: daemon.NewInsertBreakInstruction(),
}).Run()
}

Expand All @@ -181,9 +181,9 @@ func (self *RebaseCommands) EditRebaseFromBaseCommit(targetBranchName string, ba
)
self.os.LogCommand(msg, false)
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: baseCommit,
onto: targetBranchName,
instruction: daemon.NewInsertBreakInstruction(),
baseHashOrRoot: baseCommit,
onto: targetBranchName,
instruction: daemon.NewInsertBreakInstruction(),
}).Run()
}

Expand All @@ -195,7 +195,7 @@ func logTodoChanges(changes []daemon.ChangeTodoAction) string {
}

type PrepareInteractiveRebaseCommandOpts struct {
baseShaOrRoot string
baseHashOrRoot string
onto string
instruction daemon.Instruction
overrideEditor bool
Expand All @@ -216,7 +216,7 @@ func (self *RebaseCommands) PrepareInteractiveRebaseCommand(opts PrepareInteract
Arg("--no-autosquash").
ArgIf(self.version.IsAtLeast(2, 22, 0), "--rebase-merges").
ArgIf(opts.onto != "", "--onto", opts.onto).
Arg(opts.baseShaOrRoot).
Arg(opts.baseHashOrRoot).
ToArgv()

debug := "FALSE"
Expand Down Expand Up @@ -290,15 +290,15 @@ func (self *RebaseCommands) AmendTo(commits []*models.Commit, commitIndex int) e

// Get the hash of the commit we just created
cmdArgs := NewGitCmd("rev-parse").Arg("--verify", "HEAD").ToArgv()
fixupSha, err := self.cmd.New(cmdArgs).RunWithOutput()
fixupHash, err := self.cmd.New(cmdArgs).RunWithOutput()
if err != nil {
return err
}

return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: getBaseShaOrRoot(commits, commitIndex+1),
baseHashOrRoot: getBaseHashOrRoot(commits, commitIndex+1),
overrideEditor: true,
instruction: daemon.NewMoveFixupCommitDownInstruction(commit.Hash, fixupSha),
instruction: daemon.NewMoveFixupCommitDownInstruction(commit.Hash, fixupHash),
}).Run()
}

Expand Down Expand Up @@ -399,7 +399,7 @@ func (self *RebaseCommands) BeginInteractiveRebaseForCommit(
self.os.LogCommand(logTodoChanges(changes), false)

return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: getBaseShaOrRoot(commits, commitIndex+1),
baseHashOrRoot: getBaseHashOrRoot(commits, commitIndex+1),
overrideEditor: true,
keepCommitsThatBecomeEmpty: keepCommitsThatBecomeEmpty,
instruction: daemon.NewChangeTodoActionsInstruction(changes),
Expand All @@ -408,13 +408,13 @@ func (self *RebaseCommands) BeginInteractiveRebaseForCommit(

// RebaseBranch interactive rebases onto a branch
func (self *RebaseCommands) RebaseBranch(branchName string) error {
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{baseShaOrRoot: branchName}).Run()
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{baseHashOrRoot: branchName}).Run()
}

func (self *RebaseCommands) RebaseBranchFromBaseCommit(targetBranchName string, baseCommit string) error {
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: baseCommit,
onto: targetBranchName,
baseHashOrRoot: baseCommit,
onto: targetBranchName,
}).Run()
}

Expand Down Expand Up @@ -517,8 +517,8 @@ func (self *RebaseCommands) CherryPickCommits(commits []*models.Commit) error {
self.os.LogCommand(msg, false)

return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: "HEAD",
instruction: daemon.NewCherryPickCommitsInstruction(commits),
baseHashOrRoot: "HEAD",
instruction: daemon.NewCherryPickCommitsInstruction(commits),
}).Run()
}

Expand All @@ -538,7 +538,7 @@ func (self *RebaseCommands) CherryPickCommitsDuringRebase(commits []*models.Comm

// we can't start an interactive rebase from the first commit without passing the
// '--root' arg
func getBaseShaOrRoot(commits []*models.Commit, index int) string {
func getBaseHashOrRoot(commits []*models.Commit, index int) string {
// We assume that the commits slice contains the initial commit of the repo.
// Technically this assumption could prove false, but it's unlikely you'll
// be starting a rebase from 300 commits ago (which is the original commit limit
Expand Down
10 changes: 5 additions & 5 deletions pkg/commands/git_commands/stash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestStashStore(t *testing.T) {
}
}

func TestStashSha(t *testing.T) {
func TestStashHash(t *testing.T) {
runner := oscommands.NewFakeRunner(t).
ExpectGitArgs([]string{"rev-parse", "refs/stash@{5}"}, "14d94495194651adfd5f070590df566c11d28243\n", nil)
instance := buildStashCommands(commonDeps{runner: runner})
Expand Down Expand Up @@ -153,7 +153,7 @@ func TestStashRename(t *testing.T) {
testName string
index int
message string
expectedShaCmd []string
expectedHashCmd []string
shaResult string
expectedDropCmd []string
expectedStoreCmd []string
Expand All @@ -164,7 +164,7 @@ func TestStashRename(t *testing.T) {
testName: "Default case",
index: 3,
message: "New message",
expectedShaCmd: []string{"rev-parse", "refs/stash@{3}"},
expectedHashCmd: []string{"rev-parse", "refs/stash@{3}"},
shaResult: "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd\n",
expectedDropCmd: []string{"stash", "drop", "stash@{3}"},
expectedStoreCmd: []string{"stash", "store", "-m", "New message", "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd"},
Expand All @@ -173,7 +173,7 @@ func TestStashRename(t *testing.T) {
testName: "Empty message",
index: 4,
message: "",
expectedShaCmd: []string{"rev-parse", "refs/stash@{4}"},
expectedHashCmd: []string{"rev-parse", "refs/stash@{4}"},
shaResult: "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd\n",
expectedDropCmd: []string{"stash", "drop", "stash@{4}"},
expectedStoreCmd: []string{"stash", "store", "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd"},
Expand All @@ -184,7 +184,7 @@ func TestStashRename(t *testing.T) {
s := s
t.Run(s.testName, func(t *testing.T) {
runner := oscommands.NewFakeRunner(t).
ExpectGitArgs(s.expectedShaCmd, s.shaResult, nil).
ExpectGitArgs(s.expectedHashCmd, s.shaResult, nil).
ExpectGitArgs(s.expectedDropCmd, "", nil).
ExpectGitArgs(s.expectedStoreCmd, "", nil)
instance := buildStashCommands(commonDeps{runner: runner})
Expand Down
18 changes: 9 additions & 9 deletions pkg/gui/controllers/bisect_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c

bisecting := info.GetCurrentHash() != ""
shaToMark := lo.Ternary(bisecting, info.GetCurrentHash(), commit.Hash)
shortShaToMark := utils.ShortHash(shaToMark)
shortHashToMark := utils.ShortHash(shaToMark)

// For marking a commit as bad, when we're not already bisecting, we require
// a single item selected, but once we are bisecting, it doesn't matter because
Expand All @@ -92,7 +92,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c

menuItems := []*types.MenuItem{
{
Label: fmt.Sprintf(self.c.Tr.Bisect.Mark, shortShaToMark, info.NewTerm()),
Label: fmt.Sprintf(self.c.Tr.Bisect.Mark, shortHashToMark, info.NewTerm()),
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.BisectMark)
if err := self.c.Git().Bisect.Mark(shaToMark, info.NewTerm()); err != nil {
Expand All @@ -105,7 +105,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
Key: 'b',
},
{
Label: fmt.Sprintf(self.c.Tr.Bisect.Mark, shortShaToMark, info.OldTerm()),
Label: fmt.Sprintf(self.c.Tr.Bisect.Mark, shortHashToMark, info.OldTerm()),
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.BisectMark)
if err := self.c.Git().Bisect.Mark(shaToMark, info.OldTerm()); err != nil {
Expand All @@ -118,7 +118,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
Key: 'g',
},
{
Label: fmt.Sprintf(self.c.Tr.Bisect.SkipCurrent, shortShaToMark),
Label: fmt.Sprintf(self.c.Tr.Bisect.SkipCurrent, shortHashToMark),
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.BisectSkip)
if err := self.c.Git().Bisect.Skip(shaToMark); err != nil {
Expand Down Expand Up @@ -224,13 +224,13 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo,
})
}

func (self *BisectController) showBisectCompleteMessage(candidateShas []string) error {
func (self *BisectController) showBisectCompleteMessage(candidateHashes []string) error {
prompt := self.c.Tr.Bisect.CompletePrompt
if len(candidateShas) > 1 {
if len(candidateHashes) > 1 {
prompt = self.c.Tr.Bisect.CompletePromptIndeterminate
}

formattedCommits, err := self.c.Git().Commit.GetCommitsOneline(candidateShas)
formattedCommits, err := self.c.Git().Commit.GetCommitsOneline(candidateHashes)
if err != nil {
return self.c.Error(err)
}
Expand All @@ -250,7 +250,7 @@ func (self *BisectController) showBisectCompleteMessage(candidateShas []string)
}

func (self *BisectController) afterMark(selectCurrent bool, waitToReselect bool) error {
done, candidateShas, err := self.c.Git().Bisect.IsDone()
done, candidateHashes, err := self.c.Git().Bisect.IsDone()
if err != nil {
return self.c.Error(err)
}
Expand All @@ -260,7 +260,7 @@ func (self *BisectController) afterMark(selectCurrent bool, waitToReselect bool)
}

if done {
return self.showBisectCompleteMessage(candidateShas)
return self.showBisectCompleteMessage(candidateHashes)
}

return nil
Expand Down
14 changes: 7 additions & 7 deletions pkg/gui/controllers/local_commits_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,8 @@ func (self *LocalCommitsController) startInteractiveRebaseWithEdit(
self.c.LogAction(self.c.Tr.Actions.EditCommit)
selectedIdx, rangeStartIdx, rangeSelectMode := self.context().GetSelectionRangeAndMode()
commits := self.c.Model().Commits
selectedSha := commits[selectedIdx].Hash
rangeStartSha := commits[rangeStartIdx].Hash
selectedHash := commits[selectedIdx].Hash
rangeStartHash := commits[rangeStartIdx].Hash
err := self.c.Git().Rebase.EditRebase(commitsToEdit[len(commitsToEdit)-1].Hash)
return self.c.Helpers().MergeAndRebase.CheckMergeOrRebaseWithRefreshOptions(
err,
Expand All @@ -532,10 +532,10 @@ func (self *LocalCommitsController) startInteractiveRebaseWithEdit(
// new lines can be added for update-ref commands in the TODO file, due to
// stacked branches. So the selected commits may be in different positions in the list.
_, newSelectedIdx, ok1 := lo.FindIndexOf(self.c.Model().Commits, func(c *models.Commit) bool {
return c.Hash == selectedSha
return c.Hash == selectedHash
})
_, newRangeStartIdx, ok2 := lo.FindIndexOf(self.c.Model().Commits, func(c *models.Commit) bool {
return c.Hash == rangeStartSha
return c.Hash == rangeStartHash
})
if ok1 && ok2 {
self.context().SetSelectionRangeAndMode(newSelectedIdx, newRangeStartIdx, rangeSelectMode)
Expand Down Expand Up @@ -799,15 +799,15 @@ func (self *LocalCommitsController) revert(commit *models.Commit) error {

func (self *LocalCommitsController) createRevertMergeCommitMenu(commit *models.Commit) error {
menuItems := make([]*types.MenuItem, len(commit.Parents))
for i, parentSha := range commit.Parents {
for i, parentHash := range commit.Parents {
i := i
message, err := self.c.Git().Commit.GetCommitMessageFirstLine(parentSha)
message, err := self.c.Git().Commit.GetCommitMessageFirstLine(parentHash)
if err != nil {
return self.c.Error(err)
}

menuItems[i] = &types.MenuItem{
Label: fmt.Sprintf("%s: %s", utils.SafeTruncate(parentSha, 8), message),
Label: fmt.Sprintf("%s: %s", utils.SafeTruncate(parentHash, 8), message),
OnPress: func() error {
parentNumber := i + 1
self.c.LogAction(self.c.Tr.Actions.RevertCommit)
Expand Down
Loading

0 comments on commit 170c4ec

Please sign in to comment.