Skip to content

Commit

Permalink
SCM Graph - set the groundwork to show all history item groups (#227780)
Browse files Browse the repository at this point in the history
  • Loading branch information
lszomoru authored Sep 6, 2024
1 parent bcb954e commit 5ae8ffb
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
3 changes: 3 additions & 0 deletions extensions/git/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,9 @@ export class Repository {
}

if (options?.refNames) {
if (options.refNames.length === 0) {
args.push('--all');
}
args.push('--topo-order');
args.push('--decorate=full');
args.push(...options.refNames);
Expand Down
2 changes: 1 addition & 1 deletion src/vs/base/browser/markdownRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ function sanitizeRenderedMarkdown(
if (e.attrName === 'style' || e.attrName === 'class') {
if (element.tagName === 'SPAN') {
if (e.attrName === 'style') {
e.keepAttr = /^(color\:(#[0-9a-fA-F]+|var\(--vscode(-[a-zA-Z]+)+\));)?(background-color\:(#[0-9a-fA-F]+|var\(--vscode(-[a-zA-Z]+)+\));)?(border-radius:[0-9]+px;)?$/.test(e.attrValue);
e.keepAttr = /^(color\:(#[0-9a-fA-F]+|var\(--vscode(-[a-zA-Z0-9]+)+\));)?(background-color\:(#[0-9a-fA-F]+|var\(--vscode(-[a-zA-Z0-9]+)+\));)?(border-radius:[0-9]+px;)?$/.test(e.attrValue);
return;
} else if (e.attrName === 'class') {
e.keepAttr = /^codicon codicon-[a-z\-]+( codicon-modifier-[a-z\-]+)?$/.test(e.attrValue);
Expand Down
15 changes: 14 additions & 1 deletion src/vs/workbench/contrib/scm/browser/scmHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,20 @@ export function toISCMHistoryItemViewModelArray(historyItems: ISCMHistoryItem[],
// Add colors to labels
const labels = (historyItem.labels ?? [])
.map(label => {
return { ...label, color: colorMap.get(label.title) };
let color = colorMap.get(label.title);
if (!color && colorMap.has('*')) {
// Find the history item in the input swimlanes
const inputIndex = inputSwimlanes.findIndex(node => node.id === historyItem.id);

// Circle index - use the input swimlane index if present, otherwise add it to the end
const circleIndex = inputIndex !== -1 ? inputIndex : inputSwimlanes.length;

// Circle color - use the output swimlane color if present, otherwise the input swimlane color
color = circleIndex < outputSwimlanes.length ? outputSwimlanes[circleIndex].color :
circleIndex < inputSwimlanes.length ? inputSwimlanes[circleIndex].color : historyItemGroupLocal;
}

return { ...label, color };
});

viewModels.push({
Expand Down
47 changes: 34 additions & 13 deletions src/vs/workbench/contrib/scm/browser/scmHistoryViewPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,33 @@ class SCMHistoryViewModel extends Disposable {
* values are updated in the same transaction (or during the initial read of the observable value).
*/
readonly repository = latestChangedValue(this, [this._firstRepository, this._graphRepository]);
private readonly _historyItemGroupIds = observableValue<'all' | 'auto' | string[]>(this, 'auto');

private readonly _historyItemGroupFilter = observableValue<'all' | 'auto' | string[]>(this, 'auto');

readonly historyItemGroupFilter = derived<string[]>(reader => {
const filter = this._historyItemGroupFilter.read(reader);
if (Array.isArray(filter)) {
return filter;
}

if (filter === 'all') {
return [];
}

const repository = this.repository.get();
const historyProvider = repository?.provider.historyProvider.get();
const currentHistoryItemGroup = historyProvider?.currentHistoryItemGroup.get();

if (!currentHistoryItemGroup) {
return [];
}

return [
currentHistoryItemGroup.revision ?? currentHistoryItemGroup.id,
...currentHistoryItemGroup.remote ? [currentHistoryItemGroup.remote.revision ?? currentHistoryItemGroup.remote.id] : [],
...currentHistoryItemGroup.base ? [currentHistoryItemGroup.base.revision ?? currentHistoryItemGroup.base.id] : [],
];
});

private readonly _state = new Map<ISCMRepository, HistoryItemState>();

Expand Down Expand Up @@ -633,13 +659,9 @@ class SCMHistoryViewModel extends Disposable {
}

if (!state || state.loadMore) {
const historyItemGroupIds = [
currentHistoryItemGroup.revision ?? currentHistoryItemGroup.id,
...currentHistoryItemGroup.remote ? [currentHistoryItemGroup.remote.revision ?? currentHistoryItemGroup.remote.id] : [],
...currentHistoryItemGroup.base ? [currentHistoryItemGroup.base.revision ?? currentHistoryItemGroup.base.id] : [],
];

const existingHistoryItems = state?.items ?? [];

const historyItemGroupIds = this.historyItemGroupFilter.get();
const limit = clamp(this._configurationService.getValue<number>('scm.graph.pageSize'), 1, 1000);

const historyItems = await historyProvider.provideHistoryItems({
Expand All @@ -656,7 +678,7 @@ class SCMHistoryViewModel extends Disposable {
}

// Create the color map
const colorMap = this._getHistoryItemsColorMap(currentHistoryItemGroup);
const colorMap = this._getGraphColorMap(currentHistoryItemGroup);

return toISCMHistoryItemViewModelArray(state.items, colorMap)
.map(historyItemViewModel => ({
Expand All @@ -670,11 +692,7 @@ class SCMHistoryViewModel extends Disposable {
this._selectedRepository.set(repository, undefined);
}

private _getHistoryItemsColorMap(currentHistoryItemGroup: ISCMHistoryItemGroup): Map<string, ColorIdentifier> {
if (this._historyItemGroupIds.get() !== 'auto') {
return new Map<string, ColorIdentifier>();
}

private _getGraphColorMap(currentHistoryItemGroup: ISCMHistoryItemGroup): Map<string, ColorIdentifier> {
const colorMap = new Map<string, ColorIdentifier>([
[currentHistoryItemGroup.name, historyItemGroupLocal]
]);
Expand All @@ -684,6 +702,9 @@ class SCMHistoryViewModel extends Disposable {
if (currentHistoryItemGroup.base) {
colorMap.set(currentHistoryItemGroup.base.name, historyItemGroupBase);
}
if (this._historyItemGroupFilter.get() === 'all') {
colorMap.set('*', '');
}

return colorMap;
}
Expand Down

0 comments on commit 5ae8ffb

Please sign in to comment.