Skip to content

Commit a67a1a4

Browse files
committed
Use stored repository defaultBranch instead of fetching
1 parent 788539f commit a67a1a4

6 files changed

Lines changed: 35 additions & 52 deletions

File tree

app/src/lib/stores/app-store.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3961,6 +3961,13 @@ export class AppStore extends TypedBaseStore<IAppState> {
39613961
this._initializeCompare(repository)
39623962

39633963
this.updateCurrentTutorialStep(repository)
3964+
3965+
if (!repository.defaultBranch && gitStore.defaultBranch) {
3966+
this._updateRepositoryDefaultBranch(
3967+
repository,
3968+
gitStore.defaultBranch.name
3969+
)
3970+
}
39643971
}
39653972

39663973
private async updateStashEntryCountMetric(
@@ -4005,7 +4012,8 @@ export class AppStore extends TypedBaseStore<IAppState> {
40054012
lookup.set(repository.id, {
40064013
aheadBehind: status.branchAheadBehind || null,
40074014
changedFilesCount: status.workingDirectory.files.length,
4008-
branchName: status.currentBranch,
4015+
branchName: status.currentBranch || null,
4016+
defaultBranchName: repository.defaultBranch,
40094017
})
40104018
}
40114019
/**
@@ -4051,7 +4059,8 @@ export class AppStore extends TypedBaseStore<IAppState> {
40514059
// they were already set when calling `updateSidebarIndicator()` with
40524060
// the status object.
40534061
changedFilesCount: existing?.changedFilesCount ?? 0,
4054-
branchName: existing?.branchName,
4062+
branchName: existing?.branchName ?? null,
4063+
defaultBranchName: existing?.defaultBranchName ?? null,
40554064
})
40564065
this.emitUpdate()
40574066
}

app/src/models/repository.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,11 @@ export interface ILocalRepositoryState {
224224
* The name of the currently checked out branch, or `undefined` if the
225225
* branch name is not available (e.g. detached HEAD).
226226
*/
227-
readonly branchName?: string
227+
readonly branchName: string | null
228+
/**
229+
* The name of the default branch, or `undefined` if not available.
230+
*/
231+
readonly defaultBranchName: string | null
228232
}
229233

