Skip to content

Commit ffae725

Browse files
committed
Document how to rebase patch series
1 parent 2a75edd commit ffae725

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Many products apply Stackable-specific patches, managed by [Patchable](rust/patc
6464
This is not required for building the images, but is useful when debugging or hacking on our patch sets.
6565

6666
```sh
67-
cargo patchable checkout druid 26.0.0
67+
cd $(cargo patchable checkout druid 26.0.0)
6868
```
6969

7070
### Save patched sources
@@ -73,6 +73,33 @@ cargo patchable checkout druid 26.0.0
7373
cargo patchable export druid 26.0.0
7474
```
7575

76+
### Porting patch series to a new version
77+
78+
Patchable doesn't support restoring a patch series that doesn't apply cleanly. Instead, use `git cherry-pick` to rebase the patch series.
79+
80+
For example, let's try rebasing our patch series from Druid 26.0.0 to Druid 28.0.0 (which is not packaged by SDP):
81+
82+
```sh
83+
# Restore the old version
84+
# In addition to creating the version worktree, this also creates the branches patchable/26.0.0 (26.0.0 with our patches applied) and
85+
# patchable/base/26.0.0 (upstream 26.0.0 with no patches).
86+
cargo patchable checkout druid 26.0.0
87+
# Tell Patchable about the new version 28.0.0, which can be fetched from https://github.com/apache/druid.git, and has the tag druid-28.0.0
88+
cargo patchable init druid 28.0.0 --upstream https://github.com/apache/druid.git --base druid-28.0.0
89+
# Create and go to the worktree for the new version
90+
pushd $(cargo patchable checkout druid 28.0.0)
91+
92+
# Rebase the patch series
93+
git cherry-pick patchable/base/26.0.0..patchable/26.0.0
94+
# Solve conflicts and `git cherry-pick --continue` until done
95+
# You can also use `git cherry-pick --skip` to skip patches that are no longer required
96+
97+
# Leave and export the new patch series!
98+
popd
99+
cargo patchable export druid 28.0.0
100+
git status
101+
```
102+
76103
## Verify Product Images
77104

78105
To verify if Apache Zookeeper validate against OpenShift preflight, run:

rust/patchable/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ to be an individual patch.
1212
## Usage
1313

1414
```sh
15-
cargo patchable checkout druid 26.0.0
16-
pushd $(git rev-parse --show-toplevel)/druid/patchable-work/worktree/26.0.0/
15+
pushd $(cargo patchable checkout druid 26.0.0)
1716
# do stuff
1817
git commit
1918
popd

rust/patchable/src/main.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ impl ProductVersionContext<'_> {
7676
self.work_root().join("worktree").join(&self.pv.version)
7777
}
7878

79+
fn base_branch(&self) -> String {
80+
format!("patchable/base/{}", self.pv.version)
81+
}
82+
7983
fn worktree_branch(&self) -> String {
8084
format!("patchable/{}", self.pv.version)
8185
}
@@ -245,21 +249,47 @@ fn main() -> Result<()> {
245249
&config.upstream,
246250
)
247251
.context(FetchBaseCommitSnafu)?;
252+
let base_branch = ctx.base_branch();
253+
let base_branch = match product_repo
254+
.find_commit(base_commit)
255+
.and_then(|base| product_repo.branch(&base_branch, &base, true))
256+
{
257+
Ok(_) => {
258+
tracing::info!(
259+
branch.base = base_branch,
260+
branch.base.commit = %base_commit,
261+
"updated base branch"
262+
);
263+
Some(base_branch)
264+
}
265+
Err(err) => {
266+
tracing::warn!(
267+
error = &err as &dyn std::error::Error,
268+
branch.base = base_branch,
269+
branch.base.commit = %base_commit,
270+
"failed to update base branch reference, ignoring..."
271+
);
272+
None
273+
}
274+
};
248275
let patched_commit = patch::apply_patches(&product_repo, &ctx.patch_dir(), base_commit)
249276
.context(ApplyPatchesSnafu)?;
250277

251278
let product_worktree_root = ctx.worktree_root();
279+
let worktree_branch = ctx.worktree_branch();
252280
repo::ensure_worktree_is_at(
253281
&product_repo,
254282
&ctx.pv.version,
255283
&product_worktree_root,
256-
&ctx.worktree_branch(),
284+
&worktree_branch,
257285
patched_commit,
258286
)
259287
.context(CheckoutProductWorktreeSnafu)?;
260288

261289
tracing::info!(
262290
worktree.root = ?product_worktree_root,
291+
branch.worktree = worktree_branch,
292+
branch.base = base_branch,
263293
"worktree is ready!"
264294
);
265295

0 commit comments

Comments
 (0)