Repository: jesseduffield/lazygit
File: pkg/gui/gui.go (Go)

Code before:

				// setting this to nil so we don't get stuck based on a popup that was
				// previously opened
				gui.Mutexes.PopupMutex.Lock()
				gui.State.CurrentPopupOpts = nil
				gui.Mutexes.PopupMutex.Unlock()

				gui.syncViewContexts()
				return
			}
		} else {
			gui.c.Log.Error(err)
		}
	}

	contextTree := gui.contextTree()

	screenMode := SCREEN_NORMAL
	var initialContext types.IListContext = contextTree.Files
	if filterPath != "" {
		screenMode = SCREEN_HALF
		initialContext = contextTree.LocalCommits
	} else if gitArgs != "" {
		switch gitArgs {
		case "status":
			screenMode = SCREEN_HALF
			initialContext = contextTree.Files
		case "branch":
			screenMode = SCREEN_HALF
			initialContext = contextTree.Branches
		case "log":
			screenMode = SCREEN_HALF
			initialContext = contextTree.LocalCommits
		case "stash":
			screenMode = SCREEN_HALF
			initialContext = contextTree.Stash
		}
	}

	viewContextMap := context.NewViewContextMap()
	for viewName, context := range initialViewContextMapping(contextTree) {
		viewContextMap.Set(viewName, context)
	}

	gui.State = &GuiRepoState{
		Model: &types.Model{
			CommitFiles:           nil,
			Files:                 make([]*models.File, 0),
			Commits:               make([]*models.Commit, 0),
			StashEntries:          make([]*models.StashEntry, 0),
			FilteredReflogCommits: make([]*models.Commit, 0),

Review comment (refactor):
let's move this line just above the switch statement given it's being set to the same value in each leg of the switch statement (and then remove the duplicates). It will be trivially easy to revert this if in future we decide that a particular context needs a different screen mode.

Code after:

				// setting this to nil so we don't get stuck based on a popup that was
				// previously opened
				gui.Mutexes.PopupMutex.Lock()
				gui.State.CurrentPopupOpts = nil
				gui.Mutexes.PopupMutex.Unlock()

				gui.syncViewContexts()
				return
			}
		} else {
			gui.c.Log.Error(err)
		}
	}

	contextTree := gui.contextTree()

	initialContext := initialContext(contextTree, startArgs)
	initialScreenMode := initialScreenMode(startArgs)

	viewContextMap := context.NewViewContextMap()
	for viewName, context := range initialViewContextMapping(contextTree) {
		viewContextMap.Set(viewName, context)
	}

	gui.State = &GuiRepoState{
		Model: &types.Model{
			CommitFiles:           nil,
			Files:                 make([]*models.File, 0),
			Commits:               make([]*models.Commit, 0),
			StashEntries:          make([]*models.StashEntry, 0),
			FilteredReflogCommits: make([]*models.Commit, 0),
			ReflogCommits:         make([]*models.Commit, 0),
			BisectInfo:            git_commands.NewNullBisectInfo(),
			FilesTrie:             patricia.NewTrie(),
		},

		Panels: &panelStates{
			Merging: &MergingPanelState{
				State:                 mergeconflicts.NewState(),
				UserVerticalScrolling: false,
			},
		},
		Ptmx: nil,
		Modes: &types.Modes{
			Filtering:     filtering.New(startArgs.FilterPath),
			CherryPicking: cherrypicking.New(),
			Diffing:       diffing.New(),
		},
		ViewContextMap:    viewContextMap,
		ViewTabContextMap: gui.initialViewTabContextMap(contextTree),