230234
/**

app/src/ui/dispatcher/dispatcher.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
MultiCommitOperationConflictState,
2424
IMultiCommitOperationState,
2525
CommitOptions,
26-
IBranchesState,
2726
} from '../../lib/app-state'
2827
import { assertNever, fatalError } from '../../lib/fatal-error'
2928
import {
@@ -2199,11 +2198,6 @@ export class Dispatcher {
21992198
}
22002199
}
22012200

2202-
public getBranchesState(repository: Repository): IBranchesState {
2203-
const state = this.repositoryStateManager.get(repository)
2204-
return state.branchesState
2205-
}
2206-
22072201
private async openOrCloneRepository(url: string): Promise<Repository | null> {
22082202
const state = this.appStore.getState()
22092203
const repositories = state.repositories

app/src/ui/repositories-list/group-repositories.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ export interface IRepositoryListItem extends IFilterListItem {
6161
readonly needsDisambiguation: boolean
6262
readonly aheadBehind: IAheadBehind | null
6363
readonly changedFilesCount: number
64-
readonly branchName?: string
64+
readonly branchName: string | null
65+
readonly defaultBranchName: string | null
6566
}
6667

6768
const recentRepositoriesThreshold = 7
@@ -183,7 +184,8 @@ const toSortedListItems = (
183184
((allNames.get(title) ?? 0) > 1 && group.kind === 'recent'),
184185
aheadBehind: repoState?.aheadBehind ?? null,
185186
changedFilesCount: repoState?.changedFilesCount ?? 0,
186-
branchName: repoState?.branchName,
187+
branchName: repoState?.branchName ?? null,
188+
defaultBranchName: repoState?.defaultBranchName ?? null,
187189
}
188190
})
189191
.sort(({ repository: x }, { repository: y }) =>

app/src/ui/repositories-list/repositories-list.tsx

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,9 @@ import { SectionFilterList } from '../lib/section-filter-list'
2727
import { assertNever } from '../../lib/fatal-error'
2828
import { IAheadBehind } from '../../models/branch'
2929
import { ShowBranchNameInRepoListSetting } from '../../models/show-branch-name-in-repo-list'
30-
import { throttle } from 'lodash'
3130

3231
const BlankSlateImage = encodePathAsUrl(__dirname, 'static/empty-no-repo.svg')
3332

34-
const refreshRepositoryThrottled = throttle(
35-
async (dispatcher: Dispatcher, repository: Repository) => {
36-
await dispatcher.refreshRepository(repository)
37-
},
38-
5000
39-
)
40-
4133
interface IRepositoriesListProps {
4234
readonly selectedRepository: Repositoryish | null
4335
readonly repositories: ReadonlyArray<Repositoryish>
@@ -169,33 +161,19 @@ export class RepositoriesList extends React.Component<
169161

170162
private shouldShowBranchName(item: IRepositoryListItem): boolean {
171163
const { showBranchNameInRepoList } = this.props
172-
173-
if (!(item.repository instanceof Repository) || !item.branchName) {
174-
return false
175-
}
176-
if (showBranchNameInRepoList === ShowBranchNameInRepoListSetting.Never) {
177-
return false
178-
}
179-
if (showBranchNameInRepoList === ShowBranchNameInRepoListSetting.Always) {
180-
return true
181-
}
182-
183-
if (
184-
showBranchNameInRepoList ===
185-
ShowBranchNameInRepoListSetting.WhenNotDefault
186-
) {
187-
const branchState = this.props.dispatcher.getBranchesState(
188-
item.repository
189-
)
190-
if (branchState.allBranches.length === 0) {
191-
refreshRepositoryThrottled(this.props.dispatcher, item.repository)
164+
switch (showBranchNameInRepoList) {
165+
case ShowBranchNameInRepoListSetting.Never:
192166
return false
193-
}
194-
const defaultBranch = branchState.defaultBranch
195-
return defaultBranch === null || item.branchName !== defaultBranch.name
167+
case ShowBranchNameInRepoListSetting.Always:
168+
return true
169+
case ShowBranchNameInRepoListSetting.WhenNotDefault:
170+
return item.branchName !== item.defaultBranchName
171+
default:
172+
assertNever(
173+
showBranchNameInRepoList,
174+
`Unknown show branch name setting: ${showBranchNameInRepoList}`
175+
)
196176
}
197-
198-
assertNever(showBranchNameInRepoList, `Unknown show branch name setting`)
199177
}
200178

201179
private renderItem = (item: IRepositoryListItem, matches: IMatches) => {
@@ -208,9 +186,7 @@ export class RepositoriesList extends React.Component<
208186
matches={matches}
209187
aheadBehind={item.aheadBehind}
210188
changedFilesCount={item.changedFilesCount}
211-
branchName={
212-
this.shouldShowBranchName(item) ? item.branchName : undefined
213-
}
189+
branchName={this.shouldShowBranchName(item) ? item.branchName : null}
214190
/>
215191
)
216192
}
@@ -239,9 +215,7 @@ export class RepositoriesList extends React.Component<
239215
item: IRepositoryListItem
240216
): JSX.Element | string | null => {
241217
const { repository, aheadBehind, changedFilesCount } = item
242-
const branchName = this.shouldShowBranchName(item)
243-
? item.branchName
244-
: undefined
218+
const branchName = this.shouldShowBranchName(item) ? item.branchName : null
245219
const gitHubRepo =
246220
repository instanceof Repository ? repository.gitHubRepository : null
247221
const alias = repository instanceof Repository ? repository.alias : null

app/src/ui/repositories-list/repository-list-item.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ interface IRepositoryListItemProps {
2828
/** Number of uncommitted changes */
2929
readonly changedFilesCount: number
3030

31-
/** The name of the current branch, if available */
32-
readonly branchName?: string
31+
/** The name of the current branch, if it should be displayed */
32+
readonly branchName: string | null
3333
}
3434

3535
/** A repository item. */

0 commit comments

Comments
 (0)