Browse Source

Supports arbitrary commit jumping when paging

main
Eric Amodio 2 years ago
parent
commit
9646e498ab
4 changed files with 22 additions and 24 deletions
  1. +7
    -16
      src/env/node/git/localGitProvider.ts
  2. +6
    -4
      src/plus/webviews/graph/graphWebview.ts
  3. +5
    -1
      src/plus/webviews/graph/protocol.ts
  4. +4
    -3
      src/webviews/apps/plus/graph/graph.tsx

+ 7
- 16
src/env/node/git/localGitProvider.ts View File

@ -1656,26 +1656,20 @@ export class LocalGitProvider implements GitProvider, Disposable {
async function getCommitsForGraphCore( async function getCommitsForGraphCore(
this: LocalGitProvider, this: LocalGitProvider,
limit: number, limit: number,
shaOrCursor?: string | { sha: string; skip: number },
sha?: string,
cursor?: { sha: string; skip: number },
): Promise<GitGraph> { ): Promise<GitGraph> {
iterations++; iterations++;
let cursor: { sha: string; skip: number } | undefined;
let sha: string | undefined;
if (shaOrCursor != null) {
if (typeof shaOrCursor === 'string') {
sha = shaOrCursor;
} else {
cursor = shaOrCursor;
}
}
let log: string | string[] | undefined; let log: string | string[] | undefined;
let nextPageLimit = limit; let nextPageLimit = limit;
let size; let size;
do { do {
const args = [...parser.arguments, `--${ordering}-order`, '--all']; const args = [...parser.arguments, `--${ordering}-order`, '--all'];
if (cursor?.skip) {
args.push(`--skip=${cursor.skip}`);
}
let data; let data;
if (sha) { if (sha) {
@ -1688,9 +1682,6 @@ export class LocalGitProvider implements GitProvider, Disposable {
); );
} else { } else {
args.push(`-n${nextPageLimit + 1}`); args.push(`-n${nextPageLimit + 1}`);
if (cursor?.skip) {
args.push(`--skip=${cursor.skip}`);
}
data = await this.git.log2(repoPath, stdin ? { stdin: stdin } : undefined, ...args); data = await this.git.log2(repoPath, stdin ? { stdin: stdin } : undefined, ...args);
@ -1870,8 +1861,8 @@ export class LocalGitProvider implements GitProvider, Disposable {
startingCursor: startingCursor, startingCursor: startingCursor,
more: count > limit, more: count > limit,
}, },
more: async (limit: number): Promise<GitGraph | undefined> =>
getCommitsForGraphCore.call(this, limit, cursor),
more: async (limit: number, sha?: string): Promise<GitGraph | undefined> =>
getCommitsForGraphCore.call(this, limit, sha, cursor),
}; };
} }

+ 6
- 4
src/plus/webviews/graph/graphWebview.ts View File

@ -128,7 +128,8 @@ export class GraphWebview extends WebviewBase {
return; return;
} }
this.updateState();
this.setSelectedRows(args.sha);
void this.onGetMoreCommits(args.sha);
} }
}), }),
); );
@ -193,7 +194,7 @@ export class GraphWebview extends WebviewBase {
onIpc(GetMissingAvatarsCommandType, e, params => this.onGetMissingAvatars(params.emails)); onIpc(GetMissingAvatarsCommandType, e, params => this.onGetMissingAvatars(params.emails));
break; break;
case GetMoreCommitsCommandType.method: case GetMoreCommitsCommandType.method:
onIpc(GetMoreCommitsCommandType, e, () => this.onGetMoreCommits());
onIpc(GetMoreCommitsCommandType, e, params => this.onGetMoreCommits(params.sha));
break; break;
case UpdateColumnCommandType.method: case UpdateColumnCommandType.method:
onIpc(UpdateColumnCommandType, e, params => this.onColumnUpdated(params.name, params.config)); onIpc(UpdateColumnCommandType, e, params => this.onColumnUpdated(params.name, params.config));
@ -362,7 +363,7 @@ export class GraphWebview extends WebviewBase {
} }
@gate() @gate()
private async onGetMoreCommits() {
private async onGetMoreCommits(sha?: string) {
if (this._graph?.more == null || this._repository?.etag !== this._etagRepository) { if (this._graph?.more == null || this._repository?.etag !== this._etagRepository) {
this.updateState(true); this.updateState(true);
@ -370,7 +371,7 @@ export class GraphWebview extends WebviewBase {
} }
const { defaultItemLimit, pageItemLimit } = configuration.get('graph'); const { defaultItemLimit, pageItemLimit } = configuration.get('graph');
const newGraph = await this._graph.more(pageItemLimit ?? defaultItemLimit);
const newGraph = await this._graph.more(pageItemLimit ?? defaultItemLimit, sha);
if (newGraph != null) { if (newGraph != null) {
this.setGraph(newGraph); this.setGraph(newGraph);
} else { } else {
@ -505,6 +506,7 @@ export class GraphWebview extends WebviewBase {
success = await this.notify(DidChangeCommitsNotificationType, { success = await this.notify(DidChangeCommitsNotificationType, {
rows: data.rows, rows: data.rows,
avatars: Object.fromEntries(data.avatars), avatars: Object.fromEntries(data.avatars),
selectedRows: this._selectedRows,
paging: { paging: {
startingCursor: data.paging?.startingCursor, startingCursor: data.paging?.startingCursor,
more: data.paging?.more ?? false, more: data.paging?.more ?? false,

+ 5
- 1
src/plus/webviews/graph/protocol.ts View File

@ -82,7 +82,10 @@ export interface GetMissingAvatarsParams {
} }
export const GetMissingAvatarsCommandType = new IpcCommandType<GetMissingAvatarsParams>('graph/getMissingAvatars'); export const GetMissingAvatarsCommandType = new IpcCommandType<GetMissingAvatarsParams>('graph/getMissingAvatars');
export const GetMoreCommitsCommandType = new IpcCommandType<undefined>('graph/getMoreCommits');
export interface GetMoreCommitsParams {
sha?: string;
}
export const GetMoreCommitsCommandType = new IpcCommandType<GetMoreCommitsParams>('graph/getMoreCommits');
export interface UpdateColumnParams { export interface UpdateColumnParams {
name: string; name: string;
@ -133,6 +136,7 @@ export const DidChangeAvatarsNotificationType = new IpcNotificationType
export interface DidChangeCommitsParams { export interface DidChangeCommitsParams {
rows: GraphRow[]; rows: GraphRow[];
avatars: { [email: string]: string }; avatars: { [email: string]: string };
selectedRows?: { [id: string]: true };
paging?: GraphPaging; paging?: GraphPaging;
} }
export const DidChangeCommitsNotificationType = new IpcNotificationType<DidChangeCommitsParams>( export const DidChangeCommitsNotificationType = new IpcNotificationType<DidChangeCommitsParams>(

+ 4
- 3
src/webviews/apps/plus/graph/graph.tsx View File

@ -174,9 +174,10 @@ export class GraphApp extends App {
this.setState({ this.setState({
...this.state, ...this.state,
avatars: params.avatars, avatars: params.avatars,
paging: params.paging,
selectedRows: params.selectedRows,
rows: rows, rows: rows,
loading: false, loading: false,
paging: params.paging,
}); });
this.refresh(this.state); this.refresh(this.state);
}); });
@ -273,8 +274,8 @@ export class GraphApp extends App {
this.sendCommand(GetMissingAvatarsCommandType, { emails: emails }); this.sendCommand(GetMissingAvatarsCommandType, { emails: emails });
} }
private onGetMoreCommits() {
this.sendCommand(GetMoreCommitsCommandType, undefined);
private onGetMoreCommits(sha?: string) {
this.sendCommand(GetMoreCommitsCommandType, { sha: sha });
} }
private onSelectionChanged(selection: { id: string; type: GitGraphRowType }[]) { private onSelectionChanged(selection: { id: string; type: GitGraphRowType }[]) {

Loading…
Cancel
Save