From 237b803ebeecbf3f050d53727c44ff27a6f51d7b Mon Sep 17 00:00:00 2001 From: Aki <75532970+AkiSakurai@users.noreply.github.com> Date: Tue, 16 Sep 2025 21:59:46 +0800 Subject: [PATCH] Add configurable rename detection threshold Added renameThreshold setting to control git diff rename similarity index. --- package.json | 7 +++++++ src/gitHelper.ts | 5 ++--- src/treeProvider.ts | 7 ++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index b74f844..060526f 100644 --- a/package.json +++ b/package.json @@ -361,6 +361,13 @@ "description": "Whether to detect renames. Does not affect untracked files. May have a performance impact.", "default": true }, + "gitTreeCompare.renameThreshold": { + "type": "number", + "minimum": 0, + "maximum": 100, + "description": "The similarity index (in percent) for rename detection. A value of 100 means that only identical files are detected as renames, a value of 0 means that any file with any similarity is detected as a rename. Has no effect if gitTreeCompare.findRenames is false.", + "default": 50 + }, "gitTreeCompare.openChanges": { "type": "boolean", "description": "When selecting a modified file in the tree, whether to show its changes or just open the workspace file.", diff --git a/src/gitHelper.ts b/src/gitHelper.ts index 0206ab7..eefaaeb 100644 --- a/src/gitHelper.ts +++ b/src/gitHelper.ts @@ -207,7 +207,7 @@ function parseDiffIndexOutput(repoRoot: string, out: string): IDiffStatus[] { return entries; } -export async function diffIndex(repo: Repository, ref: string, refreshIndex: boolean, findRenames: boolean): Promise { +export async function diffIndex(repo: Repository, ref: string, refreshIndex: boolean, findRenames: boolean, renameThreshold: number): Promise { if (refreshIndex) { // avoid superfluous diff entries if files only got touched // (see https://github.com/letmaik/vscode-git-tree-compare/issues/37) @@ -219,8 +219,7 @@ export async function diffIndex(repo: Repository, ref: string, refreshIndex: boo } // exceptions can happen with newly initialized repos without commits, or when git is busy - - const renamesFlag = findRenames ? '--find-renames' : '--no-renames'; + const renamesFlag = findRenames ? `--find-renames=${renameThreshold}%` : '--no-renames'; let diffIndexResult = await repo.exec(['diff-index', '-z', renamesFlag, ref, '--']); let untrackedResult = await repo.exec(['ls-files', '-z', '--others', '--exclude-standard']); diff --git a/src/treeProvider.ts b/src/treeProvider.ts index 74c306a..577c0bf 100644 --- a/src/treeProvider.ts +++ b/src/treeProvider.ts @@ -100,6 +100,7 @@ export class GitTreeCompareProvider implements TreeDataProvider, Dispos private iconsMinimal: boolean; private fullDiff: boolean; private findRenames: boolean; + private renameThreshold: number; private showCollapsed: boolean; private compactFolders: boolean; private showCheckboxes: boolean; @@ -342,6 +343,7 @@ export class GitTreeCompareProvider implements TreeDataProvider, Dispos this.iconsMinimal = config.get('iconsMinimal', false); this.fullDiff = config.get('diffMode') === 'full'; this.findRenames = config.get('findRenames', true); + this.renameThreshold = config.get('renameThreshold', 50); this.showCollapsed = config.get('collapsed', false); this.compactFolders = config.get('compactFolders', false); this.showCheckboxes = config.get('showCheckboxes', false); @@ -507,7 +509,7 @@ export class GitTreeCompareProvider implements TreeDataProvider, Dispos const filesInsideTreeRoot = new Map(); const filesOutsideTreeRoot = new Map(); - const diff = await diffIndex(this.repository!, this.mergeBase, this.refreshIndex, this.findRenames); + const diff = await diffIndex(this.repository!, this.mergeBase, this.refreshIndex, this.findRenames, this.renameThreshold); const untrackedCount = diff.reduce((prev, cur, _) => prev + (cur.status === 'U' ? 1 : 0), 0); this.log(`${diff.length} diff entries (${untrackedCount} untracked)`); @@ -662,6 +664,7 @@ export class GitTreeCompareProvider implements TreeDataProvider, Dispos const oldIconsMinimal = this.iconsMinimal; const oldFullDiff = this.fullDiff; const oldFindRenames = this.findRenames; + const oldRenameThreshold = this.renameThreshold; const oldCompactFolders = this.compactFolders; const oldshowCheckboxes = this.showCheckboxes; this.readConfig(); @@ -673,6 +676,7 @@ export class GitTreeCompareProvider implements TreeDataProvider, Dispos (!oldRefreshIndex && this.refreshIndex) || oldFullDiff != this.fullDiff || oldFindRenames != this.findRenames || + oldRenameThreshold != this.renameThreshold || oldCompactFolders != this.compactFolders || oldshowCheckboxes != this.showCheckboxes) { @@ -687,6 +691,7 @@ export class GitTreeCompareProvider implements TreeDataProvider, Dispos if (oldFullDiff != this.fullDiff || oldFindRenames != this.findRenames || + oldRenameThreshold != this.renameThreshold || oldTreeRoot != this.treeRoot || (!oldAutoRefresh && this.autoRefresh) || (!oldRefreshIndex && this.refreshIndex)) {