From 959d01a2a5ccad380c1c2737361d57472579eab3 Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Tue, 21 Jan 2025 11:44:21 +0100 Subject: [PATCH] Git - fix regression with commits that contain addition/deletion/rename (#238349) * Git - fix regression with commits that contain addition/deletion/rename * Fix compilation error --- extensions/git/src/fileSystemProvider.ts | 7 +++++-- extensions/git/src/historyProvider.ts | 8 +++----- extensions/git/src/main.ts | 2 +- extensions/git/src/uri.ts | 20 +++++++++++++++---- src/vs/workbench/api/browser/mainThreadSCM.ts | 3 +-- .../workbench/api/common/extHost.protocol.ts | 1 - .../workbench/contrib/scm/common/history.ts | 1 - .../vscode.proposed.scmHistoryProvider.d.ts | 1 - 8 files changed, 26 insertions(+), 17 deletions(-) diff --git a/extensions/git/src/fileSystemProvider.ts b/extensions/git/src/fileSystemProvider.ts index 0847fe8d745..896d933cddf 100644 --- a/extensions/git/src/fileSystemProvider.ts +++ b/extensions/git/src/fileSystemProvider.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { workspace, Uri, Disposable, Event, EventEmitter, window, FileSystemProvider, FileChangeEvent, FileStat, FileType, FileChangeType, FileSystemError } from 'vscode'; +import { workspace, Uri, Disposable, Event, EventEmitter, window, FileSystemProvider, FileChangeEvent, FileStat, FileType, FileChangeType, FileSystemError, LogOutputChannel } from 'vscode'; import { debounce, throttle } from './decorators'; import { fromGitUri, toGitUri } from './uri'; import { Model, ModelChangeEvent, OriginalResourceChangeEvent } from './model'; @@ -43,7 +43,7 @@ export class GitFileSystemProvider implements FileSystemProvider { private mtime = new Date().getTime(); private disposables: Disposable[] = []; - constructor(private model: Model) { + constructor(private readonly model: Model, private readonly logger: LogOutputChannel) { this.disposables.push( model.onDidChangeRepository(this.onDidChangeRepository, this), model.onDidChangeOriginalResource(this.onDidChangeOriginalResource, this), @@ -136,6 +136,7 @@ export class GitFileSystemProvider implements FileSystemProvider { const { submoduleOf, path, ref } = fromGitUri(uri); const repository = submoduleOf ? this.model.getRepository(submoduleOf) : this.model.getRepository(uri); if (!repository) { + this.logger.warn(`[GitFileSystemProvider][stat] Repository not found - ${uri.toString()}`); throw FileSystemError.FileNotFound(); } @@ -181,6 +182,7 @@ export class GitFileSystemProvider implements FileSystemProvider { const repository = this.model.getRepository(uri); if (!repository) { + this.logger.warn(`[GitFileSystemProvider][readFile] Repository not found - ${uri.toString()}`); throw FileSystemError.FileNotFound(); } @@ -192,6 +194,7 @@ export class GitFileSystemProvider implements FileSystemProvider { try { return await repository.buffer(sanitizeRef(ref, path, repository), path); } catch (err) { + this.logger.warn(`[GitFileSystemProvider][readFile] File not found - ${uri.toString()}`); // File does not exist in git. This could be // because the file is untracked or ignored throw FileSystemError.FileNotFound(); diff --git a/extensions/git/src/historyProvider.ts b/extensions/git/src/historyProvider.ts index 1a01ae4c05e..f5605c354ab 100644 --- a/extensions/git/src/historyProvider.ts +++ b/extensions/git/src/historyProvider.ts @@ -7,7 +7,7 @@ import { Disposable, Event, EventEmitter, FileDecoration, FileDecorationProvider, SourceControlHistoryItem, SourceControlHistoryItemChange, SourceControlHistoryOptions, SourceControlHistoryProvider, ThemeIcon, Uri, window, LogOutputChannel, SourceControlHistoryItemRef, l10n, SourceControlHistoryItemRefsChangeEvent } from 'vscode'; import { Repository, Resource } from './repository'; import { IDisposable, deltaHistoryItemRefs, dispose, filterEvent, getCommitShortHash } from './util'; -import { toGitUri } from './uri'; +import { toMultiFileDiffEditorUris } from './uri'; import { AvatarQuery, AvatarQueryCommit, Branch, LogOptions, Ref, RefType } from './api/git'; import { emojify, ensureEmojis } from './emoji'; import { Commit } from './git'; @@ -333,10 +333,8 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec // History item change historyItemChanges.push({ uri: historyItemUri, - originalUri: toGitUri(change.originalUri, historyItemParentId), - modifiedUri: toGitUri(change.uri, historyItemId), - renameUri: change.renameUri, - }); + ...toMultiFileDiffEditorUris(change, historyItemParentId, historyItemId) + } satisfies SourceControlHistoryItemChange); // History item change decoration const letter = Resource.getStatusLetter(change.status); diff --git a/extensions/git/src/main.ts b/extensions/git/src/main.ts index 515f57c12cf..8205d8de69f 100644 --- a/extensions/git/src/main.ts +++ b/extensions/git/src/main.ts @@ -112,7 +112,7 @@ async function createModel(context: ExtensionContext, logger: LogOutputChannel, const cc = new CommandCenter(git, model, context.globalState, logger, telemetryReporter); disposables.push( cc, - new GitFileSystemProvider(model), + new GitFileSystemProvider(model, logger), new GitDecorations(model), new GitBlameController(model), new GitTimelineProvider(model, cc), diff --git a/extensions/git/src/uri.ts b/extensions/git/src/uri.ts index 169abd1bc35..8b04fabe583 100644 --- a/extensions/git/src/uri.ts +++ b/extensions/git/src/uri.ts @@ -64,12 +64,24 @@ export function toMergeUris(uri: Uri): { base: Uri; ours: Uri; theirs: Uri } { export function toMultiFileDiffEditorUris(change: Change, originalRef: string, modifiedRef: string): { originalUri: Uri | undefined; modifiedUri: Uri | undefined } { switch (change.status) { case Status.INDEX_ADDED: - return { originalUri: undefined, modifiedUri: toGitUri(change.uri, modifiedRef) }; + return { + originalUri: undefined, + modifiedUri: toGitUri(change.uri, modifiedRef) + }; case Status.DELETED: - return { originalUri: toGitUri(change.uri, originalRef), modifiedUri: undefined }; + return { + originalUri: toGitUri(change.uri, originalRef), + modifiedUri: undefined + }; case Status.INDEX_RENAMED: - return { originalUri: toGitUri(change.originalUri, originalRef), modifiedUri: toGitUri(change.uri, modifiedRef) }; + return { + originalUri: toGitUri(change.originalUri, originalRef), + modifiedUri: toGitUri(change.uri, modifiedRef) + }; default: - return { originalUri: toGitUri(change.uri, originalRef), modifiedUri: toGitUri(change.uri, modifiedRef) }; + return { + originalUri: toGitUri(change.uri, originalRef), + modifiedUri: toGitUri(change.uri, modifiedRef) + }; } } diff --git a/src/vs/workbench/api/browser/mainThreadSCM.ts b/src/vs/workbench/api/browser/mainThreadSCM.ts index 934aa925675..b643356323c 100644 --- a/src/vs/workbench/api/browser/mainThreadSCM.ts +++ b/src/vs/workbench/api/browser/mainThreadSCM.ts @@ -212,8 +212,7 @@ class MainThreadSCMHistoryProvider implements ISCMHistoryProvider { return changes?.map(change => ({ uri: URI.revive(change.uri), originalUri: change.originalUri && URI.revive(change.originalUri), - modifiedUri: change.modifiedUri && URI.revive(change.modifiedUri), - renameUri: change.renameUri && URI.revive(change.renameUri) + modifiedUri: change.modifiedUri && URI.revive(change.modifiedUri) })); } diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index 3f31329b105..dfe7ac5466f 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -1622,7 +1622,6 @@ export interface SCMHistoryItemChangeDto { readonly uri: UriComponents; readonly originalUri: UriComponents | undefined; readonly modifiedUri: UriComponents | undefined; - readonly renameUri: UriComponents | undefined; } export interface MainThreadSCMShape extends IDisposable { diff --git a/src/vs/workbench/contrib/scm/common/history.ts b/src/vs/workbench/contrib/scm/common/history.ts index 217c6f584c3..3e9846603f3 100644 --- a/src/vs/workbench/contrib/scm/common/history.ts +++ b/src/vs/workbench/contrib/scm/common/history.ts @@ -98,5 +98,4 @@ export interface ISCMHistoryItemChange { readonly uri: URI; readonly originalUri?: URI; readonly modifiedUri?: URI; - readonly renameUri?: URI; } diff --git a/src/vscode-dts/vscode.proposed.scmHistoryProvider.d.ts b/src/vscode-dts/vscode.proposed.scmHistoryProvider.d.ts index 690a931260e..9eedd16d767 100644 --- a/src/vscode-dts/vscode.proposed.scmHistoryProvider.d.ts +++ b/src/vscode-dts/vscode.proposed.scmHistoryProvider.d.ts @@ -72,7 +72,6 @@ declare module 'vscode' { readonly uri: Uri; readonly originalUri: Uri | undefined; readonly modifiedUri: Uri | undefined; - readonly renameUri: Uri | undefined; } export interface SourceControlHistoryItemRefsChangeEvent {