Git - add option to ignore whitespace for the blame information (#284260)

This commit is contained in:
Ladislau Szomoru
2025-12-18 14:53:58 +00:00
committed by GitHub
parent e3523eda7d
commit 6d28298bb5
5 changed files with 28 additions and 2 deletions

View File

@@ -3903,6 +3903,11 @@
"default": "${authorName} (${authorDateAgo})", "default": "${authorName} (${authorDateAgo})",
"markdownDescription": "%config.blameStatusBarItem.template%" "markdownDescription": "%config.blameStatusBarItem.template%"
}, },
"git.blame.ignoreWhitespace": {
"type": "boolean",
"default": false,
"markdownDescription": "%config.blameIgnoreWhitespace%"
},
"git.commitShortHashLength": { "git.commitShortHashLength": {
"type": "number", "type": "number",
"default": 7, "default": 7,

View File

@@ -306,6 +306,7 @@
"config.blameEditorDecoration.disableHover": "Controls whether to disable the blame information editor decoration hover.", "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.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.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.commitShortHashLength": "Controls the length of the commit short hash.",
"config.diagnosticsCommitHook.enabled": "Controls whether to check for unresolved diagnostics before committing.", "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`.", "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`.",

View File

@@ -126,6 +126,10 @@ interface LineBlameInformation {
class GitBlameInformationCache { class GitBlameInformationCache {
private readonly _cache = new Map<Repository, LRUCache<string, BlameInformation[]>>(); private readonly _cache = new Map<Repository, LRUCache<string, BlameInformation[]>>();
clear(): void {
this._cache.clear();
}
delete(repository: Repository): boolean { delete(repository: Repository): boolean {
return this._cache.delete(repository); return this._cache.delete(repository);
} }
@@ -267,11 +271,19 @@ export class GitBlameController {
private _onDidChangeConfiguration(e?: ConfigurationChangeEvent): void { private _onDidChangeConfiguration(e?: ConfigurationChangeEvent): void {
if (e && if (e &&
!e.affectsConfiguration('git.blame.ignoreWhitespace') &&
!e.affectsConfiguration('git.blame.editorDecoration.enabled') && !e.affectsConfiguration('git.blame.editorDecoration.enabled') &&
!e.affectsConfiguration('git.blame.statusBarItem.enabled')) { !e.affectsConfiguration('git.blame.statusBarItem.enabled')) {
return; 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 config = workspace.getConfiguration('git');
const editorDecorationEnabled = config.get<boolean>('blame.editorDecoration.enabled') === true; const editorDecorationEnabled = config.get<boolean>('blame.editorDecoration.enabled') === true;
const statusBarItemEnabled = config.get<boolean>('blame.statusBarItem.enabled') === true; const statusBarItemEnabled = config.get<boolean>('blame.statusBarItem.enabled') === true;

View File

@@ -2414,10 +2414,14 @@ export class Repository {
} }
} }
async blame2(path: string, ref?: string): Promise<BlameInformation[] | undefined> { async blame2(path: string, ref?: string, ignoreWhitespace?: boolean): Promise<BlameInformation[] | undefined> {
try { try {
const args = ['blame', '--root', '--incremental']; const args = ['blame', '--root', '--incremental'];
if (ignoreWhitespace) {
args.push('-w');
}
if (ref) { if (ref) {
args.push(ref); args.push(ref);
} }

View File

@@ -2104,7 +2104,11 @@ export class Repository implements Disposable {
} }
async blame2(path: string, ref?: string): Promise<BlameInformation[] | undefined> { async blame2(path: string, ref?: string): Promise<BlameInformation[] | undefined> {
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<boolean>('blame.ignoreWhitespace', false);
return this.repository.blame2(path, ref, ignoreWhitespace);
});
} }
@throttle @throttle