Skip to content

Commit 4a450d7

Browse files
committed
Fixes graph search issues with stashes
- Ensures remapped results are updated when new rows are loaded
1 parent fd9978c commit 4a450d7

File tree

4 files changed

+38
-28
lines changed

4 files changed

+38
-28
lines changed

src/env/node/git/sub-providers/graph.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,9 @@ export class GraphGitSubProvider implements GitGraphSubProvider {
438438
// Remap the "index commit" (e.g. contains staged files) of the stash
439439
remappedIds.set(parents[1], commit.sha);
440440
// Remap the "untracked commit" (e.g. contains untracked files) of the stash
441-
remappedIds.set(parents[2], commit.sha);
441+
if (parents.length > 2) {
442+
remappedIds.set(parents[2], commit.sha);
443+
}
442444
parents.splice(1, 2);
443445
}
444446

src/webviews/apps/plus/graph/stateProvider.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ export class GraphStateProvider implements StateProvider<State> {
282282
updates.rowsStats = { ...this._state.rowsStats, ...msg.params.rowsStats };
283283
}
284284
updates.rowsStatsLoading = msg.params.rowsStatsLoading;
285+
if (msg.params.searchResults != null) {
286+
updates.searchResults = msg.params.searchResults;
287+
}
285288
if (msg.params.selectedRows != null) {
286289
updates.selectedRows = msg.params.selectedRows;
287290
}

src/webviews/plus/graph/graphWebview.ts

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,7 +1514,6 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
15141514

15151515
try {
15161516
results = await this.getSearchResults(msg.params);
1517-
15181517
void this.host.respond(requestType, msg, results);
15191518
} catch (ex) {
15201519
exception = ex;
@@ -1548,24 +1547,15 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
15481547

15491548
let search: GitGraphSearch | undefined = this._search;
15501549

1550+
const graph = this._graph!;
1551+
15511552
if (e.more && search?.more != null && search.comparisonKey === getSearchQueryComparisonKey(e.search)) {
15521553
search = await search.more(e.limit ?? configuration.get('graph.searchItemLimit') ?? 100);
15531554
if (search != null) {
15541555
this._search = search;
1555-
void (await this.ensureSearchStartsInRange(this._graph!, search));
1556-
1557-
return {
1558-
results:
1559-
search.results.size > 0
1560-
? {
1561-
ids: Object.fromEntries(
1562-
map(search.results, ([k, v]) => [this._graph?.remappedIds?.get(k) ?? k, v]),
1563-
),
1564-
count: search.results.size,
1565-
paging: { hasMore: search.paging?.hasMore ?? false },
1566-
}
1567-
: undefined,
1568-
};
1556+
void (await this.ensureSearchStartsInRange(graph, search));
1557+
1558+
return { results: this.getRemappedSearchResults(graph, search) };
15691559
}
15701560

15711561
return { results: undefined };
@@ -1601,7 +1591,7 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
16011591
search = this._search!;
16021592
}
16031593

1604-
const firstResult = await this.ensureSearchStartsInRange(this._graph!, search);
1594+
const firstResult = await this.ensureSearchStartsInRange(graph, search);
16051595

16061596
let sendSelectedRows = false;
16071597
if (firstResult != null) {
@@ -1610,19 +1600,26 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
16101600
}
16111601

16121602
return {
1613-
results: !search.results.size
1614-
? { count: 0 }
1615-
: {
1616-
ids: Object.fromEntries(
1617-
map(search.results, ([k, v]) => [this._graph?.remappedIds?.get(k) ?? k, v]),
1618-
),
1619-
count: search.results.size,
1620-
paging: { hasMore: search.paging?.hasMore ?? false },
1621-
},
1603+
results: !search.results.size ? { count: 0 } : this.getRemappedSearchResults(graph, search),
16221604
selectedRows: sendSelectedRows ? this._selectedRows : undefined,
16231605
};
16241606
}
16251607

1608+
/** Remaps search results SHA for stashes to the root stash SHA */
1609+
private getRemappedSearchResults(graph: GitGraph, search: GitGraphSearch) {
1610+
if (!search.results.size) return undefined;
1611+
1612+
return {
1613+
ids: Object.fromEntries(
1614+
graph.remappedIds?.size
1615+
? map(search.results, ([k, v]) => [graph.remappedIds!.get(k) ?? k, v])
1616+
: search.results,
1617+
),
1618+
count: search.results.size,
1619+
paging: { hasMore: search.paging?.hasMore ?? false },
1620+
};
1621+
}
1622+
16261623
private onSearchOpenInView(e: SearchOpenInViewParams) {
16271624
if (this.repository == null) return;
16281625

@@ -1926,6 +1923,13 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
19261923
if (this._graph == null) return;
19271924

19281925
const graph = this._graph;
1926+
const search = this._search;
1927+
1928+
let searchResults: GraphSearchResults | undefined;
1929+
if (search?.results.size && graph.remappedIds?.size) {
1930+
searchResults = this.getRemappedSearchResults(graph, search);
1931+
}
1932+
19291933
return this.host.notify(
19301934
DidChangeRowsNotification,
19311935
{
@@ -1936,6 +1940,8 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
19361940
rowsStats: graph.rowsStats?.size ? Object.fromEntries(graph.rowsStats) : undefined,
19371941
rowsStatsLoading:
19381942
graph.rowsStatsDeferred?.isLoaded != null ? !graph.rowsStatsDeferred.isLoaded() : false,
1943+
1944+
searchResults: searchResults,
19391945
selectedRows: sendSelectedRows ? this._selectedRows : undefined,
19401946
paging: {
19411947
startingCursor: graph.paging?.startingCursor,
@@ -3110,8 +3116,6 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
31103116
search?: GitGraphSearch,
31113117
cancellation?: CancellationToken,
31123118
) {
3113-
console.warn('##### updateGraphWithMoreRows', id, search);
3114-
31153119
const { defaultItemLimit, pageItemLimit } = configuration.get('graph');
31163120
const updatedGraph = await graph.more?.(pageItemLimit ?? defaultItemLimit, id ?? undefined, cancellation);
31173121
if (updatedGraph != null) {

src/webviews/plus/graph/protocol.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ export interface DidChangeRowsParams {
473473
refsMetadata?: GraphRefsMetadata | null;
474474
rowsStats?: Record<string, GraphRowStats>;
475475
rowsStatsLoading: boolean;
476+
searchResults?: GraphSearchResults;
476477
selectedRows?: GraphSelectedRows;
477478
}
478479
export const DidChangeRowsNotification = new IpcNotification<DidChangeRowsParams>(

0 commit comments

Comments
 (0)