Skip to content

feat: patchable init mirroring #1070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

dervoeti
Copy link
Member

@dervoeti dervoeti commented Apr 30, 2025

Fixes #1049

This adds the --mirrored flag to patchable init. It assumes that a mirror repository already exist, pushes the ref specified via --base to the mirror and configures the mirrorer repo as upstream in patchable.toml.
As discussed with @lfrancke, we want to fork the repos in the stackabletech org and use forks instead of clones (the latter decision was not a strong opinion, I decided to go with forks since they would facilitate back-contributions).

I created mirror repositories (forks in our case) for all our products and synced the tags for all versions we use. I updated all patchable.toml files to use the mirror repositories (with the exception of Omid 1.1.3-SNAPSHOT, which is a temporary version we don't ship).

I had to drop the usage of FETCH_HEAD, since it caused problems when running patchable init for a tag/branch that for some reason was already present in the local Git repo. The problem is that FETCH_HEAD is empty in that case, I think that's due to no changes being fetched.

@dervoeti dervoeti requested a review from nightkr April 30, 2025 12:52
@nightkr
Copy link
Member

nightkr commented Apr 30, 2025

As a nomenclature thing, I think I prefer calling this mirroring instead.

@dervoeti
Copy link
Member Author

As a nomenclature thing, I think I prefer calling this mirroring instead.

Had the same thought when opening the PR 🙂 Will refactor it.

@dervoeti dervoeti changed the title feat: patchable init forking feat: patchable init mirroring Apr 30, 2025
@@ -1,2 +1,2 @@
upstream = "https://github.com/apache/druid.git"
upstream = "https://github.com/stackabletech/druid.git"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still want to save the original upstream, maybe add this as a new field called mirror?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, good idea. Done.

tracing::info!(commit = %base_commit_oid, "fetched base commit OID");

// Add fork remote
let temp_fork_remote = "patchable_fork_push";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to use remote_anonymous instead of creating and deleting a dummy remote.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, fixed!

// Check if the reference is a tag or branch by inspecting the git repository
let refspec = {
let tag_ref = format!("refs/tags/{}", base);
let is_tag = product_repo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I half think we should just decide on tags with a common format here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm but we can't really know if the upstream repository uses tags in a specific format (or if it uses tags at all). Zookeeper uses release-3.9.2, Trino 470, trino-storage uses v470, ...
Or do you mean we should re-tag the commit in our mirror?

Comment on lines 482 to 491
// Add progress tracking for push operation
let span_push = tracing::info_span!("pushing");
span_push.pb_set_style(&utils::progress_bar_style());
let _ = span_push.enter();
let mut quant_push = utils::Quantizer::percent();
callbacks.push_transfer_progress(move |current, total, _| {
if total > 0 {
quant_push.update_span_progress(current, total, &span_push);
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably break this stuff out into a utils module.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some refactoring here

Comment on lines 527 to 528
} else {
(repo::resolve_and_fetch_commitish(&product_repo, &base, &upstream).context(FetchBaseCommitSnafu)?, upstream)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initial resolve_and_fetch is still the same, no? The new mirroring stuff is "just" an extra step afterwards.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. Didn't notice this after my last refactoring 🙂 It's simplified now.

@@ -180,7 +180,9 @@ pub fn resolve_and_fetch_commitish(
&[commitish],
Some(
FetchOptions::new()
.update_fetchhead(true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious about the fetchhead issues you ran into, do you have a repro for that? Does that happen with the current main, or only with (the rest of) this PR applied?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly it works with the current main branch. As soon as the line .download_tags(git2::AutotagOption::Auto) is added, it starts breaking. Steps to reproduce:

Add the .download_tags(git2::AutotagOption::Auto) line after .update_fetchhead, then run

cargo patchable init zookeeper 3.9.2 --upstream=https://github.com/apache/zookeeper.git --base=release-3.9.2
rm zookeeper/stackable/patches/3.9.2/patchable.toml
cargo patchable init zookeeper 3.9.2 --upstream=https://github.com/apache/zookeeper.git --base=release-3.9.2

For me, the second command fails with:

Error: failed to fetch patch series' base commit

Caused by these errors (recent errors listed first):
  1: failed to find commit "release-3.9.2" in "/home/voeti/docker-images/zookeeper/patchable-work/product-repo/"
  2: corrupted loose reference file: FETCH_HEAD; class=Reference (4)

I'm not sure why FETCH_HEAD is empty. I'm also not sure why/if download_tags is really required to keep the tag around in patchable-work/product-repo/refs/tags. I tried a few things (disabled pruning) but I couldn't make it work, so I decided to remove the update_fetchhead and just use commitish instead of FETCH_HEAD, which circumvented the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate all mirrored sources from Nexus to GitHub repositories
2 participants