diff --git a/josh-core/src/history.rs b/josh-core/src/history.rs index 7ca8b5d9..c15f23c8 100644 --- a/josh-core/src/history.rs +++ b/josh-core/src/history.rs @@ -247,6 +247,7 @@ fn find_new_branch_base( filter: filter::Filter, contained_in: git2::Oid, filtered: git2::Oid, + base_on_oldest: bool, ) -> JoshResult { let walk = { let mut walk = transaction.repo().revwalk()?; @@ -261,12 +262,15 @@ fn find_new_branch_base( if let Ok(base) = find_unapply_base(transaction, bm, filter, contained_in, rev) { if base != git2::Oid::zero() { tracing::info!("new branch base: {:?} mapping to {:?}", base, rev); - let base = + let base = if base_on_oldest { if let Ok(new_base) = find_oldest_similar_commit(transaction, filter, base) { new_base } else { base - }; + } + } else { + base + }; tracing::info!("inserting in bm {}, {}", rev, base); bm.insert(rev, base); return Ok(rev); @@ -287,12 +291,20 @@ pub fn unapply_filter( keep_orphans: bool, reparent_orphans: Option, change_ids: &mut Option>, + base_on_oldest: bool, ) -> JoshResult { let mut bm = HashMap::new(); let mut ret = original_target; let old = if old == git2::Oid::zero() { - match find_new_branch_base(transaction, &mut bm, filterobj, original_target, new) { + match find_new_branch_base( + transaction, + &mut bm, + filterobj, + original_target, + new, + base_on_oldest, + ) { Ok(res) => { tracing::info!("No error, branch base {} ", res); res diff --git a/josh-filter/src/bin/josh-filter.rs b/josh-filter/src/bin/josh-filter.rs index 9f6622ef..58f143c9 100644 --- a/josh-filter/src/bin/josh-filter.rs +++ b/josh-filter/src/bin/josh-filter.rs @@ -371,6 +371,7 @@ fn run_filter(args: Vec) -> josh::JoshResult { false, None, &mut None, + true, ) { Ok(rewritten) => { repo.reference(&input_ref, rewritten, true, "unapply_filter")?; diff --git a/josh-proxy/src/lib.rs b/josh-proxy/src/lib.rs index 029c9258..e174efab 100644 --- a/josh-proxy/src/lib.rs +++ b/josh-proxy/src/lib.rs @@ -228,6 +228,7 @@ pub fn process_repo_update(repo_update: RepoUpdate) -> josh::JoshResult josh_merge, reparent_orphans, &mut changes, + true, )? };