Skip to content

Commit

Permalink
SCM - fix edge case to show the first commit of the repository
Browse files Browse the repository at this point in the history
  • Loading branch information
lszomoru committed Jul 29, 2024
1 parent 8194662 commit 8cfc2ec
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
49 changes: 25 additions & 24 deletions src/vs/workbench/contrib/scm/browser/scmHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ export function renderSCMHistoryItemGraph(historyItemViewModel: ISCMHistoryItemV
const circleIndex = inputIndex !== -1 ? inputIndex : inputSwimlanes.length;

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

let outputSwimlaneIndex = 0;
for (let index = 0; index < inputSwimlanes.length; index++) {
Expand Down Expand Up @@ -238,10 +239,10 @@ export function toISCMHistoryItemViewModelArray(historyItems: ISCMHistoryItem[],
const inputSwimlanes = outputSwimlanesFromPreviousItem.map(i => deepClone(i));
const outputSwimlanes: ISCMHistoryItemGraphNode[] = [];

if (historyItem.parentIds.length > 0) {
let firstParentAdded = false;
let firstParentAdded = false;

// Add first parent to the output
// Add first parent to the output
if (historyItem.parentIds.length > 0) {
for (const node of inputSwimlanes) {
if (node.id === historyItem.id) {
if (!firstParentAdded) {
Expand All @@ -257,30 +258,30 @@ export function toISCMHistoryItemViewModelArray(historyItems: ISCMHistoryItem[],

outputSwimlanes.push(deepClone(node));
}
}

// Add unprocessed parent(s) to the output
for (let i = firstParentAdded ? 1 : 0; i < historyItem.parentIds.length; i++) {
// Color index (label -> next color)
let colorIdentifier: string | undefined;

if (!firstParentAdded) {
colorIdentifier = getLabelColorIdentifier(historyItem, colorMap);
} else {
const historyItemParent = historyItems
.find(h => h.id === historyItem.parentIds[i]);
colorIdentifier = historyItemParent ? getLabelColorIdentifier(historyItemParent, colorMap) : undefined;
}
// Add unprocessed parent(s) to the output
for (let i = firstParentAdded ? 1 : 0; i < historyItem.parentIds.length; i++) {
// Color index (label -> next color)
let colorIdentifier: string | undefined;

if (!colorIdentifier) {
colorIndex = rot(colorIndex + 1, colorRegistry.length);
colorIdentifier = colorRegistry[colorIndex];
}
if (!firstParentAdded) {
colorIdentifier = getLabelColorIdentifier(historyItem, colorMap);
} else {
const historyItemParent = historyItems
.find(h => h.id === historyItem.parentIds[i]);
colorIdentifier = historyItemParent ? getLabelColorIdentifier(historyItemParent, colorMap) : undefined;
}

outputSwimlanes.push({
id: historyItem.parentIds[i],
color: colorIdentifier
});
if (!colorIdentifier) {
colorIndex = rot(colorIndex + 1, colorRegistry.length);
colorIdentifier = colorRegistry[colorIndex];
}

outputSwimlanes.push({
id: historyItem.parentIds[i],
color: colorIdentifier
});
}

viewModels.push({
Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/contrib/scm/browser/scmViewPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4123,9 +4123,9 @@ class SCMTreeHistoryProviderDataSource extends Disposable {
});
}

// If we only have one history item that contains all the
// labels (current, remote, base), we don't need to show it
if (historyItemsElement.length === 1) {
// If we only have one history item that contains all the labels (current, remote, base),
// we don't need to show it, unless it is the root commit (does not have any parents).
if (historyItemsElement.length === 1 && historyItemsElement[0].parentIds.length > 0) {
const currentHistoryItemGroupLabels = [
currentHistoryItemGroup.name,
...currentHistoryItemGroup.remote ? [currentHistoryItemGroup.remote.name] : [],
Expand Down

0 comments on commit 8cfc2ec

Please sign in to comment.