MCPcopy
hub / github.com/jesseduffield/lazygit / resetState

Method resetState

pkg/gui/gui.go:568–632  ·  view source on GitHub ↗

resetState reuses the repo state from our repo state map, if the repo was open before; otherwise it creates a new one.

(startArgs appTypes.StartArgs)

Source from the content-addressed store, hash-verified

566// resetState reuses the repo state from our repo state map, if the repo was
567// open before; otherwise it creates a new one.
568func (gui *Gui) resetState(startArgs appTypes.StartArgs) types.Context {
569 // Un-highlight the current view if there is one. The reason we do this is
570 // that the repo we are switching to might have a different view focused,
571 // and would then show an inactive highlight for the previous view.
572 if oldCurrentView := gui.g.CurrentView(); oldCurrentView != nil {
573 oldCurrentView.Highlight = false
574 }
575
576 worktreePath := gui.git.RepoPaths.WorktreePath()
577
578 if state := gui.RepoStateMap[Repo(worktreePath)]; state != nil {
579 gui.State = state
580 gui.State.ViewsSetup = false
581
582 contextTree := gui.State.Contexts
583 gui.State.WindowViewNameMap = initialWindowViewNameMap(contextTree)
584
585 // setting this to nil so we don't get stuck based on a popup that was
586 // previously opened
587 gui.Mutexes.PopupMutex.Lock()
588 gui.State.CurrentPopupOpts = nil
589 gui.Mutexes.PopupMutex.Unlock()
590
591 return gui.c.Context().Current()
592 }
593
594 contextTree := gui.contextTree()
595
596 initialScreenMode := initialScreenMode(startArgs, gui.Config)
597
598 gui.State = &GuiRepoState{
599 ViewsSetup: false,
600 Model: &types.Model{
601 CommitFiles: nil,
602 Files: make([]*models.File, 0),
603 Commits: make([]*models.Commit, 0),
604 StashEntries: make([]*models.StashEntry, 0),
605 FilteredReflogCommits: make([]*models.Commit, 0),
606 ReflogCommits: make([]*models.Commit, 0),
607 BisectInfo: git_commands.NewNullBisectInfo(),
608 FilesTrie: patricia.NewTrie(),
609 Authors: map[string]*models.Author{},
610 MainBranches: git_commands.NewMainBranches(gui.c.Common, gui.os.Cmd),
611 HashPool: &utils.StringPool{},
612 PullRequests: gui.loadCachedPullRequests(),
613 PullRequestsMap: make(map[string]*models.GithubPullRequest),
614 },
615 Modes: &types.Modes{
616 Filtering: filtering.New(startArgs.FilterPath, ""),
617 CherryPicking: cherrypicking.New(),
618 Diffing: diffing.New(),
619 MarkedBaseCommit: marked_base_commit.New(),
620 },
621 ScreenMode: initialScreenMode,
622 // TODO: only use contexts from context manager
623 ContextMgr: NewContextMgr(gui, contextTree),
624 Contexts: contextTree,
625 WindowViewNameMap: initialWindowViewNameMap(contextTree),

Callers 1

onNewRepoMethod · 0.95

Calls 15

contextTreeMethod · 0.95
NewNullBisectInfoFunction · 0.92
NewMainBranchesFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
RepoTypeAlias · 0.85
initialWindowViewNameMapFunction · 0.85
initialScreenModeFunction · 0.85
NewContextMgrFunction · 0.85

Tested by

no test coverage detected