Skip to content

Commit 8345155

Browse files
committed
refactor: use peel_to_commit
gix 0.66 added peel_to_commit(), which is now used to simplify several reference to commit function call chains.
1 parent 0dbe8f6 commit 8345155

File tree

6 files changed

+13
-28
lines changed

6 files changed

+13
-28
lines changed

src/cmd/branch/rename.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ pub(super) fn dispatch(repo: &gix::Repository, matches: &clap::ArgMatches) -> Re
6060
let state_commit = repo
6161
.find_reference(stack.get_stack_refname())
6262
.expect("just found this stack state reference")
63-
.into_fully_peeled_id()?
64-
.object()?
65-
.try_into_commit()?;
63+
.peel_to_commit()?;
6664
repo.edit_reference(gix::refs::transaction::RefEdit {
6765
change: gix::refs::transaction::Change::Update {
6866
log: gix::refs::transaction::LogChange {

src/cmd/log.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,11 @@ fn run(matches: &ArgMatches) -> Result<()> {
115115
let simplified_parent_id = stack
116116
.repo
117117
.find_reference(stack.get_stack_refname())?
118-
.into_fully_peeled_id()?
119-
.object()?
120-
.to_commit_ref()
121-
.parents()
118+
.peel_to_commit()?
119+
.parent_ids()
122120
.next()
123-
.ok_or_else(|| anyhow!("`{}` does not have any parents", stack.get_stack_refname()))?;
121+
.ok_or_else(|| anyhow!("`{}` does not have any parents", stack.get_stack_refname()))?
122+
.detach();
124123

125124
let stupid = repo.stupid();
126125

src/cmd/pull.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,10 @@ fn run(matches: &ArgMatches) -> Result<()> {
194194
let remote_name = remote_name.unwrap();
195195
print_info_message(matches, &format!("Fetching from `{remote_name}`"));
196196
stupid.user_fetch(&fetch_cmd, &remote_name)?;
197-
let fetch_head = repo
197+
let target_id = repo
198198
.find_reference("FETCH_HEAD")
199-
.context("finding `FETCH_HEAD`")?;
200-
let target_id = fetch_head
201-
.into_fully_peeled_id()
202-
.map_err(anyhow::Error::from)
203-
.and_then(|id| id.object().map_err(anyhow::Error::from))
204-
.and_then(|object| object.peel_tags_to_end().map_err(anyhow::Error::from))
205-
.and_then(|object| object.try_into_commit().map_err(anyhow::Error::from))
199+
.context("finding `FETCH_HEAD`")?
200+
.peel_to_commit()
206201
.context("peeling `FETCH_HEAD` to commit")?
207202
.id;
208203
Some(target_id)

src/cmd/undo.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ pub(super) fn find_undo_state<'repo>(
8383
stack
8484
.repo
8585
.find_reference(stack.get_stack_refname())?
86-
.into_fully_peeled_id()?
87-
.object()?
88-
.peel_tags_to_end()?
89-
.try_into_commit()?,
86+
.peel_to_commit()?,
9087
);
9188
loop {
9289
let state = StackState::from_commit(stack.repo, &state_commit)?;

src/stack/stack.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,7 @@ impl<'repo> Stack<'repo> {
309309
let prev_state_commit = self
310310
.repo
311311
.find_reference(&self.stack_refname)?
312-
.into_fully_peeled_id()?
313-
.object()?
314-
.try_into_commit()?;
312+
.peel_to_commit()?;
315313
let prev_state_commit_id = prev_state_commit.id;
316314
let state = self
317315
.state

src/stack/transaction/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,10 @@ impl<'repo> ExecuteContext<'repo> {
213213
} else {
214214
reflog_msg
215215
};
216-
let stack_ref = repo.find_reference(stack.get_stack_refname())?;
217216
let branch_ref_name = stack.get_branch_refname().to_owned();
218-
let prev_state_commit = stack_ref
219-
.into_fully_peeled_id()?
220-
.object()?
221-
.try_into_commit()?;
217+
let prev_state_commit = repo
218+
.find_reference(stack.get_stack_refname())?
219+
.peel_to_commit()?;
222220
let state = stack.state_mut();
223221
for (patchname, maybe_patch) in &updated_patches {
224222
if let Some(patch) = maybe_patch {

0 commit comments

Comments
 (0)