-
-
Notifications
You must be signed in to change notification settings - Fork 102
feat(move): implement move --reparent like amend --reparent #1631
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
b1e6810
0230f10
432fd2e
5d06c5c
7b9bc96
51dcbed
b289875
d3fa892
61ff4c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ use std::ops::Sub; | |
| use std::path::PathBuf; | ||
| use std::sync::Arc; | ||
|
|
||
| use bstr::ByteSlice; | ||
| use chashmap::CHashMap; | ||
| use eyre::Context; | ||
| use itertools::Itertools; | ||
|
|
@@ -1077,6 +1078,45 @@ impl<'a> RebasePlanBuilder<'a> { | |
| Ok(()) | ||
| } | ||
|
|
||
| /// Generate a sequence of rebase steps that cause the subtree at `source_oid` | ||
| /// to be "reparented" by `dest_oids`, namely, keeping all contents | ||
| /// of descendant commits exactly the same. | ||
| pub fn reparent_subtree( | ||
| &mut self, | ||
| source_oid: NonZeroOid, | ||
| parent_oids: Vec<NonZeroOid>, | ||
| repo: &Repo, | ||
| ) -> eyre::Result<()> { | ||
| assert!(!parent_oids.is_empty()); | ||
claytonrcarter marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // To keep the contents of all descendant commits the same, forcibly | ||
| // replace the children commits, and then rely on normal patch | ||
| // application to apply the rest. | ||
| let parents: Vec<_> = parent_oids | ||
| .into_iter() | ||
| .map(|parent_oid| repo.find_commit_or_fail(parent_oid)) | ||
| .try_collect()?; | ||
| let descendant_commit = repo.find_commit_or_fail(source_oid)?; | ||
| let descendant_message = descendant_commit.get_message_raw(); | ||
| let descendant_message = descendant_message.to_str().with_context(|| { | ||
| eyre::eyre!( | ||
| "Could not decode commit message for descendant commit: {:?}", | ||
| descendant_commit | ||
| ) | ||
| })?; | ||
| let reparented_descendant_oid = repo.create_commit( | ||
| None, | ||
| &descendant_commit.get_author(), | ||
| &descendant_commit.get_committer(), | ||
| descendant_message, | ||
| &descendant_commit.get_tree()?, | ||
| parents.iter().collect(), | ||
| )?; | ||
| self.replace_commit(source_oid, reparented_descendant_oid)?; | ||
|
Comment on lines
+1103
to
+1119
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick (subjective)] I think that these |
||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| /// Instruct the rebase planner to replace the commit at `original_oid` with the commit at | ||
| /// `replacement_oid`. | ||
| pub fn replace_commit( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[please clarify] Please correct me if I'm wrong, but I don't think that this comment nor the fn name match the actual behavior:
dest_oids"probably should be "ontoparent_oids`".self.replace_commit()also trigger a rebase of the original commit's descendants onto the replacement commit? Or does it just do a replacement w/o rebase, leaving the descendants remaining on the original commit? ? The comment forreplace_commit()doesn't mention anything about subtrees, which leads me to believe that this fn is also not actually triggering a rebase, but I don't know.replace_commit()does trigger a rebase, then we just need to address that first typo; the it doesn't rebase, then we should rewrite the comment and fn name to matchedit: I think I've confirmed that
replace_commitdoes not also trigger a rebase of descendants, but I would love your 2nd opinion!