1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-31 14:24:25 +03:00

rename sha to hash 3

This commit is contained in:
pikomonde
2024-03-21 01:27:33 +07:00
committed by Stefan Haller
parent 92aab21d3a
commit 13af335b37
11 changed files with 36 additions and 36 deletions

View File

@ -210,10 +210,10 @@ func (self *CommitCommands) GetCommitMessageFirstLine(sha string) (string, error
return self.GetCommitMessagesFirstLine([]string{sha}) return self.GetCommitMessagesFirstLine([]string{sha})
} }
func (self *CommitCommands) GetCommitMessagesFirstLine(shas []string) (string, error) { func (self *CommitCommands) GetCommitMessagesFirstLine(hashes []string) (string, error) {
cmdArgs := NewGitCmd("show"). cmdArgs := NewGitCmd("show").
Arg("--no-patch", "--pretty=format:%s"). Arg("--no-patch", "--pretty=format:%s").
Arg(shas...). Arg(hashes...).
ToArgv() ToArgv()
return self.cmd.New(cmdArgs).DontLog().RunWithOutput() return self.cmd.New(cmdArgs).DontLog().RunWithOutput()
@ -224,19 +224,19 @@ func (self *CommitCommands) GetCommitMessagesFirstLine(shas []string) (string, e
// cd50c79ae Preserve the commit message correctly even if the description has blank lines // cd50c79ae Preserve the commit message correctly even if the description has blank lines
// 3ebba5f32 Add test demonstrating a bug with preserving the commit message // 3ebba5f32 Add test demonstrating a bug with preserving the commit message
// 9a423c388 Remove unused function // 9a423c388 Remove unused function
func (self *CommitCommands) GetShasAndCommitMessagesFirstLine(shas []string) (string, error) { func (self *CommitCommands) GetHashesAndCommitMessagesFirstLine(hashes []string) (string, error) {
cmdArgs := NewGitCmd("show"). cmdArgs := NewGitCmd("show").
Arg("--no-patch", "--pretty=format:%h %s"). Arg("--no-patch", "--pretty=format:%h %s").
Arg(shas...). Arg(hashes...).
ToArgv() ToArgv()
return self.cmd.New(cmdArgs).DontLog().RunWithOutput() return self.cmd.New(cmdArgs).DontLog().RunWithOutput()
} }
func (self *CommitCommands) GetCommitsOneline(shas []string) (string, error) { func (self *CommitCommands) GetCommitsOneline(hashes []string) (string, error) {
cmdArgs := NewGitCmd("show"). cmdArgs := NewGitCmd("show").
Arg("--no-patch", "--oneline"). Arg("--no-patch", "--oneline").
Arg(shas...). Arg(hashes...).
ToArgv() ToArgv()
return self.cmd.New(cmdArgs).DontLog().RunWithOutput() return self.cmd.New(cmdArgs).DontLog().RunWithOutput()

View File

@ -48,9 +48,9 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext {
c.Model().CheckedOutBranch, c.Model().CheckedOutBranch,
hasRebaseUpdateRefsConfig, hasRebaseUpdateRefsConfig,
c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL, c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL,
c.Modes().CherryPicking.SelectedShaSet(), c.Modes().CherryPicking.SelectedHashSet(),
c.Modes().Diffing.Ref, c.Modes().Diffing.Ref,
c.Modes().MarkedBaseCommit.GetSha(), c.Modes().MarkedBaseCommit.GetHash(),
c.UserConfig.Gui.TimeFormat, c.UserConfig.Gui.TimeFormat,
c.UserConfig.Gui.ShortTimeFormat, c.UserConfig.Gui.ShortTimeFormat,
time.Now(), time.Now(),

View File

@ -30,7 +30,7 @@ func NewReflogCommitsContext(c *ContextCommon) *ReflogCommitsContext {
return presentation.GetReflogCommitListDisplayStrings( return presentation.GetReflogCommitListDisplayStrings(
viewModel.GetItems(), viewModel.GetItems(),
c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL, c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL,
c.Modes().CherryPicking.SelectedShaSet(), c.Modes().CherryPicking.SelectedHashSet(),
c.Modes().Diffing.Ref, c.Modes().Diffing.Ref,
time.Now(), time.Now(),
c.UserConfig.Gui.TimeFormat, c.UserConfig.Gui.TimeFormat,

View File

@ -63,7 +63,7 @@ func NewSubCommitsContext(
viewModel.GetRef().RefName(), viewModel.GetRef().RefName(),
hasRebaseUpdateRefsConfig, hasRebaseUpdateRefsConfig,
c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL, c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL,
c.Modes().CherryPicking.SelectedShaSet(), c.Modes().CherryPicking.SelectedHashSet(),
c.Modes().Diffing.Ref, c.Modes().Diffing.Ref,
"", "",
c.UserConfig.Gui.TimeFormat, c.UserConfig.Gui.TimeFormat,

View File

@ -38,7 +38,7 @@ func (self *CherryPickHelper) CopyRange(commitsList []*models.Commit, context ty
return err return err
} }
commitSet := self.getData().SelectedShaSet() commitSet := self.getData().SelectedHashSet()
allCommitsCopied := lo.EveryBy(commitsList[startIdx:endIdx+1], func(commit *models.Commit) bool { allCommitsCopied := lo.EveryBy(commitsList[startIdx:endIdx+1], func(commit *models.Commit) bool {
return commitSet.Includes(commit.Hash) return commitSet.Includes(commit.Hash)

View File

@ -44,14 +44,14 @@ func (self *FixupHelper) HandleFindBaseCommitForFixupPress() error {
return self.c.ErrorMsg(self.c.Tr.NoDeletedLinesInDiff) return self.c.ErrorMsg(self.c.Tr.NoDeletedLinesInDiff)
} }
shas := self.blameDeletedLines(deletedLineInfos) hashes := self.blameDeletedLines(deletedLineInfos)
if len(shas) == 0 { if len(hashes) == 0 {
// This should never happen // This should never happen
return self.c.ErrorMsg(self.c.Tr.NoBaseCommitsFound) return self.c.ErrorMsg(self.c.Tr.NoBaseCommitsFound)
} }
if len(shas) > 1 { if len(hashes) > 1 {
subjects, err := self.c.Git().Commit.GetShasAndCommitMessagesFirstLine(shas) subjects, err := self.c.Git().Commit.GetHashesAndCommitMessagesFirstLine(hashes)
if err != nil { if err != nil {
return err return err
} }
@ -62,7 +62,7 @@ func (self *FixupHelper) HandleFindBaseCommitForFixupPress() error {
} }
commit, index, ok := lo.FindIndexOf(self.c.Model().Commits, func(commit *models.Commit) bool { commit, index, ok := lo.FindIndexOf(self.c.Model().Commits, func(commit *models.Commit) bool {
return commit.Hash == shas[0] return commit.Hash == hashes[0]
}) })
if !ok { if !ok {
commits := self.c.Model().Commits commits := self.c.Model().Commits

View File

@ -241,7 +241,7 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error {
OnPress: func() error { OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.RebaseBranch) self.c.LogAction(self.c.Tr.Actions.RebaseBranch)
return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(task gocui.Task) error { return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(task gocui.Task) error {
baseCommit := self.c.Modes().MarkedBaseCommit.GetSha() baseCommit := self.c.Modes().MarkedBaseCommit.GetHash()
var err error var err error
if baseCommit != "" { if baseCommit != "" {
err = self.c.Git().Rebase.RebaseBranchFromBaseCommit(ref, baseCommit) err = self.c.Git().Rebase.RebaseBranchFromBaseCommit(ref, baseCommit)
@ -262,7 +262,7 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error {
Tooltip: self.c.Tr.InteractiveRebaseTooltip, Tooltip: self.c.Tr.InteractiveRebaseTooltip,
OnPress: func() error { OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.RebaseBranch) self.c.LogAction(self.c.Tr.Actions.RebaseBranch)
baseCommit := self.c.Modes().MarkedBaseCommit.GetSha() baseCommit := self.c.Modes().MarkedBaseCommit.GetHash()
var err error var err error
if baseCommit != "" { if baseCommit != "" {
err = self.c.Git().Rebase.EditRebaseFromBaseCommit(ref, baseCommit) err = self.c.Git().Rebase.EditRebaseFromBaseCommit(ref, baseCommit)
@ -281,7 +281,7 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error {
} }
title := utils.ResolvePlaceholderString( title := utils.ResolvePlaceholderString(
lo.Ternary(self.c.Modes().MarkedBaseCommit.GetSha() != "", lo.Ternary(self.c.Modes().MarkedBaseCommit.GetHash() != "",
self.c.Tr.RebasingFromBaseCommitTitle, self.c.Tr.RebasingFromBaseCommitTitle,
self.c.Tr.RebasingTitle), self.c.Tr.RebasingTitle),
map[string]string{ map[string]string{

View File

@ -1181,11 +1181,11 @@ func (self *LocalCommitsController) canPaste() *types.DisabledReason {
} }
func (self *LocalCommitsController) markAsBaseCommit(commit *models.Commit) error { func (self *LocalCommitsController) markAsBaseCommit(commit *models.Commit) error {
if commit.Hash == self.c.Modes().MarkedBaseCommit.GetSha() { if commit.Hash == self.c.Modes().MarkedBaseCommit.GetHash() {
// Reset when invoking it again on the marked commit // Reset when invoking it again on the marked commit
self.c.Modes().MarkedBaseCommit.SetSha("") self.c.Modes().MarkedBaseCommit.SetHash("")
} else { } else {
self.c.Modes().MarkedBaseCommit.SetSha(commit.Hash) self.c.Modes().MarkedBaseCommit.SetHash(commit.Hash)
} }
return self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits) return self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits)
} }

View File

@ -24,30 +24,30 @@ func (self *CherryPicking) Active() bool {
return len(self.CherryPickedCommits) > 0 return len(self.CherryPickedCommits) > 0
} }
func (self *CherryPicking) SelectedShaSet() *set.Set[string] { func (self *CherryPicking) SelectedHashSet() *set.Set[string] {
shas := lo.Map(self.CherryPickedCommits, func(commit *models.Commit, _ int) string { hashes := lo.Map(self.CherryPickedCommits, func(commit *models.Commit, _ int) string {
return commit.Hash return commit.Hash
}) })
return set.NewFromSlice(shas) return set.NewFromSlice(hashes)
} }
func (self *CherryPicking) Add(selectedCommit *models.Commit, commitsList []*models.Commit) { func (self *CherryPicking) Add(selectedCommit *models.Commit, commitsList []*models.Commit) {
commitSet := self.SelectedShaSet() commitSet := self.SelectedHashSet()
commitSet.Add(selectedCommit.Hash) commitSet.Add(selectedCommit.Hash)
self.update(commitSet, commitsList) self.update(commitSet, commitsList)
} }
func (self *CherryPicking) Remove(selectedCommit *models.Commit, commitsList []*models.Commit) { func (self *CherryPicking) Remove(selectedCommit *models.Commit, commitsList []*models.Commit) {
commitSet := self.SelectedShaSet() commitSet := self.SelectedHashSet()
commitSet.Remove(selectedCommit.Hash) commitSet.Remove(selectedCommit.Hash)
self.update(commitSet, commitsList) self.update(commitSet, commitsList)
} }
func (self *CherryPicking) update(selectedShaSet *set.Set[string], commitsList []*models.Commit) { func (self *CherryPicking) update(selectedHashSet *set.Set[string], commitsList []*models.Commit) {
cherryPickedCommits := lo.Filter(commitsList, func(commit *models.Commit, _ int) bool { cherryPickedCommits := lo.Filter(commitsList, func(commit *models.Commit, _ int) bool {
return selectedShaSet.Includes(commit.Hash) return selectedHashSet.Includes(commit.Hash)
}) })
self.CherryPickedCommits = lo.Map(cherryPickedCommits, func(commit *models.Commit, _ int) *models.Commit { self.CherryPickedCommits = lo.Map(cherryPickedCommits, func(commit *models.Commit, _ int) *models.Commit {

View File

@ -16,10 +16,10 @@ func (m *MarkedBaseCommit) Reset() {
m.sha = "" m.sha = ""
} }
func (m *MarkedBaseCommit) SetSha(sha string) { func (m *MarkedBaseCommit) SetHash(sha string) {
m.sha = sha m.sha = sha
} }
func (m *MarkedBaseCommit) GetSha() string { func (m *MarkedBaseCommit) GetHash() string {
return m.sha return m.sha
} }

View File

@ -38,7 +38,7 @@ func EditRebaseTodo(filePath string, changes []TodoChange, commentChar byte) err
t := &todos[i] t := &todos[i]
// This is a nested loop, but it's ok because the number of todos should be small // This is a nested loop, but it's ok because the number of todos should be small
for _, change := range changes { for _, change := range changes {
if t.Command == change.OldAction && equalShas(t.Commit, change.Hash) { if t.Command == change.OldAction && equalHash(t.Commit, change.Hash) {
matchCount++ matchCount++
t.Command = change.NewAction t.Command = change.NewAction
} }
@ -53,7 +53,7 @@ func EditRebaseTodo(filePath string, changes []TodoChange, commentChar byte) err
return WriteRebaseTodoFile(filePath, todos, commentChar) return WriteRebaseTodoFile(filePath, todos, commentChar)
} }
func equalShas(a, b string) bool { func equalHash(a, b string) bool {
return strings.HasPrefix(a, b) || strings.HasPrefix(b, a) return strings.HasPrefix(a, b) || strings.HasPrefix(b, a)
} }
@ -64,7 +64,7 @@ func findTodo(todos []todo.Todo, todoToFind Todo) (int, bool) {
// pick and later in a merge). For update-ref todos we also must compare // pick and later in a merge). For update-ref todos we also must compare
// the Ref. // the Ref.
return t.Command == todoToFind.Action && return t.Command == todoToFind.Action &&
equalShas(t.Commit, todoToFind.Hash) && equalHash(t.Commit, todoToFind.Hash) &&
t.Ref == todoToFind.Ref t.Ref == todoToFind.Ref
}) })
return idx, ok return idx, ok
@ -235,11 +235,11 @@ func MoveFixupCommitDown(fileName string, originalSha string, fixupSha string, c
func moveFixupCommitDown(todos []todo.Todo, originalSha string, fixupSha string) ([]todo.Todo, error) { func moveFixupCommitDown(todos []todo.Todo, originalSha string, fixupSha string) ([]todo.Todo, error) {
isOriginal := func(t todo.Todo) bool { isOriginal := func(t todo.Todo) bool {
return t.Command == todo.Pick && equalShas(t.Commit, originalSha) return t.Command == todo.Pick && equalHash(t.Commit, originalSha)
} }
isFixup := func(t todo.Todo) bool { isFixup := func(t todo.Todo) bool {
return t.Command == todo.Pick && equalShas(t.Commit, fixupSha) return t.Command == todo.Pick && equalHash(t.Commit, fixupSha)
} }
originalShaCount := lo.CountBy(todos, isOriginal) originalShaCount := lo.CountBy(todos, isOriginal)