-
Notifications
You must be signed in to change notification settings - Fork 13
feat: add branch sorting option #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,15 +105,22 @@ import { findDefaultBranch } from '../find-default-branch' | |
| import { cleanUntrackedFiles } from '../git/clean' | ||
| import { dotGitPath } from '../helpers/git-dir' | ||
| import { normalizePath } from '../helpers/path' | ||
| import { BranchSortOrder } from '../../models/branch-sort-order' | ||
|
|
||
| /** The number of commits to load from history per batch. */ | ||
| const CommitBatchSize = 100 | ||
| const CommitBatchSizeSearch = 500 | ||
|
|
||
| const LoadingHistoryRequestKey = 'history' | ||
|
|
||
| /** The max number of recent branches to find. */ | ||
| const RecentBranchesLimit = 5 | ||
| /** | ||
| * The max number of recent branches to include for non-alphabetic | ||
| * sorts where full "recent" list ordering is required. | ||
| */ | ||
| const RecentOptionsBranchLimit = 2500 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2500 seems like an arbitrary limit, and some repos can have way more branches. There should be no limit. |
||
|
|
||
| /** The max number of recent branches to include for alphabetic sort mode. */ | ||
| const AlphabetBranchRecentLimit = 5 | ||
|
|
||
| /** The store for a repository's git data. */ | ||
| export class GitStore extends BaseStore { | ||
|
|
@@ -178,6 +185,12 @@ export class GitStore extends BaseStore { | |
| this._tagsToPush = getTagsToPush(repository) | ||
| } | ||
|
|
||
| public getRecentBranchesLimit(branchSortOrder: BranchSortOrder): number { | ||
| return branchSortOrder === BranchSortOrder.Alphabet | ||
| ? AlphabetBranchRecentLimit | ||
| : RecentOptionsBranchLimit | ||
| } | ||
|
|
||
| /** | ||
| * Reconcile the local history view with the repository state | ||
| * after a pull has completed, to include merged remote commits. | ||
|
|
@@ -398,14 +411,16 @@ export class GitStore extends BaseStore { | |
| } | ||
|
|
||
| /** Load all the branches. */ | ||
| public async loadBranches() { | ||
| public async loadBranches( | ||
| recentBranchesLimit: number = AlphabetBranchRecentLimit | ||
| ) { | ||
kurtextrem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const [localAndRemoteBranches, recentBranchNames] = await Promise.all([ | ||
| this.performFailableOperation(() => getBranches(this.repository)) || [], | ||
| this.performFailableOperation(() => | ||
| // Chances are that the recent branches list will contain the default | ||
| // branch which we filter out in refreshRecentBranches. So grab one | ||
| // more than we need to account for that. | ||
| getRecentBranches(this.repository, RecentBranchesLimit + 1) | ||
| getRecentBranches(this.repository, recentBranchesLimit + 1) | ||
| ), | ||
| ]) | ||
|
|
||
|
|
@@ -417,7 +432,7 @@ export class GitStore extends BaseStore { | |
|
|
||
| // refreshRecentBranches is dependent on having a default branch | ||
| await this.refreshDefaultBranch() | ||
| this.refreshRecentBranches(recentBranchNames) | ||
| this.refreshRecentBranches(recentBranchNames, recentBranchesLimit) | ||
|
|
||
| await this.checkPullWithRebase() | ||
|
|
||
|
|
@@ -558,7 +573,8 @@ export class GitStore extends BaseStore { | |
| } | ||
|
|
||
| private refreshRecentBranches( | ||
| recentBranchNames: ReadonlyArray<string> | undefined | ||
| recentBranchNames: ReadonlyArray<string> | undefined, | ||
| recentBranchesLimit: number = RecentOptionsBranchLimit | ||
| ) { | ||
| if (!recentBranchNames || !recentBranchNames.length) { | ||
| this._recentBranches = [] | ||
|
|
@@ -591,7 +607,7 @@ export class GitStore extends BaseStore { | |
|
|
||
| recentBranches.push(branch) | ||
|
|
||
| if (recentBranches.length >= RecentBranchesLimit) { | ||
| if (recentBranches.length >= recentBranchesLimit) { | ||
| break | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| export enum BranchSortOrder { | ||
| Alphabet = 'Alphabet', | ||
| RecentlyAdded = 'RecentlyAdded', | ||
| RecentlyChanged = 'RecentlyChanged', | ||
| } | ||
|
|
||
| export const defaultBranchSortOrder = BranchSortOrder.Alphabet |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change the formatting in these lines? There doesn't seem to be any content changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've run prettier locally and it has changed the lines. GitHub Copilot then commented on the formatting, so not really sure what happened. I can revert.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's strange,
PR_URLShas a// prettier-ignorecomment, so it should be ignored...I added that exception because these constructed URLs become practically unreadable when formatted.