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(
this: LocalGitProvider,
limit: number,
shaOrCursor?: string | { sha: string; skip: number },
sha?: string,
cursor?: { sha: string; skip: number },
): Promise<GitGraph> {
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 nextPageLimit = limit;
let size;
do {
const args = [...parser.arguments, `--${ordering}-order`, '--all'];
if (cursor?.skip) {
args.push(`--skip=${cursor.skip}`);
}
let data;
if (sha) {
@ -1688,9 +1682,6 @@ export class LocalGitProvider implements GitProvider, Disposable {
);
} else {
args.push(`-n${nextPageLimit + 1}`);
if (cursor?.skip) {
args.push(`--skip=${cursor.skip}`);
}
data = await this.git.log2(repoPath, stdin ? { stdin: stdin } : undefined, ...args);
@ -1870,8 +1861,8 @@ export class LocalGitProvider implements GitProvider, Disposable {
startingCursor: startingCursor,
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;
}
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));
break;
case GetMoreCommitsCommandType.method:
onIpc(GetMoreCommitsCommandType, e, () => this.onGetMoreCommits());
onIpc(GetMoreCommitsCommandType, e, params => this.onGetMoreCommits(params.sha));
break;
case UpdateColumnCommandType.method:
onIpc(UpdateColumnCommandType, e, params => this.onColumnUpdated(params.name, params.config));
@ -362,7 +363,7 @@ export class GraphWebview extends WebviewBase {
}
@gate()
private async onGetMoreCommits() {
private async onGetMoreCommits(sha?: string) {
if (this._graph?.more == null || this._repository?.etag !== this._etagRepository) {
this.updateState(true);
@ -370,7 +371,7 @@ export class GraphWebview extends WebviewBase {
}
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) {
this.setGraph(newGraph);
} else {
@ -505,6 +506,7 @@ export class GraphWebview extends WebviewBase {
success = await this.notify(DidChangeCommitsNotificationType, {
rows: data.rows,
avatars: Object.fromEntries(data.avatars),
selectedRows: this._selectedRows,
paging: {
startingCursor: data.paging?.startingCursor,
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 GetMoreCommitsCommandType = new IpcCommandType<undefined>('graph/getMoreCommits');
export interface GetMoreCommitsParams {
sha?: string;
}
export const GetMoreCommitsCommandType = new IpcCommandType<GetMoreCommitsParams>('graph/getMoreCommits');
export interface UpdateColumnParams {
name: string;
@ -133,6 +136,7 @@ export const DidChangeAvatarsNotificationType = new IpcNotificationType
export interface DidChangeCommitsParams {
rows: GraphRow[];
avatars: { [email: string]: string };
selectedRows?: { [id: string]: true };
paging?: GraphPaging;
}
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.state,
avatars: params.avatars,
paging: params.paging,
selectedRows: params.selectedRows,
rows: rows,
loading: false,
paging: params.paging,
});
this.refresh(this.state);
});
@ -273,8 +274,8 @@ export class GraphApp extends App {
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 }[]) {

Loading…
Cancel
Save