1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-15 11:56:37 +02: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})
}
func (self *CommitCommands) GetCommitMessagesFirstLine(shas []string) (string, error) {
func (self *CommitCommands) GetCommitMessagesFirstLine(hashes []string) (string, error) {
cmdArgs := NewGitCmd("show").
Arg("--no-patch", "--pretty=format:%s").
Arg(shas...).
Arg(hashes...).
ToArgv()
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
// 3ebba5f32 Add test demonstrating a bug with preserving the commit message
// 9a423c388 Remove unused function
func (self *CommitCommands) GetShasAndCommitMessagesFirstLine(shas []string) (string, error) {
func (self *CommitCommands) GetHashesAndCommitMessagesFirstLine(hashes []string) (string, error) {
cmdArgs := NewGitCmd("show").
Arg("--no-patch", "--pretty=format:%h %s").
Arg(shas...).
Arg(hashes...).
ToArgv()
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").
Arg("--no-patch", "--oneline").
Arg(shas...).
Arg(hashes...).
ToArgv()
return self.cmd.New(cmdArgs).DontLog().RunWithOutput()

View File

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

View File

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

View File

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

View File

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

View File

@ -44,14 +44,14 @@ func (self *FixupHelper) HandleFindBaseCommitForFixupPress() error {
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
return self.c.ErrorMsg(self.c.Tr.NoBaseCommitsFound)
}
if len(shas) > 1 {
subjects, err := self.c.Git().Commit.GetShasAndCommitMessagesFirstLine(shas)
if len(hashes) > 1 {
subjects, err := self.c.Git().Commit.GetHashesAndCommitMessagesFirstLine(hashes)
if err != nil {
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 {
return commit.Hash == shas[0]
return commit.Hash == hashes[0]
})
if !ok {
commits := self.c.Model().Commits

View File

@ -241,7 +241,7 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error {
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.RebaseBranch)
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
if 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,
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.RebaseBranch)
baseCommit := self.c.Modes().MarkedBaseCommit.GetSha()
baseCommit := self.c.Modes().MarkedBaseCommit.GetHash()
var err error
if baseCommit != "" {
err = self.c.Git().Rebase.EditRebaseFromBaseCommit(ref, baseCommit)
@ -281,7 +281,7 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error {
}
title := utils.ResolvePlaceholderString(
lo.Ternary(self.c.Modes().MarkedBaseCommit.GetSha() != "",
lo.Ternary(self.c.Modes().MarkedBaseCommit.GetHash() != "",
self.c.Tr.RebasingFromBaseCommitTitle,
self.c.Tr.RebasingTitle),
map[string]string{

View File

@ -1181,11 +1181,11 @@ func (self *LocalCommitsController) canPaste() *types.DisabledReason {
}
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
self.c.Modes().MarkedBaseCommit.SetSha("")
self.c.Modes().MarkedBaseCommit.SetHash("")
} else {
self.c.Modes().MarkedBaseCommit.SetSha(commit.Hash)
self.c.Modes().MarkedBaseCommit.SetHash(commit.Hash)
}
return self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits)
}

View File

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

View File

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

View File

@ -38,7 +38,7 @@ func EditRebaseTodo(filePath string, changes []TodoChange, commentChar byte) err
t := &todos[i]
// This is a nested loop, but it's ok because the number of todos should be small
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++
t.Command = change.NewAction
}
@ -53,7 +53,7 @@ func EditRebaseTodo(filePath string, changes []TodoChange, commentChar byte) err
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)
}
@ -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
// the Ref.
return t.Command == todoToFind.Action &&
equalShas(t.Commit, todoToFind.Hash) &&
equalHash(t.Commit, todoToFind.Hash) &&
t.Ref == todoToFind.Ref
})
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) {
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 {
return t.Command == todo.Pick && equalShas(t.Commit, fixupSha)
return t.Command == todo.Pick && equalHash(t.Commit, fixupSha)
}
originalShaCount := lo.CountBy(todos, isOriginal)