From 377977f88b84dfa91f2b39792b93cc41e663bfc5 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sun, 1 Nov 2020 01:00:06 -0500 Subject: [PATCH] Adds "limit" to load all for branches/tags --- src/git/git.ts | 17 ++++++++++++++++- src/git/gitService.ts | 7 ++++++- src/views/nodes/branchNode.ts | 16 +++++++++++++--- src/views/nodes/branchTrackingStatusNode.ts | 10 ++++++++-- src/views/nodes/common.ts | 19 ++++++++++++++++--- src/views/nodes/contributorNode.ts | 10 ++++++++-- src/views/nodes/fileHistoryNode.ts | 10 ++++++++-- src/views/nodes/lineHistoryNode.ts | 10 ++++++++-- src/views/nodes/reflogRecordNode.ts | 10 ++++++++-- src/views/nodes/tagNode.ts | 16 +++++++++++++--- 10 files changed, 104 insertions(+), 21 deletions(-) diff --git a/src/git/git.ts b/src/git/git.ts index 70965a2..eedc2d3 100644 --- a/src/git/git.ts +++ b/src/git/git.ts @@ -1020,7 +1020,22 @@ export namespace Git { return git({ cwd: repoPath }, 'reset', '-q', '--', fileName); } - export async function rev_list( + export async function rev_list__count(repoPath: string, ref: string): Promise { + let data = await git( + { cwd: repoPath, errors: GitErrorHandling.Ignore }, + 'rev-list', + '--count', + ref, + '--', + ); + data = data.trim(); + if (data.length === 0) return undefined; + + const result = parseInt(data, 10); + return isNaN(result) ? undefined : result; + } + + export async function rev_list__left_right( repoPath: string, refs: string[], ): Promise<{ ahead: number; behind: number } | undefined> { diff --git a/src/git/gitService.ts b/src/git/gitService.ts index ff8149d..f954fc0 100644 --- a/src/git/gitService.ts +++ b/src/git/gitService.ts @@ -1318,7 +1318,12 @@ export class GitService implements Disposable { repoPath: string, refs: string[], ): Promise<{ ahead: number; behind: number } | undefined> { - return Git.rev_list(repoPath, refs); + return Git.rev_list__left_right(repoPath, refs); + } + + @log() + getCommitCount(repoPath: string, ref: string): Promise { + return Git.rev_list__count(repoPath, ref); } @log() diff --git a/src/views/nodes/branchNode.ts b/src/views/nodes/branchNode.ts index 20797b8..fc22091 100644 --- a/src/views/nodes/branchNode.ts +++ b/src/views/nodes/branchNode.ts @@ -1,5 +1,5 @@ 'use strict'; -import { TreeItem, TreeItemCollapsibleState } from 'vscode'; +import { TreeItem, TreeItemCollapsibleState, window } from 'vscode'; import { BranchesView } from '../branchesView'; import { BranchTrackingStatusNode } from './branchTrackingStatusNode'; import { CommitNode } from './commitNode'; @@ -198,7 +198,11 @@ export class BranchNode ); if (log.hasMore) { - children.push(new LoadMoreNode(this.view, this, children[children.length - 1])); + children.push( + new LoadMoreNode(this.view, this, children[children.length - 1], undefined, () => + Container.git.getCommitCount(this.branch.repoPath, this.branch.name), + ), + ); } this._children = children; @@ -350,8 +354,14 @@ export class BranchNode } limit: number | undefined = this.view.getNodeLastKnownLimit(this); + @gate() async loadMore(limit?: number | { until?: any }) { - let log = await this.getLog(); + let log = await window.withProgress( + { + location: { viewId: this.view.id }, + }, + () => this.getLog(), + ); if (log == null || !log.hasMore) return; log = await log.more?.(limit ?? this.view.config.pageItemLimit); diff --git a/src/views/nodes/branchTrackingStatusNode.ts b/src/views/nodes/branchTrackingStatusNode.ts index e922daa..bf32b54 100644 --- a/src/views/nodes/branchTrackingStatusNode.ts +++ b/src/views/nodes/branchTrackingStatusNode.ts @@ -1,5 +1,5 @@ 'use strict'; -import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode'; +import { ThemeIcon, TreeItem, TreeItemCollapsibleState, window } from 'vscode'; import { BranchNode } from './branchNode'; import { BranchTrackingStatusFilesNode } from './branchTrackingStatusFilesNode'; import { CommitNode } from './commitNode'; @@ -232,8 +232,14 @@ export class BranchTrackingStatusNode extends ViewNode implement } limit: number | undefined = this.view.getNodeLastKnownLimit(this); + @gate() async loadMore(limit?: number | { until?: any }) { - let log = await this.getLog(); + let log = await window.withProgress( + { + location: { viewId: this.view.id }, + }, + () => this.getLog(), + ); if (log == null || !log.hasMore) return; log = await log.more?.(limit ?? this.view.config.pageItemLimit); diff --git a/src/views/nodes/common.ts b/src/views/nodes/common.ts index e9cb87f..1d19528 100644 --- a/src/views/nodes/common.ts +++ b/src/views/nodes/common.ts @@ -143,12 +143,18 @@ export abstract class PagerNode extends ViewNode { protected readonly message: string, protected readonly previousNode?: ViewNode, protected readonly pageSize: number = Container.config.views.pageItemLimit, + protected readonly countFn?: () => Promise, ) { super(unknownGitUri, view, parent); } - loadAll() { - return this.view.loadMoreNodeChildren(this.parent! as ViewNode & PageableViewNode, 0, this.previousNode); + async loadAll() { + const count = (await this.countFn?.()) ?? 0; + return this.view.loadMoreNodeChildren( + this.parent! as ViewNode & PageableViewNode, + count > 5000 ? 5000 : 0, + this.previousNode, + ); } loadMore() { @@ -180,7 +186,13 @@ export abstract class PagerNode extends ViewNode { } export class LoadMoreNode extends PagerNode { - constructor(view: View, parent: ViewNode & PageableViewNode, previousNode: ViewNode, pageSize?: number) { + constructor( + view: View, + parent: ViewNode & PageableViewNode, + previousNode: ViewNode, + pageSize?: number, + countFn?: () => Promise, + ) { super( view, parent, @@ -189,6 +201,7 @@ export class LoadMoreNode extends PagerNode { : 'Load more', previousNode, pageSize, + countFn, ); } } diff --git a/src/views/nodes/contributorNode.ts b/src/views/nodes/contributorNode.ts index 977c6ba..70c3216 100644 --- a/src/views/nodes/contributorNode.ts +++ b/src/views/nodes/contributorNode.ts @@ -1,5 +1,5 @@ 'use strict'; -import { TreeItem, TreeItemCollapsibleState } from 'vscode'; +import { TreeItem, TreeItemCollapsibleState, window } from 'vscode'; import { CommitNode } from './commitNode'; import { LoadMoreNode, MessageNode } from './common'; import { GlyphChars } from '../../constants'; @@ -113,8 +113,14 @@ export class ContributorNode extends ViewNode this.getLog(), + ); if (log == null || !log.hasMore) return; log = await log.more?.(limit ?? this.view.config.pageItemLimit); diff --git a/src/views/nodes/fileHistoryNode.ts b/src/views/nodes/fileHistoryNode.ts index b852c8a..32c7cc7 100644 --- a/src/views/nodes/fileHistoryNode.ts +++ b/src/views/nodes/fileHistoryNode.ts @@ -1,5 +1,5 @@ 'use strict'; -import { Disposable, TreeItem, TreeItemCollapsibleState } from 'vscode'; +import { Disposable, TreeItem, TreeItemCollapsibleState, window } from 'vscode'; import { CommitFileNode } from './commitFileNode'; import { LoadMoreNode, MessageNode } from './common'; import { Container } from '../../container'; @@ -185,8 +185,14 @@ export class FileHistoryNode extends SubscribeableViewNode implements PageableVi } limit: number | undefined = this.view.getNodeLastKnownLimit(this); + @gate() async loadMore(limit?: number | { until?: any }) { - let log = await this.getLog(); + let log = await window.withProgress( + { + location: { viewId: this.view.id }, + }, + () => this.getLog(), + ); if (log == null || !log.hasMore) return; log = await log.more?.(limit ?? this.view.config.pageItemLimit); diff --git a/src/views/nodes/lineHistoryNode.ts b/src/views/nodes/lineHistoryNode.ts index f843172..0c71011 100644 --- a/src/views/nodes/lineHistoryNode.ts +++ b/src/views/nodes/lineHistoryNode.ts @@ -1,5 +1,5 @@ 'use strict'; -import { Disposable, Selection, TreeItem, TreeItemCollapsibleState } from 'vscode'; +import { Disposable, Selection, TreeItem, TreeItemCollapsibleState, window } from 'vscode'; import { CommitFileNode } from './commitFileNode'; import { LoadMoreNode, MessageNode } from './common'; import { Container } from '../../container'; @@ -317,8 +317,14 @@ export class LineHistoryNode extends SubscribeableViewNode implements PageableVi } limit: number | undefined = this.view.getNodeLastKnownLimit(this); + @gate() async loadMore(limit?: number | { until?: any }) { - let log = await this.getLog(); + let log = await window.withProgress( + { + location: { viewId: this.view.id }, + }, + () => this.getLog(), + ); if (log == null || !log.hasMore) return; log = await log.more?.(limit ?? this.view.config.pageItemLimit); diff --git a/src/views/nodes/reflogRecordNode.ts b/src/views/nodes/reflogRecordNode.ts index 9524432..9338933 100644 --- a/src/views/nodes/reflogRecordNode.ts +++ b/src/views/nodes/reflogRecordNode.ts @@ -1,5 +1,5 @@ 'use strict'; -import { TreeItem, TreeItemCollapsibleState } from 'vscode'; +import { TreeItem, TreeItemCollapsibleState, window } from 'vscode'; import { CommitNode } from './commitNode'; import { LoadMoreNode, MessageNode } from './common'; import { GlyphChars } from '../../constants'; @@ -104,8 +104,14 @@ export class ReflogRecordNode extends ViewNode implements Pageab } limit: number | undefined = this.view.getNodeLastKnownLimit(this); + @gate() async loadMore(limit?: number | { until?: any }) { - let log = await this.getLog(); + let log = await window.withProgress( + { + location: { viewId: this.view.id }, + }, + () => this.getLog(), + ); if (log === undefined || !log.hasMore) return; log = await log.more?.(limit ?? this.view.config.pageItemLimit); diff --git a/src/views/nodes/tagNode.ts b/src/views/nodes/tagNode.ts index 164b10c..9007035 100644 --- a/src/views/nodes/tagNode.ts +++ b/src/views/nodes/tagNode.ts @@ -1,5 +1,5 @@ 'use strict'; -import { TreeItem, TreeItemCollapsibleState } from 'vscode'; +import { TreeItem, TreeItemCollapsibleState, window } from 'vscode'; import { CommitNode } from './commitNode'; import { LoadMoreNode, MessageNode } from './common'; import { ViewBranchesLayout } from '../../configuration'; @@ -57,7 +57,11 @@ export class TagNode extends ViewRefNode + Container.git.getCommitCount(this.tag.repoPath, this.tag.name), + ), + ); } return children; } @@ -105,8 +109,14 @@ export class TagNode extends ViewRefNode this.getLog(), + ); if (log == null || !log.hasMore) return; log = await log.more?.(limit ?? this.view.config.pageItemLimit);