Skip to content

Commit

Permalink
Adds "discovered" repo sort & makes it default
Browse files Browse the repository at this point in the history
Ensures that "lastFetched" sort updates the views properly
Moves sorting settings to a new "Sorting" section
  • Loading branch information
eamodio committed Oct 31, 2023
1 parent 066d3a7 commit d641c49
Show file tree
Hide file tree
Showing 20 changed files with 223 additions and 239 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Improves the experience of the _Search Commits_ quick pick menu
- Adds a stateful authors picker to make it much easier to search for commits by specific authors
- Adds a file and folder picker to make it much easier to search for commits containing specific files or in specific folders
- Adds ability to sort repositories in the views and quick pick menus — closes [#2836](https://github.com/gitkraken/vscode-gitlens/issues/2836) thanks to [PR #2991](https://github.com/gitkraken/vscode-gitlens/pull/2991)
- Adds a `gitlens.sortRepositoriesBy` setting to specify how repositories are sorted in quick pick menus and viewsby Aidos Kanapyanov ([@aidoskanapyanov](https://github.com/aidoskanapyanov))
- Adds a _[Show|Hide] Merge Commits_ toggle to the Commits\_ view — closes [#1399](https://github.com/gitkraken/vscode-gitlens/issues/1399) thanks to [PR #1540](https://github.com/gitkraken/vscode-gitlens/pull/1540) by Shashank Shastri ([@Shashank-Shastri](https://github.com/Shashank-Shastri))
- Adds a _Filter Commits by Author..._ commands to the _Commits_ view and comparisons context menus to filter commits in the _Commits_ view by specific authors
- Adds an _Open Comparison on Remote_ command to comparisons in views
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ A big thanks to the people that have contributed to this project 🙏❤️:
- jogo- ([@jogo-](https://github.com/jogo-)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=jogo-)
- Nils K ([@septatrix](https://github.com/septatrix)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=septatrix)
- Chris Kaczor ([@ckaczor](https://github.com/ckaczor)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=ckaczor)
- Aidos Kanapyanov ([@aidoskanapyanov](https://github.com/aidoskanapyanov)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=aidoskanapyanov)
- Allan Karlson ([@bees4ever](https://github.com/bees4ever)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=bees4ever)
- Nafiur Rahman Khadem ([@ShafinKhadem](https://github.com/ShafinKhadem)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=ShafinKhadem)
- Mathew King ([@MathewKing](https://github.com/MathewKing)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=MathewKing)
Expand Down
176 changes: 92 additions & 84 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1292,25 +1292,6 @@
"scope": "window",
"order": 30
},
"gitlens.sortBranchesBy": {
"type": "string",
"default": "date:desc",
"enum": [
"date:desc",
"date:asc",
"name:asc",
"name:desc"
],
"enumDescriptions": [
"Sorts branches by the most recent commit date in descending order",
"Sorts branches by the most recent commit date in ascending order",
"Sorts branches by name in ascending order",
"Sorts branches by name in descending order"
],
"markdownDescription": "Specifies how branches are sorted in quick pick menus and views",
"scope": "window",
"order": 40
},
"gitlens.views.branches.files.layout": {
"type": "string",
"default": "auto",
Expand Down Expand Up @@ -1556,25 +1537,6 @@
"scope": "window",
"order": 10
},
"gitlens.sortTagsBy": {
"type": "string",
"default": "date:desc",
"enum": [
"date:desc",
"date:asc",
"name:asc",
"name:desc"
],
"enumDescriptions": [
"Sorts tags by date in descending order",
"Sorts tags by date in ascending order",
"Sorts tags by name in ascending order",
"Sorts tags by name in descending order"
],
"markdownDescription": "Specifies how tags are sorted in quick pick menus and views",
"scope": "window",
"order": 20
},
"gitlens.views.tags.files.layout": {
"type": "string",
"default": "auto",
Expand Down Expand Up @@ -1811,49 +1773,6 @@
"scope": "window",
"order": 31
},
"gitlens.sortContributorsBy": {
"type": "string",
"default": "count:desc",
"enum": [
"count:desc",
"count:asc",
"date:desc",
"date:asc",
"name:asc",
"name:desc"
],
"enumDescriptions": [
"Sorts contributors by commit count in descending order",
"Sorts contributors by commit count in ascending order",
"Sorts contributors by the most recent commit date in descending order",
"Sorts contributors by the most recent commit date in ascending order",
"Sorts contributors by name in ascending order",
"Sorts contributors by name in descending order"
],
"markdownDescription": "Specifies how contributors are sorted in quick pick menus and views",
"scope": "window",
"order": 40
},
"gitlens.sortRepositoriesBy": {
"type": "string",
"default": "lastFetched:desc",
"enum": [
"name:asc",
"name:desc",
"lastFetched:asc",
"lastFetched:desc"
],
"enumDescriptions": [
"Sorts repositories by name in ascending order",
"Sorts repositories by name in descending order",
"Sorts repositories by last fetched date in ascending order",
"Sorts repositories by last fetched date in descending order",
"Sorts repositories by starred first"
],
"markdownDescription": "Specifies how repositories are sorted in quick pick menus and views",
"scope": "window",
"order": 41
},
"gitlens.views.contributors.files.layout": {
"type": "string",
"default": "auto",
Expand Down Expand Up @@ -3323,10 +3242,99 @@
}
}
},
{
"id": "sorting",
"title": "Sorting",
"order": 121,
"properties": {
"gitlens.sortRepositoriesBy": {
"type": "string",
"default": "discovered",
"enum": [
"discovered",
"lastFetched:desc",
"lastFetched:asc",
"name:asc",
"name:desc"
],
"enumDescriptions": [
"Sorts repositories by discovery or workspace order",
"Sorts repositories by last fetched date in descending order",
"Sorts repositories by last fetched date in ascending order",
"Sorts repositories by name in ascending order",
"Sorts repositories by name in descending order"
],
"markdownDescription": "Specifies how repositories are sorted in quick pick menus and views",
"scope": "window",
"order": 10
},
"gitlens.sortBranchesBy": {
"type": "string",
"default": "date:desc",
"enum": [
"date:desc",
"date:asc",
"name:asc",
"name:desc"
],
"enumDescriptions": [
"Sorts branches by the most recent commit date in descending order",
"Sorts branches by the most recent commit date in ascending order",
"Sorts branches by name in ascending order",
"Sorts branches by name in descending order"
],
"markdownDescription": "Specifies how branches are sorted in quick pick menus and views",
"scope": "window",
"order": 20
},
"gitlens.sortTagsBy": {
"type": "string",
"default": "date:desc",
"enum": [
"date:desc",
"date:asc",
"name:asc",
"name:desc"
],
"enumDescriptions": [
"Sorts tags by date in descending order",
"Sorts tags by date in ascending order",
"Sorts tags by name in ascending order",
"Sorts tags by name in descending order"
],
"markdownDescription": "Specifies how tags are sorted in quick pick menus and views",
"scope": "window",
"order": 30
},
"gitlens.sortContributorsBy": {
"type": "string",
"default": "count:desc",
"enum": [
"count:desc",
"count:asc",
"date:desc",
"date:asc",
"name:asc",
"name:desc"
],
"enumDescriptions": [
"Sorts contributors by commit count in descending order",
"Sorts contributors by commit count in ascending order",
"Sorts contributors by the most recent commit date in descending order",
"Sorts contributors by the most recent commit date in ascending order",
"Sorts contributors by name in ascending order",
"Sorts contributors by name in descending order"
],
"markdownDescription": "Specifies how contributors are sorted in quick pick menus and views",
"scope": "window",
"order": 40
}
}
},
{
"id": "menus-toolbars",
"title": "Menus & Toolbars",
"order": 121,
"order": 122,
"properties": {
"gitlens.menus": {
"anyOf": [
Expand Down Expand Up @@ -3701,7 +3709,7 @@
{
"id": "keyboard",
"title": "Keyboard Shortcuts",
"order": 122,
"order": 123,
"properties": {
"gitlens.keymap": {
"type": "string",
Expand All @@ -3725,7 +3733,7 @@
{
"id": "modes",
"title": "Modes",
"order": 123,
"order": 124,
"properties": {
"gitlens.mode.statusBar.enabled": {
"type": "boolean",
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export const enum CodeLensCommand {

export type CodeLensScopes = 'document' | 'containers' | 'blocks';
export type ContributorSorting = 'count:desc' | 'count:asc' | 'date:desc' | 'date:asc' | 'name:asc' | 'name:desc';
export type RepositoriesSorting = 'name:asc' | 'name:desc' | 'lastFetched:asc' | 'lastFetched:desc';
export type RepositoriesSorting = 'discovered' | 'lastFetched:desc' | 'lastFetched:asc' | 'name:asc' | 'name:desc';
export type CustomRemoteType =
| 'AzureDevOps'
| 'Bitbucket'
Expand Down
58 changes: 30 additions & 28 deletions src/git/models/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ export const enum RepositoryChange {
Remotes = 5,
Worktrees = 6,
Config = 7,
/*
* Union of Cherry, Merge, and Rebase
*/
/** Union of Cherry, Merge, and Rebase */
Status = 8,
CherryPick = 9,
Merge = 10,
Expand All @@ -90,7 +88,6 @@ export const enum RepositoryChange {

export const enum RepositoryChangeComparisonMode {
Any,
All,
Exclusive,
}

Expand Down Expand Up @@ -194,20 +191,18 @@ export class Repository implements Disposable {
(a, b) => (a.starred ? -1 : 1) - (b.starred ? -1 : 1) || sortCompare(b.name, a.name),
);
case 'lastFetched:asc':
return repositories.sort((a, b) => {
if (typeof a._lastFetched === 'undefined' && typeof b._lastFetched === 'undefined') return 0;
else if (typeof a._lastFetched === 'undefined') return 1;
else if (typeof b._lastFetched === 'undefined') return -1;
return (a.starred ? -1 : 1) - (b.starred ? -1 : 1) || a._lastFetched - b._lastFetched;
});
return repositories.sort(
(a, b) =>
(a.starred ? -1 : 1) - (b.starred ? -1 : 1) || (a._lastFetched ?? 0) - (b._lastFetched ?? 0),
);
case 'lastFetched:desc':
return repositories.sort(
(a, b) =>
(a.starred ? -1 : 1) - (b.starred ? -1 : 1) || (b._lastFetched ?? 0) - (a._lastFetched ?? 0),
);
case 'discovered':
default:
return repositories.sort((a, b) => {
if (typeof a._lastFetched === 'undefined' && typeof b._lastFetched === 'undefined') return 0;
else if (typeof a._lastFetched === 'undefined') return 1;
else if (typeof b._lastFetched === 'undefined') return -1;
return (a.starred ? -1 : 1) - (b.starred ? -1 : 1) || b._lastFetched - a._lastFetched;
});
return repositories;
}
}

Expand Down Expand Up @@ -301,6 +296,9 @@ export class Repository implements Disposable {
);

this.onConfigurationChanged();
if (this._orderByLastFetched) {
void this.getLastFetched();
}
}

private setupRepoWatchers() {
Expand Down Expand Up @@ -388,12 +386,21 @@ export class Repository implements Disposable {
return this._updatedAt;
}

private _orderByLastFetched = false;
get orderByLastFetched(): boolean {
return this._orderByLastFetched;
}

private _updatedAt: number = 0;
get updatedAt(): number {
return this._updatedAt;
}

private onConfigurationChanged(e?: ConfigurationChangeEvent) {
if (configuration.changed(e, 'sortRepositoriesBy')) {
this._orderByLastFetched = configuration.get('sortRepositoriesBy')?.startsWith('lastFetched:') ?? false;
}

if (e != null && configuration.changed(e, 'remotes', this.folder?.uri)) {
this.resetCaches('remotes');
this.fireChange(RepositoryChange.Remotes);
Expand Down Expand Up @@ -421,6 +428,9 @@ export class Repository implements Disposable {
}

this._lastFetched = undefined;
if (this._orderByLastFetched) {
void this.getLastFetched();
}

const match =
uri != null
Expand Down Expand Up @@ -684,18 +694,10 @@ export class Repository implements Disposable {
private _lastFetched: number | undefined;
@gate()
async getLastFetched(): Promise<number> {
if (this._lastFetched == null) {
if (!(await this.hasRemotes())) return 0;
}

try {
const lastFetched = await this.container.git.getLastFetchedTimestamp(this.uri);
// If we don't get a number, assume the fetch failed, and don't update the timestamp
if (lastFetched != null) {
this._lastFetched = lastFetched;
}
} catch {
this._lastFetched = undefined;
const lastFetched = await this.container.git.getLastFetchedTimestamp(this.uri);
// If we don't get a number, assume the fetch failed, and don't update the timestamp
if (lastFetched != null) {
this._lastFetched = lastFetched;
}

return this._lastFetched ?? 0;
Expand Down
3 changes: 2 additions & 1 deletion src/views/branchesView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ export class BranchesView extends ViewBase<'branches', BranchesViewNode, Branche
!configuration.changed(e, 'defaultDateStyle') &&
!configuration.changed(e, 'defaultGravatarsStyle') &&
!configuration.changed(e, 'defaultTimeFormat') &&
!configuration.changed(e, 'sortBranchesBy')
!configuration.changed(e, 'sortBranchesBy') &&
!configuration.changed(e, 'sortRepositoriesBy')
) {
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion src/views/commitsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ export class CommitsView extends ViewBase<'commits', CommitsViewNode, CommitsVie
!configuration.changed(e, 'defaultDateStyle') &&
!configuration.changed(e, 'defaultGravatarsStyle') &&
!configuration.changed(e, 'defaultTimeFormat') &&
!configuration.changed(e, 'plusFeatures.enabled')
!configuration.changed(e, 'plusFeatures.enabled') &&
!configuration.changed(e, 'sortRepositoriesBy')
) {
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion src/views/contributorsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ export class ContributorsView extends ViewBase<'contributors', ContributorsViewN
!configuration.changed(e, 'defaultDateStyle') &&
!configuration.changed(e, 'defaultGravatarsStyle') &&
!configuration.changed(e, 'defaultTimeFormat') &&
!configuration.changed(e, 'sortContributorsBy')
!configuration.changed(e, 'sortContributorsBy') &&
!configuration.changed(e, 'sortRepositoriesBy')
) {
return false;
}
Expand Down
Loading

0 comments on commit d641c49

Please sign in to comment.