From 7f6eea2a55ee6e17660c893a9322d743c5016caf Mon Sep 17 00:00:00 2001 From: pikomonde <32364823+pikomonde@users.noreply.github.com> Date: Wed, 20 Mar 2024 03:05:19 +0700 Subject: [PATCH 01/15] standardize 'Commit Sha' to 'Commit Hash' --- docs/keybindings/Keybindings_en.md | 6 +++--- docs/keybindings/Keybindings_nl.md | 6 +++--- pkg/commands/git_commands/bisect.go | 2 +- pkg/commands/git_commands/bisect_info.go | 2 +- pkg/commands/git_commands/commit_loader.go | 2 +- pkg/commands/patch/patch_builder.go | 4 ++-- pkg/gui/controllers/helpers/refresh_helper.go | 2 +- pkg/gui/controllers/tags_controller.go | 2 +- pkg/gui/presentation/commits.go | 2 +- pkg/gui/presentation/graph/graph.go | 2 +- pkg/i18n/dutch.go | 2 +- pkg/i18n/english.go | 6 +++--- scripts/bisect.sh | 2 +- 13 files changed, 20 insertions(+), 20 deletions(-) diff --git a/docs/keybindings/Keybindings_en.md b/docs/keybindings/Keybindings_en.md index d3fa58cca02..8edeb42bccb 100644 --- a/docs/keybindings/Keybindings_en.md +++ b/docs/keybindings/Keybindings_en.md @@ -76,7 +76,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | Key | Action | Info | |-----|--------|-------------| -| `` `` | Copy commit SHA to clipboard | | +| `` `` | Copy commit hash to clipboard | | | `` `` | Reset copied (cherry-picked) commits selection | | | `` b `` | View bisect options | | | `` s `` | Squash | Squash the selected commit into the commit below it. The selected commit's message will be appended to the commit below it. | @@ -245,7 +245,7 @@ If you would instead like to start an interactive rebase from the selected commi | Key | Action | Info | |-----|--------|-------------| -| `` `` | Copy commit SHA to clipboard | | +| `` `` | Copy commit hash to clipboard | | | `` `` | Checkout | Checkout the selected commit as a detached HEAD. | | `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). | | `` o `` | Open commit in browser | | @@ -313,7 +313,7 @@ If you would instead like to start an interactive rebase from the selected commi | Key | Action | Info | |-----|--------|-------------| -| `` `` | Copy commit SHA to clipboard | | +| `` `` | Copy commit hash to clipboard | | | `` `` | Checkout | Checkout the selected commit as a detached HEAD. | | `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). | | `` o `` | Open commit in browser | | diff --git a/docs/keybindings/Keybindings_nl.md b/docs/keybindings/Keybindings_nl.md index 61bc9c41475..542786192fc 100644 --- a/docs/keybindings/Keybindings_nl.md +++ b/docs/keybindings/Keybindings_nl.md @@ -139,7 +139,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | Key | Action | Info | |-----|--------|-------------| -| `` `` | Kopieer commit SHA naar klembord | | +| `` `` | Kopieer commit hash naar klembord | | | `` `` | Reset cherry-picked (gekopieerde) commits selectie | | | `` b `` | View bisect options | | | `` s `` | Squash | Squash the selected commit into the commit below it. The selected commit's message will be appended to the commit below it. | @@ -223,7 +223,7 @@ If you would instead like to start an interactive rebase from the selected commi | Key | Action | Info | |-----|--------|-------------| -| `` `` | Kopieer commit SHA naar klembord | | +| `` `` | Kopieer commit hash naar klembord | | | `` `` | Uitchecken | Checkout the selected commit as a detached HEAD. | | `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). | | `` o `` | Open commit in browser | | @@ -313,7 +313,7 @@ If you would instead like to start an interactive rebase from the selected commi | Key | Action | Info | |-----|--------|-------------| -| `` `` | Kopieer commit SHA naar klembord | | +| `` `` | Kopieer commit hash naar klembord | | | `` `` | Uitchecken | Checkout the selected commit as a detached HEAD. | | `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). | | `` o `` | Open commit in browser | | diff --git a/pkg/commands/git_commands/bisect.go b/pkg/commands/git_commands/bisect.go index 41e99bd3c65..6d1d8853004 100644 --- a/pkg/commands/git_commands/bisect.go +++ b/pkg/commands/git_commands/bisect.go @@ -135,7 +135,7 @@ func (self *BisectCommands) StartWithTerms(oldTerm string, newTerm string) error } // tells us whether we've found our problem commit(s). We return a string slice of -// commit sha's if we're done, and that slice may have more that one item if +// commit hashes if we're done, and that slice may have more that one item if // skipped commits are involved. func (self *BisectCommands) IsDone() (bool, []string, error) { info := self.GetInfo() diff --git a/pkg/commands/git_commands/bisect_info.go b/pkg/commands/git_commands/bisect_info.go index 67293803a81..bed5bd9dbb9 100644 --- a/pkg/commands/git_commands/bisect_info.go +++ b/pkg/commands/git_commands/bisect_info.go @@ -29,7 +29,7 @@ type BisectInfo struct { newTerm string // 'bad' by default oldTerm string // 'good' by default - // map of commit sha's to their status + // map of commit hashes to their status statusMap map[string]BisectStatus // the sha of the commit that's under test diff --git a/pkg/commands/git_commands/commit_loader.go b/pkg/commands/git_commands/commit_loader.go index df22b91bfb5..a666359eb97 100644 --- a/pkg/commands/git_commands/commit_loader.go +++ b/pkg/commands/git_commands/commit_loader.go @@ -559,7 +559,7 @@ func ignoringWarnings(commandOutput string) string { return lastLine } -// getFirstPushedCommit returns the first commit SHA which has been pushed to the ref's upstream. +// getFirstPushedCommit returns the first commit hash which has been pushed to the ref's upstream. // all commits above this are deemed unpushed and marked as such. func (self *CommitLoader) getFirstPushedCommit(refName string) (string, error) { output, err := self.cmd.New( diff --git a/pkg/commands/patch/patch_builder.go b/pkg/commands/patch/patch_builder.go index 0fedacd191b..a1e2f5194ef 100644 --- a/pkg/commands/patch/patch_builder.go +++ b/pkg/commands/patch/patch_builder.go @@ -33,7 +33,7 @@ type ( // PatchBuilder manages the building of a patch for a commit to be applied to another commit (or the working tree, or removed from the current commit). We also support building patches from things like stashes, for which there is less flexibility type PatchBuilder struct { - // To is the commit sha if we're dealing with files of a commit, or a stash ref for a stash + // To is the commit hash if we're dealing with files of a commit, or a stash ref for a stash To string From string reverse bool @@ -46,7 +46,7 @@ type PatchBuilder struct { fileInfoMap map[string]*fileInfo Log *logrus.Entry - // loadFileDiff loads the diff of a file, for a given to (typically a commit SHA) + // loadFileDiff loads the diff of a file, for a given to (typically a commit hash) loadFileDiff loadFileDiffFunc } diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index 66645e698a1..a2c01e15ddb 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -267,7 +267,7 @@ func (self *RefreshHelper) refreshCommitsAndCommitFiles() { _ = self.refreshCommitsWithLimit() ctx, ok := self.c.Contexts().CommitFiles.GetParentContext() if ok && ctx.GetKey() == context.LOCAL_COMMITS_CONTEXT_KEY { - // This makes sense when we've e.g. just amended a commit, meaning we get a new commit SHA at the same position. + // This makes sense when we've e.g. just amended a commit, meaning we get a new commit hash at the same position. // However if we've just added a brand new commit, it pushes the list down by one and so we would end up // showing the contents of a different commit than the one we initially entered. // Ideally we would know when to refresh the commit files context and when not to, diff --git a/pkg/gui/controllers/tags_controller.go b/pkg/gui/controllers/tags_controller.go index 3d7609f4bad..d845f192d49 100644 --- a/pkg/gui/controllers/tags_controller.go +++ b/pkg/gui/controllers/tags_controller.go @@ -230,7 +230,7 @@ func (self *TagsController) createResetMenu(tag *models.Tag) error { } func (self *TagsController) create() error { - // leaving commit SHA blank so that we're just creating the tag for the current commit + // leaving commit hash blank so that we're just creating the tag for the current commit return self.c.Helpers().Tags.OpenCreateTagPrompt("", func() { self.context().SetSelection(0) }) diff --git a/pkg/gui/presentation/commits.go b/pkg/gui/presentation/commits.go index c5d5e92e80b..58f4651964b 100644 --- a/pkg/gui/presentation/commits.go +++ b/pkg/gui/presentation/commits.go @@ -200,7 +200,7 @@ func indexOfFirstNonTODOCommit(commits []*models.Commit) int { } func loadPipesets(commits []*models.Commit) [][]*graph.Pipe { - // given that our cache key is a commit sha and a commit count, it's very important that we don't actually try to render pipes + // given that our cache key is a commit hash and a commit count, it's very important that we don't actually try to render pipes // when dealing with things like filtered commits. cacheKey := pipeSetCacheKey{ commitSha: commits[0].Sha, diff --git a/pkg/gui/presentation/graph/graph.go b/pkg/gui/presentation/graph/graph.go index f6ecf6f0c4f..51a55aceace 100644 --- a/pkg/gui/presentation/graph/graph.go +++ b/pkg/gui/presentation/graph/graph.go @@ -385,7 +385,7 @@ func renderPipeSet( } func equalHashes(a, b string) bool { - // if our selectedCommitSha is an empty string we treat that as meaning there is no selected commit sha + // if our selectedCommitSha is an empty string we treat that as meaning there is no selected commit hash if a == "" || b == "" { return false } diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go index 0341d811ed0..6eccd3f22b4 100644 --- a/pkg/i18n/dutch.go +++ b/pkg/i18n/dutch.go @@ -308,7 +308,7 @@ func dutchTranslationSet() TranslationSet { SwapDiff: "Keer diff richting om", ViewDiffingOptions: "Open diff menu", ShowingGitDiff: "Laat output zien voor:", - CopyCommitShaToClipboard: "Kopieer commit SHA naar klembord", + CopyCommitShaToClipboard: "Kopieer commit hash naar klembord", CopyCommitMessageToClipboard: "Kopieer commit bericht naar klembord", CopyBranchNameToClipboard: "Kopieer branch name naar klembord", CopyPathToClipboard: "Kopieer de bestandsnaam naar het klembord", diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 77e2432ad62..04da3eb175a 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -1534,8 +1534,8 @@ func EnglishTranslationSet() TranslationSet { OpenCommandLogMenuTooltip: "View options for the command log e.g. show/hide the command log and focus the command log.", ShowingGitDiff: "Showing output for:", CommitDiff: "Commit diff", - CopyCommitShaToClipboard: "Copy commit SHA to clipboard", - CommitSha: "Commit SHA", + CopyCommitShaToClipboard: "Copy commit hash to clipboard", + CommitSha: "commit hash", CommitURL: "Commit URL", CopyCommitMessageToClipboard: "Copy commit message to clipboard", CommitMessage: "Commit message", @@ -1772,7 +1772,7 @@ func EnglishTranslationSet() TranslationSet { CopyCommitMessageToClipboard: "Copy commit message to clipboard", CopyCommitSubjectToClipboard: "Copy commit subject to clipboard", CopyCommitDiffToClipboard: "Copy commit diff to clipboard", - CopyCommitSHAToClipboard: "Copy full commit SHA to clipboard", + CopyCommitSHAToClipboard: "Copy full commit hash to clipboard", CopyCommitURLToClipboard: "Copy commit URL to clipboard", CopyCommitAuthorToClipboard: "Copy commit author to clipboard", CopyCommitAttributeToClipboard: "Copy to clipboard", diff --git a/scripts/bisect.sh b/scripts/bisect.sh index a3bc5f19e1e..3652a85b8d7 100755 --- a/scripts/bisect.sh +++ b/scripts/bisect.sh @@ -4,7 +4,7 @@ # 1) find a commit that is working fine. # 2) Create an integration test capturing the fact that it works (Don't commit it). See https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md # 3) checkout the commit that's known to be failing -# 4) run this script supplying the commit sha / tag name that works and the name of the newly created test +# 4) run this script supplying the commit hash / tag name that works and the name of the newly created test # usage: scripts/bisect.sh # e.g. scripts/bisect.sh v0.32.1 mergeConflictsResolvedExternally From 84333eebc3be466b23627f6709ad6b000ddd21f1 Mon Sep 17 00:00:00 2001 From: pikomonde <32364823+pikomonde@users.noreply.github.com> Date: Wed, 20 Mar 2024 03:15:20 +0700 Subject: [PATCH 02/15] renaming variable to CommitHash --- pkg/commands/git_commands/bisect_info.go | 4 +- pkg/commands/git_commands/commit.go | 16 +- pkg/commands/git_commands/commit_loader.go | 8 +- pkg/commands/git_commands/working_tree.go | 4 +- .../git_commands/working_tree_test.go | 24 +- pkg/commands/hosting_service/definitions.go | 12 +- .../hosting_service/hosting_service.go | 8 +- pkg/gui/context/local_commits_context.go | 6 +- pkg/gui/context/sub_commits_context.go | 6 +- .../controllers/basic_commits_controller.go | 8 +- pkg/gui/controllers/helpers/host_helper.go | 6 +- pkg/gui/controllers/undo_controller.go | 24 +- pkg/gui/keybindings.go | 6 +- pkg/gui/presentation/commits.go | 26 +- pkg/gui/presentation/commits_test.go | 276 +++++++++--------- pkg/gui/presentation/graph/graph.go | 20 +- pkg/gui/presentation/reflog_commits.go | 4 +- pkg/i18n/chinese.go | 2 +- pkg/i18n/dutch.go | 2 +- pkg/i18n/english.go | 12 +- pkg/i18n/japanese.go | 6 +- pkg/i18n/korean.go | 6 +- pkg/i18n/polish.go | 6 +- pkg/i18n/russian.go | 6 +- pkg/i18n/traditional_chinese.go | 6 +- 25 files changed, 252 insertions(+), 252 deletions(-) diff --git a/pkg/commands/git_commands/bisect_info.go b/pkg/commands/git_commands/bisect_info.go index bed5bd9dbb9..39bd449492d 100644 --- a/pkg/commands/git_commands/bisect_info.go +++ b/pkg/commands/git_commands/bisect_info.go @@ -67,8 +67,8 @@ func (self *BisectInfo) GetStartSha() string { return self.start } -func (self *BisectInfo) Status(commitSha string) (BisectStatus, bool) { - status, ok := self.statusMap[commitSha] +func (self *BisectInfo) Status(commitHash string) (BisectStatus, bool) { + status, ok := self.statusMap[commitHash] return status, ok } diff --git a/pkg/commands/git_commands/commit.go b/pkg/commands/git_commands/commit.go index 693fe4eba8d..61b6cc2a153 100644 --- a/pkg/commands/git_commands/commit.go +++ b/pkg/commands/git_commands/commit.go @@ -155,9 +155,9 @@ func (self *CommitCommands) signoffFlag() string { } } -func (self *CommitCommands) GetCommitMessage(commitSha string) (string, error) { +func (self *CommitCommands) GetCommitMessage(commitHash string) (string, error) { cmdArgs := NewGitCmd("log"). - Arg("--format=%B", "--max-count=1", commitSha). + Arg("--format=%B", "--max-count=1", commitHash). Config("log.showsignature=false"). ToArgv() @@ -165,9 +165,9 @@ func (self *CommitCommands) GetCommitMessage(commitSha string) (string, error) { return strings.ReplaceAll(strings.TrimSpace(message), "\r\n", "\n"), err } -func (self *CommitCommands) GetCommitSubject(commitSha string) (string, error) { +func (self *CommitCommands) GetCommitSubject(commitHash string) (string, error) { cmdArgs := NewGitCmd("log"). - Arg("--format=%s", "--max-count=1", commitSha). + Arg("--format=%s", "--max-count=1", commitHash). Config("log.showsignature=false"). ToArgv() @@ -175,8 +175,8 @@ func (self *CommitCommands) GetCommitSubject(commitSha string) (string, error) { return strings.TrimSpace(subject), err } -func (self *CommitCommands) GetCommitDiff(commitSha string) (string, error) { - cmdArgs := NewGitCmd("show").Arg("--no-color", commitSha).ToArgv() +func (self *CommitCommands) GetCommitDiff(commitHash string) (string, error) { + cmdArgs := NewGitCmd("show").Arg("--no-color", commitHash).ToArgv() diff, err := self.cmd.New(cmdArgs).DontLog().RunWithOutput() return diff, err @@ -187,9 +187,9 @@ type Author struct { Email string } -func (self *CommitCommands) GetCommitAuthor(commitSha string) (Author, error) { +func (self *CommitCommands) GetCommitAuthor(commitHash string) (Author, error) { cmdArgs := NewGitCmd("show"). - Arg("--no-patch", "--pretty=format:'%an%x00%ae'", commitSha). + Arg("--no-patch", "--pretty=format:'%an%x00%ae'", commitHash). ToArgv() output, err := self.cmd.New(cmdArgs).DontLog().RunWithOutput() diff --git a/pkg/commands/git_commands/commit_loader.go b/pkg/commands/git_commands/commit_loader.go index a666359eb97..44d0cf55d8c 100644 --- a/pkg/commands/git_commands/commit_loader.go +++ b/pkg/commands/git_commands/commit_loader.go @@ -260,7 +260,7 @@ func (self *CommitLoader) getHydratedRebasingCommits(rebaseMode enums.RebaseMode return nil, nil } - commitShas := lo.FilterMap(commits, func(commit *models.Commit, _ int) (string, bool) { + commitHashes := lo.FilterMap(commits, func(commit *models.Commit, _ int) (string, bool) { return commit.Sha, commit.Sha != "" }) @@ -270,7 +270,7 @@ func (self *CommitLoader) getHydratedRebasingCommits(rebaseMode enums.RebaseMode NewGitCmd("show"). Config("log.showSignature=false"). Arg("--no-patch", "--oneline", "--abbrev=20", prettyFormat). - Arg(commitShas...). + Arg(commitHashes...). ToArgv(), ).DontLog() @@ -337,9 +337,9 @@ func (self *CommitLoader) getRebasingCommits(rebaseMode enums.RebaseMode) []*mod // See if the current commit couldn't be applied because it conflicted; if // so, add a fake entry for it - if conflictedCommitSha := self.getConflictedCommit(todos); conflictedCommitSha != "" { + if conflictedCommitHash := self.getConflictedCommit(todos); conflictedCommitHash != "" { commits = append(commits, &models.Commit{ - Sha: conflictedCommitSha, + Sha: conflictedCommitHash, Name: "", Status: models.StatusRebasing, Action: models.ActionConflict, diff --git a/pkg/commands/git_commands/working_tree.go b/pkg/commands/git_commands/working_tree.go index c3338650a94..3346c4f357c 100644 --- a/pkg/commands/git_commands/working_tree.go +++ b/pkg/commands/git_commands/working_tree.go @@ -313,8 +313,8 @@ func (self *WorkingTreeCommands) ShowFileDiffCmdObj(from string, to string, reve } // CheckoutFile checks out the file for the given commit -func (self *WorkingTreeCommands) CheckoutFile(commitSha, fileName string) error { - cmdArgs := NewGitCmd("checkout").Arg(commitSha, "--", fileName). +func (self *WorkingTreeCommands) CheckoutFile(commitHash, fileName string) error { + cmdArgs := NewGitCmd("checkout").Arg(commitHash, "--", fileName). ToArgv() return self.cmd.New(cmdArgs).Run() diff --git a/pkg/commands/git_commands/working_tree_test.go b/pkg/commands/git_commands/working_tree_test.go index 08255e247e4..435048072dc 100644 --- a/pkg/commands/git_commands/working_tree_test.go +++ b/pkg/commands/git_commands/working_tree_test.go @@ -397,18 +397,18 @@ func TestWorkingTreeShowFileDiff(t *testing.T) { func TestWorkingTreeCheckoutFile(t *testing.T) { type scenario struct { - testName string - commitSha string - fileName string - runner *oscommands.FakeCmdObjRunner - test func(error) + testName string + commitHash string + fileName string + runner *oscommands.FakeCmdObjRunner + test func(error) } scenarios := []scenario{ { - testName: "typical case", - commitSha: "11af912", - fileName: "test999.txt", + testName: "typical case", + commitHash: "11af912", + fileName: "test999.txt", runner: oscommands.NewFakeRunner(t). ExpectGitArgs([]string{"checkout", "11af912", "--", "test999.txt"}, "", nil), test: func(err error) { @@ -416,9 +416,9 @@ func TestWorkingTreeCheckoutFile(t *testing.T) { }, }, { - testName: "returns error if there is one", - commitSha: "11af912", - fileName: "test999.txt", + testName: "returns error if there is one", + commitHash: "11af912", + fileName: "test999.txt", runner: oscommands.NewFakeRunner(t). ExpectGitArgs([]string{"checkout", "11af912", "--", "test999.txt"}, "", errors.New("error")), test: func(err error) { @@ -432,7 +432,7 @@ func TestWorkingTreeCheckoutFile(t *testing.T) { t.Run(s.testName, func(t *testing.T) { instance := buildWorkingTreeCommands(commonDeps{runner: s.runner}) - s.test(instance.CheckoutFile(s.commitSha, s.fileName)) + s.test(instance.CheckoutFile(s.commitHash, s.fileName)) s.runner.CheckForMissingCalls() }) } diff --git a/pkg/commands/hosting_service/definitions.go b/pkg/commands/hosting_service/definitions.go index 63a1b818fbb..ff872cd8c05 100644 --- a/pkg/commands/hosting_service/definitions.go +++ b/pkg/commands/hosting_service/definitions.go @@ -14,7 +14,7 @@ var githubServiceDef = ServiceDefinition{ provider: "github", pullRequestURLIntoDefaultBranch: "/compare/{{.From}}?expand=1", pullRequestURLIntoTargetBranch: "/compare/{{.To}}...{{.From}}?expand=1", - commitURL: "/commit/{{.CommitSha}}", + commitURL: "/commit/{{.CommitHash}}", regexStrings: defaultUrlRegexStrings, repoURLTemplate: defaultRepoURLTemplate, } @@ -23,7 +23,7 @@ var bitbucketServiceDef = ServiceDefinition{ provider: "bitbucket", pullRequestURLIntoDefaultBranch: "/pull-requests/new?source={{.From}}&t=1", pullRequestURLIntoTargetBranch: "/pull-requests/new?source={{.From}}&dest={{.To}}&t=1", - commitURL: "/commits/{{.CommitSha}}", + commitURL: "/commits/{{.CommitHash}}", regexStrings: []string{ `^(?:https?|ssh)://.*/(?P.*)/(?P.*?)(?:\.git)?$`, `^.*@.*:(?P.*)/(?P.*?)(?:\.git)?$`, @@ -35,7 +35,7 @@ var gitLabServiceDef = ServiceDefinition{ provider: "gitlab", pullRequestURLIntoDefaultBranch: "/-/merge_requests/new?merge_request[source_branch]={{.From}}", pullRequestURLIntoTargetBranch: "/-/merge_requests/new?merge_request[source_branch]={{.From}}&merge_request[target_branch]={{.To}}", - commitURL: "/-/commit/{{.CommitSha}}", + commitURL: "/-/commit/{{.CommitHash}}", regexStrings: defaultUrlRegexStrings, repoURLTemplate: defaultRepoURLTemplate, } @@ -44,7 +44,7 @@ var azdoServiceDef = ServiceDefinition{ provider: "azuredevops", pullRequestURLIntoDefaultBranch: "/pullrequestcreate?sourceRef={{.From}}", pullRequestURLIntoTargetBranch: "/pullrequestcreate?sourceRef={{.From}}&targetRef={{.To}}", - commitURL: "/commit/{{.CommitSha}}", + commitURL: "/commit/{{.CommitHash}}", regexStrings: []string{ `^git@ssh.dev.azure.com.*/(?P.*)/(?P.*)/(?P.*?)(?:\.git)?$`, `^https://.*@dev.azure.com/(?P.*?)/(?P.*?)/_git/(?P.*?)(?:\.git)?$`, @@ -56,7 +56,7 @@ var bitbucketServerServiceDef = ServiceDefinition{ provider: "bitbucketServer", pullRequestURLIntoDefaultBranch: "/pull-requests?create&sourceBranch={{.From}}", pullRequestURLIntoTargetBranch: "/pull-requests?create&targetBranch={{.To}}&sourceBranch={{.From}}", - commitURL: "/commits/{{.CommitSha}}", + commitURL: "/commits/{{.CommitHash}}", regexStrings: []string{ `^ssh://git@.*/(?P.*)/(?P.*?)(?:\.git)?$`, `^https://.*/scm/(?P.*)/(?P.*?)(?:\.git)?$`, @@ -68,7 +68,7 @@ var giteaServiceDef = ServiceDefinition{ provider: "gitea", pullRequestURLIntoDefaultBranch: "/compare/{{.From}}", pullRequestURLIntoTargetBranch: "/compare/{{.To}}...{{.From}}", - commitURL: "/commit/{{.CommitSha}}", + commitURL: "/commit/{{.CommitHash}}", regexStrings: defaultUrlRegexStrings, repoURLTemplate: defaultRepoURLTemplate, } diff --git a/pkg/commands/hosting_service/hosting_service.go b/pkg/commands/hosting_service/hosting_service.go index 9cb997a0ec8..2e913b654a0 100644 --- a/pkg/commands/hosting_service/hosting_service.go +++ b/pkg/commands/hosting_service/hosting_service.go @@ -51,13 +51,13 @@ func (self *HostingServiceMgr) GetPullRequestURL(from string, to string) (string } } -func (self *HostingServiceMgr) GetCommitURL(commitSha string) (string, error) { +func (self *HostingServiceMgr) GetCommitURL(commitHash string) (string, error) { gitService, err := self.getService() if err != nil { return "", err } - pullRequestURL := gitService.getCommitURL(commitSha) + pullRequestURL := gitService.getCommitURL(commitHash) return pullRequestURL, nil } @@ -174,8 +174,8 @@ func (self *Service) getPullRequestURLIntoTargetBranch(from string, to string) s return self.resolveUrl(self.pullRequestURLIntoTargetBranch, map[string]string{"From": from, "To": to}) } -func (self *Service) getCommitURL(commitSha string) string { - return self.resolveUrl(self.commitURL, map[string]string{"CommitSha": commitSha}) +func (self *Service) getCommitURL(commitHash string) string { + return self.resolveUrl(self.commitURL, map[string]string{"CommitHash": commitHash}) } func (self *Service) resolveUrl(templateString string, args map[string]string) string { diff --git a/pkg/gui/context/local_commits_context.go b/pkg/gui/context/local_commits_context.go index c6d7de99187..043483fc9ff 100644 --- a/pkg/gui/context/local_commits_context.go +++ b/pkg/gui/context/local_commits_context.go @@ -29,12 +29,12 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext { ) getDisplayStrings := func(startIdx int, endIdx int) [][]string { - selectedCommitSha := "" + selectedCommitHash := "" if c.CurrentContext().GetKey() == LOCAL_COMMITS_CONTEXT_KEY { selectedCommit := viewModel.GetSelected() if selectedCommit != nil { - selectedCommitSha = selectedCommit.Sha + selectedCommitHash = selectedCommit.Sha } } @@ -55,7 +55,7 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext { c.UserConfig.Gui.ShortTimeFormat, time.Now(), c.UserConfig.Git.ParseEmoji, - selectedCommitSha, + selectedCommitHash, startIdx, endIdx, shouldShowGraph(c), diff --git a/pkg/gui/context/sub_commits_context.go b/pkg/gui/context/sub_commits_context.go index d98188b9124..9bad0b8cf31 100644 --- a/pkg/gui/context/sub_commits_context.go +++ b/pkg/gui/context/sub_commits_context.go @@ -44,11 +44,11 @@ func NewSubCommitsContext( return [][]string{} } - selectedCommitSha := "" + selectedCommitHash := "" if c.CurrentContext().GetKey() == SUB_COMMITS_CONTEXT_KEY { selectedCommit := viewModel.GetSelected() if selectedCommit != nil { - selectedCommitSha = selectedCommit.Sha + selectedCommitHash = selectedCommit.Sha } } branches := []*models.Branch{} @@ -70,7 +70,7 @@ func NewSubCommitsContext( c.UserConfig.Gui.ShortTimeFormat, time.Now(), c.UserConfig.Git.ParseEmoji, - selectedCommitSha, + selectedCommitHash, startIdx, endIdx, // Don't show the graph in the left/right view; we'd like to, but diff --git a/pkg/gui/controllers/basic_commits_controller.go b/pkg/gui/controllers/basic_commits_controller.go index 1fde39e8b24..8bf3b7969f3 100644 --- a/pkg/gui/controllers/basic_commits_controller.go +++ b/pkg/gui/controllers/basic_commits_controller.go @@ -125,9 +125,9 @@ func (self *BasicCommitsController) copyCommitAttribute(commit *models.Commit) e Title: self.c.Tr.Actions.CopyCommitAttributeToClipboard, Items: []*types.MenuItem{ { - Label: self.c.Tr.CommitSha, + Label: self.c.Tr.CommitHash, OnPress: func() error { - return self.copyCommitSHAToClipboard(commit) + return self.copyCommitHashToClipboard(commit) }, }, { @@ -169,8 +169,8 @@ func (self *BasicCommitsController) copyCommitAttribute(commit *models.Commit) e }) } -func (self *BasicCommitsController) copyCommitSHAToClipboard(commit *models.Commit) error { - self.c.LogAction(self.c.Tr.Actions.CopyCommitSHAToClipboard) +func (self *BasicCommitsController) copyCommitHashToClipboard(commit *models.Commit) error { + self.c.LogAction(self.c.Tr.Actions.CopyCommitHashToClipboard) if err := self.c.OS().CopyToClipboard(commit.Sha); err != nil { return self.c.Error(err) } diff --git a/pkg/gui/controllers/helpers/host_helper.go b/pkg/gui/controllers/helpers/host_helper.go index 77fdd530e4e..bbd464ba8e2 100644 --- a/pkg/gui/controllers/helpers/host_helper.go +++ b/pkg/gui/controllers/helpers/host_helper.go @@ -8,7 +8,7 @@ import ( type IHostHelper interface { GetPullRequestURL(from string, to string) (string, error) - GetCommitURL(commitSha string) (string, error) + GetCommitURL(commitHash string) (string, error) } type HostHelper struct { @@ -31,12 +31,12 @@ func (self *HostHelper) GetPullRequestURL(from string, to string) (string, error return mgr.GetPullRequestURL(from, to) } -func (self *HostHelper) GetCommitURL(commitSha string) (string, error) { +func (self *HostHelper) GetCommitURL(commitHash string) (string, error) { mgr, err := self.getHostingServiceMgr() if err != nil { return "", err } - return mgr.GetCommitURL(commitSha) + return mgr.GetCommitURL(commitHash) } // getting this on every request rather than storing it in state in case our remoteURL changes diff --git a/pkg/gui/controllers/undo_controller.go b/pkg/gui/controllers/undo_controller.go index c0a75479436..402e07471bb 100644 --- a/pkg/gui/controllers/undo_controller.go +++ b/pkg/gui/controllers/undo_controller.go @@ -181,34 +181,34 @@ func (self *UndoController) reflogRedo() error { func (self *UndoController) parseReflogForActions(onUserAction func(counter int, action reflogAction) (bool, error)) error { counter := 0 reflogCommits := self.c.Model().FilteredReflogCommits - rebaseFinishCommitSha := "" + rebaseFinishCommitHash := "" var action *reflogAction for reflogCommitIdx, reflogCommit := range reflogCommits { action = nil - prevCommitSha := "" + prevCommitHash := "" if len(reflogCommits)-1 >= reflogCommitIdx+1 { - prevCommitSha = reflogCommits[reflogCommitIdx+1].Sha + prevCommitHash = reflogCommits[reflogCommitIdx+1].Sha } - if rebaseFinishCommitSha == "" { + if rebaseFinishCommitHash == "" { if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^\[lazygit undo\]`); ok { counter++ } else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^\[lazygit redo\]`); ok { counter-- } else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^rebase (-i )?\(abort\)|^rebase (-i )?\(finish\)`); ok { - rebaseFinishCommitSha = reflogCommit.Sha + rebaseFinishCommitHash = reflogCommit.Sha } else if ok, match := utils.FindStringSubmatch(reflogCommit.Name, `^checkout: moving from ([\S]+) to ([\S]+)`); ok { action = &reflogAction{kind: CHECKOUT, from: match[1], to: match[2]} } else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^commit|^reset: moving to|^pull`); ok { - action = &reflogAction{kind: COMMIT, from: prevCommitSha, to: reflogCommit.Sha} + action = &reflogAction{kind: COMMIT, from: prevCommitHash, to: reflogCommit.Sha} } else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^rebase (-i )?\(start\)`); ok { // if we're here then we must be currently inside an interactive rebase - action = &reflogAction{kind: CURRENT_REBASE, from: prevCommitSha} + action = &reflogAction{kind: CURRENT_REBASE, from: prevCommitHash} } } else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^rebase (-i )?\(start\)`); ok { - action = &reflogAction{kind: REBASE, from: prevCommitSha, to: rebaseFinishCommitSha} - rebaseFinishCommitSha = "" + action = &reflogAction{kind: REBASE, from: prevCommitHash, to: rebaseFinishCommitHash} + rebaseFinishCommitHash = "" } if action != nil { @@ -232,9 +232,9 @@ type hardResetOptions struct { } // only to be used in the undo flow for now (does an autostash) -func (self *UndoController) hardResetWithAutoStash(commitSha string, options hardResetOptions) error { +func (self *UndoController) hardResetWithAutoStash(commitHash string, options hardResetOptions) error { reset := func() error { - if err := self.c.Helpers().Refs.ResetToRef(commitSha, "hard", options.EnvVars); err != nil { + if err := self.c.Helpers().Refs.ResetToRef(commitHash, "hard", options.EnvVars); err != nil { return self.c.Error(err) } return nil @@ -249,7 +249,7 @@ func (self *UndoController) hardResetWithAutoStash(commitSha string, options har Prompt: self.c.Tr.AutoStashPrompt, HandleConfirm: func() error { return self.c.WithWaitingStatus(options.WaitingStatus, func(gocui.Task) error { - if err := self.c.Git().Stash.Push(self.c.Tr.StashPrefix + commitSha); err != nil { + if err := self.c.Git().Stash.Push(self.c.Tr.StashPrefix + commitHash); err != nil { return self.c.Error(err) } if err := reset(); err != nil { diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 9c4acd1ee2d..c6bb8ada5fd 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -148,7 +148,7 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi Key: opts.GetKey(opts.Config.Universal.CopyToClipboard), Handler: self.handleCopySelectedSideContextItemCommitHashToClipboard, GetDisabledReason: self.getCopySelectedSideContextItemToClipboardDisabledReason, - Description: self.c.Tr.CopyCommitShaToClipboard, + Description: self.c.Tr.CopyCommitHashToClipboard, }, { ViewName: "commits", @@ -161,14 +161,14 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi Key: opts.GetKey(opts.Config.Universal.CopyToClipboard), Handler: self.handleCopySelectedSideContextItemToClipboard, GetDisabledReason: self.getCopySelectedSideContextItemToClipboardDisabledReason, - Description: self.c.Tr.CopyCommitShaToClipboard, + Description: self.c.Tr.CopyCommitHashToClipboard, }, { ViewName: "subCommits", Key: opts.GetKey(opts.Config.Universal.CopyToClipboard), Handler: self.handleCopySelectedSideContextItemCommitHashToClipboard, GetDisabledReason: self.getCopySelectedSideContextItemToClipboardDisabledReason, - Description: self.c.Tr.CopyCommitShaToClipboard, + Description: self.c.Tr.CopyCommitHashToClipboard, }, { ViewName: "information", diff --git a/pkg/gui/presentation/commits.go b/pkg/gui/presentation/commits.go index 58f4651964b..d6ae519c22d 100644 --- a/pkg/gui/presentation/commits.go +++ b/pkg/gui/presentation/commits.go @@ -22,7 +22,7 @@ import ( ) type pipeSetCacheKey struct { - commitSha string + commitHash string commitCount int } @@ -43,14 +43,14 @@ func GetCommitListDisplayStrings( currentBranchName string, hasRebaseUpdateRefsConfig bool, fullDescription bool, - cherryPickedCommitShaSet *set.Set[string], + cherryPickedCommitHashSet *set.Set[string], diffName string, markedBaseCommit string, timeFormat string, shortTimeFormat string, now time.Time, parseEmoji bool, - selectedCommitSha string, + selectedCommitHash string, startIdx int, endIdx int, showGraph bool, @@ -89,7 +89,7 @@ func GetCommitListDisplayStrings( graphLines := graph.RenderAux( graphPipeSets, graphCommits, - selectedCommitSha, + selectedCommitHash, ) getGraphLine = func(idx int) string { if idx >= graphOffset { @@ -146,7 +146,7 @@ func GetCommitListDisplayStrings( commit, branchHeadsToVisualize, hasRebaseUpdateRefsConfig, - cherryPickedCommitShaSet, + cherryPickedCommitHashSet, isMarkedBaseCommit, willBeRebased, diffName, @@ -203,7 +203,7 @@ func loadPipesets(commits []*models.Commit) [][]*graph.Pipe { // given that our cache key is a commit hash and a commit count, it's very important that we don't actually try to render pipes // when dealing with things like filtered commits. cacheKey := pipeSetCacheKey{ - commitSha: commits[0].Sha, + commitHash: commits[0].Sha, commitCount: len(commits), } @@ -236,16 +236,16 @@ const ( BisectStatusCurrent ) -func getBisectStatus(index int, commitSha string, bisectInfo *git_commands.BisectInfo, bisectBounds *bisectBounds) BisectStatus { +func getBisectStatus(index int, commitHash string, bisectInfo *git_commands.BisectInfo, bisectBounds *bisectBounds) BisectStatus { if !bisectInfo.Started() { return BisectStatusNone } - if bisectInfo.GetCurrentSha() == commitSha { + if bisectInfo.GetCurrentSha() == commitHash { return BisectStatusCurrent } - status, ok := bisectInfo.Status(commitSha) + status, ok := bisectInfo.Status(commitHash) if ok { switch status { case git_commands.BisectStatusNew: @@ -298,7 +298,7 @@ func displayCommit( commit *models.Commit, branchHeadsToVisualize *set.Set[string], hasRebaseUpdateRefsConfig bool, - cherryPickedCommitShaSet *set.Set[string], + cherryPickedCommitHashSet *set.Set[string], isMarkedBaseCommit bool, willBeRebased bool, diffName string, @@ -312,7 +312,7 @@ func displayCommit( bisectInfo *git_commands.BisectInfo, isYouAreHereCommit bool, ) []string { - shaColor := getShaColor(commit, diffName, cherryPickedCommitShaSet, bisectStatus, bisectInfo) + shaColor := getShaColor(commit, diffName, cherryPickedCommitHashSet, bisectStatus, bisectInfo) bisectString := getBisectStatusText(bisectStatus, bisectInfo) actionString := "" @@ -413,7 +413,7 @@ func getBisectStatusColor(status BisectStatus) style.TextStyle { func getShaColor( commit *models.Commit, diffName string, - cherryPickedCommitShaSet *set.Set[string], + cherryPickedCommitHashSet *set.Set[string], bisectStatus BisectStatus, bisectInfo *git_commands.BisectInfo, ) style.TextStyle { @@ -439,7 +439,7 @@ func getShaColor( if diffed { shaColor = theme.DiffTerminalColor - } else if cherryPickedCommitShaSet.Includes(commit.Sha) { + } else if cherryPickedCommitHashSet.Includes(commit.Sha) { shaColor = theme.CherryPickedCommitTextStyle } else if commit.Divergence == models.DivergenceRight && commit.Status != models.StatusMerged { shaColor = style.FgBlue diff --git a/pkg/gui/presentation/commits_test.go b/pkg/gui/presentation/commits_test.go index f1f075f453f..75f96eed9cd 100644 --- a/pkg/gui/presentation/commits_test.go +++ b/pkg/gui/presentation/commits_test.go @@ -22,38 +22,38 @@ func formatExpected(expected string) string { func TestGetCommitListDisplayStrings(t *testing.T) { scenarios := []struct { - testName string - commits []*models.Commit - branches []*models.Branch - currentBranchName string - hasUpdateRefConfig bool - fullDescription bool - cherryPickedCommitShaSet *set.Set[string] - markedBaseCommit string - diffName string - timeFormat string - shortTimeFormat string - now time.Time - parseEmoji bool - selectedCommitSha string - startIdx int - endIdx int - showGraph bool - bisectInfo *git_commands.BisectInfo - showYouAreHereLabel bool - expected string - focus bool + testName string + commits []*models.Commit + branches []*models.Branch + currentBranchName string + hasUpdateRefConfig bool + fullDescription bool + cherryPickedCommitHashSet *set.Set[string] + markedBaseCommit string + diffName string + timeFormat string + shortTimeFormat string + now time.Time + parseEmoji bool + selectedCommitHash string + startIdx int + endIdx int + showGraph bool + bisectInfo *git_commands.BisectInfo + showYouAreHereLabel bool + expected string + focus bool }{ { - testName: "no commits", - commits: []*models.Commit{}, - startIdx: 0, - endIdx: 1, - showGraph: false, - bisectInfo: git_commands.NewNullBisectInfo(), - cherryPickedCommitShaSet: set.New[string](), - now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), - expected: "", + testName: "no commits", + commits: []*models.Commit{}, + startIdx: 0, + endIdx: 1, + showGraph: false, + bisectInfo: git_commands.NewNullBisectInfo(), + cherryPickedCommitHashSet: set.New[string](), + now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), + expected: "", }, { testName: "some commits", @@ -61,12 +61,12 @@ func TestGetCommitListDisplayStrings(t *testing.T) { {Name: "commit1", Sha: "sha1"}, {Name: "commit2", Sha: "sha2"}, }, - startIdx: 0, - endIdx: 2, - showGraph: false, - bisectInfo: git_commands.NewNullBisectInfo(), - cherryPickedCommitShaSet: set.New[string](), - now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), + startIdx: 0, + endIdx: 2, + showGraph: false, + bisectInfo: git_commands.NewNullBisectInfo(), + cherryPickedCommitHashSet: set.New[string](), + now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` sha1 commit1 sha2 commit2 @@ -78,12 +78,12 @@ func TestGetCommitListDisplayStrings(t *testing.T) { {Name: "commit1", Sha: "sha1", Tags: []string{"tag1", "tag2"}}, {Name: "commit2", Sha: "sha2"}, }, - startIdx: 0, - endIdx: 2, - showGraph: false, - bisectInfo: git_commands.NewNullBisectInfo(), - cherryPickedCommitShaSet: set.New[string](), - now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), + startIdx: 0, + endIdx: 2, + showGraph: false, + bisectInfo: git_commands.NewNullBisectInfo(), + cherryPickedCommitHashSet: set.New[string](), + now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` sha1 tag1 tag2 commit1 sha2 commit2 @@ -103,14 +103,14 @@ func TestGetCommitListDisplayStrings(t *testing.T) { {Name: "master", CommitHash: "sha3", Head: false}, {Name: "old-branch", CommitHash: "sha4", Head: false}, }, - currentBranchName: "current-branch", - hasUpdateRefConfig: true, - startIdx: 0, - endIdx: 4, - showGraph: false, - bisectInfo: git_commands.NewNullBisectInfo(), - cherryPickedCommitShaSet: set.New[string](), - now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), + currentBranchName: "current-branch", + hasUpdateRefConfig: true, + startIdx: 0, + endIdx: 4, + showGraph: false, + bisectInfo: git_commands.NewNullBisectInfo(), + cherryPickedCommitHashSet: set.New[string](), + now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` sha1 commit1 sha2 * commit2 @@ -128,14 +128,14 @@ func TestGetCommitListDisplayStrings(t *testing.T) { {Name: "current-branch", CommitHash: "sha1", Head: true}, {Name: "other-branch", CommitHash: "sha1", Head: false}, }, - currentBranchName: "current-branch", - hasUpdateRefConfig: true, - startIdx: 0, - endIdx: 2, - showGraph: false, - bisectInfo: git_commands.NewNullBisectInfo(), - cherryPickedCommitShaSet: set.New[string](), - now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), + currentBranchName: "current-branch", + hasUpdateRefConfig: true, + startIdx: 0, + endIdx: 2, + showGraph: false, + bisectInfo: git_commands.NewNullBisectInfo(), + cherryPickedCommitHashSet: set.New[string](), + now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` sha1 * commit1 sha2 commit2 @@ -151,14 +151,14 @@ func TestGetCommitListDisplayStrings(t *testing.T) { {Name: "current-branch", CommitHash: "sha1", Head: true}, {Name: "other-branch", CommitHash: "sha1", Head: false}, }, - currentBranchName: "current-branch", - hasUpdateRefConfig: false, - startIdx: 0, - endIdx: 2, - showGraph: false, - bisectInfo: git_commands.NewNullBisectInfo(), - cherryPickedCommitShaSet: set.New[string](), - now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), + currentBranchName: "current-branch", + hasUpdateRefConfig: false, + startIdx: 0, + endIdx: 2, + showGraph: false, + bisectInfo: git_commands.NewNullBisectInfo(), + cherryPickedCommitHashSet: set.New[string](), + now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` sha1 commit1 sha2 commit2 @@ -174,12 +174,12 @@ func TestGetCommitListDisplayStrings(t *testing.T) { branches: []*models.Branch{ {Name: "some-branch", CommitHash: "sha2"}, }, - startIdx: 0, - endIdx: 3, - showGraph: false, - bisectInfo: git_commands.NewNullBisectInfo(), - cherryPickedCommitShaSet: set.New[string](), - now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), + startIdx: 0, + endIdx: 3, + showGraph: false, + bisectInfo: git_commands.NewNullBisectInfo(), + cherryPickedCommitHashSet: set.New[string](), + now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` sha1 commit1 sha2 * some-tag commit2 @@ -195,12 +195,12 @@ func TestGetCommitListDisplayStrings(t *testing.T) { {Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}}, {Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}}, }, - startIdx: 0, - endIdx: 5, - showGraph: true, - bisectInfo: git_commands.NewNullBisectInfo(), - cherryPickedCommitShaSet: set.New[string](), - now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), + startIdx: 0, + endIdx: 5, + showGraph: true, + bisectInfo: git_commands.NewNullBisectInfo(), + cherryPickedCommitHashSet: set.New[string](), + now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` sha1 ⏣─╮ commit1 sha2 ◯ │ commit2 @@ -218,13 +218,13 @@ func TestGetCommitListDisplayStrings(t *testing.T) { {Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}}, {Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}}, }, - startIdx: 0, - endIdx: 5, - showGraph: true, - bisectInfo: git_commands.NewNullBisectInfo(), - cherryPickedCommitShaSet: set.New[string](), - showYouAreHereLabel: true, - now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), + startIdx: 0, + endIdx: 5, + showGraph: true, + bisectInfo: git_commands.NewNullBisectInfo(), + cherryPickedCommitHashSet: set.New[string](), + showYouAreHereLabel: true, + now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` sha1 pick commit1 sha2 pick commit2 @@ -242,13 +242,13 @@ func TestGetCommitListDisplayStrings(t *testing.T) { {Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}}, {Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}}, }, - startIdx: 1, - endIdx: 5, - showGraph: true, - bisectInfo: git_commands.NewNullBisectInfo(), - cherryPickedCommitShaSet: set.New[string](), - showYouAreHereLabel: true, - now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), + startIdx: 1, + endIdx: 5, + showGraph: true, + bisectInfo: git_commands.NewNullBisectInfo(), + cherryPickedCommitHashSet: set.New[string](), + showYouAreHereLabel: true, + now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` sha2 pick commit2 sha3 ◯ <-- YOU ARE HERE --- commit3 @@ -265,13 +265,13 @@ func TestGetCommitListDisplayStrings(t *testing.T) { {Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}}, {Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}}, }, - startIdx: 3, - endIdx: 5, - showGraph: true, - bisectInfo: git_commands.NewNullBisectInfo(), - cherryPickedCommitShaSet: set.New[string](), - showYouAreHereLabel: true, - now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), + startIdx: 3, + endIdx: 5, + showGraph: true, + bisectInfo: git_commands.NewNullBisectInfo(), + cherryPickedCommitHashSet: set.New[string](), + showYouAreHereLabel: true, + now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` sha4 ◯ commit4 sha5 ◯ commit5 @@ -286,13 +286,13 @@ func TestGetCommitListDisplayStrings(t *testing.T) { {Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}}, {Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}}, }, - startIdx: 0, - endIdx: 2, - showGraph: true, - bisectInfo: git_commands.NewNullBisectInfo(), - cherryPickedCommitShaSet: set.New[string](), - showYouAreHereLabel: true, - now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), + startIdx: 0, + endIdx: 2, + showGraph: true, + bisectInfo: git_commands.NewNullBisectInfo(), + cherryPickedCommitHashSet: set.New[string](), + showYouAreHereLabel: true, + now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` sha1 pick commit1 sha2 pick commit2 @@ -307,13 +307,13 @@ func TestGetCommitListDisplayStrings(t *testing.T) { {Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}}, {Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}}, }, - startIdx: 4, - endIdx: 5, - showGraph: true, - bisectInfo: git_commands.NewNullBisectInfo(), - cherryPickedCommitShaSet: set.New[string](), - showYouAreHereLabel: true, - now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), + startIdx: 4, + endIdx: 5, + showGraph: true, + bisectInfo: git_commands.NewNullBisectInfo(), + cherryPickedCommitHashSet: set.New[string](), + showYouAreHereLabel: true, + now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` sha5 ◯ commit5 `), @@ -327,13 +327,13 @@ func TestGetCommitListDisplayStrings(t *testing.T) { {Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}, Action: todo.Pick}, {Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}}, }, - startIdx: 0, - endIdx: 2, - showGraph: true, - bisectInfo: git_commands.NewNullBisectInfo(), - cherryPickedCommitShaSet: set.New[string](), - showYouAreHereLabel: true, - now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), + startIdx: 0, + endIdx: 2, + showGraph: true, + bisectInfo: git_commands.NewNullBisectInfo(), + cherryPickedCommitHashSet: set.New[string](), + showYouAreHereLabel: true, + now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` sha1 pick commit1 sha2 pick commit2 @@ -346,13 +346,13 @@ func TestGetCommitListDisplayStrings(t *testing.T) { {Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}}, {Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}}, }, - startIdx: 0, - endIdx: 3, - showGraph: true, - bisectInfo: git_commands.NewNullBisectInfo(), - cherryPickedCommitShaSet: set.New[string](), - showYouAreHereLabel: false, - now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), + startIdx: 0, + endIdx: 3, + showGraph: true, + bisectInfo: git_commands.NewNullBisectInfo(), + cherryPickedCommitHashSet: set.New[string](), + showYouAreHereLabel: false, + now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` sha1 pick commit1 sha2 ◯ commit2 @@ -365,15 +365,15 @@ func TestGetCommitListDisplayStrings(t *testing.T) { {Name: "commit1", Sha: "sha1", UnixTimestamp: 1577844184, AuthorName: "Jesse Duffield"}, {Name: "commit2", Sha: "sha2", UnixTimestamp: 1576844184, AuthorName: "Jesse Duffield"}, }, - fullDescription: true, - timeFormat: "2006-01-02", - shortTimeFormat: "3:04PM", - startIdx: 0, - endIdx: 2, - showGraph: false, - bisectInfo: git_commands.NewNullBisectInfo(), - cherryPickedCommitShaSet: set.New[string](), - now: time.Date(2020, 1, 1, 5, 3, 4, 0, time.UTC), + fullDescription: true, + timeFormat: "2006-01-02", + shortTimeFormat: "3:04PM", + startIdx: 0, + endIdx: 2, + showGraph: false, + bisectInfo: git_commands.NewNullBisectInfo(), + cherryPickedCommitHashSet: set.New[string](), + now: time.Date(2020, 1, 1, 5, 3, 4, 0, time.UTC), expected: formatExpected(` sha1 2:03AM Jesse Duffield commit1 sha2 2019-12-20 Jesse Duffield commit2 @@ -406,14 +406,14 @@ func TestGetCommitListDisplayStrings(t *testing.T) { s.currentBranchName, s.hasUpdateRefConfig, s.fullDescription, - s.cherryPickedCommitShaSet, + s.cherryPickedCommitHashSet, s.diffName, s.markedBaseCommit, s.timeFormat, s.shortTimeFormat, s.now, s.parseEmoji, - s.selectedCommitSha, + s.selectedCommitHash, s.startIdx, s.endIdx, s.showGraph, diff --git a/pkg/gui/presentation/graph/graph.go b/pkg/gui/presentation/graph/graph.go index 51a55aceace..21530ac6bfe 100644 --- a/pkg/gui/presentation/graph/graph.go +++ b/pkg/gui/presentation/graph/graph.go @@ -32,7 +32,7 @@ type Pipe struct { var highlightStyle = style.FgLightWhite.SetBold() -func ContainsCommitSha(pipes []*Pipe, sha string) bool { +func ContainsCommitHash(pipes []*Pipe, sha string) bool { for _, pipe := range pipes { if equalHashes(pipe.fromSha, sha) { return true @@ -49,13 +49,13 @@ func (self Pipe) right() int { return max(self.fromPos, self.toPos) } -func RenderCommitGraph(commits []*models.Commit, selectedCommitSha string, getStyle func(c *models.Commit) style.TextStyle) []string { +func RenderCommitGraph(commits []*models.Commit, selectedCommitHash string, getStyle func(c *models.Commit) style.TextStyle) []string { pipeSets := GetPipeSets(commits, getStyle) if len(pipeSets) == 0 { return nil } - lines := RenderAux(pipeSets, commits, selectedCommitSha) + lines := RenderAux(pipeSets, commits, selectedCommitHash) return lines } @@ -73,7 +73,7 @@ func GetPipeSets(commits []*models.Commit, getStyle func(c *models.Commit) style }) } -func RenderAux(pipeSets [][]*Pipe, commits []*models.Commit, selectedCommitSha string) []string { +func RenderAux(pipeSets [][]*Pipe, commits []*models.Commit, selectedCommitHash string) []string { maxProcs := runtime.GOMAXPROCS(0) // splitting up the rendering of the graph into multiple goroutines allows us to render the graph in parallel @@ -98,7 +98,7 @@ func RenderAux(pipeSets [][]*Pipe, commits []*models.Commit, selectedCommitSha s if k > 0 { prevCommit = commits[k-1] } - line := renderPipeSet(pipeSet, selectedCommitSha, prevCommit) + line := renderPipeSet(pipeSet, selectedCommitHash, prevCommit) innerLines = append(innerLines, line) } chunks[i] = innerLines @@ -282,7 +282,7 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod func renderPipeSet( pipes []*Pipe, - selectedCommitSha string, + selectedCommitHash string, prevCommit *models.Commit, ) string { maxPos := 0 @@ -329,10 +329,10 @@ func renderPipeSet( // we don't want to highlight two commits if they're contiguous. We only want // to highlight multiple things if there's an actual visible pipe involved. highlight := true - if prevCommit != nil && equalHashes(prevCommit.Sha, selectedCommitSha) { + if prevCommit != nil && equalHashes(prevCommit.Sha, selectedCommitHash) { highlight = false for _, pipe := range pipes { - if equalHashes(pipe.fromSha, selectedCommitSha) && (pipe.kind != TERMINATES || pipe.fromPos != pipe.toPos) { + if equalHashes(pipe.fromSha, selectedCommitHash) && (pipe.kind != TERMINATES || pipe.fromPos != pipe.toPos) { highlight = true } } @@ -341,7 +341,7 @@ func renderPipeSet( // so we have our commit pos again, now it's time to build the cells. // we'll handle the one that's sourced from our selected commit last so that it can override the other cells. selectedPipes, nonSelectedPipes := utils.Partition(pipes, func(pipe *Pipe) bool { - return highlight && equalHashes(pipe.fromSha, selectedCommitSha) + return highlight && equalHashes(pipe.fromSha, selectedCommitHash) }) for _, pipe := range nonSelectedPipes { @@ -385,7 +385,7 @@ func renderPipeSet( } func equalHashes(a, b string) bool { - // if our selectedCommitSha is an empty string we treat that as meaning there is no selected commit hash + // if our selectedCommitHash is an empty string we treat that as meaning there is no selected commit hash if a == "" || b == "" { return false } diff --git a/pkg/gui/presentation/reflog_commits.go b/pkg/gui/presentation/reflog_commits.go index cde774e4609..e38a0112643 100644 --- a/pkg/gui/presentation/reflog_commits.go +++ b/pkg/gui/presentation/reflog_commits.go @@ -12,7 +12,7 @@ import ( "github.com/samber/lo" ) -func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitShaSet *set.Set[string], diffName string, now time.Time, timeFormat string, shortTimeFormat string, parseEmoji bool) [][]string { +func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitHashSet *set.Set[string], diffName string, now time.Time, timeFormat string, shortTimeFormat string, parseEmoji bool) [][]string { var displayFunc func(*models.Commit, reflogCommitDisplayAttributes) []string if fullDescription { displayFunc = getFullDescriptionDisplayStringsForReflogCommit @@ -22,7 +22,7 @@ func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription return lo.Map(commits, func(commit *models.Commit, _ int) []string { diffed := commit.Sha == diffName - cherryPicked := cherryPickedCommitShaSet.Includes(commit.Sha) + cherryPicked := cherryPickedCommitHashSet.Includes(commit.Sha) return displayFunc(commit, reflogCommitDisplayAttributes{ cherryPicked: cherryPicked, diff --git a/pkg/i18n/chinese.go b/pkg/i18n/chinese.go index 5648c922f94..f6071b39838 100644 --- a/pkg/i18n/chinese.go +++ b/pkg/i18n/chinese.go @@ -355,7 +355,7 @@ func chineseTranslationSet() TranslationSet { // 实际视图 (actual view) 是附加视图 (extras view),未来,我打算为附加视图提供更多选项卡,但现在,上面的文本只需要提及“命令日志”这个部分 OpenCommandLogMenu: "打开命令日志菜单", ShowingGitDiff: "显示输出:", - CopyCommitShaToClipboard: "将提交的 SHA 复制到剪贴板", + CopyCommitHashToClipboard: "将提交的 SHA 复制到剪贴板", CopyCommitMessageToClipboard: "将提交消息复制到剪贴板", CopyBranchNameToClipboard: "将分支名称复制到剪贴板", CopyPathToClipboard: "将文件名复制到剪贴板", diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go index 6eccd3f22b4..4db19c43128 100644 --- a/pkg/i18n/dutch.go +++ b/pkg/i18n/dutch.go @@ -308,7 +308,7 @@ func dutchTranslationSet() TranslationSet { SwapDiff: "Keer diff richting om", ViewDiffingOptions: "Open diff menu", ShowingGitDiff: "Laat output zien voor:", - CopyCommitShaToClipboard: "Kopieer commit hash naar klembord", + CopyCommitHashToClipboard: "Kopieer commit hash naar klembord", CopyCommitMessageToClipboard: "Kopieer commit bericht naar klembord", CopyBranchNameToClipboard: "Kopieer branch name naar klembord", CopyPathToClipboard: "Kopieer de bestandsnaam naar het klembord", diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 04da3eb175a..9e728defd8c 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -571,8 +571,8 @@ type TranslationSet struct { OpenCommandLogMenuTooltip string ShowingGitDiff string CommitDiff string - CopyCommitShaToClipboard string - CommitSha string + CopyCommitHashToClipboard string + CommitHash string CommitURL string CopyCommitMessageToClipboard string CommitMessage string @@ -855,7 +855,7 @@ type Actions struct { CopyCommitMessageToClipboard string CopyCommitSubjectToClipboard string CopyCommitDiffToClipboard string - CopyCommitSHAToClipboard string + CopyCommitHashToClipboard string CopyCommitURLToClipboard string CopyCommitAuthorToClipboard string CopyCommitAttributeToClipboard string @@ -1534,8 +1534,8 @@ func EnglishTranslationSet() TranslationSet { OpenCommandLogMenuTooltip: "View options for the command log e.g. show/hide the command log and focus the command log.", ShowingGitDiff: "Showing output for:", CommitDiff: "Commit diff", - CopyCommitShaToClipboard: "Copy commit hash to clipboard", - CommitSha: "commit hash", + CopyCommitHashToClipboard: "Copy commit hash to clipboard", + CommitHash: "Commit hash", CommitURL: "Commit URL", CopyCommitMessageToClipboard: "Copy commit message to clipboard", CommitMessage: "Commit message", @@ -1772,7 +1772,7 @@ func EnglishTranslationSet() TranslationSet { CopyCommitMessageToClipboard: "Copy commit message to clipboard", CopyCommitSubjectToClipboard: "Copy commit subject to clipboard", CopyCommitDiffToClipboard: "Copy commit diff to clipboard", - CopyCommitSHAToClipboard: "Copy full commit hash to clipboard", + CopyCommitHashToClipboard: "Copy full commit hash to clipboard", CopyCommitURLToClipboard: "Copy commit URL to clipboard", CopyCommitAuthorToClipboard: "Copy commit author to clipboard", CopyCommitAttributeToClipboard: "Copy to clipboard", diff --git a/pkg/i18n/japanese.go b/pkg/i18n/japanese.go index bb709becec5..dbc7a5dc624 100644 --- a/pkg/i18n/japanese.go +++ b/pkg/i18n/japanese.go @@ -367,8 +367,8 @@ func japaneseTranslationSet() TranslationSet { OpenCommandLogMenu: "コマンドログメニューを開く", // LcShowingGitDiff: "Showing output for:", CommitDiff: "コミットの差分", - CopyCommitShaToClipboard: "コミットのSHAをクリップボードにコピー", - CommitSha: "コミットのSHA", + CopyCommitHashToClipboard: "コミットのSHAをクリップボードにコピー", + CommitHash: "コミットのSHA", CommitURL: "コミットのURL", CopyCommitMessageToClipboard: "コミットメッセージをクリップボードにコピー", CommitMessage: "コミットメッセージ", @@ -496,7 +496,7 @@ func japaneseTranslationSet() TranslationSet { CreateAnnotatedTag: "注釈付きタグを作成", CopyCommitMessageToClipboard: "コミットメッセージをクリップボードにコピー", CopyCommitDiffToClipboard: "コミットの差分をクリップボードにコピー", - CopyCommitSHAToClipboard: "コミットSHAをクリップボードにコピー", + CopyCommitHashToClipboard: "コミットSHAをクリップボードにコピー", CopyCommitURLToClipboard: "コミットのURLをクリップボードにコピー", CopyCommitAuthorToClipboard: "コミットの作成者名をクリップボードにコピー", CopyCommitAttributeToClipboard: "クリップボードにコピー", diff --git a/pkg/i18n/korean.go b/pkg/i18n/korean.go index dd9ba31c8ff..3111e6b46c9 100644 --- a/pkg/i18n/korean.go +++ b/pkg/i18n/korean.go @@ -361,8 +361,8 @@ func koreanTranslationSet() TranslationSet { OpenCommandLogMenu: "명령어 로그 메뉴 열기", ShowingGitDiff: "Showing output for:", CommitDiff: "커밋의 iff", - CopyCommitShaToClipboard: "커밋 SHA를 클립보드에 복사", - CommitSha: "커밋 SHA", + CopyCommitHashToClipboard: "커밋 SHA를 클립보드에 복사", + CommitHash: "커밋 SHA", CommitURL: "커밋 URL", CopyCommitMessageToClipboard: "커밋 메시지를 클립보드에 복사", CommitMessage: "커밋 메시지", @@ -486,7 +486,7 @@ func koreanTranslationSet() TranslationSet { CreateAnnotatedTag: "Create annotated tag", CopyCommitMessageToClipboard: "커밋 메시지를 클립보드에 복사", CopyCommitDiffToClipboard: "커밋 diff를 클립보드에 복사", - CopyCommitSHAToClipboard: "커밋 SHA를 클립보드에 복사", + CopyCommitHashToClipboard: "커밋 SHA를 클립보드에 복사", CopyCommitURLToClipboard: "커밋 URL를 클립보드에 복사", CopyCommitAuthorToClipboard: "커밋 작성자를 클립보드에 복사", CopyCommitAttributeToClipboard: "클립보드에 복사", diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go index a24d44ca236..e8d05c46f79 100644 --- a/pkg/i18n/polish.go +++ b/pkg/i18n/polish.go @@ -548,8 +548,8 @@ func polishTranslationSet() TranslationSet { OpenCommandLogMenuTooltip: "Pokaż opcje dla dziennika poleceń, np. pokazywanie/ukrywanie dziennika poleceń i skupienie na dzienniku poleceń.", ShowingGitDiff: "Pokazuje wynik dla:", CommitDiff: "Różnice commita", - CopyCommitShaToClipboard: "Kopiuj SHA commita do schowka", - CommitSha: "SHA commita", + CopyCommitHashToClipboard: "Kopiuj SHA commita do schowka", + CommitHash: "SHA commita", CommitURL: "URL commita", CopyCommitMessageToClipboard: "Kopiuj wiadomość commita do schowka", CommitMessage: "Wiadomość commita", @@ -784,7 +784,7 @@ func polishTranslationSet() TranslationSet { CopyCommitMessageToClipboard: "Kopiuj wiadomość commita do schowka", CopyCommitSubjectToClipboard: "Kopiuj temat commita do schowka", CopyCommitDiffToClipboard: "Kopiuj różnice commita do schowka", - CopyCommitSHAToClipboard: "Kopiuj SHA commita do schowka", + CopyCommitHashToClipboard: "Kopiuj SHA commita do schowka", CopyCommitURLToClipboard: "Kopiuj URL commita do schowka", CopyCommitAuthorToClipboard: "Kopiuj autora commita do schowka", CopyCommitAttributeToClipboard: "Kopiuj do schowka", diff --git a/pkg/i18n/russian.go b/pkg/i18n/russian.go index 5378d774e92..d0fe9a4575a 100644 --- a/pkg/i18n/russian.go +++ b/pkg/i18n/russian.go @@ -422,8 +422,8 @@ func RussianTranslationSet() TranslationSet { OpenCommandLogMenu: "Открыть меню журнала команд", ShowingGitDiff: "Показывает вывод для:", CommitDiff: "Разница коммита", - CopyCommitShaToClipboard: "Скопировать SHA коммита в буфер обмена", - CommitSha: "SHA коммита", + CopyCommitHashToClipboard: "Скопировать SHA коммита в буфер обмена", + CommitHash: "SHA коммита", CommitURL: "URL коммита", CopyCommitMessageToClipboard: "Скопировать сообщение коммита в буфер обмена", CommitMessage: "Полное сообщение коммита", @@ -579,7 +579,7 @@ func RussianTranslationSet() TranslationSet { CopyCommitMessageToClipboard: "Скопировать сообщение коммита в буфер обмена", CopyCommitSubjectToClipboard: "Скопировать тему коммита в буфер обмена", CopyCommitDiffToClipboard: "Скопировать сравнения коммита в буфер обмена", - CopyCommitSHAToClipboard: "Скопировать SHA коммита в буфер обмена", + CopyCommitHashToClipboard: "Скопировать SHA коммита в буфер обмена", CopyCommitURLToClipboard: "Скопировать URL коммита в буфер обмена", CopyCommitAuthorToClipboard: "Скопировать автора коммита в буфер обмена", CopyCommitAttributeToClipboard: "Скопировать в буфер обмена", diff --git a/pkg/i18n/traditional_chinese.go b/pkg/i18n/traditional_chinese.go index 56d2c99a0b3..e0e0c31ed1a 100644 --- a/pkg/i18n/traditional_chinese.go +++ b/pkg/i18n/traditional_chinese.go @@ -454,8 +454,8 @@ func traditionalChineseTranslationSet() TranslationSet { OpenCommandLogMenu: "開啟命令記錄選單", ShowingGitDiff: "顯示輸出:", CommitDiff: "提交差異", - CopyCommitShaToClipboard: "複製提交 SHA 到剪貼簿", - CommitSha: "提交 SHA", + CopyCommitHashToClipboard: "複製提交 SHA 到剪貼簿", + CommitHash: "提交 SHA", CommitURL: "提交 URL", CopyCommitMessageToClipboard: "複製提交訊息到剪貼簿", CommitMessage: "提交訊息", @@ -647,7 +647,7 @@ func traditionalChineseTranslationSet() TranslationSet { CreateAnnotatedTag: "建立附註標籤", CopyCommitMessageToClipboard: "將提交訊息複製到剪貼簿", CopyCommitDiffToClipboard: "將提交差異複製到剪貼簿", - CopyCommitSHAToClipboard: "將提交 SHA 複製到剪貼簿", + CopyCommitHashToClipboard: "將提交 SHA 複製到剪貼簿", CopyCommitURLToClipboard: "將提交 URL 複製到剪貼簿", CopyCommitAuthorToClipboard: "將提交作者複製到剪貼簿", CopyCommitAttributeToClipboard: "複製到剪貼簿", From e6ef1642fa0111e075fd14493b913cc4f7098db6 Mon Sep 17 00:00:00 2001 From: pikomonde <32364823+pikomonde@users.noreply.github.com> Date: Thu, 21 Mar 2024 00:44:56 +0700 Subject: [PATCH 03/15] rename sha to hash --- docs/Custom_Command_Keybindings.md | 4 +- pkg/app/daemon/daemon.go | 34 +- pkg/app/daemon/rebase.go | 4 +- pkg/commands/git_commands/commit_loader.go | 20 +- .../git_commands/commit_loader_test.go | 70 ++-- pkg/commands/git_commands/patch.go | 10 +- pkg/commands/git_commands/rebase.go | 28 +- pkg/commands/git_commands/rebase_test.go | 6 +- .../git_commands/reflog_commit_loader.go | 4 +- .../git_commands/reflog_commit_loader_test.go | 22 +- pkg/commands/git_commands/stash.go | 14 +- pkg/commands/git_commands/stash_test.go | 2 +- pkg/commands/models/commit.go | 10 +- pkg/gui/context/local_commits_context.go | 6 +- pkg/gui/context/sub_commits_context.go | 2 +- .../controllers/basic_commits_controller.go | 22 +- pkg/gui/controllers/bisect_controller.go | 14 +- .../custom_patch_options_menu_action.go | 6 +- .../controllers/helpers/cherry_pick_helper.go | 2 +- pkg/gui/controllers/helpers/fixup_helper.go | 2 +- .../controllers/local_commits_controller.go | 30 +- .../controllers/reflog_commits_controller.go | 2 +- pkg/gui/controllers/sub_commits_controller.go | 2 +- pkg/gui/controllers/undo_controller.go | 6 +- pkg/gui/modes/cherrypicking/cherry_picking.go | 10 +- pkg/gui/presentation/commits.go | 18 +- pkg/gui/presentation/commits_test.go | 110 +++---- pkg/gui/presentation/graph/graph.go | 102 +++--- pkg/gui/presentation/graph/graph_test.go | 304 +++++++++--------- pkg/gui/presentation/reflog_commits.go | 4 +- pkg/utils/rebase_todo.go | 12 +- pkg/utils/rebase_todo_test.go | 58 ++-- 32 files changed, 470 insertions(+), 470 deletions(-) diff --git a/docs/Custom_Command_Keybindings.md b/docs/Custom_Command_Keybindings.md index cca3985dbed..8604a5247d6 100644 --- a/docs/Custom_Command_Keybindings.md +++ b/docs/Custom_Command_Keybindings.md @@ -6,7 +6,7 @@ You can add custom command keybindings in your config.yml (accessible by pressin customCommands: - key: '' context: 'commits' - command: 'hub browse -- "commit/{{.SelectedLocalCommit.Sha}}"' + command: 'hub browse -- "commit/{{.SelectedLocalCommit.Hash}}"' - key: 'a' context: 'files' command: "git {{if .SelectedFile.HasUnstagedChanges}} add {{else}} reset {{end}} {{.SelectedFile.Name | quote}}" @@ -305,7 +305,7 @@ SelectedWorktree CheckedOutBranch ``` -To see what fields are available on e.g. the `SelectedFile`, see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/commands/models/file.go) (all the modelling lives in the same directory). Note that the custom commands feature does not guarantee backwards compatibility (until we hit Lazygit version 1.0 of course) which means a field you're accessing on an object may no longer be available from one release to the next. Typically however, all you'll need is `{{.SelectedFile.Name}}`, `{{.SelectedLocalCommit.Sha}}` and `{{.SelectedLocalBranch.Name}}`. In the future we will likely introduce a tighter interface that exposes a limited set of fields for each model. +To see what fields are available on e.g. the `SelectedFile`, see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/commands/models/file.go) (all the modelling lives in the same directory). Note that the custom commands feature does not guarantee backwards compatibility (until we hit Lazygit version 1.0 of course) which means a field you're accessing on an object may no longer be available from one release to the next. Typically however, all you'll need is `{{.SelectedFile.Name}}`, `{{.SelectedLocalCommit.Hash}}` and `{{.SelectedLocalBranch.Name}}`. In the future we will likely introduce a tighter interface that exposes a limited set of fields for each model. ## Keybinding collisions diff --git a/pkg/app/daemon/daemon.go b/pkg/app/daemon/daemon.go index 2f1cded7c23..280172ea28b 100644 --- a/pkg/app/daemon/daemon.go +++ b/pkg/app/daemon/daemon.go @@ -212,7 +212,7 @@ func (self *ChangeTodoActionsInstruction) run(common *common.Common) error { return handleInteractiveRebase(common, func(path string) error { changes := lo.Map(self.Changes, func(c ChangeTodoAction, _ int) utils.TodoChange { return utils.TodoChange{ - Sha: c.Sha, + Hash: c.Hash, OldAction: todo.Pick, NewAction: c.NewAction, } @@ -222,18 +222,18 @@ func (self *ChangeTodoActionsInstruction) run(common *common.Common) error { }) } -// Takes the sha of some commit, and the sha of a fixup commit that was created +// Takes the hash of some commit, and the hash of a fixup commit that was created // at the end of the branch, then moves the fixup commit down to right after the // original commit, changing its type to "fixup" type MoveFixupCommitDownInstruction struct { - OriginalSha string - FixupSha string + OriginalHash string + FixupHash string } func NewMoveFixupCommitDownInstruction(originalSha string, fixupSha string) Instruction { return &MoveFixupCommitDownInstruction{ - OriginalSha: originalSha, - FixupSha: fixupSha, + OriginalHash: originalSha, + FixupHash: fixupSha, } } @@ -247,17 +247,17 @@ func (self *MoveFixupCommitDownInstruction) SerializedInstructions() string { func (self *MoveFixupCommitDownInstruction) run(common *common.Common) error { return handleInteractiveRebase(common, func(path string) error { - return utils.MoveFixupCommitDown(path, self.OriginalSha, self.FixupSha, getCommentChar()) + return utils.MoveFixupCommitDown(path, self.OriginalHash, self.FixupHash, getCommentChar()) }) } type MoveTodosUpInstruction struct { - Shas []string + Hashes []string } -func NewMoveTodosUpInstruction(shas []string) Instruction { +func NewMoveTodosUpInstruction(hashes []string) Instruction { return &MoveTodosUpInstruction{ - Shas: shas, + Hashes: hashes, } } @@ -270,9 +270,9 @@ func (self *MoveTodosUpInstruction) SerializedInstructions() string { } func (self *MoveTodosUpInstruction) run(common *common.Common) error { - todosToMove := lo.Map(self.Shas, func(sha string, _ int) utils.Todo { + todosToMove := lo.Map(self.Hashes, func(hash string, _ int) utils.Todo { return utils.Todo{ - Sha: sha, + Hash: hash, Action: todo.Pick, } }) @@ -283,12 +283,12 @@ func (self *MoveTodosUpInstruction) run(common *common.Common) error { } type MoveTodosDownInstruction struct { - Shas []string + Hashes []string } -func NewMoveTodosDownInstruction(shas []string) Instruction { +func NewMoveTodosDownInstruction(hashes []string) Instruction { return &MoveTodosDownInstruction{ - Shas: shas, + Hashes: hashes, } } @@ -301,9 +301,9 @@ func (self *MoveTodosDownInstruction) SerializedInstructions() string { } func (self *MoveTodosDownInstruction) run(common *common.Common) error { - todosToMove := lo.Map(self.Shas, func(sha string, _ int) utils.Todo { + todosToMove := lo.Map(self.Hashes, func(hash string, _ int) utils.Todo { return utils.Todo{ - Sha: sha, + Hash: hash, Action: todo.Pick, } }) diff --git a/pkg/app/daemon/rebase.go b/pkg/app/daemon/rebase.go index 50494113a7f..0ca323c7de3 100644 --- a/pkg/app/daemon/rebase.go +++ b/pkg/app/daemon/rebase.go @@ -21,7 +21,7 @@ func (self *TodoLine) ToString() string { if self.Action == "break" { return self.Action + "\n" } else { - return self.Action + " " + self.Commit.Sha + " " + self.Commit.Name + "\n" + return self.Action + " " + self.Commit.Hash + " " + self.Commit.Name + "\n" } } @@ -34,7 +34,7 @@ func TodoLinesToString(todoLines []TodoLine) string { } type ChangeTodoAction struct { - Sha string + Hash string NewAction todo.TodoCommand } diff --git a/pkg/commands/git_commands/commit_loader.go b/pkg/commands/git_commands/commit_loader.go index 44d0cf55d8c..7707f9999b4 100644 --- a/pkg/commands/git_commands/commit_loader.go +++ b/pkg/commands/git_commands/commit_loader.go @@ -129,7 +129,7 @@ func (self *CommitLoader) GetCommits(opts GetCommitsOptions) ([]*models.Commit, } for _, commit := range commits { - if commit.Sha == firstPushedCommit { + if commit.Hash == firstPushedCommit { passedFirstPushedCommit = true } if commit.Status != models.StatusRebasing { @@ -205,7 +205,7 @@ func (self *CommitLoader) MergeRebasingCommits(commits []*models.Commit) ([]*mod func (self *CommitLoader) extractCommitFromLine(line string, showDivergence bool) *models.Commit { split := strings.SplitN(line, "\x00", 8) - sha := split[0] + hash := split[0] unixTimestamp := split[1] authorName := split[2] authorEmail := split[3] @@ -241,7 +241,7 @@ func (self *CommitLoader) extractCommitFromLine(line string, showDivergence bool } return &models.Commit{ - Sha: sha, + Hash: hash, Name: message, Tags: tags, ExtraInfo: extraInfo, @@ -261,7 +261,7 @@ func (self *CommitLoader) getHydratedRebasingCommits(rebaseMode enums.RebaseMode } commitHashes := lo.FilterMap(commits, func(commit *models.Commit, _ int) (string, bool) { - return commit.Sha, commit.Sha != "" + return commit.Hash, commit.Hash != "" }) // note that we're not filtering these as we do non-rebasing commits just because @@ -277,7 +277,7 @@ func (self *CommitLoader) getHydratedRebasingCommits(rebaseMode enums.RebaseMode fullCommits := map[string]*models.Commit{} err := cmdObj.RunAndProcessLines(func(line string) (bool, error) { commit := self.extractCommitFromLine(line, false) - fullCommits[commit.Sha] = commit + fullCommits[commit.Hash] = commit return false, nil }) if err != nil { @@ -299,9 +299,9 @@ func (self *CommitLoader) getHydratedRebasingCommits(rebaseMode enums.RebaseMode hydratedCommits := make([]*models.Commit, 0, len(commits)) for _, rebasingCommit := range commits { - if rebasingCommit.Sha == "" { + if rebasingCommit.Hash == "" { hydratedCommits = append(hydratedCommits, rebasingCommit) - } else if commit := findFullCommit(rebasingCommit.Sha); commit != nil { + } else if commit := findFullCommit(rebasingCommit.Hash); commit != nil { commit.Action = rebasingCommit.Action commit.Status = rebasingCommit.Status hydratedCommits = append(hydratedCommits, commit) @@ -339,7 +339,7 @@ func (self *CommitLoader) getRebasingCommits(rebaseMode enums.RebaseMode) []*mod // so, add a fake entry for it if conflictedCommitHash := self.getConflictedCommit(todos); conflictedCommitHash != "" { commits = append(commits, &models.Commit{ - Sha: conflictedCommitHash, + Hash: conflictedCommitHash, Name: "", Status: models.StatusRebasing, Action: models.ActionConflict, @@ -354,7 +354,7 @@ func (self *CommitLoader) getRebasingCommits(rebaseMode enums.RebaseMode) []*mod continue } commits = utils.Prepend(commits, &models.Commit{ - Sha: t.Commit, + Hash: t.Commit, Name: t.Msg, Status: models.StatusRebasing, Action: t.Command, @@ -459,7 +459,7 @@ func setCommitMergedStatuses(ancestor string, commits []*models.Commit) { passedAncestor := false for i, commit := range commits { // some commits aren't really commits and don't have sha's, such as the update-ref todo - if commit.Sha != "" && strings.HasPrefix(ancestor, commit.Sha) { + if commit.Hash != "" && strings.HasPrefix(ancestor, commit.Hash) { passedAncestor = true } if commit.Status != models.StatusPushed && commit.Status != models.StatusUnpushed { diff --git a/pkg/commands/git_commands/commit_loader_test.go b/pkg/commands/git_commands/commit_loader_test.go index 4792b4dffb8..38c03625f82 100644 --- a/pkg/commands/git_commands/commit_loader_test.go +++ b/pkg/commands/git_commands/commit_loader_test.go @@ -86,7 +86,7 @@ func TestGetCommits(t *testing.T) { expectedCommits: []*models.Commit{ { - Sha: "0eea75e8c631fba6b58135697835d58ba4c18dbc", + Hash: "0eea75e8c631fba6b58135697835d58ba4c18dbc", Name: "better typing for rebase mode", Status: models.StatusUnpushed, Action: models.ActionNone, @@ -100,7 +100,7 @@ func TestGetCommits(t *testing.T) { }, }, { - Sha: "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164", + Hash: "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164", Name: "fix logging", Status: models.StatusPushed, Action: models.ActionNone, @@ -114,7 +114,7 @@ func TestGetCommits(t *testing.T) { }, }, { - Sha: "e94e8fc5b6fab4cb755f29f1bdb3ee5e001df35c", + Hash: "e94e8fc5b6fab4cb755f29f1bdb3ee5e001df35c", Name: "refactor", Status: models.StatusPushed, Action: models.ActionNone, @@ -128,7 +128,7 @@ func TestGetCommits(t *testing.T) { }, }, { - Sha: "d8084cd558925eb7c9c38afeed5725c21653ab90", + Hash: "d8084cd558925eb7c9c38afeed5725c21653ab90", Name: "WIP", Status: models.StatusPushed, Action: models.ActionNone, @@ -142,7 +142,7 @@ func TestGetCommits(t *testing.T) { }, }, { - Sha: "65f910ebd85283b5cce9bf67d03d3f1a9ea3813a", + Hash: "65f910ebd85283b5cce9bf67d03d3f1a9ea3813a", Name: "WIP", Status: models.StatusPushed, Action: models.ActionNone, @@ -156,7 +156,7 @@ func TestGetCommits(t *testing.T) { }, }, { - Sha: "26c07b1ab33860a1a7591a0638f9925ccf497ffa", + Hash: "26c07b1ab33860a1a7591a0638f9925ccf497ffa", Name: "WIP", Status: models.StatusMerged, Action: models.ActionNone, @@ -170,7 +170,7 @@ func TestGetCommits(t *testing.T) { }, }, { - Sha: "3d4470a6c072208722e5ae9a54bcb9634959a1c5", + Hash: "3d4470a6c072208722e5ae9a54bcb9634959a1c5", Name: "WIP", Status: models.StatusMerged, Action: models.ActionNone, @@ -184,7 +184,7 @@ func TestGetCommits(t *testing.T) { }, }, { - Sha: "053a66a7be3da43aacdc7aa78e1fe757b82c4dd2", + Hash: "053a66a7be3da43aacdc7aa78e1fe757b82c4dd2", Name: "refactoring the config struct", Status: models.StatusMerged, Action: models.ActionNone, @@ -221,7 +221,7 @@ func TestGetCommits(t *testing.T) { expectedCommits: []*models.Commit{ { - Sha: "0eea75e8c631fba6b58135697835d58ba4c18dbc", + Hash: "0eea75e8c631fba6b58135697835d58ba4c18dbc", Name: "better typing for rebase mode", Status: models.StatusUnpushed, Action: models.ActionNone, @@ -260,7 +260,7 @@ func TestGetCommits(t *testing.T) { expectedCommits: []*models.Commit{ { - Sha: "0eea75e8c631fba6b58135697835d58ba4c18dbc", + Hash: "0eea75e8c631fba6b58135697835d58ba4c18dbc", Name: "better typing for rebase mode", Status: models.StatusUnpushed, Action: models.ActionNone, @@ -339,14 +339,14 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) { todos []todo.Todo doneTodos []todo.Todo amendFileExists bool - expectedSha string + expectedHash string }{ { testName: "no done todos", todos: []todo.Todo{}, doneTodos: []todo.Todo{}, amendFileExists: false, - expectedSha: "", + expectedHash: "", }, { testName: "common case (conflict)", @@ -362,7 +362,7 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) { }, }, amendFileExists: false, - expectedSha: "fa1afe1", + expectedHash: "fa1afe1", }, { testName: "last command was 'break'", @@ -371,7 +371,7 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) { {Command: todo.Break}, }, amendFileExists: false, - expectedSha: "", + expectedHash: "", }, { testName: "last command was 'exec'", @@ -383,7 +383,7 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) { }, }, amendFileExists: false, - expectedSha: "", + expectedHash: "", }, { testName: "last command was 'reword'", @@ -392,7 +392,7 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) { {Command: todo.Reword}, }, amendFileExists: false, - expectedSha: "", + expectedHash: "", }, { testName: "'pick' was rescheduled", @@ -409,7 +409,7 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) { }, }, amendFileExists: false, - expectedSha: "", + expectedHash: "", }, { testName: "'pick' was rescheduled, buggy git version", @@ -434,7 +434,7 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) { }, }, amendFileExists: false, - expectedSha: "", + expectedHash: "", }, { testName: "conflicting 'pick' after 'exec'", @@ -459,7 +459,7 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) { }, }, amendFileExists: false, - expectedSha: "fa1afe1", + expectedHash: "fa1afe1", }, { testName: "'edit' with amend file", @@ -471,7 +471,7 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) { }, }, amendFileExists: true, - expectedSha: "", + expectedHash: "", }, { testName: "'edit' without amend file", @@ -483,7 +483,7 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) { }, }, amendFileExists: false, - expectedSha: "fa1afe1", + expectedHash: "fa1afe1", }, } for _, scenario := range scenarios { @@ -503,8 +503,8 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) { }, } - sha := builder.getConflictedCommitImpl(scenario.todos, scenario.doneTodos, scenario.amendFileExists) - assert.Equal(t, scenario.expectedSha, sha) + hash := builder.getConflictedCommitImpl(scenario.todos, scenario.doneTodos, scenario.amendFileExists) + assert.Equal(t, scenario.expectedHash, hash) }) } } @@ -521,29 +521,29 @@ func TestCommitLoader_setCommitMergedStatuses(t *testing.T) { { testName: "basic", commits: []*models.Commit{ - {Sha: "12345", Name: "1", Action: models.ActionNone, Status: models.StatusUnpushed}, - {Sha: "67890", Name: "2", Action: models.ActionNone, Status: models.StatusPushed}, - {Sha: "abcde", Name: "3", Action: models.ActionNone, Status: models.StatusPushed}, + {Hash: "12345", Name: "1", Action: models.ActionNone, Status: models.StatusUnpushed}, + {Hash: "67890", Name: "2", Action: models.ActionNone, Status: models.StatusPushed}, + {Hash: "abcde", Name: "3", Action: models.ActionNone, Status: models.StatusPushed}, }, ancestor: "67890", expectedCommits: []*models.Commit{ - {Sha: "12345", Name: "1", Action: models.ActionNone, Status: models.StatusUnpushed}, - {Sha: "67890", Name: "2", Action: models.ActionNone, Status: models.StatusMerged}, - {Sha: "abcde", Name: "3", Action: models.ActionNone, Status: models.StatusMerged}, + {Hash: "12345", Name: "1", Action: models.ActionNone, Status: models.StatusUnpushed}, + {Hash: "67890", Name: "2", Action: models.ActionNone, Status: models.StatusMerged}, + {Hash: "abcde", Name: "3", Action: models.ActionNone, Status: models.StatusMerged}, }, }, { testName: "with update-ref", commits: []*models.Commit{ - {Sha: "12345", Name: "1", Action: models.ActionNone, Status: models.StatusUnpushed}, - {Sha: "", Name: "", Action: todo.UpdateRef, Status: models.StatusNone}, - {Sha: "abcde", Name: "3", Action: models.ActionNone, Status: models.StatusPushed}, + {Hash: "12345", Name: "1", Action: models.ActionNone, Status: models.StatusUnpushed}, + {Hash: "", Name: "", Action: todo.UpdateRef, Status: models.StatusNone}, + {Hash: "abcde", Name: "3", Action: models.ActionNone, Status: models.StatusPushed}, }, ancestor: "deadbeef", expectedCommits: []*models.Commit{ - {Sha: "12345", Name: "1", Action: models.ActionNone, Status: models.StatusUnpushed}, - {Sha: "", Name: "", Action: todo.UpdateRef, Status: models.StatusNone}, - {Sha: "abcde", Name: "3", Action: models.ActionNone, Status: models.StatusPushed}, + {Hash: "12345", Name: "1", Action: models.ActionNone, Status: models.StatusUnpushed}, + {Hash: "", Name: "", Action: todo.UpdateRef, Status: models.StatusNone}, + {Hash: "abcde", Name: "3", Action: models.ActionNone, Status: models.StatusPushed}, }, }, } diff --git a/pkg/commands/git_commands/patch.go b/pkg/commands/git_commands/patch.go index c632e35ae93..b6a8652bcbe 100644 --- a/pkg/commands/git_commands/patch.go +++ b/pkg/commands/git_commands/patch.go @@ -157,13 +157,13 @@ func (self *PatchCommands) MovePatchToSelectedCommit(commits []*models.Commit, s baseIndex := sourceCommitIdx + 1 changes := []daemon.ChangeTodoAction{ - {Sha: commits[sourceCommitIdx].Sha, NewAction: todo.Edit}, - {Sha: commits[destinationCommitIdx].Sha, NewAction: todo.Edit}, + {Hash: commits[sourceCommitIdx].Hash, NewAction: todo.Edit}, + {Hash: commits[destinationCommitIdx].Hash, NewAction: todo.Edit}, } self.os.LogCommand(logTodoChanges(changes), false) err := self.rebase.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{ - baseShaOrRoot: commits[baseIndex].Sha, + baseShaOrRoot: commits[baseIndex].Hash, overrideEditor: true, instruction: daemon.NewChangeTodoActionsInstruction(changes), }).Run() @@ -219,7 +219,7 @@ func (self *PatchCommands) MovePatchToSelectedCommit(commits []*models.Commit, s func (self *PatchCommands) MovePatchIntoIndex(commits []*models.Commit, commitIdx int, stash bool) error { if stash { - if err := self.stash.Push(self.Tr.StashPrefix + commits[commitIdx].Sha); err != nil { + if err := self.stash.Push(self.Tr.StashPrefix + commits[commitIdx].Hash); err != nil { return err } } @@ -324,7 +324,7 @@ func (self *PatchCommands) diffHeadAgainstCommit(commit *models.Commit) (string, cmdArgs := NewGitCmd("diff"). Config("diff.noprefix=false"). Arg("--no-ext-diff"). - Arg("HEAD.." + commit.Sha). + Arg("HEAD.." + commit.Hash). ToArgv() return self.cmd.New(cmdArgs).RunWithOutput() diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go index 2d1de707f38..34a6c8661b8 100644 --- a/pkg/commands/git_commands/rebase.go +++ b/pkg/commands/git_commands/rebase.go @@ -56,7 +56,7 @@ func (self *RebaseCommands) RewordCommit(commits []*models.Commit, index int, su func (self *RebaseCommands) RewordCommitInEditor(commits []*models.Commit, index int) (oscommands.ICmdObj, error) { changes := []daemon.ChangeTodoAction{{ - Sha: commits[index].Sha, + Hash: commits[index].Hash, NewAction: todo.Reword, }} self.os.LogCommand(logTodoChanges(changes), false) @@ -81,7 +81,7 @@ func (self *RebaseCommands) SetCommitAuthor(commits []*models.Commit, index int, func (self *RebaseCommands) AddCommitCoAuthor(commits []*models.Commit, index int, value string) error { return self.GenericAmend(commits, index, func() error { - return self.commit.AddCoAuthor(commits[index].Sha, value) + return self.commit.AddCoAuthor(commits[index].Hash, value) }) } @@ -109,7 +109,7 @@ func (self *RebaseCommands) MoveCommitsDown(commits []*models.Commit, startIdx i baseShaOrRoot := getBaseShaOrRoot(commits, endIdx+2) shas := lo.Map(commits[startIdx:endIdx+1], func(commit *models.Commit, _ int) string { - return commit.Sha + return commit.Hash }) return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{ @@ -123,7 +123,7 @@ func (self *RebaseCommands) MoveCommitsUp(commits []*models.Commit, startIdx int baseShaOrRoot := getBaseShaOrRoot(commits, endIdx+1) shas := lo.Map(commits[startIdx:endIdx+1], func(commit *models.Commit, _ int) string { - return commit.Sha + return commit.Hash }) return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{ @@ -143,7 +143,7 @@ func (self *RebaseCommands) InteractiveRebase(commits []*models.Commit, startIdx changes := lo.Map(commits[startIdx:endIdx+1], func(commit *models.Commit, _ int) daemon.ChangeTodoAction { return daemon.ChangeTodoAction{ - Sha: commit.Sha, + Hash: commit.Hash, NewAction: action, } }) @@ -189,7 +189,7 @@ func (self *RebaseCommands) EditRebaseFromBaseCommit(targetBranchName string, ba func logTodoChanges(changes []daemon.ChangeTodoAction) string { changeTodoStr := strings.Join(lo.Map(changes, func(c daemon.ChangeTodoAction, _ int) string { - return fmt.Sprintf("%s:%s", c.Sha, c.NewAction) + return fmt.Sprintf("%s:%s", c.Hash, c.NewAction) }), "\n") return fmt.Sprintf("Changing TODO actions:\n%s", changeTodoStr) } @@ -284,7 +284,7 @@ func (self *RebaseCommands) GitRebaseEditTodo(todosFileContent []byte) error { func (self *RebaseCommands) AmendTo(commits []*models.Commit, commitIndex int) error { commit := commits[commitIndex] - if err := self.commit.CreateFixupCommit(commit.Sha); err != nil { + if err := self.commit.CreateFixupCommit(commit.Hash); err != nil { return err } @@ -298,7 +298,7 @@ func (self *RebaseCommands) AmendTo(commits []*models.Commit, commitIndex int) e return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{ baseShaOrRoot: getBaseShaOrRoot(commits, commitIndex+1), overrideEditor: true, - instruction: daemon.NewMoveFixupCommitDownInstruction(commit.Sha, fixupSha), + instruction: daemon.NewMoveFixupCommitDownInstruction(commit.Hash, fixupSha), }).Run() } @@ -306,7 +306,7 @@ func todoFromCommit(commit *models.Commit) utils.Todo { if commit.Action == todo.UpdateRef { return utils.Todo{Ref: commit.Name, Action: commit.Action} } else { - return utils.Todo{Sha: commit.Sha, Action: commit.Action} + return utils.Todo{Hash: commit.Hash, Action: commit.Action} } } @@ -314,7 +314,7 @@ func todoFromCommit(commit *models.Commit) utils.Todo { func (self *RebaseCommands) EditRebaseTodo(commits []*models.Commit, action todo.TodoCommand) error { commitsWithAction := lo.Map(commits, func(commit *models.Commit, _ int) utils.TodoChange { return utils.TodoChange{ - Sha: commit.Sha, + Hash: commit.Hash, OldAction: commit.Action, NewAction: action, } @@ -364,7 +364,7 @@ func (self *RebaseCommands) MoveTodosUp(commits []*models.Commit) error { // SquashAllAboveFixupCommits squashes all fixup! commits above the given one func (self *RebaseCommands) SquashAllAboveFixupCommits(commit *models.Commit) error { - shaOrRoot := commit.Sha + "^" + shaOrRoot := commit.Hash + "^" if commit.IsFirstCommit() { shaOrRoot = "--root" } @@ -393,7 +393,7 @@ func (self *RebaseCommands) BeginInteractiveRebaseForCommit( } changes := []daemon.ChangeTodoAction{{ - Sha: commits[commitIndex].Sha, + Hash: commits[commitIndex].Hash, NewAction: todo.Edit, }} self.os.LogCommand(logTodoChanges(changes), false) @@ -506,7 +506,7 @@ func (self *RebaseCommands) DiscardOldFileChanges(commits []*models.Commit, comm // CherryPickCommits begins an interactive rebase with the given shas being cherry picked onto HEAD func (self *RebaseCommands) CherryPickCommits(commits []*models.Commit) error { commitLines := lo.Map(commits, func(commit *models.Commit, _ int) string { - return fmt.Sprintf("%s %s", utils.ShortSha(commit.Sha), commit.Name) + return fmt.Sprintf("%s %s", utils.ShortSha(commit.Hash), commit.Name) }) msg := utils.ResolvePlaceholderString( self.Tr.Log.CherryPickCommits, @@ -544,7 +544,7 @@ func getBaseShaOrRoot(commits []*models.Commit, index int) string { // be starting a rebase from 300 commits ago (which is the original commit limit // at time of writing) if index < len(commits) { - return commits[index].Sha + return commits[index].Hash } else { return "--root" } diff --git a/pkg/commands/git_commands/rebase_test.go b/pkg/commands/git_commands/rebase_test.go index b84621497f6..2760abd052c 100644 --- a/pkg/commands/git_commands/rebase_test.go +++ b/pkg/commands/git_commands/rebase_test.go @@ -131,7 +131,7 @@ func TestRebaseDiscardOldFileChanges(t *testing.T) { { testName: "returns error when using gpg", gitConfigMockResponses: map[string]string{"commit.gpgsign": "true"}, - commits: []*models.Commit{{Name: "commit", Sha: "123456"}}, + commits: []*models.Commit{{Name: "commit", Hash: "123456"}}, commitIndex: 0, fileName: []string{"test999.txt"}, runner: oscommands.NewFakeRunner(t), @@ -143,8 +143,8 @@ func TestRebaseDiscardOldFileChanges(t *testing.T) { testName: "checks out file if it already existed", gitConfigMockResponses: nil, commits: []*models.Commit{ - {Name: "commit", Sha: "123456"}, - {Name: "commit2", Sha: "abcdef"}, + {Name: "commit", Hash: "123456"}, + {Name: "commit2", Hash: "abcdef"}, }, commitIndex: 0, fileName: []string{"test999.txt"}, diff --git a/pkg/commands/git_commands/reflog_commit_loader.go b/pkg/commands/git_commands/reflog_commit_loader.go index b8682241a99..35120311fd6 100644 --- a/pkg/commands/git_commands/reflog_commit_loader.go +++ b/pkg/commands/git_commands/reflog_commit_loader.go @@ -65,7 +65,7 @@ func (self *ReflogCommitLoader) GetReflogCommits(lastReflogCommit *models.Commit } func (self *ReflogCommitLoader) sameReflogCommit(a *models.Commit, b *models.Commit) bool { - return a.Sha == b.Sha && a.UnixTimestamp == b.UnixTimestamp && a.Name == b.Name + return a.Hash == b.Hash && a.UnixTimestamp == b.UnixTimestamp && a.Name == b.Name } func (self *ReflogCommitLoader) parseLine(line string) (*models.Commit, bool) { @@ -83,7 +83,7 @@ func (self *ReflogCommitLoader) parseLine(line string) (*models.Commit, bool) { } return &models.Commit{ - Sha: fields[0], + Hash: fields[0], Name: fields[2], UnixTimestamp: int64(unixTimestamp), Status: models.StatusReflog, diff --git a/pkg/commands/git_commands/reflog_commit_loader_test.go b/pkg/commands/git_commands/reflog_commit_loader_test.go index a8a249588ae..ca02f2b51f6 100644 --- a/pkg/commands/git_commands/reflog_commit_loader_test.go +++ b/pkg/commands/git_commands/reflog_commit_loader_test.go @@ -50,35 +50,35 @@ func TestGetReflogCommits(t *testing.T) { lastReflogCommit: nil, expectedCommits: []*models.Commit{ { - Sha: "c3c4b66b64c97ffeecde", + Hash: "c3c4b66b64c97ffeecde", Name: "checkout: moving from A to B", Status: models.StatusReflog, UnixTimestamp: 1643150483, Parents: []string{"51baa8c1"}, }, { - Sha: "c3c4b66b64c97ffeecde", + Hash: "c3c4b66b64c97ffeecde", Name: "checkout: moving from B to A", Status: models.StatusReflog, UnixTimestamp: 1643150483, Parents: []string{"51baa8c1"}, }, { - Sha: "c3c4b66b64c97ffeecde", + Hash: "c3c4b66b64c97ffeecde", Name: "checkout: moving from A to B", Status: models.StatusReflog, UnixTimestamp: 1643150483, Parents: []string{"51baa8c1"}, }, { - Sha: "c3c4b66b64c97ffeecde", + Hash: "c3c4b66b64c97ffeecde", Name: "checkout: moving from master to A", Status: models.StatusReflog, UnixTimestamp: 1643150483, Parents: []string{"51baa8c1"}, }, { - Sha: "f4ddf2f0d4be4ccc7efa", + Hash: "f4ddf2f0d4be4ccc7efa", Name: "checkout: moving from A to master", Status: models.StatusReflog, UnixTimestamp: 1643149435, @@ -94,7 +94,7 @@ func TestGetReflogCommits(t *testing.T) { ExpectGitArgs([]string{"-c", "log.showSignature=false", "log", "-g", "--abbrev=40", "--format=%h%x00%ct%x00%gs%x00%p"}, reflogOutput, nil), lastReflogCommit: &models.Commit{ - Sha: "c3c4b66b64c97ffeecde", + Hash: "c3c4b66b64c97ffeecde", Name: "checkout: moving from B to A", Status: models.StatusReflog, UnixTimestamp: 1643150483, @@ -102,7 +102,7 @@ func TestGetReflogCommits(t *testing.T) { }, expectedCommits: []*models.Commit{ { - Sha: "c3c4b66b64c97ffeecde", + Hash: "c3c4b66b64c97ffeecde", Name: "checkout: moving from A to B", Status: models.StatusReflog, UnixTimestamp: 1643150483, @@ -118,7 +118,7 @@ func TestGetReflogCommits(t *testing.T) { ExpectGitArgs([]string{"-c", "log.showSignature=false", "log", "-g", "--abbrev=40", "--format=%h%x00%ct%x00%gs%x00%p", "--follow", "--", "path"}, reflogOutput, nil), lastReflogCommit: &models.Commit{ - Sha: "c3c4b66b64c97ffeecde", + Hash: "c3c4b66b64c97ffeecde", Name: "checkout: moving from B to A", Status: models.StatusReflog, UnixTimestamp: 1643150483, @@ -127,7 +127,7 @@ func TestGetReflogCommits(t *testing.T) { filterPath: "path", expectedCommits: []*models.Commit{ { - Sha: "c3c4b66b64c97ffeecde", + Hash: "c3c4b66b64c97ffeecde", Name: "checkout: moving from A to B", Status: models.StatusReflog, UnixTimestamp: 1643150483, @@ -143,7 +143,7 @@ func TestGetReflogCommits(t *testing.T) { ExpectGitArgs([]string{"-c", "log.showSignature=false", "log", "-g", "--abbrev=40", "--format=%h%x00%ct%x00%gs%x00%p", "--author=John Doe "}, reflogOutput, nil), lastReflogCommit: &models.Commit{ - Sha: "c3c4b66b64c97ffeecde", + Hash: "c3c4b66b64c97ffeecde", Name: "checkout: moving from B to A", Status: models.StatusReflog, UnixTimestamp: 1643150483, @@ -152,7 +152,7 @@ func TestGetReflogCommits(t *testing.T) { filterAuthor: "John Doe ", expectedCommits: []*models.Commit{ { - Sha: "c3c4b66b64c97ffeecde", + Hash: "c3c4b66b64c97ffeecde", Name: "checkout: moving from A to B", Status: models.StatusReflog, UnixTimestamp: 1643150483, diff --git a/pkg/commands/git_commands/stash.go b/pkg/commands/git_commands/stash.go index 29140e68e76..906535fe568 100644 --- a/pkg/commands/git_commands/stash.go +++ b/pkg/commands/git_commands/stash.go @@ -60,24 +60,24 @@ func (self *StashCommands) Push(message string) error { return self.cmd.New(cmdArgs).Run() } -func (self *StashCommands) Store(sha string, message string) error { +func (self *StashCommands) Store(hash string, message string) error { trimmedMessage := strings.Trim(message, " \t") cmdArgs := NewGitCmd("stash").Arg("store"). ArgIf(trimmedMessage != "", "-m", trimmedMessage). - Arg(sha). + Arg(hash). ToArgv() return self.cmd.New(cmdArgs).Run() } -func (self *StashCommands) Sha(index int) (string, error) { +func (self *StashCommands) Hash(index int) (string, error) { cmdArgs := NewGitCmd("rev-parse"). Arg(fmt.Sprintf("refs/stash@{%d}", index)). ToArgv() - sha, _, err := self.cmd.New(cmdArgs).DontLog().RunWithOutputs() - return strings.Trim(sha, "\r\n"), err + hash, _, err := self.cmd.New(cmdArgs).DontLog().RunWithOutputs() + return strings.Trim(hash, "\r\n"), err } func (self *StashCommands) ShowStashEntryCmdObj(index int) oscommands.ICmdObj { @@ -179,7 +179,7 @@ func (self *StashCommands) StashIncludeUntrackedChanges(message string) error { } func (self *StashCommands) Rename(index int, message string) error { - sha, err := self.Sha(index) + hash, err := self.Hash(index) if err != nil { return err } @@ -188,7 +188,7 @@ func (self *StashCommands) Rename(index int, message string) error { return err } - err = self.Store(sha, message) + err = self.Store(hash, message) if err != nil { return err } diff --git a/pkg/commands/git_commands/stash_test.go b/pkg/commands/git_commands/stash_test.go index 6954a3cf817..3f112cd0c33 100644 --- a/pkg/commands/git_commands/stash_test.go +++ b/pkg/commands/git_commands/stash_test.go @@ -91,7 +91,7 @@ func TestStashSha(t *testing.T) { ExpectGitArgs([]string{"rev-parse", "refs/stash@{5}"}, "14d94495194651adfd5f070590df566c11d28243\n", nil) instance := buildStashCommands(commonDeps{runner: runner}) - sha, err := instance.Sha(5) + sha, err := instance.Hash(5) assert.NoError(t, err) assert.Equal(t, "14d94495194651adfd5f070590df566c11d28243", sha) runner.CheckForMissingCalls() diff --git a/pkg/commands/models/commit.go b/pkg/commands/models/commit.go index c2cdc4815dc..9dae21850cc 100644 --- a/pkg/commands/models/commit.go +++ b/pkg/commands/models/commit.go @@ -43,7 +43,7 @@ const ( // Commit : A git commit type Commit struct { - Sha string + Hash string Name string Status CommitStatus Action todo.TodoCommand @@ -59,15 +59,15 @@ type Commit struct { } func (c *Commit) ShortSha() string { - return utils.ShortSha(c.Sha) + return utils.ShortSha(c.Hash) } func (c *Commit) FullRefName() string { - return c.Sha + return c.Hash } func (c *Commit) RefName() string { - return c.Sha + return c.Hash } func (c *Commit) ParentRefName() string { @@ -86,7 +86,7 @@ func (c *Commit) ID() string { } func (c *Commit) Description() string { - return fmt.Sprintf("%s %s", c.Sha[:7], c.Name) + return fmt.Sprintf("%s %s", c.Hash[:7], c.Name) } func (c *Commit) IsMerge() bool { diff --git a/pkg/gui/context/local_commits_context.go b/pkg/gui/context/local_commits_context.go index 043483fc9ff..0b168cad5d4 100644 --- a/pkg/gui/context/local_commits_context.go +++ b/pkg/gui/context/local_commits_context.go @@ -34,7 +34,7 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext { if c.CurrentContext().GetKey() == LOCAL_COMMITS_CONTEXT_KEY { selectedCommit := viewModel.GetSelected() if selectedCommit != nil { - selectedCommitHash = selectedCommit.Sha + selectedCommitHash = selectedCommit.Hash } } @@ -133,7 +133,7 @@ func (self *LocalCommitsContext) GetSelectedCommitHash() string { if commit == nil { return "" } - return commit.Sha + return commit.Hash } func (self *LocalCommitsContext) SelectCommitByHash(hash string) bool { @@ -141,7 +141,7 @@ func (self *LocalCommitsContext) SelectCommitByHash(hash string) bool { return false } - if _, idx, found := lo.FindIndexOf(self.GetItems(), func(c *models.Commit) bool { return c.Sha == hash }); found { + if _, idx, found := lo.FindIndexOf(self.GetItems(), func(c *models.Commit) bool { return c.Hash == hash }); found { self.SetSelection(idx) return true } diff --git a/pkg/gui/context/sub_commits_context.go b/pkg/gui/context/sub_commits_context.go index 9bad0b8cf31..0dc2cd39b06 100644 --- a/pkg/gui/context/sub_commits_context.go +++ b/pkg/gui/context/sub_commits_context.go @@ -48,7 +48,7 @@ func NewSubCommitsContext( if c.CurrentContext().GetKey() == SUB_COMMITS_CONTEXT_KEY { selectedCommit := viewModel.GetSelected() if selectedCommit != nil { - selectedCommitHash = selectedCommit.Sha + selectedCommitHash = selectedCommit.Hash } } branches := []*models.Branch{} diff --git a/pkg/gui/controllers/basic_commits_controller.go b/pkg/gui/controllers/basic_commits_controller.go index 8bf3b7969f3..caff6798305 100644 --- a/pkg/gui/controllers/basic_commits_controller.go +++ b/pkg/gui/controllers/basic_commits_controller.go @@ -171,16 +171,16 @@ func (self *BasicCommitsController) copyCommitAttribute(commit *models.Commit) e func (self *BasicCommitsController) copyCommitHashToClipboard(commit *models.Commit) error { self.c.LogAction(self.c.Tr.Actions.CopyCommitHashToClipboard) - if err := self.c.OS().CopyToClipboard(commit.Sha); err != nil { + if err := self.c.OS().CopyToClipboard(commit.Hash); err != nil { return self.c.Error(err) } - self.c.Toast(fmt.Sprintf("'%s' %s", commit.Sha, self.c.Tr.CopiedToClipboard)) + self.c.Toast(fmt.Sprintf("'%s' %s", commit.Hash, self.c.Tr.CopiedToClipboard)) return nil } func (self *BasicCommitsController) copyCommitURLToClipboard(commit *models.Commit) error { - url, err := self.c.Helpers().Host.GetCommitURL(commit.Sha) + url, err := self.c.Helpers().Host.GetCommitURL(commit.Hash) if err != nil { return self.c.Error(err) } @@ -195,7 +195,7 @@ func (self *BasicCommitsController) copyCommitURLToClipboard(commit *models.Comm } func (self *BasicCommitsController) copyCommitDiffToClipboard(commit *models.Commit) error { - diff, err := self.c.Git().Commit.GetCommitDiff(commit.Sha) + diff, err := self.c.Git().Commit.GetCommitDiff(commit.Hash) if err != nil { return self.c.Error(err) } @@ -210,7 +210,7 @@ func (self *BasicCommitsController) copyCommitDiffToClipboard(commit *models.Com } func (self *BasicCommitsController) copyAuthorToClipboard(commit *models.Commit) error { - author, err := self.c.Git().Commit.GetCommitAuthor(commit.Sha) + author, err := self.c.Git().Commit.GetCommitAuthor(commit.Hash) if err != nil { return self.c.Error(err) } @@ -227,7 +227,7 @@ func (self *BasicCommitsController) copyAuthorToClipboard(commit *models.Commit) } func (self *BasicCommitsController) copyCommitMessageToClipboard(commit *models.Commit) error { - message, err := self.c.Git().Commit.GetCommitMessage(commit.Sha) + message, err := self.c.Git().Commit.GetCommitMessage(commit.Hash) if err != nil { return self.c.Error(err) } @@ -242,7 +242,7 @@ func (self *BasicCommitsController) copyCommitMessageToClipboard(commit *models. } func (self *BasicCommitsController) copyCommitSubjectToClipboard(commit *models.Commit) error { - message, err := self.c.Git().Commit.GetCommitSubject(commit.Sha) + message, err := self.c.Git().Commit.GetCommitSubject(commit.Hash) if err != nil { return self.c.Error(err) } @@ -257,7 +257,7 @@ func (self *BasicCommitsController) copyCommitSubjectToClipboard(commit *models. } func (self *BasicCommitsController) openInBrowser(commit *models.Commit) error { - url, err := self.c.Helpers().Host.GetCommitURL(commit.Sha) + url, err := self.c.Helpers().Host.GetCommitURL(commit.Hash) if err != nil { return self.c.Error(err) } @@ -275,7 +275,7 @@ func (self *BasicCommitsController) newBranch(commit *models.Commit) error { } func (self *BasicCommitsController) createResetMenu(commit *models.Commit) error { - return self.c.Helpers().Refs.CreateGitResetMenu(commit.Sha) + return self.c.Helpers().Refs.CreateGitResetMenu(commit.Hash) } func (self *BasicCommitsController) checkout(commit *models.Commit) error { @@ -284,7 +284,7 @@ func (self *BasicCommitsController) checkout(commit *models.Commit) error { Prompt: self.c.Tr.SureCheckoutThisCommit, HandleConfirm: func() error { self.c.LogAction(self.c.Tr.Actions.CheckoutCommit) - return self.c.Helpers().Refs.CheckoutRef(commit.Sha, types.CheckoutRefOptions{}) + return self.c.Helpers().Refs.CheckoutRef(commit.Hash, types.CheckoutRefOptions{}) }, }) } @@ -295,7 +295,7 @@ func (self *BasicCommitsController) copyRange(*models.Commit) error { func (self *BasicCommitsController) canCopyCommits(selectedCommits []*models.Commit, startIdx int, endIdx int) *types.DisabledReason { for _, commit := range selectedCommits { - if commit.Sha == "" { + if commit.Hash == "" { return &types.DisabledReason{Text: self.c.Tr.CannotCherryPickNonCommit, ShowErrorInPanel: true} } diff --git a/pkg/gui/controllers/bisect_controller.go b/pkg/gui/controllers/bisect_controller.go index 2f9a7ec36fb..8e9bd77dfb5 100644 --- a/pkg/gui/controllers/bisect_controller.go +++ b/pkg/gui/controllers/bisect_controller.go @@ -69,7 +69,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c // Originally we were allowing the user to, from the bisect menu, select whether // they were talking about the selected commit or the current bisect commit, // and that was a bit confusing (and required extra keypresses). - selectCurrentAfter := info.GetCurrentSha() == "" || info.GetCurrentSha() == commit.Sha + selectCurrentAfter := info.GetCurrentSha() == "" || info.GetCurrentSha() == commit.Hash // we need to wait to reselect if our bisect commits aren't ancestors of our 'start' // ref, because we'll be reloading our commits in that case. waitToReselect := selectCurrentAfter && !self.c.Git().Bisect.ReachableFromStart(info) @@ -79,7 +79,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c // use the selected commit in that case. bisecting := info.GetCurrentSha() != "" - shaToMark := lo.Ternary(bisecting, info.GetCurrentSha(), commit.Sha) + shaToMark := lo.Ternary(bisecting, info.GetCurrentSha(), commit.Hash) shortShaToMark := utils.ShortSha(shaToMark) // For marking a commit as bad, when we're not already bisecting, we require @@ -131,12 +131,12 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c Key: 's', }, } - if info.GetCurrentSha() != "" && info.GetCurrentSha() != commit.Sha { + if info.GetCurrentSha() != "" && info.GetCurrentSha() != commit.Hash { menuItems = append(menuItems, lo.ToPtr(types.MenuItem{ Label: fmt.Sprintf(self.c.Tr.Bisect.SkipSelected, commit.ShortSha()), OnPress: func() error { self.c.LogAction(self.c.Tr.Actions.BisectSkip) - if err := self.c.Git().Bisect.Skip(commit.Sha); err != nil { + if err := self.c.Git().Bisect.Skip(commit.Hash); err != nil { return self.c.Error(err) } @@ -172,7 +172,7 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo, return self.c.Error(err) } - if err := self.c.Git().Bisect.Mark(commit.Sha, info.NewTerm()); err != nil { + if err := self.c.Git().Bisect.Mark(commit.Hash, info.NewTerm()); err != nil { return self.c.Error(err) } @@ -189,7 +189,7 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo, return self.c.Error(err) } - if err := self.c.Git().Bisect.Mark(commit.Sha, info.OldTerm()); err != nil { + if err := self.c.Git().Bisect.Mark(commit.Hash, info.OldTerm()); err != nil { return self.c.Error(err) } @@ -287,7 +287,7 @@ func (self *BisectController) selectCurrentBisectCommit() { if info.GetCurrentSha() != "" { // find index of commit with that sha, move cursor to that. for i, commit := range self.c.Model().Commits { - if commit.Sha == info.GetCurrentSha() { + if commit.Hash == info.GetCurrentSha() { self.context().SetSelection(i) _ = self.context().HandleFocus(types.OnFocusOpts{}) break diff --git a/pkg/gui/controllers/custom_patch_options_menu_action.go b/pkg/gui/controllers/custom_patch_options_menu_action.go index 701c3c7d15e..bc37bc2d89a 100644 --- a/pkg/gui/controllers/custom_patch_options_menu_action.go +++ b/pkg/gui/controllers/custom_patch_options_menu_action.go @@ -67,7 +67,7 @@ func (self *CustomPatchOptionsMenuAction) Call() error { if self.c.CurrentContext().GetKey() == self.c.Contexts().LocalCommits.GetKey() { selectedCommit := self.c.Contexts().LocalCommits.GetSelected() - if selectedCommit != nil && self.c.Git().Patch.PatchBuilder.To != selectedCommit.Sha { + if selectedCommit != nil && self.c.Git().Patch.PatchBuilder.To != selectedCommit.Hash { var disabledReason *types.DisabledReason if self.c.Contexts().LocalCommits.AreMultipleItemsSelected() { @@ -80,7 +80,7 @@ func (self *CustomPatchOptionsMenuAction) Call() error { append( []*types.MenuItem{ { - Label: fmt.Sprintf(self.c.Tr.MovePatchToSelectedCommit, selectedCommit.Sha), + Label: fmt.Sprintf(self.c.Tr.MovePatchToSelectedCommit, selectedCommit.Hash), Tooltip: self.c.Tr.MovePatchToSelectedCommitTooltip, OnPress: self.handleMovePatchToSelectedCommit, Key: 'm', @@ -106,7 +106,7 @@ func (self *CustomPatchOptionsMenuAction) Call() error { func (self *CustomPatchOptionsMenuAction) getPatchCommitIndex() int { for index, commit := range self.c.Model().Commits { - if commit.Sha == self.c.Git().Patch.PatchBuilder.To { + if commit.Hash == self.c.Git().Patch.PatchBuilder.To { return index } } diff --git a/pkg/gui/controllers/helpers/cherry_pick_helper.go b/pkg/gui/controllers/helpers/cherry_pick_helper.go index e57d743b747..0095a1d2a19 100644 --- a/pkg/gui/controllers/helpers/cherry_pick_helper.go +++ b/pkg/gui/controllers/helpers/cherry_pick_helper.go @@ -41,7 +41,7 @@ func (self *CherryPickHelper) CopyRange(commitsList []*models.Commit, context ty commitSet := self.getData().SelectedShaSet() allCommitsCopied := lo.EveryBy(commitsList[startIdx:endIdx+1], func(commit *models.Commit) bool { - return commitSet.Includes(commit.Sha) + return commitSet.Includes(commit.Hash) }) // if all selected commits are already copied, we'll uncopy them diff --git a/pkg/gui/controllers/helpers/fixup_helper.go b/pkg/gui/controllers/helpers/fixup_helper.go index 0a1bc713ed5..e7c7bf7d804 100644 --- a/pkg/gui/controllers/helpers/fixup_helper.go +++ b/pkg/gui/controllers/helpers/fixup_helper.go @@ -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.Sha == shas[0] + return commit.Hash == shas[0] }) if !ok { commits := self.c.Model().Commits diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index 5e850626ddb..c6bde3745f7 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -285,7 +285,7 @@ func (self *LocalCommitsController) GetOnRenderToMain() func() error { "ref": strings.TrimPrefix(commit.Name, "refs/heads/"), })) } else { - cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Sha, self.c.Modes().Filtering.GetPath()) + cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Hash, self.c.Modes().Filtering.GetPath()) task = types.NewRunPtyTask(cmdObj.GetCmd()) } @@ -350,7 +350,7 @@ func (self *LocalCommitsController) fixup(selectedCommits []*models.Commit, star } func (self *LocalCommitsController) reword(commit *models.Commit) error { - commitMessage, err := self.c.Git().Commit.GetCommitMessage(commit.Sha) + commitMessage, err := self.c.Git().Commit.GetCommitMessage(commit.Hash) if err != nil { return self.c.Error(err) } @@ -508,9 +508,9 @@ 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].Sha - rangeStartSha := commits[rangeStartIdx].Sha - err := self.c.Git().Rebase.EditRebase(commitsToEdit[len(commitsToEdit)-1].Sha) + selectedSha := commits[selectedIdx].Hash + rangeStartSha := commits[rangeStartIdx].Hash + err := self.c.Git().Rebase.EditRebase(commitsToEdit[len(commitsToEdit)-1].Hash) return self.c.Helpers().MergeAndRebase.CheckMergeOrRebaseWithRefreshOptions( err, types.RefreshOptions{Mode: types.BLOCK_UI, Then: func() { @@ -518,7 +518,7 @@ func (self *LocalCommitsController) startInteractiveRebaseWithEdit( for _, c := range commitsToEdit[:len(commitsToEdit)-1] { // Merge commits can't be set to "edit", so just skip them if !c.IsMerge() { - todos = append(todos, &models.Commit{Sha: c.Sha, Action: todo.Pick}) + todos = append(todos, &models.Commit{Hash: c.Hash, Action: todo.Pick}) } } if len(todos) > 0 { @@ -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.Sha == selectedSha + return c.Hash == selectedSha }) _, newRangeStartIdx, ok2 := lo.FindIndexOf(self.c.Model().Commits, func(c *models.Commit) bool { - return c.Sha == rangeStartSha + return c.Hash == rangeStartSha }) if ok1 && ok2 { self.context().SetSelectionRangeAndMode(newSelectedIdx, newRangeStartIdx, rangeSelectMode) @@ -787,7 +787,7 @@ func (self *LocalCommitsController) revert(commit *models.Commit) error { HandleConfirm: func() error { self.c.LogAction(self.c.Tr.Actions.RevertCommit) return self.c.WithWaitingStatusSync(self.c.Tr.RevertingStatus, func() error { - if err := self.c.Git().Commit.Revert(commit.Sha); err != nil { + if err := self.c.Git().Commit.Revert(commit.Hash); err != nil { return err } return self.afterRevertCommit() @@ -812,7 +812,7 @@ func (self *LocalCommitsController) createRevertMergeCommitMenu(commit *models.C parentNumber := i + 1 self.c.LogAction(self.c.Tr.Actions.RevertCommit) return self.c.WithWaitingStatusSync(self.c.Tr.RevertingStatus, func() error { - if err := self.c.Git().Commit.RevertMerge(commit.Sha, parentNumber); err != nil { + if err := self.c.Git().Commit.RevertMerge(commit.Hash, parentNumber); err != nil { return err } return self.afterRevertCommit() @@ -850,7 +850,7 @@ func (self *LocalCommitsController) createFixupCommit(commit *models.Commit) err return self.c.Helpers().WorkingTree.WithEnsureCommitableFiles(func() error { self.c.LogAction(self.c.Tr.Actions.CreateFixupCommit) return self.c.WithWaitingStatusSync(self.c.Tr.CreatingFixupCommitStatus, func() error { - if err := self.c.Git().Commit.CreateFixupCommit(commit.Sha); err != nil { + if err := self.c.Git().Commit.CreateFixupCommit(commit.Hash); err != nil { return self.c.Error(err) } @@ -884,7 +884,7 @@ func (self *LocalCommitsController) createFixupCommit(commit *models.Commit) err } func (self *LocalCommitsController) createAmendCommit(commit *models.Commit, includeFileChanges bool) error { - commitMessage, err := self.c.Git().Commit.GetCommitMessage(commit.Sha) + commitMessage, err := self.c.Git().Commit.GetCommitMessage(commit.Hash) if err != nil { return self.c.Error(err) } @@ -1024,7 +1024,7 @@ func isFixupCommit(subject string) (string, bool) { } func (self *LocalCommitsController) createTag(commit *models.Commit) error { - return self.c.Helpers().Tags.OpenCreateTagPrompt(commit.Sha, func() {}) + return self.c.Helpers().Tags.OpenCreateTagPrompt(commit.Hash, func() {}) } func (self *LocalCommitsController) openSearch() error { @@ -1181,11 +1181,11 @@ func (self *LocalCommitsController) canPaste() *types.DisabledReason { } func (self *LocalCommitsController) markAsBaseCommit(commit *models.Commit) error { - if commit.Sha == self.c.Modes().MarkedBaseCommit.GetSha() { + if commit.Hash == self.c.Modes().MarkedBaseCommit.GetSha() { // Reset when invoking it again on the marked commit self.c.Modes().MarkedBaseCommit.SetSha("") } else { - self.c.Modes().MarkedBaseCommit.SetSha(commit.Sha) + self.c.Modes().MarkedBaseCommit.SetSha(commit.Hash) } return self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits) } diff --git a/pkg/gui/controllers/reflog_commits_controller.go b/pkg/gui/controllers/reflog_commits_controller.go index d9ca3fd0260..b4250f4c975 100644 --- a/pkg/gui/controllers/reflog_commits_controller.go +++ b/pkg/gui/controllers/reflog_commits_controller.go @@ -45,7 +45,7 @@ func (self *ReflogCommitsController) GetOnRenderToMain() func() error { if commit == nil { task = types.NewRenderStringTask("No reflog history") } else { - cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Sha, self.c.Modes().Filtering.GetPath()) + cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Hash, self.c.Modes().Filtering.GetPath()) task = types.NewRunPtyTask(cmdObj.GetCmd()) } diff --git a/pkg/gui/controllers/sub_commits_controller.go b/pkg/gui/controllers/sub_commits_controller.go index 0acd1f1c419..90c6461a6fe 100644 --- a/pkg/gui/controllers/sub_commits_controller.go +++ b/pkg/gui/controllers/sub_commits_controller.go @@ -46,7 +46,7 @@ func (self *SubCommitsController) GetOnRenderToMain() func() error { if commit == nil { task = types.NewRenderStringTask("No commits") } else { - cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Sha, self.c.Modes().Filtering.GetPath()) + cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Hash, self.c.Modes().Filtering.GetPath()) task = types.NewRunPtyTask(cmdObj.GetCmd()) } diff --git a/pkg/gui/controllers/undo_controller.go b/pkg/gui/controllers/undo_controller.go index 402e07471bb..2df3b8689f7 100644 --- a/pkg/gui/controllers/undo_controller.go +++ b/pkg/gui/controllers/undo_controller.go @@ -188,7 +188,7 @@ func (self *UndoController) parseReflogForActions(onUserAction func(counter int, prevCommitHash := "" if len(reflogCommits)-1 >= reflogCommitIdx+1 { - prevCommitHash = reflogCommits[reflogCommitIdx+1].Sha + prevCommitHash = reflogCommits[reflogCommitIdx+1].Hash } if rebaseFinishCommitHash == "" { @@ -197,11 +197,11 @@ func (self *UndoController) parseReflogForActions(onUserAction func(counter int, } else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^\[lazygit redo\]`); ok { counter-- } else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^rebase (-i )?\(abort\)|^rebase (-i )?\(finish\)`); ok { - rebaseFinishCommitHash = reflogCommit.Sha + rebaseFinishCommitHash = reflogCommit.Hash } else if ok, match := utils.FindStringSubmatch(reflogCommit.Name, `^checkout: moving from ([\S]+) to ([\S]+)`); ok { action = &reflogAction{kind: CHECKOUT, from: match[1], to: match[2]} } else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^commit|^reset: moving to|^pull`); ok { - action = &reflogAction{kind: COMMIT, from: prevCommitHash, to: reflogCommit.Sha} + action = &reflogAction{kind: COMMIT, from: prevCommitHash, to: reflogCommit.Hash} } else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^rebase (-i )?\(start\)`); ok { // if we're here then we must be currently inside an interactive rebase action = &reflogAction{kind: CURRENT_REBASE, from: prevCommitHash} diff --git a/pkg/gui/modes/cherrypicking/cherry_picking.go b/pkg/gui/modes/cherrypicking/cherry_picking.go index ffbe51a806d..be4177f4166 100644 --- a/pkg/gui/modes/cherrypicking/cherry_picking.go +++ b/pkg/gui/modes/cherrypicking/cherry_picking.go @@ -26,31 +26,31 @@ func (self *CherryPicking) Active() bool { func (self *CherryPicking) SelectedShaSet() *set.Set[string] { shas := lo.Map(self.CherryPickedCommits, func(commit *models.Commit, _ int) string { - return commit.Sha + return commit.Hash }) return set.NewFromSlice(shas) } func (self *CherryPicking) Add(selectedCommit *models.Commit, commitsList []*models.Commit) { commitSet := self.SelectedShaSet() - commitSet.Add(selectedCommit.Sha) + commitSet.Add(selectedCommit.Hash) self.update(commitSet, commitsList) } func (self *CherryPicking) Remove(selectedCommit *models.Commit, commitsList []*models.Commit) { commitSet := self.SelectedShaSet() - commitSet.Remove(selectedCommit.Sha) + commitSet.Remove(selectedCommit.Hash) self.update(commitSet, commitsList) } func (self *CherryPicking) update(selectedShaSet *set.Set[string], commitsList []*models.Commit) { cherryPickedCommits := lo.Filter(commitsList, func(commit *models.Commit, _ int) bool { - return selectedShaSet.Includes(commit.Sha) + return selectedShaSet.Includes(commit.Hash) }) self.CherryPickedCommits = lo.Map(cherryPickedCommits, func(commit *models.Commit, _ int) *models.Commit { - return &models.Commit{Name: commit.Name, Sha: commit.Sha} + return &models.Commit{Name: commit.Name, Hash: commit.Hash} }) } diff --git a/pkg/gui/presentation/commits.go b/pkg/gui/presentation/commits.go index d6ae519c22d..a46911f4eca 100644 --- a/pkg/gui/presentation/commits.go +++ b/pkg/gui/presentation/commits.go @@ -123,7 +123,7 @@ func GetCommitListDisplayStrings( !lo.Contains(common.UserConfig.Git.MainBranches, b.Name) && // Don't show a marker for the head commit unless the // rebase.updateRefs config is on - (hasRebaseUpdateRefsConfig || b.CommitHash != commits[0].Sha) + (hasRebaseUpdateRefsConfig || b.CommitHash != commits[0].Hash) })) lines := make([][]string, 0, len(filteredCommits)) @@ -131,13 +131,13 @@ func GetCommitListDisplayStrings( willBeRebased := markedBaseCommit == "" for i, commit := range filteredCommits { unfilteredIdx := i + startIdx - bisectStatus = getBisectStatus(unfilteredIdx, commit.Sha, bisectInfo, bisectBounds) + bisectStatus = getBisectStatus(unfilteredIdx, commit.Hash, bisectInfo, bisectBounds) isYouAreHereCommit := false if showYouAreHereLabel && (commit.Action == models.ActionConflict || unfilteredIdx == rebaseOffset) { isYouAreHereCommit = true showYouAreHereLabel = false } - isMarkedBaseCommit := commit.Sha != "" && commit.Sha == markedBaseCommit + isMarkedBaseCommit := commit.Hash != "" && commit.Hash == markedBaseCommit if isMarkedBaseCommit { willBeRebased = true } @@ -172,11 +172,11 @@ func getbisectBounds(commits []*models.Commit, bisectInfo *git_commands.BisectIn bisectBounds := &bisectBounds{} for i, commit := range commits { - if commit.Sha == bisectInfo.GetNewSha() { + if commit.Hash == bisectInfo.GetNewSha() { bisectBounds.newIndex = i } - status, ok := bisectInfo.Status(commit.Sha) + status, ok := bisectInfo.Status(commit.Hash) if ok && status == git_commands.BisectStatusOld { bisectBounds.oldIndex = i return bisectBounds @@ -203,7 +203,7 @@ func loadPipesets(commits []*models.Commit) [][]*graph.Pipe { // given that our cache key is a commit hash and a commit count, it's very important that we don't actually try to render pipes // when dealing with things like filtered commits. cacheKey := pipeSetCacheKey{ - commitHash: commits[0].Sha, + commitHash: commits[0].Hash, commitCount: len(commits), } @@ -331,7 +331,7 @@ func displayCommit( tagString = theme.DiffTerminalColor.SetBold().Sprint(strings.Join(commit.Tags, " ")) + " " } - if branchHeadsToVisualize.Includes(commit.Sha) && + if branchHeadsToVisualize.Includes(commit.Hash) && // Don't show branch head on commits that are already merged to a main branch commit.Status != models.StatusMerged && // Don't show branch head on a "pick" todo if the rebase.updateRefs config is on @@ -421,7 +421,7 @@ func getShaColor( return getBisectStatusColor(bisectStatus) } - diffed := commit.Sha != "" && commit.Sha == diffName + diffed := commit.Hash != "" && commit.Hash == diffName shaColor := theme.DefaultTextColor switch commit.Status { case models.StatusUnpushed: @@ -439,7 +439,7 @@ func getShaColor( if diffed { shaColor = theme.DiffTerminalColor - } else if cherryPickedCommitHashSet.Includes(commit.Sha) { + } else if cherryPickedCommitHashSet.Includes(commit.Hash) { shaColor = theme.CherryPickedCommitTextStyle } else if commit.Divergence == models.DivergenceRight && commit.Status != models.StatusMerged { shaColor = style.FgBlue diff --git a/pkg/gui/presentation/commits_test.go b/pkg/gui/presentation/commits_test.go index 75f96eed9cd..5c0100ea035 100644 --- a/pkg/gui/presentation/commits_test.go +++ b/pkg/gui/presentation/commits_test.go @@ -58,8 +58,8 @@ func TestGetCommitListDisplayStrings(t *testing.T) { { testName: "some commits", commits: []*models.Commit{ - {Name: "commit1", Sha: "sha1"}, - {Name: "commit2", Sha: "sha2"}, + {Name: "commit1", Hash: "sha1"}, + {Name: "commit2", Hash: "sha2"}, }, startIdx: 0, endIdx: 2, @@ -75,8 +75,8 @@ func TestGetCommitListDisplayStrings(t *testing.T) { { testName: "commit with tags", commits: []*models.Commit{ - {Name: "commit1", Sha: "sha1", Tags: []string{"tag1", "tag2"}}, - {Name: "commit2", Sha: "sha2"}, + {Name: "commit1", Hash: "sha1", Tags: []string{"tag1", "tag2"}}, + {Name: "commit2", Hash: "sha2"}, }, startIdx: 0, endIdx: 2, @@ -92,10 +92,10 @@ func TestGetCommitListDisplayStrings(t *testing.T) { { testName: "show local branch head, except the current branch, main branches, or merged branches", commits: []*models.Commit{ - {Name: "commit1", Sha: "sha1"}, - {Name: "commit2", Sha: "sha2"}, - {Name: "commit3", Sha: "sha3"}, - {Name: "commit4", Sha: "sha4", Status: models.StatusMerged}, + {Name: "commit1", Hash: "sha1"}, + {Name: "commit2", Hash: "sha2"}, + {Name: "commit3", Hash: "sha3"}, + {Name: "commit4", Hash: "sha4", Status: models.StatusMerged}, }, branches: []*models.Branch{ {Name: "current-branch", CommitHash: "sha1", Head: true}, @@ -121,8 +121,8 @@ func TestGetCommitListDisplayStrings(t *testing.T) { { testName: "show local branch head for head commit if updateRefs is on", commits: []*models.Commit{ - {Name: "commit1", Sha: "sha1"}, - {Name: "commit2", Sha: "sha2"}, + {Name: "commit1", Hash: "sha1"}, + {Name: "commit2", Hash: "sha2"}, }, branches: []*models.Branch{ {Name: "current-branch", CommitHash: "sha1", Head: true}, @@ -144,8 +144,8 @@ func TestGetCommitListDisplayStrings(t *testing.T) { { testName: "don't show local branch head for head commit if updateRefs is off", commits: []*models.Commit{ - {Name: "commit1", Sha: "sha1"}, - {Name: "commit2", Sha: "sha2"}, + {Name: "commit1", Hash: "sha1"}, + {Name: "commit2", Hash: "sha2"}, }, branches: []*models.Branch{ {Name: "current-branch", CommitHash: "sha1", Head: true}, @@ -167,9 +167,9 @@ func TestGetCommitListDisplayStrings(t *testing.T) { { testName: "show local branch head and tag if both exist", commits: []*models.Commit{ - {Name: "commit1", Sha: "sha1"}, - {Name: "commit2", Sha: "sha2", Tags: []string{"some-tag"}}, - {Name: "commit3", Sha: "sha3"}, + {Name: "commit1", Hash: "sha1"}, + {Name: "commit2", Hash: "sha2", Tags: []string{"some-tag"}}, + {Name: "commit3", Hash: "sha3"}, }, branches: []*models.Branch{ {Name: "some-branch", CommitHash: "sha2"}, @@ -189,11 +189,11 @@ func TestGetCommitListDisplayStrings(t *testing.T) { { testName: "showing graph", commits: []*models.Commit{ - {Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}}, - {Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}}, - {Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}}, - {Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}}, - {Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}}, + {Name: "commit1", Hash: "sha1", Parents: []string{"sha2", "sha3"}}, + {Name: "commit2", Hash: "sha2", Parents: []string{"sha3"}}, + {Name: "commit3", Hash: "sha3", Parents: []string{"sha4"}}, + {Name: "commit4", Hash: "sha4", Parents: []string{"sha5"}}, + {Name: "commit5", Hash: "sha5", Parents: []string{"sha7"}}, }, startIdx: 0, endIdx: 5, @@ -212,11 +212,11 @@ func TestGetCommitListDisplayStrings(t *testing.T) { { testName: "showing graph, including rebase commits", commits: []*models.Commit{ - {Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick}, - {Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}, Action: todo.Pick}, - {Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}}, - {Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}}, - {Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}}, + {Name: "commit1", Hash: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick}, + {Name: "commit2", Hash: "sha2", Parents: []string{"sha3"}, Action: todo.Pick}, + {Name: "commit3", Hash: "sha3", Parents: []string{"sha4"}}, + {Name: "commit4", Hash: "sha4", Parents: []string{"sha5"}}, + {Name: "commit5", Hash: "sha5", Parents: []string{"sha7"}}, }, startIdx: 0, endIdx: 5, @@ -236,11 +236,11 @@ func TestGetCommitListDisplayStrings(t *testing.T) { { testName: "showing graph, including rebase commits, with offset", commits: []*models.Commit{ - {Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick}, - {Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}, Action: todo.Pick}, - {Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}}, - {Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}}, - {Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}}, + {Name: "commit1", Hash: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick}, + {Name: "commit2", Hash: "sha2", Parents: []string{"sha3"}, Action: todo.Pick}, + {Name: "commit3", Hash: "sha3", Parents: []string{"sha4"}}, + {Name: "commit4", Hash: "sha4", Parents: []string{"sha5"}}, + {Name: "commit5", Hash: "sha5", Parents: []string{"sha7"}}, }, startIdx: 1, endIdx: 5, @@ -259,11 +259,11 @@ func TestGetCommitListDisplayStrings(t *testing.T) { { testName: "startIdx is past TODO commits", commits: []*models.Commit{ - {Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick}, - {Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}, Action: todo.Pick}, - {Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}}, - {Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}}, - {Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}}, + {Name: "commit1", Hash: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick}, + {Name: "commit2", Hash: "sha2", Parents: []string{"sha3"}, Action: todo.Pick}, + {Name: "commit3", Hash: "sha3", Parents: []string{"sha4"}}, + {Name: "commit4", Hash: "sha4", Parents: []string{"sha5"}}, + {Name: "commit5", Hash: "sha5", Parents: []string{"sha7"}}, }, startIdx: 3, endIdx: 5, @@ -280,11 +280,11 @@ func TestGetCommitListDisplayStrings(t *testing.T) { { testName: "only showing TODO commits", commits: []*models.Commit{ - {Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick}, - {Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}, Action: todo.Pick}, - {Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}}, - {Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}}, - {Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}}, + {Name: "commit1", Hash: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick}, + {Name: "commit2", Hash: "sha2", Parents: []string{"sha3"}, Action: todo.Pick}, + {Name: "commit3", Hash: "sha3", Parents: []string{"sha4"}}, + {Name: "commit4", Hash: "sha4", Parents: []string{"sha5"}}, + {Name: "commit5", Hash: "sha5", Parents: []string{"sha7"}}, }, startIdx: 0, endIdx: 2, @@ -301,11 +301,11 @@ func TestGetCommitListDisplayStrings(t *testing.T) { { testName: "no TODO commits, towards bottom", commits: []*models.Commit{ - {Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}}, - {Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}}, - {Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}}, - {Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}}, - {Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}}, + {Name: "commit1", Hash: "sha1", Parents: []string{"sha2", "sha3"}}, + {Name: "commit2", Hash: "sha2", Parents: []string{"sha3"}}, + {Name: "commit3", Hash: "sha3", Parents: []string{"sha4"}}, + {Name: "commit4", Hash: "sha4", Parents: []string{"sha5"}}, + {Name: "commit5", Hash: "sha5", Parents: []string{"sha7"}}, }, startIdx: 4, endIdx: 5, @@ -321,11 +321,11 @@ func TestGetCommitListDisplayStrings(t *testing.T) { { testName: "only TODO commits except last", commits: []*models.Commit{ - {Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick}, - {Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}, Action: todo.Pick}, - {Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}, Action: todo.Pick}, - {Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}, Action: todo.Pick}, - {Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}}, + {Name: "commit1", Hash: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick}, + {Name: "commit2", Hash: "sha2", Parents: []string{"sha3"}, Action: todo.Pick}, + {Name: "commit3", Hash: "sha3", Parents: []string{"sha4"}, Action: todo.Pick}, + {Name: "commit4", Hash: "sha4", Parents: []string{"sha5"}, Action: todo.Pick}, + {Name: "commit5", Hash: "sha5", Parents: []string{"sha7"}}, }, startIdx: 0, endIdx: 2, @@ -342,9 +342,9 @@ func TestGetCommitListDisplayStrings(t *testing.T) { { testName: "don't show YOU ARE HERE label when not asked for (e.g. in branches panel)", commits: []*models.Commit{ - {Name: "commit1", Sha: "sha1", Parents: []string{"sha2"}, Action: todo.Pick}, - {Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}}, - {Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}}, + {Name: "commit1", Hash: "sha1", Parents: []string{"sha2"}, Action: todo.Pick}, + {Name: "commit2", Hash: "sha2", Parents: []string{"sha3"}}, + {Name: "commit3", Hash: "sha3", Parents: []string{"sha4"}}, }, startIdx: 0, endIdx: 3, @@ -362,8 +362,8 @@ func TestGetCommitListDisplayStrings(t *testing.T) { { testName: "custom time format", commits: []*models.Commit{ - {Name: "commit1", Sha: "sha1", UnixTimestamp: 1577844184, AuthorName: "Jesse Duffield"}, - {Name: "commit2", Sha: "sha2", UnixTimestamp: 1576844184, AuthorName: "Jesse Duffield"}, + {Name: "commit1", Hash: "sha1", UnixTimestamp: 1577844184, AuthorName: "Jesse Duffield"}, + {Name: "commit2", Hash: "sha2", UnixTimestamp: 1576844184, AuthorName: "Jesse Duffield"}, }, fullDescription: true, timeFormat: "2006-01-02", diff --git a/pkg/gui/presentation/graph/graph.go b/pkg/gui/presentation/graph/graph.go index 21530ac6bfe..e13f6916adb 100644 --- a/pkg/gui/presentation/graph/graph.go +++ b/pkg/gui/presentation/graph/graph.go @@ -22,19 +22,19 @@ const ( ) type Pipe struct { - fromPos int - toPos int - fromSha string - toSha string - kind PipeKind - style style.TextStyle + fromPos int + toPos int + fromHash string + toHash string + kind PipeKind + style style.TextStyle } var highlightStyle = style.FgLightWhite.SetBold() func ContainsCommitHash(pipes []*Pipe, sha string) bool { for _, pipe := range pipes { - if equalHashes(pipe.fromSha, sha) { + if equalHashes(pipe.fromHash, sha) { return true } } @@ -65,7 +65,7 @@ func GetPipeSets(commits []*models.Commit, getStyle func(c *models.Commit) style return nil } - pipes := []*Pipe{{fromPos: 0, toPos: 0, fromSha: "START", toSha: commits[0].Sha, kind: STARTS, style: style.FgDefault}} + pipes := []*Pipe{{fromPos: 0, toPos: 0, fromHash: "START", toHash: commits[0].Hash, kind: STARTS, style: style.FgDefault}} return lo.Map(commits, func(commit *models.Commit, _ int) []*Pipe { pipes = getNextPipes(pipes, commit, getStyle) @@ -130,7 +130,7 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod // (this only happens when we're doing `git log --all`). These will be tacked onto the far end. pos := maxPos + 1 for _, pipe := range currentPipes { - if equalHashes(pipe.toSha, commit.Sha) { + if equalHashes(pipe.toHash, commit.Hash) { // turns out this commit does have a descendant so we'll place it right under the first instance pos = pipe.toPos break @@ -144,27 +144,27 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod if len(commit.Parents) > 0 { // merge commit newPipes = append(newPipes, &Pipe{ - fromPos: pos, - toPos: pos, - fromSha: commit.Sha, - toSha: commit.Parents[0], - kind: STARTS, - style: getStyle(commit), + fromPos: pos, + toPos: pos, + fromHash: commit.Hash, + toHash: commit.Parents[0], + kind: STARTS, + style: getStyle(commit), }) } else if len(commit.Parents) == 0 { // root commit newPipes = append(newPipes, &Pipe{ - fromPos: pos, - toPos: pos, - fromSha: commit.Sha, - toSha: models.EmptyTreeCommitHash, - kind: STARTS, - style: getStyle(commit), + fromPos: pos, + toPos: pos, + fromHash: commit.Hash, + toHash: models.EmptyTreeCommitHash, + kind: STARTS, + style: getStyle(commit), }) } traversedSpotsForContinuingPipes := set.New[int]() for _, pipe := range currentPipes { - if !equalHashes(pipe.toSha, commit.Sha) { + if !equalHashes(pipe.toHash, commit.Hash) { traversedSpotsForContinuingPipes.Add(pipe.toPos) } } @@ -203,27 +203,27 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod } for _, pipe := range currentPipes { - if equalHashes(pipe.toSha, commit.Sha) { + if equalHashes(pipe.toHash, commit.Hash) { // terminating here newPipes = append(newPipes, &Pipe{ - fromPos: pipe.toPos, - toPos: pos, - fromSha: pipe.fromSha, - toSha: pipe.toSha, - kind: TERMINATES, - style: pipe.style, + fromPos: pipe.toPos, + toPos: pos, + fromHash: pipe.fromHash, + toHash: pipe.toHash, + kind: TERMINATES, + style: pipe.style, }) traverse(pipe.toPos, pos) } else if pipe.toPos < pos { // continuing here availablePos := getNextAvailablePosForContinuingPipe() newPipes = append(newPipes, &Pipe{ - fromPos: pipe.toPos, - toPos: availablePos, - fromSha: pipe.fromSha, - toSha: pipe.toSha, - kind: CONTINUES, - style: pipe.style, + fromPos: pipe.toPos, + toPos: availablePos, + fromHash: pipe.fromHash, + toHash: pipe.toHash, + kind: CONTINUES, + style: pipe.style, }) traverse(pipe.toPos, availablePos) } @@ -234,12 +234,12 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod availablePos := getNextAvailablePosForNewPipe() // need to act as if continuing pipes are going to continue on the same line. newPipes = append(newPipes, &Pipe{ - fromPos: pos, - toPos: availablePos, - fromSha: commit.Sha, - toSha: parent, - kind: STARTS, - style: getStyle(commit), + fromPos: pos, + toPos: availablePos, + fromHash: commit.Hash, + toHash: parent, + kind: STARTS, + style: getStyle(commit), }) takenSpots.Add(availablePos) @@ -247,7 +247,7 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod } for _, pipe := range currentPipes { - if !equalHashes(pipe.toSha, commit.Sha) && pipe.toPos > pos { + if !equalHashes(pipe.toHash, commit.Hash) && pipe.toPos > pos { // continuing on, potentially moving left to fill in a blank spot last := pipe.toPos for i := pipe.toPos; i > pos; i-- { @@ -258,12 +258,12 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod } } newPipes = append(newPipes, &Pipe{ - fromPos: pipe.toPos, - toPos: last, - fromSha: pipe.fromSha, - toSha: pipe.toSha, - kind: CONTINUES, - style: pipe.style, + fromPos: pipe.toPos, + toPos: last, + fromHash: pipe.fromHash, + toHash: pipe.toHash, + kind: CONTINUES, + style: pipe.style, }) traverse(pipe.toPos, last) } @@ -329,10 +329,10 @@ func renderPipeSet( // we don't want to highlight two commits if they're contiguous. We only want // to highlight multiple things if there's an actual visible pipe involved. highlight := true - if prevCommit != nil && equalHashes(prevCommit.Sha, selectedCommitHash) { + if prevCommit != nil && equalHashes(prevCommit.Hash, selectedCommitHash) { highlight = false for _, pipe := range pipes { - if equalHashes(pipe.fromSha, selectedCommitHash) && (pipe.kind != TERMINATES || pipe.fromPos != pipe.toPos) { + if equalHashes(pipe.fromHash, selectedCommitHash) && (pipe.kind != TERMINATES || pipe.fromPos != pipe.toPos) { highlight = true } } @@ -341,7 +341,7 @@ func renderPipeSet( // so we have our commit pos again, now it's time to build the cells. // we'll handle the one that's sourced from our selected commit last so that it can override the other cells. selectedPipes, nonSelectedPipes := utils.Partition(pipes, func(pipe *Pipe) bool { - return highlight && equalHashes(pipe.fromSha, selectedCommitHash) + return highlight && equalHashes(pipe.fromHash, selectedCommitHash) }) for _, pipe := range nonSelectedPipes { diff --git a/pkg/gui/presentation/graph/graph_test.go b/pkg/gui/presentation/graph/graph_test.go index a7fe5879b3d..57df5489254 100644 --- a/pkg/gui/presentation/graph/graph_test.go +++ b/pkg/gui/presentation/graph/graph_test.go @@ -24,20 +24,20 @@ func TestRenderCommitGraph(t *testing.T) { { name: "with some merges", commits: []*models.Commit{ - {Sha: "1", Parents: []string{"2"}}, - {Sha: "2", Parents: []string{"3"}}, - {Sha: "3", Parents: []string{"4"}}, - {Sha: "4", Parents: []string{"5", "7"}}, - {Sha: "7", Parents: []string{"5"}}, - {Sha: "5", Parents: []string{"8"}}, - {Sha: "8", Parents: []string{"9"}}, - {Sha: "9", Parents: []string{"A", "B"}}, - {Sha: "B", Parents: []string{"D"}}, - {Sha: "D", Parents: []string{"D"}}, - {Sha: "A", Parents: []string{"E"}}, - {Sha: "E", Parents: []string{"F"}}, - {Sha: "F", Parents: []string{"D"}}, - {Sha: "D", Parents: []string{"G"}}, + {Hash: "1", Parents: []string{"2"}}, + {Hash: "2", Parents: []string{"3"}}, + {Hash: "3", Parents: []string{"4"}}, + {Hash: "4", Parents: []string{"5", "7"}}, + {Hash: "7", Parents: []string{"5"}}, + {Hash: "5", Parents: []string{"8"}}, + {Hash: "8", Parents: []string{"9"}}, + {Hash: "9", Parents: []string{"A", "B"}}, + {Hash: "B", Parents: []string{"D"}}, + {Hash: "D", Parents: []string{"D"}}, + {Hash: "A", Parents: []string{"E"}}, + {Hash: "E", Parents: []string{"F"}}, + {Hash: "F", Parents: []string{"D"}}, + {Hash: "D", Parents: []string{"G"}}, }, expectedOutput: ` 1 ◯ @@ -58,12 +58,12 @@ func TestRenderCommitGraph(t *testing.T) { { name: "with a path that has room to move to the left", commits: []*models.Commit{ - {Sha: "1", Parents: []string{"2"}}, - {Sha: "2", Parents: []string{"3", "4"}}, - {Sha: "4", Parents: []string{"3", "5"}}, - {Sha: "3", Parents: []string{"5"}}, - {Sha: "5", Parents: []string{"6"}}, - {Sha: "6", Parents: []string{"7"}}, + {Hash: "1", Parents: []string{"2"}}, + {Hash: "2", Parents: []string{"3", "4"}}, + {Hash: "4", Parents: []string{"3", "5"}}, + {Hash: "3", Parents: []string{"5"}}, + {Hash: "5", Parents: []string{"6"}}, + {Hash: "6", Parents: []string{"7"}}, }, expectedOutput: ` 1 ◯ @@ -76,13 +76,13 @@ func TestRenderCommitGraph(t *testing.T) { { name: "with a new commit", commits: []*models.Commit{ - {Sha: "1", Parents: []string{"2"}}, - {Sha: "2", Parents: []string{"3", "4"}}, - {Sha: "4", Parents: []string{"3", "5"}}, - {Sha: "Z", Parents: []string{"Z"}}, - {Sha: "3", Parents: []string{"5"}}, - {Sha: "5", Parents: []string{"6"}}, - {Sha: "6", Parents: []string{"7"}}, + {Hash: "1", Parents: []string{"2"}}, + {Hash: "2", Parents: []string{"3", "4"}}, + {Hash: "4", Parents: []string{"3", "5"}}, + {Hash: "Z", Parents: []string{"Z"}}, + {Hash: "3", Parents: []string{"5"}}, + {Hash: "5", Parents: []string{"6"}}, + {Hash: "6", Parents: []string{"7"}}, }, expectedOutput: ` 1 ◯ @@ -96,12 +96,12 @@ func TestRenderCommitGraph(t *testing.T) { { name: "with a path that has room to move to the left and continues", commits: []*models.Commit{ - {Sha: "1", Parents: []string{"2"}}, - {Sha: "2", Parents: []string{"3", "4"}}, - {Sha: "3", Parents: []string{"5", "4"}}, - {Sha: "5", Parents: []string{"7", "8"}}, - {Sha: "4", Parents: []string{"7"}}, - {Sha: "7", Parents: []string{"11"}}, + {Hash: "1", Parents: []string{"2"}}, + {Hash: "2", Parents: []string{"3", "4"}}, + {Hash: "3", Parents: []string{"5", "4"}}, + {Hash: "5", Parents: []string{"7", "8"}}, + {Hash: "4", Parents: []string{"7"}}, + {Hash: "7", Parents: []string{"11"}}, }, expectedOutput: ` 1 ◯ @@ -114,13 +114,13 @@ func TestRenderCommitGraph(t *testing.T) { { name: "with a path that has room to move to the left and continues", commits: []*models.Commit{ - {Sha: "1", Parents: []string{"2"}}, - {Sha: "2", Parents: []string{"3", "4"}}, - {Sha: "3", Parents: []string{"5", "4"}}, - {Sha: "5", Parents: []string{"7", "8"}}, - {Sha: "7", Parents: []string{"4", "A"}}, - {Sha: "4", Parents: []string{"B"}}, - {Sha: "B", Parents: []string{"C"}}, + {Hash: "1", Parents: []string{"2"}}, + {Hash: "2", Parents: []string{"3", "4"}}, + {Hash: "3", Parents: []string{"5", "4"}}, + {Hash: "5", Parents: []string{"7", "8"}}, + {Hash: "7", Parents: []string{"4", "A"}}, + {Hash: "4", Parents: []string{"B"}}, + {Hash: "B", Parents: []string{"C"}}, }, expectedOutput: ` 1 ◯ @@ -134,11 +134,11 @@ func TestRenderCommitGraph(t *testing.T) { { name: "with a path that has room to move to the left and continues", commits: []*models.Commit{ - {Sha: "1", Parents: []string{"2", "3"}}, - {Sha: "3", Parents: []string{"2"}}, - {Sha: "2", Parents: []string{"4", "5"}}, - {Sha: "4", Parents: []string{"6", "7"}}, - {Sha: "6", Parents: []string{"8"}}, + {Hash: "1", Parents: []string{"2", "3"}}, + {Hash: "3", Parents: []string{"2"}}, + {Hash: "2", Parents: []string{"4", "5"}}, + {Hash: "4", Parents: []string{"6", "7"}}, + {Hash: "6", Parents: []string{"8"}}, }, expectedOutput: ` 1 ⏣─╮ @@ -150,11 +150,11 @@ func TestRenderCommitGraph(t *testing.T) { { name: "new merge path fills gap before continuing path on right", commits: []*models.Commit{ - {Sha: "1", Parents: []string{"2", "3", "4", "5"}}, - {Sha: "4", Parents: []string{"2"}}, - {Sha: "2", Parents: []string{"A"}}, - {Sha: "A", Parents: []string{"6", "B"}}, - {Sha: "B", Parents: []string{"C"}}, + {Hash: "1", Parents: []string{"2", "3", "4", "5"}}, + {Hash: "4", Parents: []string{"2"}}, + {Hash: "2", Parents: []string{"A"}}, + {Hash: "A", Parents: []string{"6", "B"}}, + {Hash: "B", Parents: []string{"C"}}, }, expectedOutput: ` 1 ⏣─┬─┬─╮ @@ -166,14 +166,14 @@ func TestRenderCommitGraph(t *testing.T) { { name: "with a path that has room to move to the left and continues", commits: []*models.Commit{ - {Sha: "1", Parents: []string{"2"}}, - {Sha: "2", Parents: []string{"3", "4"}}, - {Sha: "3", Parents: []string{"5", "4"}}, - {Sha: "5", Parents: []string{"7", "8"}}, - {Sha: "7", Parents: []string{"4", "A"}}, - {Sha: "4", Parents: []string{"B"}}, - {Sha: "B", Parents: []string{"C"}}, - {Sha: "C", Parents: []string{"D"}}, + {Hash: "1", Parents: []string{"2"}}, + {Hash: "2", Parents: []string{"3", "4"}}, + {Hash: "3", Parents: []string{"5", "4"}}, + {Hash: "5", Parents: []string{"7", "8"}}, + {Hash: "7", Parents: []string{"4", "A"}}, + {Hash: "4", Parents: []string{"B"}}, + {Hash: "B", Parents: []string{"C"}}, + {Hash: "C", Parents: []string{"D"}}, }, expectedOutput: ` 1 ◯ @@ -188,16 +188,16 @@ func TestRenderCommitGraph(t *testing.T) { { name: "with a path that has room to move to the left and continues", commits: []*models.Commit{ - {Sha: "1", Parents: []string{"2"}}, - {Sha: "2", Parents: []string{"3", "4"}}, - {Sha: "3", Parents: []string{"5", "4"}}, - {Sha: "5", Parents: []string{"7", "G"}}, - {Sha: "7", Parents: []string{"8", "A"}}, - {Sha: "8", Parents: []string{"4", "E"}}, - {Sha: "4", Parents: []string{"B"}}, - {Sha: "B", Parents: []string{"C"}}, - {Sha: "C", Parents: []string{"D"}}, - {Sha: "D", Parents: []string{"F"}}, + {Hash: "1", Parents: []string{"2"}}, + {Hash: "2", Parents: []string{"3", "4"}}, + {Hash: "3", Parents: []string{"5", "4"}}, + {Hash: "5", Parents: []string{"7", "G"}}, + {Hash: "7", Parents: []string{"8", "A"}}, + {Hash: "8", Parents: []string{"4", "E"}}, + {Hash: "4", Parents: []string{"B"}}, + {Hash: "B", Parents: []string{"C"}}, + {Hash: "C", Parents: []string{"D"}}, + {Hash: "D", Parents: []string{"F"}}, }, expectedOutput: ` 1 ◯ @@ -231,7 +231,7 @@ func TestRenderCommitGraph(t *testing.T) { output := "" for i, line := range lines { - description := test.commits[i].Sha + description := test.commits[i].Hash output += strings.TrimSpace(description+" "+utils.Decolorise(line)) + "\n" } t.Log("\nactual: \n" + output) @@ -263,32 +263,32 @@ func TestRenderPipeSet(t *testing.T) { { name: "single cell", pipes: []*Pipe{ - {fromPos: 0, toPos: 0, fromSha: "a", toSha: "b", kind: TERMINATES, style: cyan}, - {fromPos: 0, toPos: 0, fromSha: "b", toSha: "c", kind: STARTS, style: green}, + {fromPos: 0, toPos: 0, fromHash: "a", toHash: "b", kind: TERMINATES, style: cyan}, + {fromPos: 0, toPos: 0, fromHash: "b", toHash: "c", kind: STARTS, style: green}, }, - prevCommit: &models.Commit{Sha: "a"}, + prevCommit: &models.Commit{Hash: "a"}, expectedStr: "◯", expectedStyles: []style.TextStyle{green}, }, { name: "single cell, selected", pipes: []*Pipe{ - {fromPos: 0, toPos: 0, fromSha: "a", toSha: "selected", kind: TERMINATES, style: cyan}, - {fromPos: 0, toPos: 0, fromSha: "selected", toSha: "c", kind: STARTS, style: green}, + {fromPos: 0, toPos: 0, fromHash: "a", toHash: "selected", kind: TERMINATES, style: cyan}, + {fromPos: 0, toPos: 0, fromHash: "selected", toHash: "c", kind: STARTS, style: green}, }, - prevCommit: &models.Commit{Sha: "a"}, + prevCommit: &models.Commit{Hash: "a"}, expectedStr: "◯", expectedStyles: []style.TextStyle{highlightStyle}, }, { name: "terminating hook and starting hook, selected", pipes: []*Pipe{ - {fromPos: 0, toPos: 0, fromSha: "a", toSha: "selected", kind: TERMINATES, style: cyan}, - {fromPos: 1, toPos: 0, fromSha: "c", toSha: "selected", kind: TERMINATES, style: yellow}, - {fromPos: 0, toPos: 0, fromSha: "selected", toSha: "d", kind: STARTS, style: green}, - {fromPos: 0, toPos: 1, fromSha: "selected", toSha: "e", kind: STARTS, style: green}, + {fromPos: 0, toPos: 0, fromHash: "a", toHash: "selected", kind: TERMINATES, style: cyan}, + {fromPos: 1, toPos: 0, fromHash: "c", toHash: "selected", kind: TERMINATES, style: yellow}, + {fromPos: 0, toPos: 0, fromHash: "selected", toHash: "d", kind: STARTS, style: green}, + {fromPos: 0, toPos: 1, fromHash: "selected", toHash: "e", kind: STARTS, style: green}, }, - prevCommit: &models.Commit{Sha: "a"}, + prevCommit: &models.Commit{Hash: "a"}, expectedStr: "⏣─╮", expectedStyles: []style.TextStyle{ highlightStyle, highlightStyle, highlightStyle, @@ -297,12 +297,12 @@ func TestRenderPipeSet(t *testing.T) { { name: "terminating hook and starting hook, prioritise the terminating one", pipes: []*Pipe{ - {fromPos: 0, toPos: 0, fromSha: "a", toSha: "b", kind: TERMINATES, style: red}, - {fromPos: 1, toPos: 0, fromSha: "c", toSha: "b", kind: TERMINATES, style: magenta}, - {fromPos: 0, toPos: 0, fromSha: "b", toSha: "d", kind: STARTS, style: green}, - {fromPos: 0, toPos: 1, fromSha: "b", toSha: "e", kind: STARTS, style: green}, + {fromPos: 0, toPos: 0, fromHash: "a", toHash: "b", kind: TERMINATES, style: red}, + {fromPos: 1, toPos: 0, fromHash: "c", toHash: "b", kind: TERMINATES, style: magenta}, + {fromPos: 0, toPos: 0, fromHash: "b", toHash: "d", kind: STARTS, style: green}, + {fromPos: 0, toPos: 1, fromHash: "b", toHash: "e", kind: STARTS, style: green}, }, - prevCommit: &models.Commit{Sha: "a"}, + prevCommit: &models.Commit{Hash: "a"}, expectedStr: "⏣─│", expectedStyles: []style.TextStyle{ green, green, magenta, @@ -311,13 +311,13 @@ func TestRenderPipeSet(t *testing.T) { { name: "starting and terminating pipe sharing some space", pipes: []*Pipe{ - {fromPos: 0, toPos: 0, fromSha: "a1", toSha: "a2", kind: TERMINATES, style: red}, - {fromPos: 0, toPos: 0, fromSha: "a2", toSha: "a3", kind: STARTS, style: yellow}, - {fromPos: 1, toPos: 1, fromSha: "b1", toSha: "b2", kind: CONTINUES, style: magenta}, - {fromPos: 3, toPos: 0, fromSha: "e1", toSha: "a2", kind: TERMINATES, style: green}, - {fromPos: 0, toPos: 2, fromSha: "a2", toSha: "c3", kind: STARTS, style: yellow}, + {fromPos: 0, toPos: 0, fromHash: "a1", toHash: "a2", kind: TERMINATES, style: red}, + {fromPos: 0, toPos: 0, fromHash: "a2", toHash: "a3", kind: STARTS, style: yellow}, + {fromPos: 1, toPos: 1, fromHash: "b1", toHash: "b2", kind: CONTINUES, style: magenta}, + {fromPos: 3, toPos: 0, fromHash: "e1", toHash: "a2", kind: TERMINATES, style: green}, + {fromPos: 0, toPos: 2, fromHash: "a2", toHash: "c3", kind: STARTS, style: yellow}, }, - prevCommit: &models.Commit{Sha: "a1"}, + prevCommit: &models.Commit{Hash: "a1"}, expectedStr: "⏣─│─┬─╯", expectedStyles: []style.TextStyle{ yellow, yellow, magenta, yellow, yellow, green, green, @@ -326,13 +326,13 @@ func TestRenderPipeSet(t *testing.T) { { name: "starting and terminating pipe sharing some space, with selection", pipes: []*Pipe{ - {fromPos: 0, toPos: 0, fromSha: "a1", toSha: "selected", kind: TERMINATES, style: red}, - {fromPos: 0, toPos: 0, fromSha: "selected", toSha: "a3", kind: STARTS, style: yellow}, - {fromPos: 1, toPos: 1, fromSha: "b1", toSha: "b2", kind: CONTINUES, style: magenta}, - {fromPos: 3, toPos: 0, fromSha: "e1", toSha: "selected", kind: TERMINATES, style: green}, - {fromPos: 0, toPos: 2, fromSha: "selected", toSha: "c3", kind: STARTS, style: yellow}, + {fromPos: 0, toPos: 0, fromHash: "a1", toHash: "selected", kind: TERMINATES, style: red}, + {fromPos: 0, toPos: 0, fromHash: "selected", toHash: "a3", kind: STARTS, style: yellow}, + {fromPos: 1, toPos: 1, fromHash: "b1", toHash: "b2", kind: CONTINUES, style: magenta}, + {fromPos: 3, toPos: 0, fromHash: "e1", toHash: "selected", kind: TERMINATES, style: green}, + {fromPos: 0, toPos: 2, fromHash: "selected", toHash: "c3", kind: STARTS, style: yellow}, }, - prevCommit: &models.Commit{Sha: "a1"}, + prevCommit: &models.Commit{Hash: "a1"}, expectedStr: "⏣───╮ ╯", expectedStyles: []style.TextStyle{ highlightStyle, highlightStyle, highlightStyle, highlightStyle, highlightStyle, nothing, green, @@ -341,12 +341,12 @@ func TestRenderPipeSet(t *testing.T) { { name: "many terminating pipes", pipes: []*Pipe{ - {fromPos: 0, toPos: 0, fromSha: "a1", toSha: "a2", kind: TERMINATES, style: red}, - {fromPos: 0, toPos: 0, fromSha: "a2", toSha: "a3", kind: STARTS, style: yellow}, - {fromPos: 1, toPos: 0, fromSha: "b1", toSha: "a2", kind: TERMINATES, style: magenta}, - {fromPos: 2, toPos: 0, fromSha: "c1", toSha: "a2", kind: TERMINATES, style: green}, + {fromPos: 0, toPos: 0, fromHash: "a1", toHash: "a2", kind: TERMINATES, style: red}, + {fromPos: 0, toPos: 0, fromHash: "a2", toHash: "a3", kind: STARTS, style: yellow}, + {fromPos: 1, toPos: 0, fromHash: "b1", toHash: "a2", kind: TERMINATES, style: magenta}, + {fromPos: 2, toPos: 0, fromHash: "c1", toHash: "a2", kind: TERMINATES, style: green}, }, - prevCommit: &models.Commit{Sha: "a1"}, + prevCommit: &models.Commit{Hash: "a1"}, expectedStr: "◯─┴─╯", expectedStyles: []style.TextStyle{ yellow, magenta, magenta, green, green, @@ -355,13 +355,13 @@ func TestRenderPipeSet(t *testing.T) { { name: "starting pipe passing through", pipes: []*Pipe{ - {fromPos: 0, toPos: 0, fromSha: "a1", toSha: "a2", kind: TERMINATES, style: red}, - {fromPos: 0, toPos: 0, fromSha: "a2", toSha: "a3", kind: STARTS, style: yellow}, - {fromPos: 0, toPos: 3, fromSha: "a2", toSha: "d3", kind: STARTS, style: yellow}, - {fromPos: 1, toPos: 1, fromSha: "b1", toSha: "b3", kind: CONTINUES, style: magenta}, - {fromPos: 2, toPos: 2, fromSha: "c1", toSha: "c3", kind: CONTINUES, style: green}, + {fromPos: 0, toPos: 0, fromHash: "a1", toHash: "a2", kind: TERMINATES, style: red}, + {fromPos: 0, toPos: 0, fromHash: "a2", toHash: "a3", kind: STARTS, style: yellow}, + {fromPos: 0, toPos: 3, fromHash: "a2", toHash: "d3", kind: STARTS, style: yellow}, + {fromPos: 1, toPos: 1, fromHash: "b1", toHash: "b3", kind: CONTINUES, style: magenta}, + {fromPos: 2, toPos: 2, fromHash: "c1", toHash: "c3", kind: CONTINUES, style: green}, }, - prevCommit: &models.Commit{Sha: "a1"}, + prevCommit: &models.Commit{Hash: "a1"}, expectedStr: "⏣─│─│─╮", expectedStyles: []style.TextStyle{ yellow, yellow, magenta, yellow, green, yellow, yellow, @@ -370,13 +370,13 @@ func TestRenderPipeSet(t *testing.T) { { name: "starting and terminating path crossing continuing path", pipes: []*Pipe{ - {fromPos: 0, toPos: 0, fromSha: "a1", toSha: "a2", kind: TERMINATES, style: red}, - {fromPos: 0, toPos: 0, fromSha: "a2", toSha: "a3", kind: STARTS, style: yellow}, - {fromPos: 0, toPos: 1, fromSha: "a2", toSha: "b3", kind: STARTS, style: yellow}, - {fromPos: 1, toPos: 1, fromSha: "b1", toSha: "a2", kind: CONTINUES, style: green}, - {fromPos: 2, toPos: 0, fromSha: "c1", toSha: "a2", kind: TERMINATES, style: magenta}, + {fromPos: 0, toPos: 0, fromHash: "a1", toHash: "a2", kind: TERMINATES, style: red}, + {fromPos: 0, toPos: 0, fromHash: "a2", toHash: "a3", kind: STARTS, style: yellow}, + {fromPos: 0, toPos: 1, fromHash: "a2", toHash: "b3", kind: STARTS, style: yellow}, + {fromPos: 1, toPos: 1, fromHash: "b1", toHash: "a2", kind: CONTINUES, style: green}, + {fromPos: 2, toPos: 0, fromHash: "c1", toHash: "a2", kind: TERMINATES, style: magenta}, }, - prevCommit: &models.Commit{Sha: "a1"}, + prevCommit: &models.Commit{Hash: "a1"}, expectedStr: "⏣─│─╯", expectedStyles: []style.TextStyle{ yellow, yellow, green, magenta, magenta, @@ -385,13 +385,13 @@ func TestRenderPipeSet(t *testing.T) { { name: "another clash of starting and terminating paths", pipes: []*Pipe{ - {fromPos: 0, toPos: 0, fromSha: "a1", toSha: "a2", kind: TERMINATES, style: red}, - {fromPos: 0, toPos: 0, fromSha: "a2", toSha: "a3", kind: STARTS, style: yellow}, - {fromPos: 0, toPos: 1, fromSha: "a2", toSha: "b3", kind: STARTS, style: yellow}, - {fromPos: 2, toPos: 2, fromSha: "c1", toSha: "c3", kind: CONTINUES, style: green}, - {fromPos: 3, toPos: 0, fromSha: "d1", toSha: "a2", kind: TERMINATES, style: magenta}, + {fromPos: 0, toPos: 0, fromHash: "a1", toHash: "a2", kind: TERMINATES, style: red}, + {fromPos: 0, toPos: 0, fromHash: "a2", toHash: "a3", kind: STARTS, style: yellow}, + {fromPos: 0, toPos: 1, fromHash: "a2", toHash: "b3", kind: STARTS, style: yellow}, + {fromPos: 2, toPos: 2, fromHash: "c1", toHash: "c3", kind: CONTINUES, style: green}, + {fromPos: 3, toPos: 0, fromHash: "d1", toHash: "a2", kind: TERMINATES, style: magenta}, }, - prevCommit: &models.Commit{Sha: "a1"}, + prevCommit: &models.Commit{Hash: "a1"}, expectedStr: "⏣─┬─│─╯", expectedStyles: []style.TextStyle{ yellow, yellow, yellow, magenta, green, magenta, magenta, @@ -400,10 +400,10 @@ func TestRenderPipeSet(t *testing.T) { { name: "commit whose previous commit is selected", pipes: []*Pipe{ - {fromPos: 0, toPos: 0, fromSha: "selected", toSha: "a2", kind: TERMINATES, style: red}, - {fromPos: 0, toPos: 0, fromSha: "a2", toSha: "a3", kind: STARTS, style: yellow}, + {fromPos: 0, toPos: 0, fromHash: "selected", toHash: "a2", kind: TERMINATES, style: red}, + {fromPos: 0, toPos: 0, fromHash: "a2", toHash: "a3", kind: STARTS, style: yellow}, }, - prevCommit: &models.Commit{Sha: "selected"}, + prevCommit: &models.Commit{Hash: "selected"}, expectedStr: "◯", expectedStyles: []style.TextStyle{ yellow, @@ -412,10 +412,10 @@ func TestRenderPipeSet(t *testing.T) { { name: "commit whose previous commit is selected and is a merge commit", pipes: []*Pipe{ - {fromPos: 0, toPos: 0, fromSha: "selected", toSha: "a2", kind: TERMINATES, style: red}, - {fromPos: 1, toPos: 1, fromSha: "selected", toSha: "b3", kind: CONTINUES, style: red}, + {fromPos: 0, toPos: 0, fromHash: "selected", toHash: "a2", kind: TERMINATES, style: red}, + {fromPos: 1, toPos: 1, fromHash: "selected", toHash: "b3", kind: CONTINUES, style: red}, }, - prevCommit: &models.Commit{Sha: "selected"}, + prevCommit: &models.Commit{Hash: "selected"}, expectedStr: "◯ │", expectedStyles: []style.TextStyle{ highlightStyle, nothing, highlightStyle, @@ -424,11 +424,11 @@ func TestRenderPipeSet(t *testing.T) { { name: "commit whose previous commit is selected and is a merge commit, with continuing pipe inbetween", pipes: []*Pipe{ - {fromPos: 0, toPos: 0, fromSha: "selected", toSha: "a2", kind: TERMINATES, style: red}, - {fromPos: 1, toPos: 1, fromSha: "z1", toSha: "z3", kind: CONTINUES, style: green}, - {fromPos: 2, toPos: 2, fromSha: "selected", toSha: "b3", kind: CONTINUES, style: red}, + {fromPos: 0, toPos: 0, fromHash: "selected", toHash: "a2", kind: TERMINATES, style: red}, + {fromPos: 1, toPos: 1, fromHash: "z1", toHash: "z3", kind: CONTINUES, style: green}, + {fromPos: 2, toPos: 2, fromHash: "selected", toHash: "b3", kind: CONTINUES, style: red}, }, - prevCommit: &models.Commit{Sha: "selected"}, + prevCommit: &models.Commit{Hash: "selected"}, expectedStr: "◯ │ │", expectedStyles: []style.TextStyle{ highlightStyle, nothing, green, nothing, highlightStyle, @@ -437,12 +437,12 @@ func TestRenderPipeSet(t *testing.T) { { name: "when previous commit is selected, not a merge commit, and spawns a continuing pipe", pipes: []*Pipe{ - {fromPos: 0, toPos: 0, fromSha: "a1", toSha: "a2", kind: TERMINATES, style: red}, - {fromPos: 0, toPos: 0, fromSha: "a2", toSha: "a3", kind: STARTS, style: green}, - {fromPos: 0, toPos: 1, fromSha: "a2", toSha: "b3", kind: STARTS, style: green}, - {fromPos: 1, toPos: 0, fromSha: "selected", toSha: "a2", kind: TERMINATES, style: yellow}, + {fromPos: 0, toPos: 0, fromHash: "a1", toHash: "a2", kind: TERMINATES, style: red}, + {fromPos: 0, toPos: 0, fromHash: "a2", toHash: "a3", kind: STARTS, style: green}, + {fromPos: 0, toPos: 1, fromHash: "a2", toHash: "b3", kind: STARTS, style: green}, + {fromPos: 1, toPos: 0, fromHash: "selected", toHash: "a2", kind: TERMINATES, style: yellow}, }, - prevCommit: &models.Commit{Sha: "selected"}, + prevCommit: &models.Commit{Hash: "selected"}, expectedStr: "⏣─╯", expectedStyles: []style.TextStyle{ highlightStyle, highlightStyle, highlightStyle, @@ -483,43 +483,43 @@ func TestGetNextPipes(t *testing.T) { }{ { prevPipes: []*Pipe{ - {fromPos: 0, toPos: 0, fromSha: "a", toSha: "b", kind: STARTS, style: style.FgDefault}, + {fromPos: 0, toPos: 0, fromHash: "a", toHash: "b", kind: STARTS, style: style.FgDefault}, }, commit: &models.Commit{ - Sha: "b", + Hash: "b", Parents: []string{"c"}, }, expected: []*Pipe{ - {fromPos: 0, toPos: 0, fromSha: "a", toSha: "b", kind: TERMINATES, style: style.FgDefault}, - {fromPos: 0, toPos: 0, fromSha: "b", toSha: "c", kind: STARTS, style: style.FgDefault}, + {fromPos: 0, toPos: 0, fromHash: "a", toHash: "b", kind: TERMINATES, style: style.FgDefault}, + {fromPos: 0, toPos: 0, fromHash: "b", toHash: "c", kind: STARTS, style: style.FgDefault}, }, }, { prevPipes: []*Pipe{ - {fromPos: 0, toPos: 0, fromSha: "a", toSha: "b", kind: TERMINATES, style: style.FgDefault}, - {fromPos: 0, toPos: 0, fromSha: "b", toSha: "c", kind: STARTS, style: style.FgDefault}, - {fromPos: 0, toPos: 1, fromSha: "b", toSha: "d", kind: STARTS, style: style.FgDefault}, + {fromPos: 0, toPos: 0, fromHash: "a", toHash: "b", kind: TERMINATES, style: style.FgDefault}, + {fromPos: 0, toPos: 0, fromHash: "b", toHash: "c", kind: STARTS, style: style.FgDefault}, + {fromPos: 0, toPos: 1, fromHash: "b", toHash: "d", kind: STARTS, style: style.FgDefault}, }, commit: &models.Commit{ - Sha: "d", + Hash: "d", Parents: []string{"e"}, }, expected: []*Pipe{ - {fromPos: 0, toPos: 0, fromSha: "b", toSha: "c", kind: CONTINUES, style: style.FgDefault}, - {fromPos: 1, toPos: 1, fromSha: "b", toSha: "d", kind: TERMINATES, style: style.FgDefault}, - {fromPos: 1, toPos: 1, fromSha: "d", toSha: "e", kind: STARTS, style: style.FgDefault}, + {fromPos: 0, toPos: 0, fromHash: "b", toHash: "c", kind: CONTINUES, style: style.FgDefault}, + {fromPos: 1, toPos: 1, fromHash: "b", toHash: "d", kind: TERMINATES, style: style.FgDefault}, + {fromPos: 1, toPos: 1, fromHash: "d", toHash: "e", kind: STARTS, style: style.FgDefault}, }, }, { prevPipes: []*Pipe{ - {fromPos: 0, toPos: 0, fromSha: "a", toSha: "root", kind: TERMINATES, style: style.FgDefault}, + {fromPos: 0, toPos: 0, fromHash: "a", toHash: "root", kind: TERMINATES, style: style.FgDefault}, }, commit: &models.Commit{ - Sha: "root", + Hash: "root", Parents: []string{}, }, expected: []*Pipe{ - {fromPos: 1, toPos: 1, fromSha: "root", toSha: models.EmptyTreeCommitHash, kind: STARTS, style: style.FgDefault}, + {fromPos: 1, toPos: 1, fromHash: "root", toHash: models.EmptyTreeCommitHash, kind: STARTS, style: style.FgDefault}, }, }, } @@ -557,7 +557,7 @@ func BenchmarkRenderCommitGraph(b *testing.B) { func generateCommits(count int) []*models.Commit { rnd := rand.New(rand.NewSource(1234)) - pool := []*models.Commit{{Sha: "a", AuthorName: "A"}} + pool := []*models.Commit{{Hash: "a", AuthorName: "A"}} commits := make([]*models.Commit, 0, count) authorPool := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"} for len(commits) < count { @@ -574,12 +574,12 @@ func generateCommits(count int) []*models.Commit { newParent = pool[j] } else { newParent = &models.Commit{ - Sha: fmt.Sprintf("%s%d", currentCommit.Sha, j), + Hash: fmt.Sprintf("%s%d", currentCommit.Hash, j), AuthorName: authorPool[rnd.Intn(len(authorPool))], } pool = append(pool, newParent) } - currentCommit.Parents = append(currentCommit.Parents, newParent.Sha) + currentCommit.Parents = append(currentCommit.Parents, newParent.Hash) } commits = append(commits, currentCommit) diff --git a/pkg/gui/presentation/reflog_commits.go b/pkg/gui/presentation/reflog_commits.go index e38a0112643..b520521cc74 100644 --- a/pkg/gui/presentation/reflog_commits.go +++ b/pkg/gui/presentation/reflog_commits.go @@ -21,8 +21,8 @@ func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription } return lo.Map(commits, func(commit *models.Commit, _ int) []string { - diffed := commit.Sha == diffName - cherryPicked := cherryPickedCommitHashSet.Includes(commit.Sha) + diffed := commit.Hash == diffName + cherryPicked := cherryPickedCommitHashSet.Includes(commit.Hash) return displayFunc(commit, reflogCommitDisplayAttributes{ cherryPicked: cherryPicked, diff --git a/pkg/utils/rebase_todo.go b/pkg/utils/rebase_todo.go index f2b60a09769..20db7f8d1e3 100644 --- a/pkg/utils/rebase_todo.go +++ b/pkg/utils/rebase_todo.go @@ -11,7 +11,7 @@ import ( ) type Todo struct { - Sha string // for todos that have one, e.g. pick, drop, fixup, etc. + Hash string // for todos that have one, e.g. pick, drop, fixup, etc. Ref string // for update-ref todos Action todo.TodoCommand } @@ -20,7 +20,7 @@ type Todo struct { // because sometimes the same sha appears multiple times in the file (e.g. in a pick // and later in a merge) type TodoChange struct { - Sha string + Hash string OldAction todo.TodoCommand NewAction todo.TodoCommand } @@ -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.Sha) { + if t.Command == change.OldAction && equalShas(t.Commit, change.Hash) { matchCount++ t.Command = change.NewAction } @@ -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.Sha) && + equalShas(t.Commit, todoToFind.Hash) && t.Ref == todoToFind.Ref }) return idx, ok @@ -136,7 +136,7 @@ func deleteTodos(todos []todo.Todo, todosToDelete []Todo) ([]todo.Todo, error) { if !ok { // Should never happen - return []todo.Todo{}, fmt.Errorf("Todo %s not found in git-rebase-todo", todoToDelete.Sha) + return []todo.Todo{}, fmt.Errorf("Todo %s not found in git-rebase-todo", todoToDelete.Hash) } todos = Remove(todos, idx) @@ -184,7 +184,7 @@ func moveTodoUp(todos []todo.Todo, todoToMove Todo) ([]todo.Todo, error) { if !ok { // Should never happen - return []todo.Todo{}, fmt.Errorf("Todo %s not found in git-rebase-todo", todoToMove.Sha) + return []todo.Todo{}, fmt.Errorf("Todo %s not found in git-rebase-todo", todoToMove.Hash) } // The todos are ordered backwards compared to our model commits, so diff --git a/pkg/utils/rebase_todo_test.go b/pkg/utils/rebase_todo_test.go index fd87d7c7ca9..c75d6d786d1 100644 --- a/pkg/utils/rebase_todo_test.go +++ b/pkg/utils/rebase_todo_test.go @@ -25,7 +25,7 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) { {Command: todo.Pick, Commit: "5678"}, {Command: todo.Pick, Commit: "abcd"}, }, - todoToMoveDown: Todo{Sha: "5678", Action: todo.Pick}, + todoToMoveDown: Todo{Hash: "5678", Action: todo.Pick}, expectedErr: "", expectedTodos: []todo.Todo{ {Command: todo.Pick, Commit: "5678"}, @@ -40,7 +40,7 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) { {Command: todo.Pick, Commit: "5678"}, {Command: todo.Pick, Commit: "abcd"}, }, - todoToMoveDown: Todo{Sha: "abcd", Action: todo.Pick}, + todoToMoveDown: Todo{Hash: "abcd", Action: todo.Pick}, expectedErr: "", expectedTodos: []todo.Todo{ {Command: todo.Pick, Commit: "1234"}, @@ -72,7 +72,7 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) { {Command: todo.Pick, Commit: "5678"}, {Command: todo.Pick, Commit: "def0"}, }, - todoToMoveDown: Todo{Sha: "5678", Action: todo.Pick}, + todoToMoveDown: Todo{Hash: "5678", Action: todo.Pick}, expectedErr: "", expectedTodos: []todo.Todo{ {Command: todo.Pick, Commit: "1234"}, @@ -91,7 +91,7 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) { {Command: todo.Pick, Commit: "5678"}, {Command: todo.Pick, Commit: "abcd"}, }, - todoToMoveDown: Todo{Sha: "def0", Action: todo.Pick}, + todoToMoveDown: Todo{Hash: "def0", Action: todo.Pick}, expectedErr: "Todo def0 not found in git-rebase-todo", expectedTodos: []todo.Todo{}, }, @@ -102,7 +102,7 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) { {Command: todo.Pick, Commit: "5678"}, {Command: todo.Pick, Commit: "abcd"}, }, - todoToMoveDown: Todo{Sha: "1234", Action: todo.Pick}, + todoToMoveDown: Todo{Hash: "1234", Action: todo.Pick}, expectedErr: "Destination position for moving todo is out of range", expectedTodos: []todo.Todo{}, }, @@ -114,7 +114,7 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) { {Command: todo.Pick, Commit: "1234"}, {Command: todo.Pick, Commit: "5678"}, }, - todoToMoveDown: Todo{Sha: "1234", Action: todo.Pick}, + todoToMoveDown: Todo{Hash: "1234", Action: todo.Pick}, expectedErr: "Destination position for moving todo is out of range", expectedTodos: []todo.Todo{}, }, @@ -151,7 +151,7 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) { {Command: todo.Pick, Commit: "5678"}, {Command: todo.Pick, Commit: "abcd"}, }, - todoToMoveUp: Todo{Sha: "5678", Action: todo.Pick}, + todoToMoveUp: Todo{Hash: "5678", Action: todo.Pick}, expectedErr: "", expectedTodos: []todo.Todo{ {Command: todo.Pick, Commit: "1234"}, @@ -166,7 +166,7 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) { {Command: todo.Pick, Commit: "5678"}, {Command: todo.Pick, Commit: "abcd"}, }, - todoToMoveUp: Todo{Sha: "1234", Action: todo.Pick}, + todoToMoveUp: Todo{Hash: "1234", Action: todo.Pick}, expectedErr: "", expectedTodos: []todo.Todo{ {Command: todo.Pick, Commit: "5678"}, @@ -198,7 +198,7 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) { {Command: todo.Pick, Commit: "5678"}, {Command: todo.Pick, Commit: "def0"}, }, - todoToMoveUp: Todo{Sha: "abcd", Action: todo.Pick}, + todoToMoveUp: Todo{Hash: "abcd", Action: todo.Pick}, expectedErr: "", expectedTodos: []todo.Todo{ {Command: todo.Pick, Commit: "1234"}, @@ -217,7 +217,7 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) { {Command: todo.Pick, Commit: "5678"}, {Command: todo.Pick, Commit: "abcd"}, }, - todoToMoveUp: Todo{Sha: "def0", Action: todo.Pick}, + todoToMoveUp: Todo{Hash: "def0", Action: todo.Pick}, expectedErr: "Todo def0 not found in git-rebase-todo", expectedTodos: []todo.Todo{}, }, @@ -228,7 +228,7 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) { {Command: todo.Pick, Commit: "5678"}, {Command: todo.Pick, Commit: "abcd"}, }, - todoToMoveUp: Todo{Sha: "abcd", Action: todo.Pick}, + todoToMoveUp: Todo{Hash: "abcd", Action: todo.Pick}, expectedErr: "Destination position for moving todo is out of range", expectedTodos: []todo.Todo{}, }, @@ -240,7 +240,7 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) { {Command: todo.Label, Label: "myLabel"}, {Command: todo.Reset, Label: "otherlabel"}, }, - todoToMoveUp: Todo{Sha: "5678", Action: todo.Pick}, + todoToMoveUp: Todo{Hash: "5678", Action: todo.Pick}, expectedErr: "Destination position for moving todo is out of range", expectedTodos: []todo.Todo{}, }, @@ -264,8 +264,8 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) { scenarios := []struct { name string todos []todo.Todo - originalSha string - fixupSha string + originalHash string + fixupHash string expectedTodos []todo.Todo expectedErr error }{ @@ -275,8 +275,8 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) { {Command: todo.Pick, Commit: "original"}, {Command: todo.Pick, Commit: "fixup"}, }, - originalSha: "original", - fixupSha: "fixup", + originalHash: "original", + fixupHash: "fixup", expectedTodos: []todo.Todo{ {Command: todo.Pick, Commit: "original"}, {Command: todo.Fixup, Commit: "fixup"}, @@ -291,8 +291,8 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) { {Command: todo.Pick, Commit: "other"}, {Command: todo.Pick, Commit: "fixup"}, }, - originalSha: "original", - fixupSha: "fixup", + originalHash: "original", + fixupHash: "fixup", expectedTodos: []todo.Todo{ {Command: todo.Pick, Commit: "original"}, {Command: todo.Fixup, Commit: "fixup"}, @@ -307,8 +307,8 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) { {Command: todo.Pick, Commit: "original"}, {Command: todo.Pick, Commit: "fixup"}, }, - originalSha: "original", - fixupSha: "fixup", + originalHash: "original", + fixupHash: "fixup", expectedTodos: nil, expectedErr: errors.New("Expected exactly one original SHA, found 2"), }, @@ -319,8 +319,8 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) { {Command: todo.Pick, Commit: "fixup"}, {Command: todo.Pick, Commit: "fixup"}, }, - originalSha: "original", - fixupSha: "fixup", + originalHash: "original", + fixupHash: "fixup", expectedTodos: nil, expectedErr: errors.New("Expected exactly one fixup SHA, found 2"), }, @@ -329,8 +329,8 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) { todos: []todo.Todo{ {Command: todo.Pick, Commit: "original"}, }, - originalSha: "original", - fixupSha: "fixup", + originalHash: "original", + fixupHash: "fixup", expectedTodos: nil, expectedErr: errors.New("Expected exactly one fixup SHA, found 0"), }, @@ -339,8 +339,8 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) { todos: []todo.Todo{ {Command: todo.Pick, Commit: "fixup"}, }, - originalSha: "original", - fixupSha: "fixup", + originalHash: "original", + fixupHash: "fixup", expectedTodos: nil, expectedErr: errors.New("Expected exactly one original SHA, found 0"), }, @@ -348,7 +348,7 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) { for _, scenario := range scenarios { t.Run(scenario.name, func(t *testing.T) { - actualTodos, actualErr := moveFixupCommitDown(scenario.todos, scenario.originalSha, scenario.fixupSha) + actualTodos, actualErr := moveFixupCommitDown(scenario.todos, scenario.originalHash, scenario.fixupHash) if scenario.expectedErr == nil { assert.NoError(t, actualErr) @@ -379,7 +379,7 @@ func TestRebaseCommands_deleteTodos(t *testing.T) { }, todosToDelete: []Todo{ {Ref: "refs/heads/some_branch", Action: todo.UpdateRef}, - {Sha: "abcd", Action: todo.Pick}, + {Hash: "abcd", Action: todo.Pick}, }, expectedTodos: []todo.Todo{ {Command: todo.Pick, Commit: "1234"}, @@ -394,7 +394,7 @@ func TestRebaseCommands_deleteTodos(t *testing.T) { {Command: todo.Pick, Commit: "5678"}, }, todosToDelete: []Todo{ - {Sha: "abcd", Action: todo.Pick}, + {Hash: "abcd", Action: todo.Pick}, }, expectedTodos: []todo.Todo{}, expectedErr: errors.New("Todo abcd not found in git-rebase-todo"), From 92aab21d3af6c84ee9142bb7eb8e8d00d4157831 Mon Sep 17 00:00:00 2001 From: pikomonde <32364823+pikomonde@users.noreply.github.com> Date: Thu, 21 Mar 2024 00:45:04 +0700 Subject: [PATCH 04/15] rename sha to hash 2 --- pkg/commands/git_commands/bisect.go | 4 ++-- pkg/commands/git_commands/bisect_info.go | 14 +++++++------- pkg/gui/controllers/bisect_controller.go | 12 ++++++------ pkg/gui/controllers/helpers/refresh_helper.go | 8 ++++---- pkg/gui/presentation/commits.go | 4 ++-- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pkg/commands/git_commands/bisect.go b/pkg/commands/git_commands/bisect.go index 6d1d8853004..61fe7a641f1 100644 --- a/pkg/commands/git_commands/bisect.go +++ b/pkg/commands/git_commands/bisect.go @@ -143,7 +143,7 @@ func (self *BisectCommands) IsDone() (bool, []string, error) { return false, nil, nil } - newSha := info.GetNewSha() + newSha := info.GetNewHash() if newSha == "" { return false, nil, nil } @@ -185,7 +185,7 @@ func (self *BisectCommands) IsDone() (bool, []string, error) { // render the commits from the bad commit. func (self *BisectCommands) ReachableFromStart(bisectInfo *BisectInfo) bool { cmdArgs := NewGitCmd("merge-base"). - Arg("--is-ancestor", bisectInfo.GetNewSha(), bisectInfo.GetStartSha()). + Arg("--is-ancestor", bisectInfo.GetNewHash(), bisectInfo.GetStartHash()). ToArgv() err := self.cmd.New(cmdArgs).DontLog().Run() diff --git a/pkg/commands/git_commands/bisect_info.go b/pkg/commands/git_commands/bisect_info.go index 39bd449492d..c49d6866f70 100644 --- a/pkg/commands/git_commands/bisect_info.go +++ b/pkg/commands/git_commands/bisect_info.go @@ -32,7 +32,7 @@ type BisectInfo struct { // map of commit hashes to their status statusMap map[string]BisectStatus - // the sha of the commit that's under test + // the hash of the commit that's under test current string } @@ -49,21 +49,21 @@ func NewNullBisectInfo() *BisectInfo { return &BisectInfo{started: false} } -func (self *BisectInfo) GetNewSha() string { - for sha, status := range self.statusMap { +func (self *BisectInfo) GetNewHash() string { + for hash, status := range self.statusMap { if status == BisectStatusNew { - return sha + return hash } } return "" } -func (self *BisectInfo) GetCurrentSha() string { +func (self *BisectInfo) GetCurrentHash() string { return self.current } -func (self *BisectInfo) GetStartSha() string { +func (self *BisectInfo) GetStartHash() string { return self.start } @@ -93,7 +93,7 @@ func (self *BisectInfo) Bisecting() bool { return false } - if self.GetNewSha() == "" { + if self.GetNewHash() == "" { return false } diff --git a/pkg/gui/controllers/bisect_controller.go b/pkg/gui/controllers/bisect_controller.go index 8e9bd77dfb5..4fc2ec77252 100644 --- a/pkg/gui/controllers/bisect_controller.go +++ b/pkg/gui/controllers/bisect_controller.go @@ -69,7 +69,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c // Originally we were allowing the user to, from the bisect menu, select whether // they were talking about the selected commit or the current bisect commit, // and that was a bit confusing (and required extra keypresses). - selectCurrentAfter := info.GetCurrentSha() == "" || info.GetCurrentSha() == commit.Hash + selectCurrentAfter := info.GetCurrentHash() == "" || info.GetCurrentHash() == commit.Hash // we need to wait to reselect if our bisect commits aren't ancestors of our 'start' // ref, because we'll be reloading our commits in that case. waitToReselect := selectCurrentAfter && !self.c.Git().Bisect.ReachableFromStart(info) @@ -78,8 +78,8 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c // not, we're still picking the initial commits before we really start, so // use the selected commit in that case. - bisecting := info.GetCurrentSha() != "" - shaToMark := lo.Ternary(bisecting, info.GetCurrentSha(), commit.Hash) + bisecting := info.GetCurrentHash() != "" + shaToMark := lo.Ternary(bisecting, info.GetCurrentHash(), commit.Hash) shortShaToMark := utils.ShortSha(shaToMark) // For marking a commit as bad, when we're not already bisecting, we require @@ -131,7 +131,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c Key: 's', }, } - if info.GetCurrentSha() != "" && info.GetCurrentSha() != commit.Hash { + if info.GetCurrentHash() != "" && info.GetCurrentHash() != commit.Hash { menuItems = append(menuItems, lo.ToPtr(types.MenuItem{ Label: fmt.Sprintf(self.c.Tr.Bisect.SkipSelected, commit.ShortSha()), OnPress: func() error { @@ -284,10 +284,10 @@ func (self *BisectController) afterBisectMarkRefresh(selectCurrent bool, waitToR func (self *BisectController) selectCurrentBisectCommit() { info := self.c.Git().Bisect.GetInfo() - if info.GetCurrentSha() != "" { + if info.GetCurrentHash() != "" { // find index of commit with that sha, move cursor to that. for i, commit := range self.c.Model().Commits { - if commit.Hash == info.GetCurrentSha() { + if commit.Hash == info.GetCurrentHash() { self.context().SetSelection(i) _ = self.context().HandleFocus(types.OnFocusOpts{}) break diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index a2c01e15ddb..34e390bde6e 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -290,10 +290,10 @@ func (self *RefreshHelper) determineCheckedOutBranchName() string { return strings.TrimPrefix(rebasedBranch, "refs/heads/") } - if bisectInfo := self.c.Git().Bisect.GetInfo(); bisectInfo.Bisecting() && bisectInfo.GetStartSha() != "" { + if bisectInfo := self.c.Git().Bisect.GetInfo(); bisectInfo.Bisecting() && bisectInfo.GetStartHash() != "" { // Likewise, when we're bisecting we're on a detached head as well. In // this case we read the branch name from the ".git/BISECT_START" file. - return bisectInfo.GetStartSha() + return bisectInfo.GetStartHash() } // In all other cases, get the branch name by asking git what branch is @@ -721,10 +721,10 @@ func (self *RefreshHelper) refForLog() string { // need to see if our bisect's current commit is reachable from our 'new' ref. if bisectInfo.Bisecting() && !self.c.Git().Bisect.ReachableFromStart(bisectInfo) { - return bisectInfo.GetNewSha() + return bisectInfo.GetNewHash() } - return bisectInfo.GetStartSha() + return bisectInfo.GetStartHash() } func (self *RefreshHelper) refreshView(context types.Context) error { diff --git a/pkg/gui/presentation/commits.go b/pkg/gui/presentation/commits.go index a46911f4eca..8823d508ea2 100644 --- a/pkg/gui/presentation/commits.go +++ b/pkg/gui/presentation/commits.go @@ -172,7 +172,7 @@ func getbisectBounds(commits []*models.Commit, bisectInfo *git_commands.BisectIn bisectBounds := &bisectBounds{} for i, commit := range commits { - if commit.Hash == bisectInfo.GetNewSha() { + if commit.Hash == bisectInfo.GetNewHash() { bisectBounds.newIndex = i } @@ -241,7 +241,7 @@ func getBisectStatus(index int, commitHash string, bisectInfo *git_commands.Bise return BisectStatusNone } - if bisectInfo.GetCurrentSha() == commitHash { + if bisectInfo.GetCurrentHash() == commitHash { return BisectStatusCurrent } From 13af335b377a5c646f664669f3ede44377a921f0 Mon Sep 17 00:00:00 2001 From: pikomonde <32364823+pikomonde@users.noreply.github.com> Date: Thu, 21 Mar 2024 01:27:33 +0700 Subject: [PATCH 05/15] rename sha to hash 3 --- pkg/commands/git_commands/commit.go | 12 ++++++------ pkg/gui/context/local_commits_context.go | 4 ++-- pkg/gui/context/reflog_commits_context.go | 2 +- pkg/gui/context/sub_commits_context.go | 2 +- pkg/gui/controllers/helpers/cherry_pick_helper.go | 2 +- pkg/gui/controllers/helpers/fixup_helper.go | 10 +++++----- .../controllers/helpers/merge_and_rebase_helper.go | 6 +++--- pkg/gui/controllers/local_commits_controller.go | 6 +++--- pkg/gui/modes/cherrypicking/cherry_picking.go | 14 +++++++------- .../modes/marked_base_commit/marked_base_commit.go | 4 ++-- pkg/utils/rebase_todo.go | 10 +++++----- 11 files changed, 36 insertions(+), 36 deletions(-) diff --git a/pkg/commands/git_commands/commit.go b/pkg/commands/git_commands/commit.go index 61b6cc2a153..05ab8d36bfc 100644 --- a/pkg/commands/git_commands/commit.go +++ b/pkg/commands/git_commands/commit.go @@ -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() diff --git a/pkg/gui/context/local_commits_context.go b/pkg/gui/context/local_commits_context.go index 0b168cad5d4..d3fc6e240b8 100644 --- a/pkg/gui/context/local_commits_context.go +++ b/pkg/gui/context/local_commits_context.go @@ -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(), diff --git a/pkg/gui/context/reflog_commits_context.go b/pkg/gui/context/reflog_commits_context.go index 65137d633d2..5b3c72360f8 100644 --- a/pkg/gui/context/reflog_commits_context.go +++ b/pkg/gui/context/reflog_commits_context.go @@ -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, diff --git a/pkg/gui/context/sub_commits_context.go b/pkg/gui/context/sub_commits_context.go index 0dc2cd39b06..b37be8667e9 100644 --- a/pkg/gui/context/sub_commits_context.go +++ b/pkg/gui/context/sub_commits_context.go @@ -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, diff --git a/pkg/gui/controllers/helpers/cherry_pick_helper.go b/pkg/gui/controllers/helpers/cherry_pick_helper.go index 0095a1d2a19..6742bd79a77 100644 --- a/pkg/gui/controllers/helpers/cherry_pick_helper.go +++ b/pkg/gui/controllers/helpers/cherry_pick_helper.go @@ -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) diff --git a/pkg/gui/controllers/helpers/fixup_helper.go b/pkg/gui/controllers/helpers/fixup_helper.go index e7c7bf7d804..5be1ba83ff8 100644 --- a/pkg/gui/controllers/helpers/fixup_helper.go +++ b/pkg/gui/controllers/helpers/fixup_helper.go @@ -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 diff --git a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go index 1fe6738e3c3..16b1eea2b08 100644 --- a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go +++ b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go @@ -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{ diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index c6bde3745f7..e33d7802203 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -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) } diff --git a/pkg/gui/modes/cherrypicking/cherry_picking.go b/pkg/gui/modes/cherrypicking/cherry_picking.go index be4177f4166..4e76cbd094e 100644 --- a/pkg/gui/modes/cherrypicking/cherry_picking.go +++ b/pkg/gui/modes/cherrypicking/cherry_picking.go @@ -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 { diff --git a/pkg/gui/modes/marked_base_commit/marked_base_commit.go b/pkg/gui/modes/marked_base_commit/marked_base_commit.go index 516dd0f2f0a..3a239235d59 100644 --- a/pkg/gui/modes/marked_base_commit/marked_base_commit.go +++ b/pkg/gui/modes/marked_base_commit/marked_base_commit.go @@ -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 } diff --git a/pkg/utils/rebase_todo.go b/pkg/utils/rebase_todo.go index 20db7f8d1e3..ee5e3d65646 100644 --- a/pkg/utils/rebase_todo.go +++ b/pkg/utils/rebase_todo.go @@ -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) From dc6863b83d5d0a1343ef1e42601ce3dfaf2b60d8 Mon Sep 17 00:00:00 2001 From: pikomonde <32364823+pikomonde@users.noreply.github.com> Date: Thu, 21 Mar 2024 01:43:31 +0700 Subject: [PATCH 06/15] rename sha to hash 4 --- pkg/gui/presentation/commits_test.go | 210 +++++++++++++-------------- 1 file changed, 105 insertions(+), 105 deletions(-) diff --git a/pkg/gui/presentation/commits_test.go b/pkg/gui/presentation/commits_test.go index 5c0100ea035..8f43da50d98 100644 --- a/pkg/gui/presentation/commits_test.go +++ b/pkg/gui/presentation/commits_test.go @@ -58,8 +58,8 @@ func TestGetCommitListDisplayStrings(t *testing.T) { { testName: "some commits", commits: []*models.Commit{ - {Name: "commit1", Hash: "sha1"}, - {Name: "commit2", Hash: "sha2"}, + {Name: "commit1", Hash: "hash1"}, + {Name: "commit2", Hash: "hash2"}, }, startIdx: 0, endIdx: 2, @@ -68,15 +68,15 @@ func TestGetCommitListDisplayStrings(t *testing.T) { cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` - sha1 commit1 - sha2 commit2 + hash1 commit1 + hash2 commit2 `), }, { testName: "commit with tags", commits: []*models.Commit{ - {Name: "commit1", Hash: "sha1", Tags: []string{"tag1", "tag2"}}, - {Name: "commit2", Hash: "sha2"}, + {Name: "commit1", Hash: "hash1", Tags: []string{"tag1", "tag2"}}, + {Name: "commit2", Hash: "hash2"}, }, startIdx: 0, endIdx: 2, @@ -85,23 +85,23 @@ func TestGetCommitListDisplayStrings(t *testing.T) { cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` - sha1 tag1 tag2 commit1 - sha2 commit2 + hash1 tag1 tag2 commit1 + hash2 commit2 `), }, { testName: "show local branch head, except the current branch, main branches, or merged branches", commits: []*models.Commit{ - {Name: "commit1", Hash: "sha1"}, - {Name: "commit2", Hash: "sha2"}, - {Name: "commit3", Hash: "sha3"}, - {Name: "commit4", Hash: "sha4", Status: models.StatusMerged}, + {Name: "commit1", Hash: "hash1"}, + {Name: "commit2", Hash: "hash2"}, + {Name: "commit3", Hash: "hash3"}, + {Name: "commit4", Hash: "hash4", Status: models.StatusMerged}, }, branches: []*models.Branch{ - {Name: "current-branch", CommitHash: "sha1", Head: true}, - {Name: "other-branch", CommitHash: "sha2", Head: false}, - {Name: "master", CommitHash: "sha3", Head: false}, - {Name: "old-branch", CommitHash: "sha4", Head: false}, + {Name: "current-branch", CommitHash: "hash1", Head: true}, + {Name: "other-branch", CommitHash: "hash2", Head: false}, + {Name: "master", CommitHash: "hash3", Head: false}, + {Name: "old-branch", CommitHash: "hash4", Head: false}, }, currentBranchName: "current-branch", hasUpdateRefConfig: true, @@ -112,21 +112,21 @@ func TestGetCommitListDisplayStrings(t *testing.T) { cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` - sha1 commit1 - sha2 * commit2 - sha3 commit3 - sha4 commit4 + hash1 commit1 + hash2 * commit2 + hash3 commit3 + hash4 commit4 `), }, { testName: "show local branch head for head commit if updateRefs is on", commits: []*models.Commit{ - {Name: "commit1", Hash: "sha1"}, - {Name: "commit2", Hash: "sha2"}, + {Name: "commit1", Hash: "hash1"}, + {Name: "commit2", Hash: "hash2"}, }, branches: []*models.Branch{ - {Name: "current-branch", CommitHash: "sha1", Head: true}, - {Name: "other-branch", CommitHash: "sha1", Head: false}, + {Name: "current-branch", CommitHash: "hash1", Head: true}, + {Name: "other-branch", CommitHash: "hash1", Head: false}, }, currentBranchName: "current-branch", hasUpdateRefConfig: true, @@ -137,19 +137,19 @@ func TestGetCommitListDisplayStrings(t *testing.T) { cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` - sha1 * commit1 - sha2 commit2 + hash1 * commit1 + hash2 commit2 `), }, { testName: "don't show local branch head for head commit if updateRefs is off", commits: []*models.Commit{ - {Name: "commit1", Hash: "sha1"}, - {Name: "commit2", Hash: "sha2"}, + {Name: "commit1", Hash: "hash1"}, + {Name: "commit2", Hash: "hash2"}, }, branches: []*models.Branch{ - {Name: "current-branch", CommitHash: "sha1", Head: true}, - {Name: "other-branch", CommitHash: "sha1", Head: false}, + {Name: "current-branch", CommitHash: "hash1", Head: true}, + {Name: "other-branch", CommitHash: "hash1", Head: false}, }, currentBranchName: "current-branch", hasUpdateRefConfig: false, @@ -160,19 +160,19 @@ func TestGetCommitListDisplayStrings(t *testing.T) { cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` - sha1 commit1 - sha2 commit2 + hash1 commit1 + hash2 commit2 `), }, { testName: "show local branch head and tag if both exist", commits: []*models.Commit{ - {Name: "commit1", Hash: "sha1"}, - {Name: "commit2", Hash: "sha2", Tags: []string{"some-tag"}}, - {Name: "commit3", Hash: "sha3"}, + {Name: "commit1", Hash: "hash1"}, + {Name: "commit2", Hash: "hash2", Tags: []string{"some-tag"}}, + {Name: "commit3", Hash: "hash3"}, }, branches: []*models.Branch{ - {Name: "some-branch", CommitHash: "sha2"}, + {Name: "some-branch", CommitHash: "hash2"}, }, startIdx: 0, endIdx: 3, @@ -181,19 +181,19 @@ func TestGetCommitListDisplayStrings(t *testing.T) { cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` - sha1 commit1 - sha2 * some-tag commit2 - sha3 commit3 + hash1 commit1 + hash2 * some-tag commit2 + hash3 commit3 `), }, { testName: "showing graph", commits: []*models.Commit{ - {Name: "commit1", Hash: "sha1", Parents: []string{"sha2", "sha3"}}, - {Name: "commit2", Hash: "sha2", Parents: []string{"sha3"}}, - {Name: "commit3", Hash: "sha3", Parents: []string{"sha4"}}, - {Name: "commit4", Hash: "sha4", Parents: []string{"sha5"}}, - {Name: "commit5", Hash: "sha5", Parents: []string{"sha7"}}, + {Name: "commit1", Hash: "hash1", Parents: []string{"hash2", "hash3"}}, + {Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}}, + {Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}}, + {Name: "commit4", Hash: "hash4", Parents: []string{"hash5"}}, + {Name: "commit5", Hash: "hash5", Parents: []string{"hash7"}}, }, startIdx: 0, endIdx: 5, @@ -202,21 +202,21 @@ func TestGetCommitListDisplayStrings(t *testing.T) { cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` - sha1 ⏣─╮ commit1 - sha2 ◯ │ commit2 - sha3 ◯─╯ commit3 - sha4 ◯ commit4 - sha5 ◯ commit5 + hash1 ⏣─╮ commit1 + hash2 ◯ │ commit2 + hash3 ◯─╯ commit3 + hash4 ◯ commit4 + hash5 ◯ commit5 `), }, { testName: "showing graph, including rebase commits", commits: []*models.Commit{ - {Name: "commit1", Hash: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick}, - {Name: "commit2", Hash: "sha2", Parents: []string{"sha3"}, Action: todo.Pick}, - {Name: "commit3", Hash: "sha3", Parents: []string{"sha4"}}, - {Name: "commit4", Hash: "sha4", Parents: []string{"sha5"}}, - {Name: "commit5", Hash: "sha5", Parents: []string{"sha7"}}, + {Name: "commit1", Hash: "hash1", Parents: []string{"hash2", "hash3"}, Action: todo.Pick}, + {Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}, Action: todo.Pick}, + {Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}}, + {Name: "commit4", Hash: "hash4", Parents: []string{"hash5"}}, + {Name: "commit5", Hash: "hash5", Parents: []string{"hash7"}}, }, startIdx: 0, endIdx: 5, @@ -226,21 +226,21 @@ func TestGetCommitListDisplayStrings(t *testing.T) { showYouAreHereLabel: true, now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` - sha1 pick commit1 - sha2 pick commit2 - sha3 ◯ <-- YOU ARE HERE --- commit3 - sha4 ◯ commit4 - sha5 ◯ commit5 + hash1 pick commit1 + hash2 pick commit2 + hash3 ◯ <-- YOU ARE HERE --- commit3 + hash4 ◯ commit4 + hash5 ◯ commit5 `), }, { testName: "showing graph, including rebase commits, with offset", commits: []*models.Commit{ - {Name: "commit1", Hash: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick}, - {Name: "commit2", Hash: "sha2", Parents: []string{"sha3"}, Action: todo.Pick}, - {Name: "commit3", Hash: "sha3", Parents: []string{"sha4"}}, - {Name: "commit4", Hash: "sha4", Parents: []string{"sha5"}}, - {Name: "commit5", Hash: "sha5", Parents: []string{"sha7"}}, + {Name: "commit1", Hash: "hash1", Parents: []string{"hash2", "hash3"}, Action: todo.Pick}, + {Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}, Action: todo.Pick}, + {Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}}, + {Name: "commit4", Hash: "hash4", Parents: []string{"hash5"}}, + {Name: "commit5", Hash: "hash5", Parents: []string{"hash7"}}, }, startIdx: 1, endIdx: 5, @@ -250,20 +250,20 @@ func TestGetCommitListDisplayStrings(t *testing.T) { showYouAreHereLabel: true, now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` - sha2 pick commit2 - sha3 ◯ <-- YOU ARE HERE --- commit3 - sha4 ◯ commit4 - sha5 ◯ commit5 + hash2 pick commit2 + hash3 ◯ <-- YOU ARE HERE --- commit3 + hash4 ◯ commit4 + hash5 ◯ commit5 `), }, { testName: "startIdx is past TODO commits", commits: []*models.Commit{ - {Name: "commit1", Hash: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick}, - {Name: "commit2", Hash: "sha2", Parents: []string{"sha3"}, Action: todo.Pick}, - {Name: "commit3", Hash: "sha3", Parents: []string{"sha4"}}, - {Name: "commit4", Hash: "sha4", Parents: []string{"sha5"}}, - {Name: "commit5", Hash: "sha5", Parents: []string{"sha7"}}, + {Name: "commit1", Hash: "hash1", Parents: []string{"hash2", "hash3"}, Action: todo.Pick}, + {Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}, Action: todo.Pick}, + {Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}}, + {Name: "commit4", Hash: "hash4", Parents: []string{"hash5"}}, + {Name: "commit5", Hash: "hash5", Parents: []string{"hash7"}}, }, startIdx: 3, endIdx: 5, @@ -273,18 +273,18 @@ func TestGetCommitListDisplayStrings(t *testing.T) { showYouAreHereLabel: true, now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` - sha4 ◯ commit4 - sha5 ◯ commit5 + hash4 ◯ commit4 + hash5 ◯ commit5 `), }, { testName: "only showing TODO commits", commits: []*models.Commit{ - {Name: "commit1", Hash: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick}, - {Name: "commit2", Hash: "sha2", Parents: []string{"sha3"}, Action: todo.Pick}, - {Name: "commit3", Hash: "sha3", Parents: []string{"sha4"}}, - {Name: "commit4", Hash: "sha4", Parents: []string{"sha5"}}, - {Name: "commit5", Hash: "sha5", Parents: []string{"sha7"}}, + {Name: "commit1", Hash: "hash1", Parents: []string{"hash2", "hash3"}, Action: todo.Pick}, + {Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}, Action: todo.Pick}, + {Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}}, + {Name: "commit4", Hash: "hash4", Parents: []string{"hash5"}}, + {Name: "commit5", Hash: "hash5", Parents: []string{"hash7"}}, }, startIdx: 0, endIdx: 2, @@ -294,18 +294,18 @@ func TestGetCommitListDisplayStrings(t *testing.T) { showYouAreHereLabel: true, now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` - sha1 pick commit1 - sha2 pick commit2 + hash1 pick commit1 + hash2 pick commit2 `), }, { testName: "no TODO commits, towards bottom", commits: []*models.Commit{ - {Name: "commit1", Hash: "sha1", Parents: []string{"sha2", "sha3"}}, - {Name: "commit2", Hash: "sha2", Parents: []string{"sha3"}}, - {Name: "commit3", Hash: "sha3", Parents: []string{"sha4"}}, - {Name: "commit4", Hash: "sha4", Parents: []string{"sha5"}}, - {Name: "commit5", Hash: "sha5", Parents: []string{"sha7"}}, + {Name: "commit1", Hash: "hash1", Parents: []string{"hash2", "hash3"}}, + {Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}}, + {Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}}, + {Name: "commit4", Hash: "hash4", Parents: []string{"hash5"}}, + {Name: "commit5", Hash: "hash5", Parents: []string{"hash7"}}, }, startIdx: 4, endIdx: 5, @@ -315,17 +315,17 @@ func TestGetCommitListDisplayStrings(t *testing.T) { showYouAreHereLabel: true, now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` - sha5 ◯ commit5 + hash5 ◯ commit5 `), }, { testName: "only TODO commits except last", commits: []*models.Commit{ - {Name: "commit1", Hash: "sha1", Parents: []string{"sha2", "sha3"}, Action: todo.Pick}, - {Name: "commit2", Hash: "sha2", Parents: []string{"sha3"}, Action: todo.Pick}, - {Name: "commit3", Hash: "sha3", Parents: []string{"sha4"}, Action: todo.Pick}, - {Name: "commit4", Hash: "sha4", Parents: []string{"sha5"}, Action: todo.Pick}, - {Name: "commit5", Hash: "sha5", Parents: []string{"sha7"}}, + {Name: "commit1", Hash: "hash1", Parents: []string{"hash2", "hash3"}, Action: todo.Pick}, + {Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}, Action: todo.Pick}, + {Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}, Action: todo.Pick}, + {Name: "commit4", Hash: "hash4", Parents: []string{"hash5"}, Action: todo.Pick}, + {Name: "commit5", Hash: "hash5", Parents: []string{"hash7"}}, }, startIdx: 0, endIdx: 2, @@ -335,16 +335,16 @@ func TestGetCommitListDisplayStrings(t *testing.T) { showYouAreHereLabel: true, now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` - sha1 pick commit1 - sha2 pick commit2 + hash1 pick commit1 + hash2 pick commit2 `), }, { testName: "don't show YOU ARE HERE label when not asked for (e.g. in branches panel)", commits: []*models.Commit{ - {Name: "commit1", Hash: "sha1", Parents: []string{"sha2"}, Action: todo.Pick}, - {Name: "commit2", Hash: "sha2", Parents: []string{"sha3"}}, - {Name: "commit3", Hash: "sha3", Parents: []string{"sha4"}}, + {Name: "commit1", Hash: "hash1", Parents: []string{"hash2"}, Action: todo.Pick}, + {Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}}, + {Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}}, }, startIdx: 0, endIdx: 3, @@ -354,16 +354,16 @@ func TestGetCommitListDisplayStrings(t *testing.T) { showYouAreHereLabel: false, now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), expected: formatExpected(` - sha1 pick commit1 - sha2 ◯ commit2 - sha3 ◯ commit3 + hash1 pick commit1 + hash2 ◯ commit2 + hash3 ◯ commit3 `), }, { testName: "custom time format", commits: []*models.Commit{ - {Name: "commit1", Hash: "sha1", UnixTimestamp: 1577844184, AuthorName: "Jesse Duffield"}, - {Name: "commit2", Hash: "sha2", UnixTimestamp: 1576844184, AuthorName: "Jesse Duffield"}, + {Name: "commit1", Hash: "hash1", UnixTimestamp: 1577844184, AuthorName: "Jesse Duffield"}, + {Name: "commit2", Hash: "hash2", UnixTimestamp: 1576844184, AuthorName: "Jesse Duffield"}, }, fullDescription: true, timeFormat: "2006-01-02", @@ -375,8 +375,8 @@ func TestGetCommitListDisplayStrings(t *testing.T) { cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 5, 3, 4, 0, time.UTC), expected: formatExpected(` - sha1 2:03AM Jesse Duffield commit1 - sha2 2019-12-20 Jesse Duffield commit2 + hash1 2:03AM Jesse Duffield commit1 + hash2 2019-12-20 Jesse Duffield commit2 `), }, } From 9cf1ca10a20e5897012c853887f8ce64c885cd84 Mon Sep 17 00:00:00 2001 From: pikomonde <32364823+pikomonde@users.noreply.github.com> Date: Thu, 21 Mar 2024 01:54:24 +0700 Subject: [PATCH 07/15] rename sha to hash 5 --- pkg/commands/git_commands/bisect.go | 10 +++---- pkg/commands/git_commands/branch.go | 4 +-- pkg/commands/git_commands/commit.go | 30 +++++++++---------- pkg/commands/git_commands/commit_loader.go | 12 ++++---- pkg/commands/git_commands/commit_test.go | 6 ++-- pkg/commands/git_commands/rebase.go | 2 +- pkg/commands/git_commands/stash_test.go | 14 ++++----- pkg/gui/controllers/bisect_controller.go | 4 +-- pkg/gui/controllers/helpers/fixup_helper.go | 10 +++---- pkg/gui/controllers/helpers/refresh_helper.go | 2 +- .../marked_base_commit/marked_base_commit.go | 12 ++++---- pkg/gui/presentation/graph/graph.go | 4 +-- pkg/utils/formatting.go | 8 ++--- pkg/utils/rebase_todo.go | 6 ++-- 14 files changed, 62 insertions(+), 62 deletions(-) diff --git a/pkg/commands/git_commands/bisect.go b/pkg/commands/git_commands/bisect.go index 61fe7a641f1..1c70537d98a 100644 --- a/pkg/commands/git_commands/bisect.go +++ b/pkg/commands/git_commands/bisect.go @@ -76,7 +76,7 @@ func (self *BisectCommands) GetInfoForGitDir(gitDir string) *BisectInfo { return info } - sha := strings.TrimSpace(string(fileContent)) + hash := strings.TrimSpace(string(fileContent)) if name == info.newTerm { status = BisectStatusNew @@ -86,7 +86,7 @@ func (self *BisectCommands) GetInfoForGitDir(gitDir string) *BisectInfo { status = BisectStatusSkipped } - info.statusMap[sha] = status + info.statusMap[hash] = status } currentContent, err := os.ReadFile(filepath.Join(gitDir, "BISECT_EXPECTED_REV")) @@ -155,12 +155,12 @@ func (self *BisectCommands) IsDone() (bool, []string, error) { cmdArgs := NewGitCmd("rev-list").Arg(newSha).ToArgv() err := self.cmd.New(cmdArgs).RunAndProcessLines(func(line string) (bool, error) { - sha := strings.TrimSpace(line) + hash := strings.TrimSpace(line) - if status, ok := info.statusMap[sha]; ok { + if status, ok := info.statusMap[hash]; ok { switch status { case BisectStatusSkipped, BisectStatusNew: - candidates = append(candidates, sha) + candidates = append(candidates, hash) return false, nil case BisectStatusOld: done = true diff --git a/pkg/commands/git_commands/branch.go b/pkg/commands/git_commands/branch.go index 6a347b8ac3c..8212b29b3d9 100644 --- a/pkg/commands/git_commands/branch.go +++ b/pkg/commands/git_commands/branch.go @@ -65,10 +65,10 @@ func (self *BranchCommands) CurrentBranchInfo() (BranchInfo, error) { for _, line := range utils.SplitLines(output) { split := strings.Split(strings.TrimRight(line, "\r\n"), "\x00") if len(split) == 3 && split[0] == "*" { - sha := split[1] + hash := split[1] displayName := split[2] return BranchInfo{ - RefName: sha, + RefName: hash, DisplayName: displayName, DetachedHead: true, }, nil diff --git a/pkg/commands/git_commands/commit.go b/pkg/commands/git_commands/commit.go index 05ab8d36bfc..517be276e88 100644 --- a/pkg/commands/git_commands/commit.go +++ b/pkg/commands/git_commands/commit.go @@ -39,8 +39,8 @@ func (self *CommitCommands) SetAuthor(value string) error { } // Add a commit's coauthor using Github/Gitlab Co-authored-by metadata. Value is expected to be of the form 'Name ' -func (self *CommitCommands) AddCoAuthor(sha string, author string) error { - message, err := self.GetCommitMessage(sha) +func (self *CommitCommands) AddCoAuthor(hash string, author string) error { + message, err := self.GetCommitMessage(hash) if err != nil { return err } @@ -74,8 +74,8 @@ func AddCoAuthorToDescription(description string, author string) string { } // ResetToCommit reset to commit -func (self *CommitCommands) ResetToCommit(sha string, strength string, envVars []string) error { - cmdArgs := NewGitCmd("reset").Arg("--"+strength, sha).ToArgv() +func (self *CommitCommands) ResetToCommit(hash string, strength string, envVars []string) error { + cmdArgs := NewGitCmd("reset").Arg("--"+strength, hash).ToArgv() return self.cmd.New(cmdArgs). // prevents git from prompting us for input which would freeze the program @@ -206,8 +206,8 @@ func (self *CommitCommands) GetCommitAuthor(commitHash string) (Author, error) { return author, err } -func (self *CommitCommands) GetCommitMessageFirstLine(sha string) (string, error) { - return self.GetCommitMessagesFirstLine([]string{sha}) +func (self *CommitCommands) GetCommitMessageFirstLine(hash string) (string, error) { + return self.GetCommitMessagesFirstLine([]string{hash}) } func (self *CommitCommands) GetCommitMessagesFirstLine(hashes []string) (string, error) { @@ -255,7 +255,7 @@ func (self *CommitCommands) AmendHeadCmdObj() oscommands.ICmdObj { return self.cmd.New(cmdArgs) } -func (self *CommitCommands) ShowCmdObj(sha string, filterPath string) oscommands.ICmdObj { +func (self *CommitCommands) ShowCmdObj(hash string, filterPath string) oscommands.ICmdObj { contextSize := self.AppState.DiffContextSize extDiffCmd := self.UserConfig.Git.Paging.ExternalDiffCommand @@ -269,7 +269,7 @@ func (self *CommitCommands) ShowCmdObj(sha string, filterPath string) oscommands Arg("--stat"). Arg("--decorate"). Arg("-p"). - Arg(sha). + Arg(hash). ArgIf(self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space"). ArgIf(filterPath != "", "--", filterPath). Dir(self.repoPaths.worktreePath). @@ -278,23 +278,23 @@ func (self *CommitCommands) ShowCmdObj(sha string, filterPath string) oscommands return self.cmd.New(cmdArgs).DontLog() } -// Revert reverts the selected commit by sha -func (self *CommitCommands) Revert(sha string) error { - cmdArgs := NewGitCmd("revert").Arg(sha).ToArgv() +// Revert reverts the selected commit by hash +func (self *CommitCommands) Revert(hash string) error { + cmdArgs := NewGitCmd("revert").Arg(hash).ToArgv() return self.cmd.New(cmdArgs).Run() } -func (self *CommitCommands) RevertMerge(sha string, parentNumber int) error { - cmdArgs := NewGitCmd("revert").Arg(sha, "-m", fmt.Sprintf("%d", parentNumber)). +func (self *CommitCommands) RevertMerge(hash string, parentNumber int) error { + cmdArgs := NewGitCmd("revert").Arg(hash, "-m", fmt.Sprintf("%d", parentNumber)). ToArgv() return self.cmd.New(cmdArgs).Run() } // CreateFixupCommit creates a commit that fixes up a previous commit -func (self *CommitCommands) CreateFixupCommit(sha string) error { - cmdArgs := NewGitCmd("commit").Arg("--fixup=" + sha).ToArgv() +func (self *CommitCommands) CreateFixupCommit(hash string) error { + cmdArgs := NewGitCmd("commit").Arg("--fixup=" + hash).ToArgv() return self.cmd.New(cmdArgs).Run() } diff --git a/pkg/commands/git_commands/commit_loader.go b/pkg/commands/git_commands/commit_loader.go index 7707f9999b4..50d9db709e3 100644 --- a/pkg/commands/git_commands/commit_loader.go +++ b/pkg/commands/git_commands/commit_loader.go @@ -198,7 +198,7 @@ func (self *CommitLoader) MergeRebasingCommits(commits []*models.Commit) ([]*mod return result, nil } -// extractCommitFromLine takes a line from a git log and extracts the sha, message, date, and tag if present +// extractCommitFromLine takes a line from a git log and extracts the hash, message, date, and tag if present // then puts them into a commit object // example input: // 8ad01fe32fcc20f07bc6693f87aa4977c327f1e1|10 hours ago|Jesse Duffield| (HEAD -> master, tag: v0.15.2)|refresh commits when adding a tag @@ -285,16 +285,16 @@ func (self *CommitLoader) getHydratedRebasingCommits(rebaseMode enums.RebaseMode } findFullCommit := lo.Ternary(self.version.IsOlderThan(2, 25, 2), - func(sha string) *models.Commit { + func(hash string) *models.Commit { for s, c := range fullCommits { - if strings.HasPrefix(s, sha) { + if strings.HasPrefix(s, hash) { return c } } return nil }, - func(sha string) *models.Commit { - return fullCommits[sha] + func(hash string) *models.Commit { + return fullCommits[hash] }) hydratedCommits := make([]*models.Commit, 0, len(commits)) @@ -458,7 +458,7 @@ func setCommitMergedStatuses(ancestor string, commits []*models.Commit) { passedAncestor := false for i, commit := range commits { - // some commits aren't really commits and don't have sha's, such as the update-ref todo + // some commits aren't really commits and don't have hashes, such as the update-ref todo if commit.Hash != "" && strings.HasPrefix(ancestor, commit.Hash) { passedAncestor = true } diff --git a/pkg/commands/git_commands/commit_test.go b/pkg/commands/git_commands/commit_test.go index 4dd9322f13a..43a8d05565d 100644 --- a/pkg/commands/git_commands/commit_test.go +++ b/pkg/commands/git_commands/commit_test.go @@ -153,7 +153,7 @@ func TestCommitCommitEditorCmdObj(t *testing.T) { func TestCommitCreateFixupCommit(t *testing.T) { type scenario struct { testName string - sha string + hash string runner *oscommands.FakeCmdObjRunner test func(error) } @@ -161,7 +161,7 @@ func TestCommitCreateFixupCommit(t *testing.T) { scenarios := []scenario{ { testName: "valid case", - sha: "12345", + hash: "12345", runner: oscommands.NewFakeRunner(t). ExpectGitArgs([]string{"commit", "--fixup=12345"}, "", nil), test: func(err error) { @@ -174,7 +174,7 @@ func TestCommitCreateFixupCommit(t *testing.T) { s := s t.Run(s.testName, func(t *testing.T) { instance := buildCommitCommands(commonDeps{runner: s.runner}) - s.test(instance.CreateFixupCommit(s.sha)) + s.test(instance.CreateFixupCommit(s.hash)) s.runner.CheckForMissingCalls() }) } diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go index 34a6c8661b8..50cadd8a3c5 100644 --- a/pkg/commands/git_commands/rebase.go +++ b/pkg/commands/git_commands/rebase.go @@ -288,7 +288,7 @@ func (self *RebaseCommands) AmendTo(commits []*models.Commit, commitIndex int) e return err } - // Get the sha of the commit we just created + // Get the hash of the commit we just created cmdArgs := NewGitCmd("rev-parse").Arg("--verify", "HEAD").ToArgv() fixupSha, err := self.cmd.New(cmdArgs).RunWithOutput() if err != nil { diff --git a/pkg/commands/git_commands/stash_test.go b/pkg/commands/git_commands/stash_test.go index 3f112cd0c33..ad44d72397a 100644 --- a/pkg/commands/git_commands/stash_test.go +++ b/pkg/commands/git_commands/stash_test.go @@ -47,7 +47,7 @@ func TestStashSave(t *testing.T) { func TestStashStore(t *testing.T) { type scenario struct { testName string - sha string + hash string message string expected []string } @@ -55,19 +55,19 @@ func TestStashStore(t *testing.T) { scenarios := []scenario{ { testName: "Non-empty message", - sha: "0123456789abcdef", + hash: "0123456789abcdef", message: "New stash name", expected: []string{"stash", "store", "-m", "New stash name", "0123456789abcdef"}, }, { testName: "Empty message", - sha: "0123456789abcdef", + hash: "0123456789abcdef", message: "", expected: []string{"stash", "store", "0123456789abcdef"}, }, { testName: "Space message", - sha: "0123456789abcdef", + hash: "0123456789abcdef", message: " ", expected: []string{"stash", "store", "0123456789abcdef"}, }, @@ -80,7 +80,7 @@ func TestStashStore(t *testing.T) { ExpectGitArgs(s.expected, "", nil) instance := buildStashCommands(commonDeps{runner: runner}) - assert.NoError(t, instance.Store(s.sha, s.message)) + assert.NoError(t, instance.Store(s.hash, s.message)) runner.CheckForMissingCalls() }) } @@ -91,9 +91,9 @@ func TestStashSha(t *testing.T) { ExpectGitArgs([]string{"rev-parse", "refs/stash@{5}"}, "14d94495194651adfd5f070590df566c11d28243\n", nil) instance := buildStashCommands(commonDeps{runner: runner}) - sha, err := instance.Hash(5) + hash, err := instance.Hash(5) assert.NoError(t, err) - assert.Equal(t, "14d94495194651adfd5f070590df566c11d28243", sha) + assert.Equal(t, "14d94495194651adfd5f070590df566c11d28243", hash) runner.CheckForMissingCalls() } diff --git a/pkg/gui/controllers/bisect_controller.go b/pkg/gui/controllers/bisect_controller.go index 4fc2ec77252..ddd2f9735f8 100644 --- a/pkg/gui/controllers/bisect_controller.go +++ b/pkg/gui/controllers/bisect_controller.go @@ -74,7 +74,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c // ref, because we'll be reloading our commits in that case. waitToReselect := selectCurrentAfter && !self.c.Git().Bisect.ReachableFromStart(info) - // If we have a current sha already, then we always want to use that one. If + // If we have a current hash already, then we always want to use that one. If // not, we're still picking the initial commits before we really start, so // use the selected commit in that case. @@ -285,7 +285,7 @@ func (self *BisectController) afterBisectMarkRefresh(selectCurrent bool, waitToR func (self *BisectController) selectCurrentBisectCommit() { info := self.c.Git().Bisect.GetInfo() if info.GetCurrentHash() != "" { - // find index of commit with that sha, move cursor to that. + // find index of commit with that hash, move cursor to that. for i, commit := range self.c.Model().Commits { if commit.Hash == info.GetCurrentHash() { self.context().SetSelection(i) diff --git a/pkg/gui/controllers/helpers/fixup_helper.go b/pkg/gui/controllers/helpers/fixup_helper.go index 5be1ba83ff8..79104120e55 100644 --- a/pkg/gui/controllers/helpers/fixup_helper.go +++ b/pkg/gui/controllers/helpers/fixup_helper.go @@ -164,7 +164,7 @@ func (self *FixupHelper) parseDiff(diff string) ([]*deletedLineInfo, bool) { // returns the list of commit hashes that introduced the lines which have now been deleted func (self *FixupHelper) blameDeletedLines(deletedLineInfos []*deletedLineInfo) []string { var wg sync.WaitGroup - shaChan := make(chan string) + hashChan := make(chan string) for _, info := range deletedLineInfos { wg.Add(1) @@ -178,19 +178,19 @@ func (self *FixupHelper) blameDeletedLines(deletedLineInfos []*deletedLineInfo) } blameLines := strings.Split(strings.TrimSuffix(blameOutput, "\n"), "\n") for _, line := range blameLines { - shaChan <- strings.Split(line, " ")[0] + hashChan <- strings.Split(line, " ")[0] } }(info) } go func() { wg.Wait() - close(shaChan) + close(hashChan) }() result := set.New[string]() - for sha := range shaChan { - result.Add(sha) + for hash := range hashChan { + result.Add(hash) } return result.ToSlice() diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index 34e390bde6e..4e1a9fc543a 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -299,7 +299,7 @@ func (self *RefreshHelper) determineCheckedOutBranchName() string { // In all other cases, get the branch name by asking git what branch is // checked out. Note that if we're on a detached head (for reasons other // than rebasing or bisecting, i.e. it was explicitly checked out), then - // this will return its sha. + // this will return its hash. if branchName, err := self.c.Git().Branch.CurrentBranchName(); err == nil { return branchName } diff --git a/pkg/gui/modes/marked_base_commit/marked_base_commit.go b/pkg/gui/modes/marked_base_commit/marked_base_commit.go index 3a239235d59..ace1e35d0fb 100644 --- a/pkg/gui/modes/marked_base_commit/marked_base_commit.go +++ b/pkg/gui/modes/marked_base_commit/marked_base_commit.go @@ -1,7 +1,7 @@ package marked_base_commit type MarkedBaseCommit struct { - sha string // the sha of the commit used as a rebase base commit; empty string when unset + hash string // the hash of the commit used as a rebase base commit; empty string when unset } func New() MarkedBaseCommit { @@ -9,17 +9,17 @@ func New() MarkedBaseCommit { } func (m *MarkedBaseCommit) Active() bool { - return m.sha != "" + return m.hash != "" } func (m *MarkedBaseCommit) Reset() { - m.sha = "" + m.hash = "" } -func (m *MarkedBaseCommit) SetHash(sha string) { - m.sha = sha +func (m *MarkedBaseCommit) SetHash(hash string) { + m.hash = hash } func (m *MarkedBaseCommit) GetHash() string { - return m.sha + return m.hash } diff --git a/pkg/gui/presentation/graph/graph.go b/pkg/gui/presentation/graph/graph.go index e13f6916adb..8133fd9b686 100644 --- a/pkg/gui/presentation/graph/graph.go +++ b/pkg/gui/presentation/graph/graph.go @@ -32,9 +32,9 @@ type Pipe struct { var highlightStyle = style.FgLightWhite.SetBold() -func ContainsCommitHash(pipes []*Pipe, sha string) bool { +func ContainsCommitHash(pipes []*Pipe, hash string) bool { for _, pipe := range pipes { - if equalHashes(pipe.fromHash, sha) { + if equalHashes(pipe.fromHash, hash) { return true } } diff --git a/pkg/utils/formatting.go b/pkg/utils/formatting.go index 1f5d47db6c0..ffc530068ab 100644 --- a/pkg/utils/formatting.go +++ b/pkg/utils/formatting.go @@ -177,11 +177,11 @@ func SafeTruncate(str string, limit int) string { const COMMIT_HASH_SHORT_SIZE = 8 -func ShortSha(sha string) string { - if len(sha) < COMMIT_HASH_SHORT_SIZE { - return sha +func ShortSha(hash string) string { + if len(hash) < COMMIT_HASH_SHORT_SIZE { + return hash } - return sha[:COMMIT_HASH_SHORT_SIZE] + return hash[:COMMIT_HASH_SHORT_SIZE] } // Returns comma-separated list of paths, with ellipsis if there are more than 3 diff --git a/pkg/utils/rebase_todo.go b/pkg/utils/rebase_todo.go index ee5e3d65646..6062d6785ec 100644 --- a/pkg/utils/rebase_todo.go +++ b/pkg/utils/rebase_todo.go @@ -17,7 +17,7 @@ type Todo struct { } // In order to change a TODO in git-rebase-todo, we need to specify the old action, -// because sometimes the same sha appears multiple times in the file (e.g. in a pick +// because sometimes the same hash appears multiple times in the file (e.g. in a pick // and later in a merge) type TodoChange struct { Hash string @@ -59,8 +59,8 @@ func equalHash(a, b string) bool { func findTodo(todos []todo.Todo, todoToFind Todo) (int, bool) { _, idx, ok := lo.FindIndexOf(todos, func(t todo.Todo) bool { - // Comparing just the sha is not enough; we need to compare both the - // action and the sha, as the sha could appear multiple times (e.g. in a + // Comparing just the hash is not enough; we need to compare both the + // action and the hash, as the hash could appear multiple times (e.g. in a // pick and later in a merge). For update-ref todos we also must compare // the Ref. return t.Command == todoToFind.Action && From 05fb12b1d58a664ac2b9d392979d0f71490ea28a Mon Sep 17 00:00:00 2001 From: pikomonde <32364823+pikomonde@users.noreply.github.com> Date: Thu, 21 Mar 2024 01:59:00 +0700 Subject: [PATCH 08/15] rename sha to hash 6, update short hash --- pkg/app/entry_point.go | 2 +- pkg/commands/git_commands/rebase.go | 2 +- pkg/commands/models/commit.go | 4 ++-- pkg/gui/context/reflog_commits_context.go | 2 +- pkg/gui/controllers/bisect_controller.go | 8 ++++---- pkg/gui/controllers/helpers/repos_helper.go | 2 +- pkg/gui/controllers/local_commits_controller.go | 2 +- pkg/gui/presentation/branches.go | 2 +- pkg/gui/presentation/commits.go | 2 +- pkg/gui/presentation/reflog_commits.go | 4 ++-- pkg/utils/formatting.go | 2 +- 11 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/app/entry_point.go b/pkg/app/entry_point.go index fb19f06f6c6..baeb43ae571 100644 --- a/pkg/app/entry_point.go +++ b/pkg/app/entry_point.go @@ -263,7 +263,7 @@ func mergeBuildInfo(buildInfo *BuildInfo) { buildInfo.Commit = revision.Value // if lazygit was built from source we'll show the version as the // abbreviated commit hash - buildInfo.Version = utils.ShortSha(revision.Value) + buildInfo.Version = utils.ShortHash(revision.Value) } // if version hasn't been set we assume that neither has the date diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go index 50cadd8a3c5..e84afdc76b5 100644 --- a/pkg/commands/git_commands/rebase.go +++ b/pkg/commands/git_commands/rebase.go @@ -506,7 +506,7 @@ func (self *RebaseCommands) DiscardOldFileChanges(commits []*models.Commit, comm // CherryPickCommits begins an interactive rebase with the given shas being cherry picked onto HEAD func (self *RebaseCommands) CherryPickCommits(commits []*models.Commit) error { commitLines := lo.Map(commits, func(commit *models.Commit, _ int) string { - return fmt.Sprintf("%s %s", utils.ShortSha(commit.Hash), commit.Name) + return fmt.Sprintf("%s %s", utils.ShortHash(commit.Hash), commit.Name) }) msg := utils.ResolvePlaceholderString( self.Tr.Log.CherryPickCommits, diff --git a/pkg/commands/models/commit.go b/pkg/commands/models/commit.go index 9dae21850cc..a6b4af0babf 100644 --- a/pkg/commands/models/commit.go +++ b/pkg/commands/models/commit.go @@ -58,8 +58,8 @@ type Commit struct { Parents []string } -func (c *Commit) ShortSha() string { - return utils.ShortSha(c.Hash) +func (c *Commit) ShortHash() string { + return utils.ShortHash(c.Hash) } func (c *Commit) FullRefName() string { diff --git a/pkg/gui/context/reflog_commits_context.go b/pkg/gui/context/reflog_commits_context.go index 5b3c72360f8..57ca7c4dc39 100644 --- a/pkg/gui/context/reflog_commits_context.go +++ b/pkg/gui/context/reflog_commits_context.go @@ -22,7 +22,7 @@ func NewReflogCommitsContext(c *ContextCommon) *ReflogCommitsContext { viewModel := NewFilteredListViewModel( func() []*models.Commit { return c.Model().FilteredReflogCommits }, func(commit *models.Commit) []string { - return []string{commit.ShortSha(), commit.Name} + return []string{commit.ShortHash(), commit.Name} }, ) diff --git a/pkg/gui/controllers/bisect_controller.go b/pkg/gui/controllers/bisect_controller.go index ddd2f9735f8..35327a3d6e7 100644 --- a/pkg/gui/controllers/bisect_controller.go +++ b/pkg/gui/controllers/bisect_controller.go @@ -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.ShortSha(shaToMark) + shortShaToMark := 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 @@ -133,7 +133,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c } if info.GetCurrentHash() != "" && info.GetCurrentHash() != commit.Hash { menuItems = append(menuItems, lo.ToPtr(types.MenuItem{ - Label: fmt.Sprintf(self.c.Tr.Bisect.SkipSelected, commit.ShortSha()), + Label: fmt.Sprintf(self.c.Tr.Bisect.SkipSelected, commit.ShortHash()), OnPress: func() error { self.c.LogAction(self.c.Tr.Actions.BisectSkip) if err := self.c.Git().Bisect.Skip(commit.Hash); err != nil { @@ -165,7 +165,7 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo, Title: self.c.Tr.Bisect.BisectMenuTitle, Items: []*types.MenuItem{ { - Label: fmt.Sprintf(self.c.Tr.Bisect.MarkStart, commit.ShortSha(), info.NewTerm()), + Label: fmt.Sprintf(self.c.Tr.Bisect.MarkStart, commit.ShortHash(), info.NewTerm()), OnPress: func() error { self.c.LogAction(self.c.Tr.Actions.StartBisect) if err := self.c.Git().Bisect.Start(); err != nil { @@ -182,7 +182,7 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo, Key: 'b', }, { - Label: fmt.Sprintf(self.c.Tr.Bisect.MarkStart, commit.ShortSha(), info.OldTerm()), + Label: fmt.Sprintf(self.c.Tr.Bisect.MarkStart, commit.ShortHash(), info.OldTerm()), OnPress: func() error { self.c.LogAction(self.c.Tr.Actions.StartBisect) if err := self.c.Git().Bisect.Start(); err != nil { diff --git a/pkg/gui/controllers/helpers/repos_helper.go b/pkg/gui/controllers/helpers/repos_helper.go index c4a00cb7334..c2c177078d6 100644 --- a/pkg/gui/controllers/helpers/repos_helper.go +++ b/pkg/gui/controllers/helpers/repos_helper.go @@ -63,7 +63,7 @@ func (self *ReposHelper) getCurrentBranch(path string) string { branchDisplay = strings.TrimPrefix(content, refsPrefix) } else { // detached HEAD state, displaying short SHA - branchDisplay = utils.ShortSha(content) + branchDisplay = utils.ShortHash(content) } return branchDisplay, nil } diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index e33d7802203..8b4e388cb7a 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -782,7 +782,7 @@ func (self *LocalCommitsController) revert(commit *models.Commit) error { Prompt: utils.ResolvePlaceholderString( self.c.Tr.ConfirmRevertCommit, map[string]string{ - "selectedCommit": commit.ShortSha(), + "selectedCommit": commit.ShortHash(), }), HandleConfirm: func() error { self.c.LogAction(self.c.Tr.Actions.RevertCommit) diff --git a/pkg/gui/presentation/branches.go b/pkg/gui/presentation/branches.go index 9d0625ea1e6..0abf2d4cd08 100644 --- a/pkg/gui/presentation/branches.go +++ b/pkg/gui/presentation/branches.go @@ -106,7 +106,7 @@ func getBranchDisplayStrings( } if showCommitHash { - res = append(res, utils.ShortSha(b.CommitHash)) + res = append(res, utils.ShortHash(b.CommitHash)) } res = append(res, coloredName) diff --git a/pkg/gui/presentation/commits.go b/pkg/gui/presentation/commits.go index 8823d508ea2..3571461268d 100644 --- a/pkg/gui/presentation/commits.go +++ b/pkg/gui/presentation/commits.go @@ -373,7 +373,7 @@ func displayCommit( } else if icons.IsIconEnabled() { cols = append(cols, shaColor.Sprint(icons.IconForCommit(commit))) } - cols = append(cols, shaColor.Sprint(commit.ShortSha())) + cols = append(cols, shaColor.Sprint(commit.ShortHash())) cols = append(cols, bisectString) if fullDescription { cols = append(cols, style.FgBlue.Sprint( diff --git a/pkg/gui/presentation/reflog_commits.go b/pkg/gui/presentation/reflog_commits.go index b520521cc74..243fea1a391 100644 --- a/pkg/gui/presentation/reflog_commits.go +++ b/pkg/gui/presentation/reflog_commits.go @@ -64,7 +64,7 @@ func getFullDescriptionDisplayStringsForReflogCommit(c *models.Commit, attrs ref } return []string{ - reflogShaColor(attrs.cherryPicked, attrs.diffed).Sprint(c.ShortSha()), + reflogShaColor(attrs.cherryPicked, attrs.diffed).Sprint(c.ShortHash()), style.FgMagenta.Sprint(utils.UnixToDateSmart(attrs.now, c.UnixTimestamp, attrs.timeFormat, attrs.shortTimeFormat)), theme.DefaultTextColor.Sprint(name), } @@ -77,7 +77,7 @@ func getDisplayStringsForReflogCommit(c *models.Commit, attrs reflogCommitDispla } return []string{ - reflogShaColor(attrs.cherryPicked, attrs.diffed).Sprint(c.ShortSha()), + reflogShaColor(attrs.cherryPicked, attrs.diffed).Sprint(c.ShortHash()), theme.DefaultTextColor.Sprint(name), } } diff --git a/pkg/utils/formatting.go b/pkg/utils/formatting.go index ffc530068ab..139946ddbd7 100644 --- a/pkg/utils/formatting.go +++ b/pkg/utils/formatting.go @@ -177,7 +177,7 @@ func SafeTruncate(str string, limit int) string { const COMMIT_HASH_SHORT_SIZE = 8 -func ShortSha(hash string) string { +func ShortHash(hash string) string { if len(hash) < COMMIT_HASH_SHORT_SIZE { return hash } From fccfbf1f639d32569b142ae50bc1920a389b41ef Mon Sep 17 00:00:00 2001 From: pikomonde <32364823+pikomonde@users.noreply.github.com> Date: Thu, 21 Mar 2024 02:04:00 +0700 Subject: [PATCH 09/15] rename sha to hash 7, language translate --- docs/keybindings/Keybindings_ja.md | 6 +++--- docs/keybindings/Keybindings_ko.md | 6 +++--- docs/keybindings/Keybindings_pl.md | 6 +++--- docs/keybindings/Keybindings_ru.md | 6 +++--- docs/keybindings/Keybindings_zh-CN.md | 6 +++--- docs/keybindings/Keybindings_zh-TW.md | 6 +++--- pkg/i18n/chinese.go | 2 +- pkg/i18n/japanese.go | 6 +++--- pkg/i18n/korean.go | 6 +++--- pkg/i18n/polish.go | 6 +++--- pkg/i18n/russian.go | 6 +++--- pkg/i18n/traditional_chinese.go | 6 +++--- 12 files changed, 34 insertions(+), 34 deletions(-) diff --git a/docs/keybindings/Keybindings_ja.md b/docs/keybindings/Keybindings_ja.md index 863ecddd4c3..359972acecb 100644 --- a/docs/keybindings/Keybindings_ja.md +++ b/docs/keybindings/Keybindings_ja.md @@ -66,7 +66,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | Key | Action | Info | |-----|--------|-------------| -| `` `` | コミットのSHAをクリップボードにコピー | | +| `` `` | コミットのhashをクリップボードにコピー | | | `` `` | チェックアウト | Checkout the selected commit as a detached HEAD. | | `` y `` | コミットの情報をコピー | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). | | `` o `` | ブラウザでコミットを開く | | @@ -93,7 +93,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | Key | Action | Info | |-----|--------|-------------| -| `` `` | コミットのSHAをクリップボードにコピー | | +| `` `` | コミットのhashをクリップボードにコピー | | | `` `` | Reset copied (cherry-picked) commits selection | | | `` b `` | View bisect options | | | `` s `` | Squash | Squash the selected commit into the commit below it. The selected commit's message will be appended to the commit below it. | @@ -343,7 +343,7 @@ If you would instead like to start an interactive rebase from the selected commi | Key | Action | Info | |-----|--------|-------------| -| `` `` | コミットのSHAをクリップボードにコピー | | +| `` `` | コミットのhashをクリップボードにコピー | | | `` `` | チェックアウト | Checkout the selected commit as a detached HEAD. | | `` y `` | コミットの情報をコピー | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). | | `` o `` | ブラウザでコミットを開く | | diff --git a/docs/keybindings/Keybindings_ko.md b/docs/keybindings/Keybindings_ko.md index 531ed4e4688..15b8521b443 100644 --- a/docs/keybindings/Keybindings_ko.md +++ b/docs/keybindings/Keybindings_ko.md @@ -53,7 +53,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | Key | Action | Info | |-----|--------|-------------| -| `` `` | 커밋 SHA를 클립보드에 복사 | | +| `` `` | 커밋 hash를 클립보드에 복사 | | | `` `` | 체크아웃 | Checkout the selected commit as a detached HEAD. | | `` y `` | 커밋 attribute 복사 | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). | | `` o `` | 브라우저에서 커밋 열기 | | @@ -83,7 +83,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | Key | Action | Info | |-----|--------|-------------| -| `` `` | 커밋 SHA를 클립보드에 복사 | | +| `` `` | 커밋 hash를 클립보드에 복사 | | | `` `` | 체크아웃 | Checkout the selected commit as a detached HEAD. | | `` y `` | 커밋 attribute 복사 | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). | | `` o `` | 브라우저에서 커밋 열기 | | @@ -256,7 +256,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | Key | Action | Info | |-----|--------|-------------| -| `` `` | 커밋 SHA를 클립보드에 복사 | | +| `` `` | 커밋 hash를 클립보드에 복사 | | | `` `` | Reset cherry-picked (copied) commits selection | | | `` b `` | Bisect 옵션 보기 | | | `` s `` | Squash | Squash the selected commit into the commit below it. The selected commit's message will be appended to the commit below it. | diff --git a/docs/keybindings/Keybindings_pl.md b/docs/keybindings/Keybindings_pl.md index 8c8e5b102c3..e41c07e4d0e 100644 --- a/docs/keybindings/Keybindings_pl.md +++ b/docs/keybindings/Keybindings_pl.md @@ -53,7 +53,7 @@ _Legenda: `` oznacza ctrl+b, `` oznacza alt+b, `B` oznacza shift+b_ | Key | Action | Info | |-----|--------|-------------| -| `` `` | Kopiuj SHA commita do schowka | | +| `` `` | Kopiuj hash commita do schowka | | | `` `` | Resetuj wybrane (cherry-picked) commity | | | `` b `` | Zobacz opcje bisect | | | `` s `` | Scal | Scal wybrany commit z commitami poniżej. Wiadomość wybranego commita zostanie dołączona do commita poniżej. | @@ -255,7 +255,7 @@ Jeśli chcesz zamiast tego rozpocząć interaktywny rebase od wybranego commita, | Key | Action | Info | |-----|--------|-------------| -| `` `` | Kopiuj SHA commita do schowka | | +| `` `` | Kopiuj hash commita do schowka | | | `` `` | Przełącz | Przełącz wybrany commit jako odłączoną HEAD. | | `` y `` | Kopiuj atrybut commita do schowka | Kopiuj atrybut commita do schowka (np. hash, URL, różnice, wiadomość, autor). | | `` o `` | Otwórz commit w przeglądarce | | @@ -295,7 +295,7 @@ Jeśli chcesz zamiast tego rozpocząć interaktywny rebase od wybranego commita, | Key | Action | Info | |-----|--------|-------------| -| `` `` | Kopiuj SHA commita do schowka | | +| `` `` | Kopiuj hash commita do schowka | | | `` `` | Przełącz | Przełącz wybrany commit jako odłączoną HEAD. | | `` y `` | Kopiuj atrybut commita do schowka | Kopiuj atrybut commita do schowka (np. hash, URL, różnice, wiadomość, autor). | | `` o `` | Otwórz commit w przeglądarce | | diff --git a/docs/keybindings/Keybindings_ru.md b/docs/keybindings/Keybindings_ru.md index 8eb34a5bb39..c83652ee980 100644 --- a/docs/keybindings/Keybindings_ru.md +++ b/docs/keybindings/Keybindings_ru.md @@ -123,7 +123,7 @@ _Связки клавиш_ | Key | Action | Info | |-----|--------|-------------| -| `` `` | Скопировать SHA коммита в буфер обмена | | +| `` `` | Скопировать hash коммита в буфер обмена | | | `` `` | Переключить | Checkout the selected commit as a detached HEAD. | | `` y `` | Скопировать атрибут коммита | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). | | `` o `` | Открыть коммит в браузере | | @@ -140,7 +140,7 @@ _Связки клавиш_ | Key | Action | Info | |-----|--------|-------------| -| `` `` | Скопировать SHA коммита в буфер обмена | | +| `` `` | Скопировать hash коммита в буфер обмена | | | `` `` | Сбросить отобранную (скопированную | cherry-picked) выборку коммитов | | | `` b `` | Просмотреть параметры бинарного поиска | | | `` s `` | Объединить коммиты (Squash) | Squash the selected commit into the commit below it. The selected commit's message will be appended to the commit below it. | @@ -219,7 +219,7 @@ If you would instead like to start an interactive rebase from the selected commi | Key | Action | Info | |-----|--------|-------------| -| `` `` | Скопировать SHA коммита в буфер обмена | | +| `` `` | Скопировать hash коммита в буфер обмена | | | `` `` | Переключить | Checkout the selected commit as a detached HEAD. | | `` y `` | Скопировать атрибут коммита | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). | | `` o `` | Открыть коммит в браузере | | diff --git a/docs/keybindings/Keybindings_zh-CN.md b/docs/keybindings/Keybindings_zh-CN.md index c6d426b7fb8..e0f3a819c2e 100644 --- a/docs/keybindings/Keybindings_zh-CN.md +++ b/docs/keybindings/Keybindings_zh-CN.md @@ -53,7 +53,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | Key | Action | Info | |-----|--------|-------------| -| `` `` | 将提交的 SHA 复制到剪贴板 | | +| `` `` | 将提交的 hash 复制到剪贴板 | | | `` `` | 检出 | Checkout the selected commit as a detached HEAD. | | `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). | | `` o `` | 在浏览器中打开提交 | | @@ -106,7 +106,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | Key | Action | Info | |-----|--------|-------------| -| `` `` | 将提交的 SHA 复制到剪贴板 | | +| `` `` | 将提交的 hash 复制到剪贴板 | | | `` `` | 检出 | Checkout the selected commit as a detached HEAD. | | `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). | | `` o `` | 在浏览器中打开提交 | | @@ -137,7 +137,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | Key | Action | Info | |-----|--------|-------------| -| `` `` | 将提交的 SHA 复制到剪贴板 | | +| `` `` | 将提交的 hash 复制到剪贴板 | | | `` `` | 重置已拣选(复制)的提交 | | | `` b `` | 查看二分查找选项 | | | `` s `` | 压缩 | Squash the selected commit into the commit below it. The selected commit's message will be appended to the commit below it. | diff --git a/docs/keybindings/Keybindings_zh-TW.md b/docs/keybindings/Keybindings_zh-TW.md index 2cb92f88e50..5457b05d233 100644 --- a/docs/keybindings/Keybindings_zh-TW.md +++ b/docs/keybindings/Keybindings_zh-TW.md @@ -121,7 +121,7 @@ _說明:`` 表示 Ctrl+B、`` 表示 Alt+B,`B`表示 Shift+B | Key | Action | Info | |-----|--------|-------------| -| `` `` | 複製提交 SHA 到剪貼簿 | | +| `` `` | 複製提交 hash 到剪貼簿 | | | `` `` | 檢出 | Checkout the selected commit as a detached HEAD. | | `` y `` | 複製提交屬性 | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). | | `` o `` | 在瀏覽器中開啟提交 | | @@ -162,7 +162,7 @@ _說明:`` 表示 Ctrl+B、`` 表示 Alt+B,`B`表示 Shift+B | Key | Action | Info | |-----|--------|-------------| -| `` `` | 複製提交 SHA 到剪貼簿 | | +| `` `` | 複製提交 hash 到剪貼簿 | | | `` `` | 重設選定的揀選 (複製) 提交 | | | `` b `` | 查看二分選項 | | | `` s `` | 壓縮 (Squash) | Squash the selected commit into the commit below it. The selected commit's message will be appended to the commit below it. | @@ -236,7 +236,7 @@ If you would instead like to start an interactive rebase from the selected commi | Key | Action | Info | |-----|--------|-------------| -| `` `` | 複製提交 SHA 到剪貼簿 | | +| `` `` | 複製提交 hash 到剪貼簿 | | | `` `` | 檢出 | Checkout the selected commit as a detached HEAD. | | `` y `` | 複製提交屬性 | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). | | `` o `` | 在瀏覽器中開啟提交 | | diff --git a/pkg/i18n/chinese.go b/pkg/i18n/chinese.go index f6071b39838..002143b282e 100644 --- a/pkg/i18n/chinese.go +++ b/pkg/i18n/chinese.go @@ -355,7 +355,7 @@ func chineseTranslationSet() TranslationSet { // 实际视图 (actual view) 是附加视图 (extras view),未来,我打算为附加视图提供更多选项卡,但现在,上面的文本只需要提及“命令日志”这个部分 OpenCommandLogMenu: "打开命令日志菜单", ShowingGitDiff: "显示输出:", - CopyCommitHashToClipboard: "将提交的 SHA 复制到剪贴板", + CopyCommitHashToClipboard: "将提交的 hash 复制到剪贴板", CopyCommitMessageToClipboard: "将提交消息复制到剪贴板", CopyBranchNameToClipboard: "将分支名称复制到剪贴板", CopyPathToClipboard: "将文件名复制到剪贴板", diff --git a/pkg/i18n/japanese.go b/pkg/i18n/japanese.go index dbc7a5dc624..869203addeb 100644 --- a/pkg/i18n/japanese.go +++ b/pkg/i18n/japanese.go @@ -367,8 +367,8 @@ func japaneseTranslationSet() TranslationSet { OpenCommandLogMenu: "コマンドログメニューを開く", // LcShowingGitDiff: "Showing output for:", CommitDiff: "コミットの差分", - CopyCommitHashToClipboard: "コミットのSHAをクリップボードにコピー", - CommitHash: "コミットのSHA", + CopyCommitHashToClipboard: "コミットのhashをクリップボードにコピー", + CommitHash: "コミットのhash", CommitURL: "コミットのURL", CopyCommitMessageToClipboard: "コミットメッセージをクリップボードにコピー", CommitMessage: "コミットメッセージ", @@ -496,7 +496,7 @@ func japaneseTranslationSet() TranslationSet { CreateAnnotatedTag: "注釈付きタグを作成", CopyCommitMessageToClipboard: "コミットメッセージをクリップボードにコピー", CopyCommitDiffToClipboard: "コミットの差分をクリップボードにコピー", - CopyCommitHashToClipboard: "コミットSHAをクリップボードにコピー", + CopyCommitHashToClipboard: "コミットhashをクリップボードにコピー", CopyCommitURLToClipboard: "コミットのURLをクリップボードにコピー", CopyCommitAuthorToClipboard: "コミットの作成者名をクリップボードにコピー", CopyCommitAttributeToClipboard: "クリップボードにコピー", diff --git a/pkg/i18n/korean.go b/pkg/i18n/korean.go index 3111e6b46c9..34d5bf6aee0 100644 --- a/pkg/i18n/korean.go +++ b/pkg/i18n/korean.go @@ -361,8 +361,8 @@ func koreanTranslationSet() TranslationSet { OpenCommandLogMenu: "명령어 로그 메뉴 열기", ShowingGitDiff: "Showing output for:", CommitDiff: "커밋의 iff", - CopyCommitHashToClipboard: "커밋 SHA를 클립보드에 복사", - CommitHash: "커밋 SHA", + CopyCommitHashToClipboard: "커밋 hash를 클립보드에 복사", + CommitHash: "커밋 hash", CommitURL: "커밋 URL", CopyCommitMessageToClipboard: "커밋 메시지를 클립보드에 복사", CommitMessage: "커밋 메시지", @@ -486,7 +486,7 @@ func koreanTranslationSet() TranslationSet { CreateAnnotatedTag: "Create annotated tag", CopyCommitMessageToClipboard: "커밋 메시지를 클립보드에 복사", CopyCommitDiffToClipboard: "커밋 diff를 클립보드에 복사", - CopyCommitHashToClipboard: "커밋 SHA를 클립보드에 복사", + CopyCommitHashToClipboard: "커밋 hash를 클립보드에 복사", CopyCommitURLToClipboard: "커밋 URL를 클립보드에 복사", CopyCommitAuthorToClipboard: "커밋 작성자를 클립보드에 복사", CopyCommitAttributeToClipboard: "클립보드에 복사", diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go index e8d05c46f79..6299c3595f2 100644 --- a/pkg/i18n/polish.go +++ b/pkg/i18n/polish.go @@ -548,8 +548,8 @@ func polishTranslationSet() TranslationSet { OpenCommandLogMenuTooltip: "Pokaż opcje dla dziennika poleceń, np. pokazywanie/ukrywanie dziennika poleceń i skupienie na dzienniku poleceń.", ShowingGitDiff: "Pokazuje wynik dla:", CommitDiff: "Różnice commita", - CopyCommitHashToClipboard: "Kopiuj SHA commita do schowka", - CommitHash: "SHA commita", + CopyCommitHashToClipboard: "Kopiuj hash commita do schowka", + CommitHash: "hash commita", CommitURL: "URL commita", CopyCommitMessageToClipboard: "Kopiuj wiadomość commita do schowka", CommitMessage: "Wiadomość commita", @@ -784,7 +784,7 @@ func polishTranslationSet() TranslationSet { CopyCommitMessageToClipboard: "Kopiuj wiadomość commita do schowka", CopyCommitSubjectToClipboard: "Kopiuj temat commita do schowka", CopyCommitDiffToClipboard: "Kopiuj różnice commita do schowka", - CopyCommitHashToClipboard: "Kopiuj SHA commita do schowka", + CopyCommitHashToClipboard: "Kopiuj hash commita do schowka", CopyCommitURLToClipboard: "Kopiuj URL commita do schowka", CopyCommitAuthorToClipboard: "Kopiuj autora commita do schowka", CopyCommitAttributeToClipboard: "Kopiuj do schowka", diff --git a/pkg/i18n/russian.go b/pkg/i18n/russian.go index d0fe9a4575a..a52d19cde7c 100644 --- a/pkg/i18n/russian.go +++ b/pkg/i18n/russian.go @@ -422,8 +422,8 @@ func RussianTranslationSet() TranslationSet { OpenCommandLogMenu: "Открыть меню журнала команд", ShowingGitDiff: "Показывает вывод для:", CommitDiff: "Разница коммита", - CopyCommitHashToClipboard: "Скопировать SHA коммита в буфер обмена", - CommitHash: "SHA коммита", + CopyCommitHashToClipboard: "Скопировать hash коммита в буфер обмена", + CommitHash: "hash коммита", CommitURL: "URL коммита", CopyCommitMessageToClipboard: "Скопировать сообщение коммита в буфер обмена", CommitMessage: "Полное сообщение коммита", @@ -579,7 +579,7 @@ func RussianTranslationSet() TranslationSet { CopyCommitMessageToClipboard: "Скопировать сообщение коммита в буфер обмена", CopyCommitSubjectToClipboard: "Скопировать тему коммита в буфер обмена", CopyCommitDiffToClipboard: "Скопировать сравнения коммита в буфер обмена", - CopyCommitHashToClipboard: "Скопировать SHA коммита в буфер обмена", + CopyCommitHashToClipboard: "Скопировать hash коммита в буфер обмена", CopyCommitURLToClipboard: "Скопировать URL коммита в буфер обмена", CopyCommitAuthorToClipboard: "Скопировать автора коммита в буфер обмена", CopyCommitAttributeToClipboard: "Скопировать в буфер обмена", diff --git a/pkg/i18n/traditional_chinese.go b/pkg/i18n/traditional_chinese.go index e0e0c31ed1a..d6ec8f71ea9 100644 --- a/pkg/i18n/traditional_chinese.go +++ b/pkg/i18n/traditional_chinese.go @@ -454,8 +454,8 @@ func traditionalChineseTranslationSet() TranslationSet { OpenCommandLogMenu: "開啟命令記錄選單", ShowingGitDiff: "顯示輸出:", CommitDiff: "提交差異", - CopyCommitHashToClipboard: "複製提交 SHA 到剪貼簿", - CommitHash: "提交 SHA", + CopyCommitHashToClipboard: "複製提交 hash 到剪貼簿", + CommitHash: "提交 hash", CommitURL: "提交 URL", CopyCommitMessageToClipboard: "複製提交訊息到剪貼簿", CommitMessage: "提交訊息", @@ -647,7 +647,7 @@ func traditionalChineseTranslationSet() TranslationSet { CreateAnnotatedTag: "建立附註標籤", CopyCommitMessageToClipboard: "將提交訊息複製到剪貼簿", CopyCommitDiffToClipboard: "將提交差異複製到剪貼簿", - CopyCommitHashToClipboard: "將提交 SHA 複製到剪貼簿", + CopyCommitHashToClipboard: "將提交 hash 複製到剪貼簿", CopyCommitURLToClipboard: "將提交 URL 複製到剪貼簿", CopyCommitAuthorToClipboard: "將提交作者複製到剪貼簿", CopyCommitAttributeToClipboard: "複製到剪貼簿", From de1c4957040c8f6176f05cc8c7b7e79b588071e0 Mon Sep 17 00:00:00 2001 From: pikomonde <32364823+pikomonde@users.noreply.github.com> Date: Thu, 21 Mar 2024 02:04:35 +0700 Subject: [PATCH 10/15] rename sha to hash 8, update some log and comment --- .../git_commands/reflog_commit_loader.go | 2 +- pkg/commands/models/commit.go | 2 +- pkg/gui/controllers/helpers/repos_helper.go | 2 +- pkg/gui/types/context.go | 2 +- pkg/utils/rebase_todo.go | 4 ++-- pkg/utils/rebase_todo_test.go | 16 ++++++++-------- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pkg/commands/git_commands/reflog_commit_loader.go b/pkg/commands/git_commands/reflog_commit_loader.go index 35120311fd6..721bb99e71f 100644 --- a/pkg/commands/git_commands/reflog_commit_loader.go +++ b/pkg/commands/git_commands/reflog_commit_loader.go @@ -45,7 +45,7 @@ func (self *ReflogCommitLoader) GetReflogCommits(lastReflogCommit *models.Commit } // note that the unix timestamp here is the timestamp of the COMMIT, not the reflog entry itself, - // so two consecutive reflog entries may have both the same SHA and therefore same timestamp. + // so two consecutive reflog entries may have both the same hash and therefore same timestamp. // We use the reflog message to disambiguate, and fingers crossed that we never see the same of those // twice in a row. Reason being that it would mean we'd be erroneously exiting early. if lastReflogCommit != nil && self.sameReflogCommit(commit, lastReflogCommit) { diff --git a/pkg/commands/models/commit.go b/pkg/commands/models/commit.go index a6b4af0babf..64b89db8f60 100644 --- a/pkg/commands/models/commit.go +++ b/pkg/commands/models/commit.go @@ -54,7 +54,7 @@ type Commit struct { UnixTimestamp int64 Divergence Divergence // set to DivergenceNone unless we are showing the divergence view - // SHAs of parent commits (will be multiple if it's a merge commit) + // Hashes of parent commits (will be multiple if it's a merge commit) Parents []string } diff --git a/pkg/gui/controllers/helpers/repos_helper.go b/pkg/gui/controllers/helpers/repos_helper.go index c2c177078d6..22883510a53 100644 --- a/pkg/gui/controllers/helpers/repos_helper.go +++ b/pkg/gui/controllers/helpers/repos_helper.go @@ -62,7 +62,7 @@ func (self *ReposHelper) getCurrentBranch(path string) string { // is a branch branchDisplay = strings.TrimPrefix(content, refsPrefix) } else { - // detached HEAD state, displaying short SHA + // detached HEAD state, displaying short hash branchDisplay = utils.ShortHash(content) } return branchDisplay, nil diff --git a/pkg/gui/types/context.go b/pkg/gui/types/context.go index bb57375f9ee..63c759eb6ae 100644 --- a/pkg/gui/types/context.go +++ b/pkg/gui/types/context.go @@ -245,7 +245,7 @@ type IListPanelState interface { } type ListItem interface { - // ID is a SHA when the item is a commit, a filename when the item is a file, 'stash@{4}' when it's a stash entry, 'my_branch' when it's a branch + // ID is a hash when the item is a commit, a filename when the item is a file, 'stash@{4}' when it's a stash entry, 'my_branch' when it's a branch ID() string // Description is something we would show in a message e.g. '123as14: push blah' for a commit diff --git a/pkg/utils/rebase_todo.go b/pkg/utils/rebase_todo.go index 6062d6785ec..c3186a04a98 100644 --- a/pkg/utils/rebase_todo.go +++ b/pkg/utils/rebase_todo.go @@ -244,12 +244,12 @@ func moveFixupCommitDown(todos []todo.Todo, originalSha string, fixupSha string) originalShaCount := lo.CountBy(todos, isOriginal) if originalShaCount != 1 { - return nil, fmt.Errorf("Expected exactly one original SHA, found %d", originalShaCount) + return nil, fmt.Errorf("Expected exactly one original hash, found %d", originalShaCount) } fixupShaCount := lo.CountBy(todos, isFixup) if fixupShaCount != 1 { - return nil, fmt.Errorf("Expected exactly one fixup SHA, found %d", fixupShaCount) + return nil, fmt.Errorf("Expected exactly one fixup hash, found %d", fixupShaCount) } _, fixupIndex, _ := lo.FindIndexOf(todos, isFixup) diff --git a/pkg/utils/rebase_todo_test.go b/pkg/utils/rebase_todo_test.go index c75d6d786d1..9e7e6ca9762 100644 --- a/pkg/utils/rebase_todo_test.go +++ b/pkg/utils/rebase_todo_test.go @@ -301,7 +301,7 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) { expectedErr: nil, }, { - name: "More original SHAs than expected", + name: "More original hashes than expected", todos: []todo.Todo{ {Command: todo.Pick, Commit: "original"}, {Command: todo.Pick, Commit: "original"}, @@ -310,10 +310,10 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) { originalHash: "original", fixupHash: "fixup", expectedTodos: nil, - expectedErr: errors.New("Expected exactly one original SHA, found 2"), + expectedErr: errors.New("Expected exactly one original hash, found 2"), }, { - name: "More fixup SHAs than expected", + name: "More fixup hashes than expected", todos: []todo.Todo{ {Command: todo.Pick, Commit: "original"}, {Command: todo.Pick, Commit: "fixup"}, @@ -322,27 +322,27 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) { originalHash: "original", fixupHash: "fixup", expectedTodos: nil, - expectedErr: errors.New("Expected exactly one fixup SHA, found 2"), + expectedErr: errors.New("Expected exactly one fixup hash, found 2"), }, { - name: "No fixup SHAs found", + name: "No fixup hashes found", todos: []todo.Todo{ {Command: todo.Pick, Commit: "original"}, }, originalHash: "original", fixupHash: "fixup", expectedTodos: nil, - expectedErr: errors.New("Expected exactly one fixup SHA, found 0"), + expectedErr: errors.New("Expected exactly one fixup hash, found 0"), }, { - name: "No original SHAs found", + name: "No original hashes found", todos: []todo.Todo{ {Command: todo.Pick, Commit: "fixup"}, }, originalHash: "original", fixupHash: "fixup", expectedTodos: nil, - expectedErr: errors.New("Expected exactly one original SHA, found 0"), + expectedErr: errors.New("Expected exactly one original hash, found 0"), }, } From 170c4ecb8cca77be883f6eebcb46a7631f82ff65 Mon Sep 17 00:00:00 2001 From: pikomonde <32364823+pikomonde@users.noreply.github.com> Date: Thu, 21 Mar 2024 02:14:17 +0700 Subject: [PATCH 11/15] rename sha to hash 9, case: Sha --- pkg/app/daemon/daemon.go | 6 +-- pkg/commands/git_commands/bisect.go | 10 ++-- pkg/commands/git_commands/patch.go | 2 +- pkg/commands/git_commands/rebase.go | 50 +++++++++---------- pkg/commands/git_commands/stash_test.go | 10 ++-- pkg/gui/controllers/bisect_controller.go | 18 +++---- .../controllers/local_commits_controller.go | 14 +++--- pkg/gui/presentation/commits.go | 30 +++++------ pkg/gui/presentation/reflog_commits.go | 6 +-- pkg/i18n/english.go | 6 +-- pkg/i18n/polish.go | 6 +-- pkg/utils/rebase_todo.go | 22 ++++---- 12 files changed, 90 insertions(+), 90 deletions(-) diff --git a/pkg/app/daemon/daemon.go b/pkg/app/daemon/daemon.go index 280172ea28b..e815b6e826b 100644 --- a/pkg/app/daemon/daemon.go +++ b/pkg/app/daemon/daemon.go @@ -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, } } diff --git a/pkg/commands/git_commands/bisect.go b/pkg/commands/git_commands/bisect.go index 1c70537d98a..300613e1673 100644 --- a/pkg/commands/git_commands/bisect.go +++ b/pkg/commands/git_commands/bisect.go @@ -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 } @@ -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 } @@ -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) diff --git a/pkg/commands/git_commands/patch.go b/pkg/commands/git_commands/patch.go index b6a8652bcbe..fa84361018d 100644 --- a/pkg/commands/git_commands/patch.go +++ b/pkg/commands/git_commands/patch.go @@ -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() diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go index e84afdc76b5..fe5cf603707 100644 --- a/pkg/commands/git_commands/rebase.go +++ b/pkg/commands/git_commands/rebase.go @@ -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 } @@ -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() @@ -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{ @@ -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() @@ -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() } @@ -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() } @@ -195,7 +195,7 @@ func logTodoChanges(changes []daemon.ChangeTodoAction) string { } type PrepareInteractiveRebaseCommandOpts struct { - baseShaOrRoot string + baseHashOrRoot string onto string instruction daemon.Instruction overrideEditor bool @@ -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" @@ -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() } @@ -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), @@ -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() } @@ -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() } @@ -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 diff --git a/pkg/commands/git_commands/stash_test.go b/pkg/commands/git_commands/stash_test.go index ad44d72397a..fae0a0b5e10 100644 --- a/pkg/commands/git_commands/stash_test.go +++ b/pkg/commands/git_commands/stash_test.go @@ -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}) @@ -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 @@ -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"}, @@ -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"}, @@ -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}) diff --git a/pkg/gui/controllers/bisect_controller.go b/pkg/gui/controllers/bisect_controller.go index 35327a3d6e7..f65f05e02d7 100644 --- a/pkg/gui/controllers/bisect_controller.go +++ b/pkg/gui/controllers/bisect_controller.go @@ -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 @@ -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 { @@ -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 { @@ -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 { @@ -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) } @@ -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) } @@ -260,7 +260,7 @@ func (self *BisectController) afterMark(selectCurrent bool, waitToReselect bool) } if done { - return self.showBisectCompleteMessage(candidateShas) + return self.showBisectCompleteMessage(candidateHashes) } return nil diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index 8b4e388cb7a..3f301b3ea47 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -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, @@ -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) @@ -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) diff --git a/pkg/gui/presentation/commits.go b/pkg/gui/presentation/commits.go index 3571461268d..1fc2c7d919b 100644 --- a/pkg/gui/presentation/commits.go +++ b/pkg/gui/presentation/commits.go @@ -312,7 +312,7 @@ func displayCommit( bisectInfo *git_commands.BisectInfo, isYouAreHereCommit bool, ) []string { - shaColor := getShaColor(commit, diffName, cherryPickedCommitHashSet, bisectStatus, bisectInfo) + hashColor := getHashColor(commit, diffName, cherryPickedCommitHashSet, bisectStatus, bisectInfo) bisectString := getBisectStatusText(bisectStatus, bisectInfo) actionString := "" @@ -369,11 +369,11 @@ func displayCommit( cols := make([]string, 0, 7) if commit.Divergence != models.DivergenceNone { - cols = append(cols, shaColor.Sprint(lo.Ternary(commit.Divergence == models.DivergenceLeft, "↑", "↓"))) + cols = append(cols, hashColor.Sprint(lo.Ternary(commit.Divergence == models.DivergenceLeft, "↑", "↓"))) } else if icons.IsIconEnabled() { - cols = append(cols, shaColor.Sprint(icons.IconForCommit(commit))) + cols = append(cols, hashColor.Sprint(icons.IconForCommit(commit))) } - cols = append(cols, shaColor.Sprint(commit.ShortHash())) + cols = append(cols, hashColor.Sprint(commit.ShortHash())) cols = append(cols, bisectString) if fullDescription { cols = append(cols, style.FgBlue.Sprint( @@ -410,7 +410,7 @@ func getBisectStatusColor(status BisectStatus) style.TextStyle { return style.FgWhite } -func getShaColor( +func getHashColor( commit *models.Commit, diffName string, cherryPickedCommitHashSet *set.Set[string], @@ -422,30 +422,30 @@ func getShaColor( } diffed := commit.Hash != "" && commit.Hash == diffName - shaColor := theme.DefaultTextColor + hashColor := theme.DefaultTextColor switch commit.Status { case models.StatusUnpushed: - shaColor = style.FgRed + hashColor = style.FgRed case models.StatusPushed: - shaColor = style.FgYellow + hashColor = style.FgYellow case models.StatusMerged: - shaColor = style.FgGreen + hashColor = style.FgGreen case models.StatusRebasing: - shaColor = style.FgBlue + hashColor = style.FgBlue case models.StatusReflog: - shaColor = style.FgBlue + hashColor = style.FgBlue default: } if diffed { - shaColor = theme.DiffTerminalColor + hashColor = theme.DiffTerminalColor } else if cherryPickedCommitHashSet.Includes(commit.Hash) { - shaColor = theme.CherryPickedCommitTextStyle + hashColor = theme.CherryPickedCommitTextStyle } else if commit.Divergence == models.DivergenceRight && commit.Status != models.StatusMerged { - shaColor = style.FgBlue + hashColor = style.FgBlue } - return shaColor + return hashColor } func actionColorMap(action todo.TodoCommand) style.TextStyle { diff --git a/pkg/gui/presentation/reflog_commits.go b/pkg/gui/presentation/reflog_commits.go index 243fea1a391..b40f33b23b9 100644 --- a/pkg/gui/presentation/reflog_commits.go +++ b/pkg/gui/presentation/reflog_commits.go @@ -35,7 +35,7 @@ func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription }) } -func reflogShaColor(cherryPicked, diffed bool) style.TextStyle { +func reflogHashColor(cherryPicked, diffed bool) style.TextStyle { if diffed { return theme.DiffTerminalColor } @@ -64,7 +64,7 @@ func getFullDescriptionDisplayStringsForReflogCommit(c *models.Commit, attrs ref } return []string{ - reflogShaColor(attrs.cherryPicked, attrs.diffed).Sprint(c.ShortHash()), + reflogHashColor(attrs.cherryPicked, attrs.diffed).Sprint(c.ShortHash()), style.FgMagenta.Sprint(utils.UnixToDateSmart(attrs.now, c.UnixTimestamp, attrs.timeFormat, attrs.shortTimeFormat)), theme.DefaultTextColor.Sprint(name), } @@ -77,7 +77,7 @@ func getDisplayStringsForReflogCommit(c *models.Commit, attrs reflogCommitDispla } return []string{ - reflogShaColor(attrs.cherryPicked, attrs.diffed).Sprint(c.ShortHash()), + reflogHashColor(attrs.cherryPicked, attrs.diffed).Sprint(c.ShortHash()), theme.DefaultTextColor.Sprint(name), } } diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 9e728defd8c..27905cf9bb1 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -1875,11 +1875,11 @@ func EnglishTranslationSet() TranslationSet { }, Log: Log{ EditRebase: "Beginning interactive rebase at '{{.ref}}'", - MoveCommitUp: "Moving TODO down: '{{.shortSha}}'", - MoveCommitDown: "Moving TODO down: '{{.shortSha}}'", + MoveCommitUp: "Moving TODO down: '{{.shortHash}}'", + MoveCommitDown: "Moving TODO down: '{{.shortHash}}'", CherryPickCommits: "Cherry-picking commits:\n'{{.commitLines}}'", HandleUndo: "Undoing last conflict resolution", - HandleMidRebaseCommand: "Updating rebase action of commit {{.shortSha}} to '{{.action}}'", + HandleMidRebaseCommand: "Updating rebase action of commit {{.shortHash}} to '{{.action}}'", RemoveFile: "Deleting path '{{.path}}'", CopyToClipboard: "Copying '{{.str}}' to clipboard", Remove: "Removing '{{.filename}}'", diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go index 6299c3595f2..64067fb1dfc 100644 --- a/pkg/i18n/polish.go +++ b/pkg/i18n/polish.go @@ -887,11 +887,11 @@ func polishTranslationSet() TranslationSet { }, Log: Log{ EditRebase: "Rozpoczynanie interaktywnego rebazowania od '{{.ref}}'", - MoveCommitUp: "Przenoszenie TODO w dół: '{{.shortSha}}'", - MoveCommitDown: "Przenoszenie TODO w dół: '{{.shortSha}}'", + MoveCommitUp: "Przenoszenie TODO w dół: '{{.shortHash}}'", + MoveCommitDown: "Przenoszenie TODO w dół: '{{.shortHash}}'", CherryPickCommits: "Cherry-picking commitów:\n'{{.commitLines}}'", HandleUndo: "Cofanie ostatniego rozwiązania konfliktu", - HandleMidRebaseCommand: "Aktualizacja akcji rebazowania commita {{.shortSha}} na '{{.action}}'", + HandleMidRebaseCommand: "Aktualizacja akcji rebazowania commita {{.shortHash}} na '{{.action}}'", RemoveFile: "Usuwanie ścieżki '{{.path}}'", CopyToClipboard: "Kopiowanie '{{.str}}' do schowka", Remove: "Usuwanie '{{.filename}}'", diff --git a/pkg/utils/rebase_todo.go b/pkg/utils/rebase_todo.go index c3186a04a98..fca1944f138 100644 --- a/pkg/utils/rebase_todo.go +++ b/pkg/utils/rebase_todo.go @@ -219,13 +219,13 @@ func moveTodosUp(todos []todo.Todo, todosToMove []Todo) ([]todo.Todo, error) { return todos, nil } -func MoveFixupCommitDown(fileName string, originalSha string, fixupSha string, commentChar byte) error { +func MoveFixupCommitDown(fileName string, originalHash string, fixupHash string, commentChar byte) error { todos, err := ReadRebaseTodoFile(fileName, commentChar) if err != nil { return err } - newTodos, err := moveFixupCommitDown(todos, originalSha, fixupSha) + newTodos, err := moveFixupCommitDown(todos, originalHash, fixupHash) if err != nil { return err } @@ -233,23 +233,23 @@ func MoveFixupCommitDown(fileName string, originalSha string, fixupSha string, c return WriteRebaseTodoFile(fileName, newTodos, commentChar) } -func moveFixupCommitDown(todos []todo.Todo, originalSha string, fixupSha string) ([]todo.Todo, error) { +func moveFixupCommitDown(todos []todo.Todo, originalHash string, fixupHash string) ([]todo.Todo, error) { isOriginal := func(t todo.Todo) bool { - return t.Command == todo.Pick && equalHash(t.Commit, originalSha) + return t.Command == todo.Pick && equalHash(t.Commit, originalHash) } isFixup := func(t todo.Todo) bool { - return t.Command == todo.Pick && equalHash(t.Commit, fixupSha) + return t.Command == todo.Pick && equalHash(t.Commit, fixupHash) } - originalShaCount := lo.CountBy(todos, isOriginal) - if originalShaCount != 1 { - return nil, fmt.Errorf("Expected exactly one original hash, found %d", originalShaCount) + originalHashCount := lo.CountBy(todos, isOriginal) + if originalHashCount != 1 { + return nil, fmt.Errorf("Expected exactly one original hash, found %d", originalHashCount) } - fixupShaCount := lo.CountBy(todos, isFixup) - if fixupShaCount != 1 { - return nil, fmt.Errorf("Expected exactly one fixup hash, found %d", fixupShaCount) + fixupHashCount := lo.CountBy(todos, isFixup) + if fixupHashCount != 1 { + return nil, fmt.Errorf("Expected exactly one fixup hash, found %d", fixupHashCount) } _, fixupIndex, _ := lo.FindIndexOf(todos, isFixup) From 19bef17042c4a9426afcefc89fcc9ce672fb2216 Mon Sep 17 00:00:00 2001 From: pikomonde <32364823+pikomonde@users.noreply.github.com> Date: Thu, 21 Mar 2024 02:23:10 +0700 Subject: [PATCH 12/15] rename sha to hash 10, last remaining sha (hopefully) --- pkg/commands/git_commands/commit_test.go | 2 +- pkg/commands/git_commands/rebase.go | 16 ++++++++-------- pkg/commands/git_commands/stash_test.go | 8 ++++---- pkg/gui/controllers/bisect_controller.go | 10 +++++----- pkg/gui/presentation/reflog_commits.go | 6 +++--- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pkg/commands/git_commands/commit_test.go b/pkg/commands/git_commands/commit_test.go index 43a8d05565d..2e36636c50a 100644 --- a/pkg/commands/git_commands/commit_test.go +++ b/pkg/commands/git_commands/commit_test.go @@ -365,7 +365,7 @@ func TestGetCommitMessageFromHistory(t *testing.T) { }, { "Default case to retrieve a commit in history", - oscommands.NewFakeRunner(t).ExpectGitArgs([]string{"log", "-1", "--skip=2", "--pretty=%H"}, "sha3 \n", nil).ExpectGitArgs([]string{"-c", "log.showsignature=false", "log", "--format=%B", "--max-count=1", "sha3"}, `use generics to DRY up context code`, nil), + oscommands.NewFakeRunner(t).ExpectGitArgs([]string{"log", "-1", "--skip=2", "--pretty=%H"}, "hash3 \n", nil).ExpectGitArgs([]string{"-c", "log.showsignature=false", "log", "--format=%B", "--max-count=1", "hash3"}, `use generics to DRY up context code`, nil), func(output string, err error) { assert.NoError(t, err) assert.Equal(t, "use generics to DRY up context code", output) diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go index fe5cf603707..f7b8b43dcec 100644 --- a/pkg/commands/git_commands/rebase.go +++ b/pkg/commands/git_commands/rebase.go @@ -108,13 +108,13 @@ func (self *RebaseCommands) GenericAmend(commits []*models.Commit, index int, f func (self *RebaseCommands) MoveCommitsDown(commits []*models.Commit, startIdx int, endIdx int) error { baseHashOrRoot := getBaseHashOrRoot(commits, endIdx+2) - shas := lo.Map(commits[startIdx:endIdx+1], func(commit *models.Commit, _ int) string { + hashes := lo.Map(commits[startIdx:endIdx+1], func(commit *models.Commit, _ int) string { return commit.Hash }) return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{ baseHashOrRoot: baseHashOrRoot, - instruction: daemon.NewMoveTodosDownInstruction(shas), + instruction: daemon.NewMoveTodosDownInstruction(hashes), overrideEditor: true, }).Run() } @@ -122,13 +122,13 @@ func (self *RebaseCommands) MoveCommitsDown(commits []*models.Commit, startIdx i func (self *RebaseCommands) MoveCommitsUp(commits []*models.Commit, startIdx int, endIdx int) error { baseHashOrRoot := getBaseHashOrRoot(commits, endIdx+1) - shas := lo.Map(commits[startIdx:endIdx+1], func(commit *models.Commit, _ int) string { + hashes := lo.Map(commits[startIdx:endIdx+1], func(commit *models.Commit, _ int) string { return commit.Hash }) return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{ baseHashOrRoot: baseHashOrRoot, - instruction: daemon.NewMoveTodosUpInstruction(shas), + instruction: daemon.NewMoveTodosUpInstruction(hashes), overrideEditor: true, }).Run() } @@ -364,13 +364,13 @@ func (self *RebaseCommands) MoveTodosUp(commits []*models.Commit) error { // SquashAllAboveFixupCommits squashes all fixup! commits above the given one func (self *RebaseCommands) SquashAllAboveFixupCommits(commit *models.Commit) error { - shaOrRoot := commit.Hash + "^" + hashOrRoot := commit.Hash + "^" if commit.IsFirstCommit() { - shaOrRoot = "--root" + hashOrRoot = "--root" } cmdArgs := NewGitCmd("rebase"). - Arg("--interactive", "--rebase-merges", "--autostash", "--autosquash", shaOrRoot). + Arg("--interactive", "--rebase-merges", "--autostash", "--autosquash", hashOrRoot). ToArgv() return self.runSkipEditorCommand(self.cmd.New(cmdArgs)) @@ -503,7 +503,7 @@ func (self *RebaseCommands) DiscardOldFileChanges(commits []*models.Commit, comm return self.ContinueRebase() } -// CherryPickCommits begins an interactive rebase with the given shas being cherry picked onto HEAD +// CherryPickCommits begins an interactive rebase with the given hashes being cherry picked onto HEAD func (self *RebaseCommands) CherryPickCommits(commits []*models.Commit) error { commitLines := lo.Map(commits, func(commit *models.Commit, _ int) string { return fmt.Sprintf("%s %s", utils.ShortHash(commit.Hash), commit.Name) diff --git a/pkg/commands/git_commands/stash_test.go b/pkg/commands/git_commands/stash_test.go index fae0a0b5e10..35b48e42db8 100644 --- a/pkg/commands/git_commands/stash_test.go +++ b/pkg/commands/git_commands/stash_test.go @@ -154,7 +154,7 @@ func TestStashRename(t *testing.T) { index int message string expectedHashCmd []string - shaResult string + hashResult string expectedDropCmd []string expectedStoreCmd []string } @@ -165,7 +165,7 @@ func TestStashRename(t *testing.T) { index: 3, message: "New message", expectedHashCmd: []string{"rev-parse", "refs/stash@{3}"}, - shaResult: "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd\n", + hashResult: "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd\n", expectedDropCmd: []string{"stash", "drop", "stash@{3}"}, expectedStoreCmd: []string{"stash", "store", "-m", "New message", "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd"}, }, @@ -174,7 +174,7 @@ func TestStashRename(t *testing.T) { index: 4, message: "", expectedHashCmd: []string{"rev-parse", "refs/stash@{4}"}, - shaResult: "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd\n", + hashResult: "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd\n", expectedDropCmd: []string{"stash", "drop", "stash@{4}"}, expectedStoreCmd: []string{"stash", "store", "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd"}, }, @@ -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.expectedHashCmd, s.shaResult, nil). + ExpectGitArgs(s.expectedHashCmd, s.hashResult, nil). ExpectGitArgs(s.expectedDropCmd, "", nil). ExpectGitArgs(s.expectedStoreCmd, "", nil) instance := buildStashCommands(commonDeps{runner: runner}) diff --git a/pkg/gui/controllers/bisect_controller.go b/pkg/gui/controllers/bisect_controller.go index f65f05e02d7..89cc6241f7c 100644 --- a/pkg/gui/controllers/bisect_controller.go +++ b/pkg/gui/controllers/bisect_controller.go @@ -79,8 +79,8 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c // use the selected commit in that case. bisecting := info.GetCurrentHash() != "" - shaToMark := lo.Ternary(bisecting, info.GetCurrentHash(), commit.Hash) - shortHashToMark := utils.ShortHash(shaToMark) + hashToMark := lo.Ternary(bisecting, info.GetCurrentHash(), commit.Hash) + shortHashToMark := utils.ShortHash(hashToMark) // 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 @@ -95,7 +95,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c 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 { + if err := self.c.Git().Bisect.Mark(hashToMark, info.NewTerm()); err != nil { return self.c.Error(err) } @@ -108,7 +108,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c 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 { + if err := self.c.Git().Bisect.Mark(hashToMark, info.OldTerm()); err != nil { return self.c.Error(err) } @@ -121,7 +121,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c 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 { + if err := self.c.Git().Bisect.Skip(hashToMark); err != nil { return self.c.Error(err) } diff --git a/pkg/gui/presentation/reflog_commits.go b/pkg/gui/presentation/reflog_commits.go index b40f33b23b9..b97064d5111 100644 --- a/pkg/gui/presentation/reflog_commits.go +++ b/pkg/gui/presentation/reflog_commits.go @@ -40,12 +40,12 @@ func reflogHashColor(cherryPicked, diffed bool) style.TextStyle { return theme.DiffTerminalColor } - shaColor := style.FgBlue + hashColor := style.FgBlue if cherryPicked { - shaColor = theme.CherryPickedCommitTextStyle + hashColor = theme.CherryPickedCommitTextStyle } - return shaColor + return hashColor } type reflogCommitDisplayAttributes struct { From 28923fc9d01da73d3dc0cf1112c09b9fa2bd451c Mon Sep 17 00:00:00 2001 From: Shin-JaeHeon Date: Thu, 11 Apr 2024 23:27:56 +0900 Subject: [PATCH 13/15] improve korean translation --- docs/keybindings/Keybindings_ko.md | 6 +++--- pkg/i18n/korean.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/keybindings/Keybindings_ko.md b/docs/keybindings/Keybindings_ko.md index 15b8521b443..1313ad9d3e4 100644 --- a/docs/keybindings/Keybindings_ko.md +++ b/docs/keybindings/Keybindings_ko.md @@ -53,7 +53,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | Key | Action | Info | |-----|--------|-------------| -| `` `` | 커밋 hash를 클립보드에 복사 | | +| `` `` | 커밋 해시를 클립보드에 복사 | | | `` `` | 체크아웃 | Checkout the selected commit as a detached HEAD. | | `` y `` | 커밋 attribute 복사 | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). | | `` o `` | 브라우저에서 커밋 열기 | | @@ -83,7 +83,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | Key | Action | Info | |-----|--------|-------------| -| `` `` | 커밋 hash를 클립보드에 복사 | | +| `` `` | 커밋 해시를 클립보드에 복사 | | | `` `` | 체크아웃 | Checkout the selected commit as a detached HEAD. | | `` y `` | 커밋 attribute 복사 | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). | | `` o `` | 브라우저에서 커밋 열기 | | @@ -256,7 +256,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | Key | Action | Info | |-----|--------|-------------| -| `` `` | 커밋 hash를 클립보드에 복사 | | +| `` `` | 커밋 해시를 클립보드에 복사 | | | `` `` | Reset cherry-picked (copied) commits selection | | | `` b `` | Bisect 옵션 보기 | | | `` s `` | Squash | Squash the selected commit into the commit below it. The selected commit's message will be appended to the commit below it. | diff --git a/pkg/i18n/korean.go b/pkg/i18n/korean.go index 34d5bf6aee0..e333dd29267 100644 --- a/pkg/i18n/korean.go +++ b/pkg/i18n/korean.go @@ -361,8 +361,8 @@ func koreanTranslationSet() TranslationSet { OpenCommandLogMenu: "명령어 로그 메뉴 열기", ShowingGitDiff: "Showing output for:", CommitDiff: "커밋의 iff", - CopyCommitHashToClipboard: "커밋 hash를 클립보드에 복사", - CommitHash: "커밋 hash", + CopyCommitHashToClipboard: "커밋 해시를 클립보드에 복사", + CommitHash: "커밋 해시", CommitURL: "커밋 URL", CopyCommitMessageToClipboard: "커밋 메시지를 클립보드에 복사", CommitMessage: "커밋 메시지", @@ -486,7 +486,7 @@ func koreanTranslationSet() TranslationSet { CreateAnnotatedTag: "Create annotated tag", CopyCommitMessageToClipboard: "커밋 메시지를 클립보드에 복사", CopyCommitDiffToClipboard: "커밋 diff를 클립보드에 복사", - CopyCommitHashToClipboard: "커밋 hash를 클립보드에 복사", + CopyCommitHashToClipboard: "커밋 해시를 클립보드에 복사", CopyCommitURLToClipboard: "커밋 URL를 클립보드에 복사", CopyCommitAuthorToClipboard: "커밋 작성자를 클립보드에 복사", CopyCommitAttributeToClipboard: "클립보드에 복사", From e6a07b3f03170ff7a10ce192546643c88da78486 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 11 Apr 2024 18:38:20 +0200 Subject: [PATCH 14/15] Add integration test that accesses commit properties in a custom command Useful as a regression test to check that the following commit doesn't break it. --- pkg/integration/components/git.go | 8 ++++ .../access_commit_properties.go | 37 +++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 3 files changed, 46 insertions(+) create mode 100644 pkg/integration/tests/custom_commands/access_commit_properties.go diff --git a/pkg/integration/components/git.go b/pkg/integration/components/git.go index 1e2975be25a..1b07e5cf802 100644 --- a/pkg/integration/components/git.go +++ b/pkg/integration/components/git.go @@ -55,3 +55,11 @@ func (self *Git) Version() *git_commands.GitVersion { } return version } + +func (self *Git) GetCommitHash(ref string) string { + output, err := self.shell.runCommandWithOutput([]string{"git", "rev-parse", ref}) + if err != nil { + log.Fatalf("Could not get commit hash: %v", err) + } + return strings.TrimSpace(output) +} diff --git a/pkg/integration/tests/custom_commands/access_commit_properties.go b/pkg/integration/tests/custom_commands/access_commit_properties.go new file mode 100644 index 00000000000..fbb54bf8135 --- /dev/null +++ b/pkg/integration/tests/custom_commands/access_commit_properties.go @@ -0,0 +1,37 @@ +package custom_commands + +import ( + "fmt" + + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var AccessCommitProperties = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Run a command that accesses properties of a commit", + ExtraCmdArgs: []string{}, + Skip: false, + SetupRepo: func(shell *Shell) { + shell.EmptyCommit("my change") + }, + SetupConfig: func(cfg *config.AppConfig) { + cfg.UserConfig.CustomCommands = []config.CustomCommand{ + { + Key: "X", + Context: "commits", + Command: "printf '%s\n%s' '{{ .SelectedLocalCommit.Name }}' '{{ .SelectedLocalCommit.Hash }}' > file.txt", + }, + } + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Lines( + Contains("my change").IsSelected(), + ). + Press("X") + + hash := t.Git().GetCommitHash("HEAD") + t.FileSystem().FileContent("file.txt", Equals(fmt.Sprintf("my change\n%s", hash))) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 8f62ca7f5ee..cb1a66ac5b5 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -97,6 +97,7 @@ var tests = []*components.IntegrationTest{ conflicts.ResolveExternally, conflicts.ResolveMultipleFiles, conflicts.UndoChooseHunk, + custom_commands.AccessCommitProperties, custom_commands.BasicCmdAtRuntime, custom_commands.BasicCmdFromConfig, custom_commands.CheckForConflicts, From 7e14d88dc94c868c0ac9743b688f6d9a3d6698d7 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 11 Apr 2024 18:39:21 +0200 Subject: [PATCH 15/15] Support both Sha and Hash on commits in custom commands We achieve this by wrapping the model Commit in a custom struct that provides both. --- .../custom_commands/session_state_loader.go | 49 ++++++++++++++++--- .../access_commit_properties.go | 4 +- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/pkg/gui/services/custom_commands/session_state_loader.go b/pkg/gui/services/custom_commands/session_state_loader.go index d5d34bfc947..93ce9d17995 100644 --- a/pkg/gui/services/custom_commands/session_state_loader.go +++ b/pkg/gui/services/custom_commands/session_state_loader.go @@ -1,6 +1,7 @@ package custom_commands import ( + "github.com/fsmiamoto/git-todo-parser/todo" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers" ) @@ -19,11 +20,47 @@ func NewSessionStateLoader(c *helpers.HelperCommon, refsHelper *helpers.RefsHelp } } +type Commit struct { + Hash string + Sha string + Name string + Status models.CommitStatus + Action todo.TodoCommand + Tags []string + ExtraInfo string + AuthorName string + AuthorEmail string + UnixTimestamp int64 + Divergence models.Divergence + Parents []string +} + +func commitWrapperFromModelCommit(commit *models.Commit) *Commit { + if commit == nil { + return nil + } + + return &Commit{ + Hash: commit.Hash, + Sha: commit.Hash, + Name: commit.Name, + Status: commit.Status, + Action: commit.Action, + Tags: commit.Tags, + ExtraInfo: commit.ExtraInfo, + AuthorName: commit.AuthorName, + AuthorEmail: commit.AuthorEmail, + UnixTimestamp: commit.UnixTimestamp, + Divergence: commit.Divergence, + Parents: commit.Parents, + } +} + // SessionState captures the current state of the application for use in custom commands type SessionState struct { - SelectedLocalCommit *models.Commit - SelectedReflogCommit *models.Commit - SelectedSubCommit *models.Commit + SelectedLocalCommit *Commit + SelectedReflogCommit *Commit + SelectedSubCommit *Commit SelectedFile *models.File SelectedPath string SelectedLocalBranch *models.Branch @@ -41,8 +78,8 @@ func (self *SessionStateLoader) call() *SessionState { return &SessionState{ SelectedFile: self.c.Contexts().Files.GetSelectedFile(), SelectedPath: self.c.Contexts().Files.GetSelectedPath(), - SelectedLocalCommit: self.c.Contexts().LocalCommits.GetSelected(), - SelectedReflogCommit: self.c.Contexts().ReflogCommits.GetSelected(), + SelectedLocalCommit: commitWrapperFromModelCommit(self.c.Contexts().LocalCommits.GetSelected()), + SelectedReflogCommit: commitWrapperFromModelCommit(self.c.Contexts().ReflogCommits.GetSelected()), SelectedLocalBranch: self.c.Contexts().Branches.GetSelected(), SelectedRemoteBranch: self.c.Contexts().RemoteBranches.GetSelected(), SelectedRemote: self.c.Contexts().Remotes.GetSelected(), @@ -50,7 +87,7 @@ func (self *SessionStateLoader) call() *SessionState { SelectedStashEntry: self.c.Contexts().Stash.GetSelected(), SelectedCommitFile: self.c.Contexts().CommitFiles.GetSelectedFile(), SelectedCommitFilePath: self.c.Contexts().CommitFiles.GetSelectedPath(), - SelectedSubCommit: self.c.Contexts().SubCommits.GetSelected(), + SelectedSubCommit: commitWrapperFromModelCommit(self.c.Contexts().SubCommits.GetSelected()), SelectedWorktree: self.c.Contexts().Worktrees.GetSelected(), CheckedOutBranch: self.refsHelper.GetCheckedOutRef(), } diff --git a/pkg/integration/tests/custom_commands/access_commit_properties.go b/pkg/integration/tests/custom_commands/access_commit_properties.go index fbb54bf8135..6ac77faf85a 100644 --- a/pkg/integration/tests/custom_commands/access_commit_properties.go +++ b/pkg/integration/tests/custom_commands/access_commit_properties.go @@ -19,7 +19,7 @@ var AccessCommitProperties = NewIntegrationTest(NewIntegrationTestArgs{ { Key: "X", Context: "commits", - Command: "printf '%s\n%s' '{{ .SelectedLocalCommit.Name }}' '{{ .SelectedLocalCommit.Hash }}' > file.txt", + Command: "printf '%s\n%s\n%s' '{{ .SelectedLocalCommit.Name }}' '{{ .SelectedLocalCommit.Hash }}' '{{ .SelectedLocalCommit.Sha }}' > file.txt", }, } }, @@ -32,6 +32,6 @@ var AccessCommitProperties = NewIntegrationTest(NewIntegrationTestArgs{ Press("X") hash := t.Git().GetCommitHash("HEAD") - t.FileSystem().FileContent("file.txt", Equals(fmt.Sprintf("my change\n%s", hash))) + t.FileSystem().FileContent("file.txt", Equals(fmt.Sprintf("my change\n%s\n%s", hash, hash))) }, })