Skip to content

Add subtree filter support and improve round-trip check#38

Merged
Kobzol merged 2 commits intorust-lang:mainfrom
makai410:feat/scope
Mar 26, 2026
Merged

Add subtree filter support and improve round-trip check#38
Kobzol merged 2 commits intorust-lang:mainfrom
makai410:feat/scope

Conversation

@makai410
Copy link
Copy Markdown
Member

@makai410 makai410 commented Mar 20, 2026

Fixes: #37

To explain what the subtree filter is, here's an example with rustc_public:

org = "rust-lang"
repo = "project-stable-mir"
filter = ":/compiler/rustc_public:exclude[:[::build.rs,::tests/,::Cargo.toml]]:prefix=rustc_public"
subtree-filter = ":/rustc_public:exclude[:[::build.rs,::tests/,::Cargo.toml]]:prefix=rustc_public"

The filter is applied to the rust-lang/rust side, while subtree-filter is applied to the rust-lang/project-stable-mir side. Ideally, both should produce the same SHA, confirming a successful round-trip.

For repos doing a 1:1 mirror, subtree-filter should be empty, in that case this PR will not download the josh-filter tool.

And basically, the round-trip check in this PR looks like:

$ git fetch <josh_url with the `filter`> <branch>
# if the `sym-filter` is set
  # install the josh-filter tool
  $ cargo install josh-cli --git https://github.com/josh-project/josh.git
  $ josh-filter "<subtree-filter>" HEAD
  $ git rev-parse FILTERED_HEAD
  $ git rev-parse FETCH_HEAD
  # then compare FILTERED_HEAD and FETCH_HEAD
# else
  $ git rev-parse HEAD
  $ git rev-parse FETCH_HEAD
  # then compare HEAD and FETCH_HEAD

Copy link
Copy Markdown
Member

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

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

We should probably start using the new Josh CLI in josh-sync, I feel like we are reimplementing a lot of stuff in josh-sync that is already there as a single command :) In any case, if this helps your use-case, it seems fine.

I would maybe rename sym-filter to subtree-filter or something, to make it more explicit about what it does, but it doesn't matter much, sym-filter is fine too.

}

pub fn try_install_josh_filter(verbose: bool) -> Option<JoshFilter> {
run_command(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you please pin the version/tag/commit SHA? I don't want josh-sync to install unpinned versions of Josh, we had enough trouble with that in the past.

}
}

pub fn run_command_by_path<'a, Args: AsRef<[&'a str]>>(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why was a new function needed here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's basically a copy-paste of run_command_inner but accepting a PathBuf as the command. But yeah I see that's kind of duplicate, I'm going to fix it.

src/config.rs Outdated
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub post_pull: Vec<PostPullOperation>,
/// Optional symmetry filter applied to the local `HEAD` during round-trip check.
pub sym_filter: Option<String>,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
pub sym_filter: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub sym_filter: Option<String>,

Otherwise the config would fail to be parsed if the field is missing, I think.

@makai410
Copy link
Copy Markdown
Member Author

I would maybe rename sym-filter to subtree-filter or something, to make it more explicit about what it does, but it doesn't matter much, sym-filter is fine too.

Totally, I agree that subtree-filter is way more clear than sym-filter. sym-filter is kind of ambiguous without taking a look at its definition :)

Co-authored-by: Jakub Beránek <berykubik@gmail.com>
@makai410 makai410 changed the title Add symmetry filter support and improve round-trip check Add subtree filter support and improve round-trip check Mar 26, 2026
Copy link
Copy Markdown
Member

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

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

Thanks! Let's hope this doesn't break anything :)

@Kobzol Kobzol merged commit d43bc70 into rust-lang:main Mar 26, 2026
1 check passed
@makai410 makai410 deleted the feat/scope branch March 27, 2026 04:42
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.

More robust round-trip check

2 participants