Browse Source

Adds "limit" to load all for branches/tags

main
Eric Amodio 4 years ago
parent
commit
377977f88b
10 changed files with 104 additions and 21 deletions
  1. +16
    -1
      src/git/git.ts
  2. +6
    -1
      src/git/gitService.ts
  3. +13
    -3
      src/views/nodes/branchNode.ts
  4. +8
    -2
      src/views/nodes/branchTrackingStatusNode.ts
  5. +16
    -3
      src/views/nodes/common.ts
  6. +8
    -2
      src/views/nodes/contributorNode.ts
  7. +8
    -2
      src/views/nodes/fileHistoryNode.ts
  8. +8
    -2
      src/views/nodes/lineHistoryNode.ts
  9. +8
    -2
      src/views/nodes/reflogRecordNode.ts
  10. +13
    -3
      src/views/nodes/tagNode.ts

+ 16
- 1
src/git/git.ts View File

@ -1020,7 +1020,22 @@ export namespace Git {
return git<string>({ cwd: repoPath }, 'reset', '-q', '--', fileName); return git<string>({ cwd: repoPath }, 'reset', '-q', '--', fileName);
} }
export async function rev_list(
export async function rev_list__count(repoPath: string, ref: string): Promise<number | undefined> {
let data = await git<string>(
{ 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, repoPath: string,
refs: string[], refs: string[],
): Promise<{ ahead: number; behind: number } | undefined> { ): Promise<{ ahead: number; behind: number } | undefined> {

+ 6
- 1
src/git/gitService.ts View File

@ -1318,7 +1318,12 @@ export class GitService implements Disposable {
repoPath: string, repoPath: string,
refs: string[], refs: string[],
): Promise<{ ahead: number; behind: number } | undefined> { ): 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<number | undefined> {
return Git.rev_list__count(repoPath, ref);
} }
@log() @log()

+ 13
- 3
src/views/nodes/branchNode.ts View File

@ -1,5 +1,5 @@
'use strict'; 'use strict';
import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import { BranchesView } from '../branchesView'; import { BranchesView } from '../branchesView';
import { BranchTrackingStatusNode } from './branchTrackingStatusNode'; import { BranchTrackingStatusNode } from './branchTrackingStatusNode';
import { CommitNode } from './commitNode'; import { CommitNode } from './commitNode';
@ -198,7 +198,11 @@ export class BranchNode
); );
if (log.hasMore) { 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; this._children = children;
@ -350,8 +354,14 @@ export class BranchNode
} }
limit: number | undefined = this.view.getNodeLastKnownLimit(this); limit: number | undefined = this.view.getNodeLastKnownLimit(this);
@gate()
async loadMore(limit?: number | { until?: any }) { 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; if (log == null || !log.hasMore) return;
log = await log.more?.(limit ?? this.view.config.pageItemLimit); log = await log.more?.(limit ?? this.view.config.pageItemLimit);

+ 8
- 2
src/views/nodes/branchTrackingStatusNode.ts View File

@ -1,5 +1,5 @@
'use strict'; 'use strict';
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import { BranchNode } from './branchNode'; import { BranchNode } from './branchNode';
import { BranchTrackingStatusFilesNode } from './branchTrackingStatusFilesNode'; import { BranchTrackingStatusFilesNode } from './branchTrackingStatusFilesNode';
import { CommitNode } from './commitNode'; import { CommitNode } from './commitNode';
@ -232,8 +232,14 @@ export class BranchTrackingStatusNode extends ViewNode implement
} }
limit: number | undefined = this.view.getNodeLastKnownLimit(this); limit: number | undefined = this.view.getNodeLastKnownLimit(this);
@gate()
async loadMore(limit?: number | { until?: any }) { 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; if (log == null || !log.hasMore) return;
log = await log.more?.(limit ?? this.view.config.pageItemLimit); log = await log.more?.(limit ?? this.view.config.pageItemLimit);

+ 16
- 3
src/views/nodes/common.ts View File

@ -143,12 +143,18 @@ export abstract class PagerNode extends ViewNode {
protected readonly message: string, protected readonly message: string,
protected readonly previousNode?: ViewNode, protected readonly previousNode?: ViewNode,
protected readonly pageSize: number = Container.config.views.pageItemLimit, protected readonly pageSize: number = Container.config.views.pageItemLimit,
protected readonly countFn?: () => Promise<number | undefined>,
) { ) {
super(unknownGitUri, view, parent); 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() { loadMore() {
@ -180,7 +186,13 @@ export abstract class PagerNode extends ViewNode {
} }
export class LoadMoreNode extends PagerNode { 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<number | undefined>,
) {
super( super(
view, view,
parent, parent,
@ -189,6 +201,7 @@ export class LoadMoreNode extends PagerNode {
: 'Load more', : 'Load more',
previousNode, previousNode,
pageSize, pageSize,
countFn,
); );
} }
} }

+ 8
- 2
src/views/nodes/contributorNode.ts View File

@ -1,5 +1,5 @@
'use strict'; 'use strict';
import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import { CommitNode } from './commitNode'; import { CommitNode } from './commitNode';
import { LoadMoreNode, MessageNode } from './common'; import { LoadMoreNode, MessageNode } from './common';
import { GlyphChars } from '../../constants'; import { GlyphChars } from '../../constants';
@ -113,8 +113,14 @@ export class ContributorNode extends ViewNode
} }
limit: number | undefined = this.view.getNodeLastKnownLimit(this); limit: number | undefined = this.view.getNodeLastKnownLimit(this);
@gate()
async loadMore(limit?: number | { until?: any }) { 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; if (log == null || !log.hasMore) return;
log = await log.more?.(limit ?? this.view.config.pageItemLimit); log = await log.more?.(limit ?? this.view.config.pageItemLimit);

+ 8
- 2
src/views/nodes/fileHistoryNode.ts View File

@ -1,5 +1,5 @@
'use strict'; 'use strict';
import { Disposable, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { Disposable, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import { CommitFileNode } from './commitFileNode'; import { CommitFileNode } from './commitFileNode';
import { LoadMoreNode, MessageNode } from './common'; import { LoadMoreNode, MessageNode } from './common';
import { Container } from '../../container'; import { Container } from '../../container';
@ -185,8 +185,14 @@ export class FileHistoryNode extends SubscribeableViewNode implements PageableVi
} }
limit: number | undefined = this.view.getNodeLastKnownLimit(this); limit: number | undefined = this.view.getNodeLastKnownLimit(this);
@gate()
async loadMore(limit?: number | { until?: any }) { 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; if (log == null || !log.hasMore) return;
log = await log.more?.(limit ?? this.view.config.pageItemLimit); log = await log.more?.(limit ?? this.view.config.pageItemLimit);

+ 8
- 2
src/views/nodes/lineHistoryNode.ts View File

@ -1,5 +1,5 @@
'use strict'; 'use strict';
import { Disposable, Selection, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { Disposable, Selection, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import { CommitFileNode } from './commitFileNode'; import { CommitFileNode } from './commitFileNode';
import { LoadMoreNode, MessageNode } from './common'; import { LoadMoreNode, MessageNode } from './common';
import { Container } from '../../container'; import { Container } from '../../container';
@ -317,8 +317,14 @@ export class LineHistoryNode extends SubscribeableViewNode implements PageableVi
} }
limit: number | undefined = this.view.getNodeLastKnownLimit(this); limit: number | undefined = this.view.getNodeLastKnownLimit(this);
@gate()
async loadMore(limit?: number | { until?: any }) { 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; if (log == null || !log.hasMore) return;
log = await log.more?.(limit ?? this.view.config.pageItemLimit); log = await log.more?.(limit ?? this.view.config.pageItemLimit);

+ 8
- 2
src/views/nodes/reflogRecordNode.ts View File

@ -1,5 +1,5 @@
'use strict'; 'use strict';
import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import { CommitNode } from './commitNode'; import { CommitNode } from './commitNode';
import { LoadMoreNode, MessageNode } from './common'; import { LoadMoreNode, MessageNode } from './common';
import { GlyphChars } from '../../constants'; import { GlyphChars } from '../../constants';
@ -104,8 +104,14 @@ export class ReflogRecordNode extends ViewNode implements Pageab
} }
limit: number | undefined = this.view.getNodeLastKnownLimit(this); limit: number | undefined = this.view.getNodeLastKnownLimit(this);
@gate()
async loadMore(limit?: number | { until?: any }) { 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; if (log === undefined || !log.hasMore) return;
log = await log.more?.(limit ?? this.view.config.pageItemLimit); log = await log.more?.(limit ?? this.view.config.pageItemLimit);

+ 13
- 3
src/views/nodes/tagNode.ts View File

@ -1,5 +1,5 @@
'use strict'; 'use strict';
import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import { CommitNode } from './commitNode'; import { CommitNode } from './commitNode';
import { LoadMoreNode, MessageNode } from './common'; import { LoadMoreNode, MessageNode } from './common';
import { ViewBranchesLayout } from '../../configuration'; import { ViewBranchesLayout } from '../../configuration';
@ -57,7 +57,11 @@ export class TagNode extends ViewRefNode
]; ];
if (log.hasMore) { 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.tag.repoPath, this.tag.name),
),
);
} }
return children; return children;
} }
@ -105,8 +109,14 @@ export class TagNode extends ViewRefNode
} }
limit: number | undefined = this.view.getNodeLastKnownLimit(this); limit: number | undefined = this.view.getNodeLastKnownLimit(this);
@gate()
async loadMore(limit?: number | { until?: any }) { 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; if (log == null || !log.hasMore) return;
log = await log.more?.(limit ?? this.view.config.pageItemLimit); log = await log.more?.(limit ?? this.view.config.pageItemLimit);

Loading…
Cancel
Save