From 6d28298bb50aafb1008ecb162c8b093411b9a562 Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Thu, 18 Dec 2025 14:53:58 +0000 Subject: [PATCH] Git - add option to ignore whitespace for the blame information (#284260) --- extensions/git/package.json | 5 +++++ extensions/git/package.nls.json | 1 + extensions/git/src/blame.ts | 12 ++++++++++++ extensions/git/src/git.ts | 6 +++++- extensions/git/src/repository.ts | 6 +++++- 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/extensions/git/package.json b/extensions/git/package.json index 906398098b7..2c6eadd99dd 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -3903,6 +3903,11 @@ "default": "${authorName} (${authorDateAgo})", "markdownDescription": "%config.blameStatusBarItem.template%" }, + "git.blame.ignoreWhitespace": { + "type": "boolean", + "default": false, + "markdownDescription": "%config.blameIgnoreWhitespace%" + }, "git.commitShortHashLength": { "type": "number", "default": 7, diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index bb7ef820fab..c8834151c6f 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -306,6 +306,7 @@ "config.blameEditorDecoration.disableHover": "Controls whether to disable the blame information editor decoration hover.", "config.blameStatusBarItem.enabled": "Controls whether to show blame information in the status bar.", "config.blameStatusBarItem.template": "Template for the blame information status bar item. Supported variables:\n\n* `hash`: Commit hash\n\n* `hashShort`: First N characters of the commit hash according to `#git.commitShortHashLength#`\n\n* `subject`: First line of the commit message\n\n* `authorName`: Author name\n\n* `authorEmail`: Author email\n\n* `authorDate`: Author date\n\n* `authorDateAgo`: Time difference between now and the author date\n\n", + "config.blameIgnoreWhitespace": "Controls whether to ignore whitespace changes when computing blame information.", "config.commitShortHashLength": "Controls the length of the commit short hash.", "config.diagnosticsCommitHook.enabled": "Controls whether to check for unresolved diagnostics before committing.", "config.diagnosticsCommitHook.sources": "Controls the list of sources (**Item**) and the minimum severity (**Value**) to be considered before committing. **Note:** To ignore diagnostics from a particular source, add the source to the list and set the minimum severity to `none`.", diff --git a/extensions/git/src/blame.ts b/extensions/git/src/blame.ts index 92ae680ae61..c6f121a01b3 100644 --- a/extensions/git/src/blame.ts +++ b/extensions/git/src/blame.ts @@ -126,6 +126,10 @@ interface LineBlameInformation { class GitBlameInformationCache { private readonly _cache = new Map>(); + clear(): void { + this._cache.clear(); + } + delete(repository: Repository): boolean { return this._cache.delete(repository); } @@ -267,11 +271,19 @@ export class GitBlameController { private _onDidChangeConfiguration(e?: ConfigurationChangeEvent): void { if (e && + !e.affectsConfiguration('git.blame.ignoreWhitespace') && !e.affectsConfiguration('git.blame.editorDecoration.enabled') && !e.affectsConfiguration('git.blame.statusBarItem.enabled')) { return; } + // Clear cache when ignoreWhitespace setting changes + if (e && e.affectsConfiguration('git.blame.ignoreWhitespace')) { + this._repositoryBlameCache.clear(); + this._updateTextEditorBlameInformation(window.activeTextEditor); + return; + } + const config = workspace.getConfiguration('git'); const editorDecorationEnabled = config.get('blame.editorDecoration.enabled') === true; const statusBarItemEnabled = config.get('blame.statusBarItem.enabled') === true; diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index 5c2dc12996e..5c47f7f5b6b 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -2414,10 +2414,14 @@ export class Repository { } } - async blame2(path: string, ref?: string): Promise { + async blame2(path: string, ref?: string, ignoreWhitespace?: boolean): Promise { try { const args = ['blame', '--root', '--incremental']; + if (ignoreWhitespace) { + args.push('-w'); + } + if (ref) { args.push(ref); } diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index d9e35e751ba..70957d2949c 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -2104,7 +2104,11 @@ export class Repository implements Disposable { } async blame2(path: string, ref?: string): Promise { - return await this.run(Operation.Blame(false), () => this.repository.blame2(path, ref)); + return await this.run(Operation.Blame(false), () => { + const config = workspace.getConfiguration('git', Uri.file(this.root)); + const ignoreWhitespace = config.get('blame.ignoreWhitespace', false); + return this.repository.blame2(path, ref, ignoreWhitespace); + }); } @throttle