Skip to content

Commit

Permalink
fixup! Create shims for all model classes in SessionStateLoader
Browse files Browse the repository at this point in the history
Remove the "Shim" from the type names after all, as it could be confusing for
users.
  • Loading branch information
stefanhaller committed May 19, 2024
1 parent 7ab7fae commit 416106a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 41 deletions.
20 changes: 10 additions & 10 deletions pkg/gui/services/custom_commands/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// the new, better name to the shim but keep the old one for backwards
// compatibility. We already did this for Commit.Sha, which was renamed to Hash.

type CommitShim struct {
type Commit struct {
Hash string // deprecated: use Sha
Sha string
Name string
Expand All @@ -28,7 +28,7 @@ type CommitShim struct {
Parents []string
}

type FileShim struct {
type File struct {
Name string
PreviousName string
HasStagedChanges bool
Expand All @@ -43,7 +43,7 @@ type FileShim struct {
IsWorktree bool
}

type BranchShim struct {
type Branch struct {
Name string
DisplayName string
Recency string
Expand All @@ -62,34 +62,34 @@ type BranchShim struct {
CommitHash string
}

type RemoteBranchShim struct {
type RemoteBranch struct {
Name string
RemoteName string
}

type RemoteShim struct {
type Remote struct {
Name string
Urls []string
Branches []*RemoteBranchShim
Branches []*RemoteBranch
}

type TagShim struct {
type Tag struct {
Name string
Message string
}

type StashEntryShim struct {
type StashEntry struct {
Index int
Recency string
Name string
}

type CommitFileShim struct {
type CommitFile struct {
Name string
ChangeStatus string
}

type WorktreeShim struct {
type Worktree struct {
IsMain bool
IsCurrent bool
Path string
Expand Down
62 changes: 31 additions & 31 deletions pkg/gui/services/custom_commands/session_state_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ func NewSessionStateLoader(c *helpers.HelperCommon, refsHelper *helpers.RefsHelp
}
}

func commitShimFromModelCommit(commit *models.Commit) *CommitShim {
func commitShimFromModelCommit(commit *models.Commit) *Commit {
if commit == nil {
return nil
}

return &CommitShim{
return &Commit{
Hash: commit.Hash,
Sha: commit.Hash,
Name: commit.Name,
Expand All @@ -41,12 +41,12 @@ func commitShimFromModelCommit(commit *models.Commit) *CommitShim {
}
}

func fileShimFromModelFile(file *models.File) *FileShim {
func fileShimFromModelFile(file *models.File) *File {
if file == nil {
return nil
}

return &FileShim{
return &File{
Name: file.Name,
PreviousName: file.PreviousName,
HasStagedChanges: file.HasStagedChanges,
Expand All @@ -62,12 +62,12 @@ func fileShimFromModelFile(file *models.File) *FileShim {
}
}

func branchShimFromModelBranch(branch *models.Branch) *BranchShim {
func branchShimFromModelBranch(branch *models.Branch) *Branch {
if branch == nil {
return nil
}

return &BranchShim{
return &Branch{
Name: branch.Name,
DisplayName: branch.DisplayName,
Recency: branch.Recency,
Expand All @@ -87,71 +87,71 @@ func branchShimFromModelBranch(branch *models.Branch) *BranchShim {
}
}

func remoteBranchShimFromModelRemoteBranch(remoteBranch *models.RemoteBranch) *RemoteBranchShim {
func remoteBranchShimFromModelRemoteBranch(remoteBranch *models.RemoteBranch) *RemoteBranch {
if remoteBranch == nil {
return nil
}

return &RemoteBranchShim{
return &RemoteBranch{
Name: remoteBranch.Name,
RemoteName: remoteBranch.RemoteName,
}
}

func remoteShimFromModelRemote(remote *models.Remote) *RemoteShim {
func remoteShimFromModelRemote(remote *models.Remote) *Remote {
if remote == nil {
return nil
}

return &RemoteShim{
return &Remote{
Name: remote.Name,
Urls: remote.Urls,
Branches: lo.Map(remote.Branches, func(branch *models.RemoteBranch, _ int) *RemoteBranchShim {
Branches: lo.Map(remote.Branches, func(branch *models.RemoteBranch, _ int) *RemoteBranch {
return remoteBranchShimFromModelRemoteBranch(branch)
}),
}
}

func tagShimFromModelRemote(tag *models.Tag) *TagShim {
func tagShimFromModelRemote(tag *models.Tag) *Tag {
if tag == nil {
return nil
}

return &TagShim{
return &Tag{
Name: tag.Name,
Message: tag.Message,
}
}

func stashEntryShimFromModelRemote(stashEntry *models.StashEntry) *StashEntryShim {
func stashEntryShimFromModelRemote(stashEntry *models.StashEntry) *StashEntry {
if stashEntry == nil {
return nil
}

return &StashEntryShim{
return &StashEntry{
Index: stashEntry.Index,
Recency: stashEntry.Recency,
Name: stashEntry.Name,
}
}

func commitFileShimFromModelRemote(commitFile *models.CommitFile) *CommitFileShim {
func commitFileShimFromModelRemote(commitFile *models.CommitFile) *CommitFile {
if commitFile == nil {
return nil
}

return &CommitFileShim{
return &CommitFile{
Name: commitFile.Name,
ChangeStatus: commitFile.ChangeStatus,
}
}

func worktreeShimFromModelRemote(worktree *models.Worktree) *WorktreeShim {
func worktreeShimFromModelRemote(worktree *models.Worktree) *Worktree {
if worktree == nil {
return nil
}

return &WorktreeShim{
return &Worktree{
IsMain: worktree.IsMain,
IsCurrent: worktree.IsCurrent,
Path: worktree.Path,
Expand All @@ -164,20 +164,20 @@ func worktreeShimFromModelRemote(worktree *models.Worktree) *WorktreeShim {

// SessionState captures the current state of the application for use in custom commands
type SessionState struct {
SelectedLocalCommit *CommitShim
SelectedReflogCommit *CommitShim
SelectedSubCommit *CommitShim
SelectedFile *FileShim
SelectedLocalCommit *Commit
SelectedReflogCommit *Commit
SelectedSubCommit *Commit
SelectedFile *File
SelectedPath string
SelectedLocalBranch *BranchShim
SelectedRemoteBranch *RemoteBranchShim
SelectedRemote *RemoteShim
SelectedTag *TagShim
SelectedStashEntry *StashEntryShim
SelectedCommitFile *CommitFileShim
SelectedLocalBranch *Branch
SelectedRemoteBranch *RemoteBranch
SelectedRemote *Remote
SelectedTag *Tag
SelectedStashEntry *StashEntry
SelectedCommitFile *CommitFile
SelectedCommitFilePath string
SelectedWorktree *WorktreeShim
CheckedOutBranch *BranchShim
SelectedWorktree *Worktree
CheckedOutBranch *Branch
}

func (self *SessionStateLoader) call() *SessionState {
Expand Down

0 comments on commit 416106a

Please sign in to comment.