Skip to content

Commit 0339122

Browse files
committed
CIHelper: offer to pre-populate the upstream branches
GitGitGadget's code has auto-magic logic to fetch those, but even in a partial clone that would result in a ~100MB fetch. Maybe that's okay, and I worry too much about bandwidth? Inside hosted Actions runners, download speeds of ~30MB/sec are not unheard of, after all... But then, I do think that too few people are careful to waste less resources than is ethical, so I want to be mindful. Note that we use a "funny" `--filter=blob:limit=1g` option here instead of the more natural `--no-filter`: Git introduced a subtle bug (that I have no time nor patience to pursue any further) in v2.48.0-rc0~58^2 (index-pack: repack local links into promisor packs, 2024-11-01) that would occasionally result in this strange error when fetching in the partial clone after an occasional `--no-filter` fetch: git -C git.git fetch upstream remote: Enumerating objects: 2, done. remote: Counting objects: 100% (2/2), done. remote: Compressing objects: 100% (2/2), done. remote: Total 2 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0) Receiving objects: 100% (2/2), 14.66 KiB | 7.33 MiB/s, done. BUG: builtin/pack-objects.c:4320: should_include_obj should only be called on existing objects error: pack-objects died of signal 6 fatal: could not finish pack-objects to repack local links fatal: index-pack failed The most likely reason is that the logic needs to improved to accommodate for situations where commits are fetched into a non-promisor pack as part of fetch that notices that some of the commits reachable from that pack are present locally (but they are in promisor packs, which the naïve `pack-objects` call fails to anticipate). But again, I do not have time to pursue this any further. Keeping out non-promisor packs avoids the bug, and that's that. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 90989ff commit 0339122

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

lib/ci-helper.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ export class CIHelper {
6767
this.urlRepo = `${this.urlBase}${this.config.repo.name}/`;
6868
}
6969

70-
public async setupGitHubAction(setupOptions?: { needsMailingListMirror?: boolean }): Promise<void> {
70+
public async setupGitHubAction(setupOptions?: {
71+
needsMailingListMirror?: boolean;
72+
needsUpstreamBranches?: boolean;
73+
}): Promise<void> {
7174
// help dugite realize where `git` is...
7275
const gitExecutable = os.type() === "Windows_NT" ? "git.exe" : "git";
7376
const stripSuffix = `bin${path.sep}${gitExecutable}`;
@@ -123,6 +126,9 @@ export class CIHelper {
123126
["remote.origin.url", `https://github.com/${this.config.repo.owner}/${this.config.repo.name}`],
124127
["remote.origin.promisor", "true"],
125128
["remote.origin.partialCloneFilter", "blob:none"],
129+
["remote.upstream.url", `https://github.com/${this.config.repo.baseOwner}/${this.config.repo.name}`],
130+
["remote.upstream.promisor", "true"],
131+
["remote.upstream.partialCloneFilter", "blob:none"],
126132
]) {
127133
await git(["config", key, value], { workDir: this.workDir });
128134
}
@@ -142,6 +148,41 @@ export class CIHelper {
142148
);
143149
console.timeEnd("fetch Git notes");
144150
this.gggNotesUpdated = true;
151+
if (setupOptions?.needsUpstreamBranches) {
152+
console.time("fetch upstream branches");
153+
await git(
154+
[
155+
"fetch",
156+
"origin",
157+
"--no-tags",
158+
"--depth=500",
159+
"--filter=blob:limit=1g",
160+
...this.config.repo.trackingBranches.map(
161+
(name) => `+refs/heads/${name}:refs/remotes/upstream/${name}`,
162+
),
163+
],
164+
{
165+
workDir: this.workDir,
166+
},
167+
);
168+
console.timeEnd("fetch upstream branches");
169+
console.time("get open PR head commits");
170+
const openPRCommits = (
171+
await Promise.all(
172+
this.config.repo.owners.map(async (repositoryOwner) => {
173+
return await this.github.getOpenPRs(repositoryOwner);
174+
}),
175+
)
176+
)
177+
.flat()
178+
.map((pr) => pr.headCommit);
179+
console.timeEnd("get open PR head commits");
180+
console.time("fetch open PR head commits");
181+
await git(["fetch", "--no-tags", "origin", "--filter=blob:limit=1g", ...openPRCommits], {
182+
workDir: this.workDir,
183+
});
184+
console.timeEnd("fetch open PR head commits");
185+
}
145186
// "Unshallow" the refs by fetching the shallow commits with a tree-less filter.
146187
// This is needed because Git will otherwise fall over left and right when trying
147188
// to determine merge bases with really old branches.

0 commit comments

Comments
 (0)