Skip to content

Commit 3e9ea02

Browse files
committed
Avoid potentially expensive fetching of tags
Right now, there is no problem: GitGitGadget uses a couple of Azure Pipelines that all run on the same, single runner inside a dedicated pool, and this runner has a persistent clone of the `gitgitgadget/git` repository. However, my current plan is to migrate to GitHub Actions, away from that self-hosted runner, which means that there is no persistent clone to work with. Therefore, a local Git repository has to be initialized in every workflow run, and to make that efficient (and fast!), only the minimal set of refs is fetched. That idea works only when preventing Git from _implicitly_ fetching all tags, so let's do that. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 30643c3 commit 3e9ea02

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

lib/ci-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ export class CIHelper {
524524
const prKey = getPullRequestKeyFromURL(prMeta.pullRequestURL);
525525
const fetchURL = `https://github.com/${prKey.owner}/${prKey.repo}`;
526526
const fetchRef = `refs/pull/${prKey.pull_number}/head`;
527-
await git(["fetch", fetchURL, fetchRef, prMeta.latestTag], {
527+
await git(["fetch", "--no-tags", fetchURL, fetchRef, prMeta.latestTag], {
528528
workDir: this.workDir,
529529
});
530530
}

lib/git-notes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class GitNotes {
3939
// wait a while before trying again to push (after fetching the remote notes ref and merging it)
4040
await sleep(backoff);
4141

42-
const output = await git(["fetch", "--porcelain", url, "--", `${this.notesRef}`], {
42+
const output = await git(["fetch", "--porcelain", "--no-tags", url, "--", `${this.notesRef}`], {
4343
workDir: this.workDir,
4444
});
4545
// parse the output to obtain the OID of the remote notes ref
@@ -122,7 +122,7 @@ export class GitNotes {
122122

123123
public async update(url: string): Promise<void> {
124124
if (this.notesRef.match(/^refs\/notes\/(gitgitgadget|commit-to-mail|mail-to-commit)$/)) {
125-
await git(["fetch", url, `+${this.notesRef}:${this.notesRef}`], { workDir: this.workDir });
125+
await git(["fetch", "--no-tags", url, `+${this.notesRef}:${this.notesRef}`], { workDir: this.workDir });
126126
} else {
127127
throw new Error(`Don't know how to update ${this.notesRef}`);
128128
}

lib/gitgitgadget.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ export class GitGitGadget {
5959

6060
// Always fetch the Git notes first thing
6161
await git(
62-
["fetch", publishTagsAndNotesToRemote, "--", `+${GitNotes.defaultNotesRef}:${GitNotes.defaultNotesRef}`],
62+
[
63+
"fetch",
64+
"--no-tags",
65+
publishTagsAndNotesToRemote,
66+
"--",
67+
`+${GitNotes.defaultNotesRef}:${GitNotes.defaultNotesRef}`,
68+
],
6369
{ workDir },
6470
);
6571

@@ -215,6 +221,7 @@ export class GitGitGadget {
215221
const pullRequestMerge = `refs/pull/${pullRequestNumber}/merge`;
216222
const args = [
217223
"fetch",
224+
"--no-tags",
218225
this.publishTagsAndNotesToRemote,
219226
"--",
220227
`+${this.notes.notesRef}:${this.notes.notesRef}`,
@@ -233,9 +240,12 @@ export class GitGitGadget {
233240
if (repositoryOwner === this.config.repo.owner) {
234241
args.push(...prArgs);
235242
} else {
236-
await git(["fetch", `https://github.com/${repositoryOwner}/${this.config.repo.name}`, ...prArgs], {
237-
workDir: this.workDir,
238-
});
243+
await git(
244+
["fetch", "--no-tags", `https://github.com/${repositoryOwner}/${this.config.repo.name}`, ...prArgs],
245+
{
246+
workDir: this.workDir,
247+
},
248+
);
239249
}
240250
await git(args, { workDir: this.workDir });
241251

@@ -249,6 +259,7 @@ export class GitGitGadget {
249259
await git(
250260
[
251261
"fetch",
262+
"--no-tags",
252263
this.publishTagsAndNotesToRemote,
253264
"--",
254265
`+${GitNotes.defaultNotesRef}:${GitNotes.defaultNotesRef}`,

lib/mail-commit-mapping.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,17 @@ export class MailCommitMapping {
4343
}
4444
if (refs.length) {
4545
console.log(`Updating mail-to-commit/refs: ${refs.join(", ")}`);
46-
await git(["fetch", `https://github.com/${this.config.repo.owner}/${this.config.repo.name}`, ...refs], {
47-
workDir: this.workDir,
48-
});
46+
await git(
47+
[
48+
"fetch",
49+
"--no-tags",
50+
`https://github.com/${this.config.repo.owner}/${this.config.repo.name}`,
51+
...refs,
52+
],
53+
{
54+
workDir: this.workDir,
55+
},
56+
);
4957
}
5058
}
5159
}

0 commit comments

Comments
 (0)