From 55c75da16f700a897ab3b928d92988d35ff2b679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85smund=20Grammeltvedt?= Date: Fri, 6 May 2022 09:11:04 +0200 Subject: [PATCH 1/2] feat: Support limited search for added file If we know that a file was added in a range of commits (typically something like origin/main..HEAD), we don't need to search the entire repo history for the file. This can yield significant speedups in large repos. --- src/git.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/git.ts b/src/git.ts index 58758143..962b046d 100644 --- a/src/git.ts +++ b/src/git.ts @@ -264,8 +264,9 @@ export function getCurrentHash(cwd: string) { /** * Get the commit hash in which the file was first added. */ -export function getFileAddedHash(filename: string, cwd: string) { - const results = git(["rev-list", "HEAD", filename], { cwd }); +export function getFileAddedHash(filename: string, cwd: string, fromRef?: string, toRef?: string) { + const ref = fromRef && toRef ? `${fromRef}..${toRef}` : "HEAD"; + const results = git(["rev-list", ref, filename], { cwd }); if (results.success) { return results.stdout.trim().split("\n").slice(-1)[0]; From 74f1259214bac5032672b93030da6f3aa609ee10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85smund=20Grammeltvedt?= Date: Fri, 6 May 2022 09:14:39 +0200 Subject: [PATCH 2/2] Change files --- ...2022-05-06-09-14-39-asmundg-limit-rev-list-search.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 change/workspace-tools-2022-05-06-09-14-39-asmundg-limit-rev-list-search.json diff --git a/change/workspace-tools-2022-05-06-09-14-39-asmundg-limit-rev-list-search.json b/change/workspace-tools-2022-05-06-09-14-39-asmundg-limit-rev-list-search.json new file mode 100644 index 00000000..495f06a7 --- /dev/null +++ b/change/workspace-tools-2022-05-06-09-14-39-asmundg-limit-rev-list-search.json @@ -0,0 +1,8 @@ +{ + "type": "minor", + "comment": "feat: Support limited search for added file", + "packageName": "workspace-tools", + "email": "asgramme@microsoft.com", + "dependentChangeType": "patch", + "date": "2022-05-06T07:14:39.673Z" +}