Skip to content

Commit b6fbf05

Browse files
cruesslerByron
authored andcommitted
feat: replace Head::(try_)peel_to_x_in_place with Head::peel_to_x.
The `_in_place()` suffixed methods are now deprecated.
1 parent e60e253 commit b6fbf05

File tree

7 files changed

+54
-20
lines changed

7 files changed

+54
-20
lines changed

gix/src/clone/checkout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub mod main_worktree {
9898

9999
let root_tree_id = match &self.ref_name {
100100
Some(reference_val) => Some(repo.find_reference(reference_val)?.peel_to_id()?),
101-
None => repo.head()?.try_peel_to_id_in_place()?,
101+
None => repo.head()?.try_peel_to_id()?,
102102
};
103103

104104
let root_tree = match root_tree_id {

gix/src/config/cache/access.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ impl Cache {
349349
if let Ok(mut head) = repo.head() {
350350
let ctx = filters.driver_context_mut();
351351
ctx.ref_name = head.referent_name().map(|name| name.as_bstr().to_owned());
352-
ctx.treeish = head.peel_to_commit_in_place().ok().map(|commit| commit.id);
352+
ctx.treeish = head.peel_to_commit().ok().map(|commit| commit.id);
353353
}
354354
filters
355355
};

gix/src/head/peel.rs

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use crate::{
77
mod error {
88
use crate::{object, reference};
99

10-
/// The error returned by [`Head::peel_to_id_in_place()`](super::Head::try_peel_to_id_in_place())
11-
/// and [`Head::into_fully_peeled_id()`](super::Head::try_into_peeled_id()).
10+
/// The error returned by [`Head::peel_to_id()`](super::Head::try_peel_to_id()) and
11+
/// [`Head::into_fully_peeled_id()`](super::Head::try_into_peeled_id()).
1212
#[derive(Debug, thiserror::Error)]
1313
#[allow(missing_docs)]
1414
pub enum Error {
@@ -42,7 +42,7 @@ pub mod into_id {
4242
pub mod to_commit {
4343
use crate::object;
4444

45-
/// The error returned by [`Head::peel_to_commit_in_place()`](super::Head::peel_to_commit_in_place()).
45+
/// The error returned by [`Head::peel_to_commit()`](super::Head::peel_to_commit()).
4646
#[derive(Debug, thiserror::Error)]
4747
#[allow(missing_docs)]
4848
pub enum Error {
@@ -55,7 +55,7 @@ pub mod to_commit {
5555

5656
///
5757
pub mod to_object {
58-
/// The error returned by [`Head::peel_to_object_in_place()`](super::Head::peel_to_object_in_place()).
58+
/// The error returned by [`Head::peel_to_object()`](super::Head::peel_to_object()).
5959
#[derive(Debug, thiserror::Error)]
6060
#[allow(missing_docs)]
6161
pub enum Error {
@@ -72,7 +72,7 @@ impl<'repo> Head<'repo> {
7272
/// The final target is obtained by following symbolic references and peeling tags to their final destination, which
7373
/// typically is a commit, but can be any object.
7474
pub fn into_peeled_id(mut self) -> Result<crate::Id<'repo>, into_id::Error> {
75-
self.try_peel_to_id_in_place()?;
75+
self.try_peel_to_id()?;
7676
self.id().ok_or_else(|| match self.kind {
7777
Kind::Symbolic(gix_ref::Reference { name, .. }) | Kind::Unborn(name) => into_id::Error::Unborn { name },
7878
Kind::Detached { .. } => unreachable!("id can be returned after peeling"),
@@ -84,7 +84,7 @@ impl<'repo> Head<'repo> {
8484
/// The final target is obtained by following symbolic references and peeling tags to their final destination, which
8585
/// typically is a commit, but can be any object as well.
8686
pub fn into_peeled_object(mut self) -> Result<crate::Object<'repo>, to_object::Error> {
87-
self.peel_to_object_in_place()
87+
self.peel_to_object()
8888
}
8989

9090
/// Consume this instance and transform it into the final object that it points to, or `Ok(None)` if the `HEAD`
@@ -93,7 +93,7 @@ impl<'repo> Head<'repo> {
9393
/// The final target is obtained by following symbolic references and peeling tags to their final destination, which
9494
/// typically is a commit, but can be any object.
9595
pub fn try_into_peeled_id(mut self) -> Result<Option<crate::Id<'repo>>, Error> {
96-
self.try_peel_to_id_in_place()
96+
self.try_peel_to_id()
9797
}
9898

9999
/// Follow the symbolic reference of this head until its target object and peel it by following tag objects until there is no
@@ -103,7 +103,21 @@ impl<'repo> Head<'repo> {
103103
///
104104
/// The final target is obtained by following symbolic references and peeling tags to their final destination, which
105105
/// typically is a commit, but can be any object.
106+
#[deprecated = "Use `try_peel_to_id()` instead"]
106107
pub fn try_peel_to_id_in_place(&mut self) -> Result<Option<crate::Id<'repo>>, Error> {
108+
self.try_peel_to_id()
109+
}
110+
111+
/// Follow the symbolic reference of this head until its target object and peel it by following tag objects until there is no
112+
/// more object to follow, and return that object id.
113+
///
114+
/// Returns `Ok(None)` if the head is unborn.
115+
///
116+
/// The final target is obtained by following symbolic references and peeling tags to their final destination, which
117+
/// typically is a commit, but can be any object.
118+
///
119+
/// Note that this method mutates `self` in place.
120+
pub fn try_peel_to_id(&mut self) -> Result<Option<crate::Id<'repo>>, Error> {
107121
Ok(Some(match &mut self.kind {
108122
Kind::Unborn(_name) => return Ok(None),
109123
Kind::Detached {
@@ -139,12 +153,21 @@ impl<'repo> Head<'repo> {
139153
/// more object to follow, transform the id into a commit if possible and return that.
140154
///
141155
/// Returns an error if the head is unborn or if it doesn't point to a commit.
156+
#[deprecated = "Use `peel_to_object()` instead"]
142157
pub fn peel_to_object_in_place(&mut self) -> Result<crate::Object<'repo>, to_object::Error> {
143-
let id = self
144-
.try_peel_to_id_in_place()?
145-
.ok_or_else(|| to_object::Error::Unborn {
146-
name: self.referent_name().expect("unborn").to_owned(),
147-
})?;
158+
self.peel_to_object()
159+
}
160+
161+
/// Follow the symbolic reference of this head until its target object and peel it by following tag objects until there is no
162+
/// more object to follow, transform the id into a commit if possible and return that.
163+
///
164+
/// Returns an error if the head is unborn or if it doesn't point to a commit.
165+
///
166+
/// Note that this method mutates `self` in place.
167+
pub fn peel_to_object(&mut self) -> Result<crate::Object<'repo>, to_object::Error> {
168+
let id = self.try_peel_to_id()?.ok_or_else(|| to_object::Error::Unborn {
169+
name: self.referent_name().expect("unborn").to_owned(),
170+
})?;
148171
id.object()
149172
.map_err(|err| to_object::Error::Peel(Error::FindExistingObject(err)))
150173
}
@@ -153,7 +176,18 @@ impl<'repo> Head<'repo> {
153176
/// more object to follow, transform the id into a commit if possible and return that.
154177
///
155178
/// Returns an error if the head is unborn or if it doesn't point to a commit.
179+
#[deprecated = "Use `peel_to_commit()` instead"]
156180
pub fn peel_to_commit_in_place(&mut self) -> Result<crate::Commit<'repo>, to_commit::Error> {
157-
Ok(self.peel_to_object_in_place()?.try_into_commit()?)
181+
self.peel_to_commit()
182+
}
183+
184+
/// Follow the symbolic reference of this head until its target object and peel it by following tag objects until there is no
185+
/// more object to follow, transform the id into a commit if possible and return that.
186+
///
187+
/// Returns an error if the head is unborn or if it doesn't point to a commit.
188+
///
189+
/// Note that this method mutates `self` in place.
190+
pub fn peel_to_commit(&mut self) -> Result<crate::Commit<'repo>, to_commit::Error> {
191+
Ok(self.peel_to_object()?.try_into_commit()?)
158192
}
159193
}

gix/src/repository/mailmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl crate::Repository {
3636
None => {
3737
blob_id = blob_id.or_else(|| {
3838
self.head().ok().and_then(|mut head| {
39-
let commit = head.peel_to_commit_in_place().ok()?;
39+
let commit = head.peel_to_commit().ok()?;
4040
let tree = commit.tree().ok()?;
4141
tree.find_entry(".mailmap").map(|e| e.object_id())
4242
})

gix/src/repository/reference.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl crate::Repository {
214214
/// is freshly initialized and doesn't have any commits yet. It could also fail if the
215215
/// head does not point to a commit.
216216
pub fn head_commit(&self) -> Result<crate::Commit<'_>, reference::head_commit::Error> {
217-
Ok(self.head()?.peel_to_commit_in_place()?)
217+
Ok(self.head()?.peel_to_commit()?)
218218
}
219219

220220
/// Return the tree id the `HEAD` reference currently points to after peeling it fully,

gix/src/repository/submodule.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl Repository {
5555
Some(id) => id,
5656
None => match self
5757
.head()?
58-
.try_peel_to_id_in_place()?
58+
.try_peel_to_id()?
5959
.map(|id| -> Result<Option<_>, submodule::modules::Error> {
6060
Ok(id
6161
.object()?

gix/tests/gix/head.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ mod peel {
1414
assert_eq!(repo.head_tree_id()?, commit.tree_id()?);
1515
assert_eq!(repo.head_tree_id_or_empty()?, commit.tree_id()?);
1616
assert_eq!(repo.head()?.try_into_peeled_id()?.expect("born"), expected_commit);
17-
assert_eq!(repo.head()?.peel_to_object_in_place()?.id, expected_commit);
18-
assert_eq!(repo.head()?.try_peel_to_id_in_place()?.expect("born"), expected_commit);
17+
assert_eq!(repo.head()?.peel_to_object()?.id, expected_commit);
18+
assert_eq!(repo.head()?.try_peel_to_id()?.expect("born"), expected_commit);
1919
}
2020
Ok(())
2121
}

0 commit comments

Comments
 (0)