History

Merge branch 'git-ref-refactor'

Sebastian Thiel committed 5 years ago

Commit 5dbf7532 parents 09a777f 679895c57 files · +556 −561Browse files

Unified · Split

57 files
  1. Cargo.lock +1 −1
  2. cargo-smart-release/src/command/release/git.rs +2 −5
  3. experiments/diffing/src/main.rs +1 −1
  4. experiments/traversal/src/main.rs +1 −1
  5. git-actor/Cargo.toml +1 −1
  6. git-actor/src/lib.rs +0 −2
  7. git-actor/src/signature/decode.rs +2 −5
  8. git-actor/src/signature/mod.rs +17 −0
  9. git-actor/src/signature_ref/mod.rs +0 −14
  10. git-object/Cargo.toml +1 −1
  11. git-object/src/immutable/parse.rs +1 −1
  12. git-object/src/types.rs +1 −1
  13. git-ref/Cargo.toml +1 −1
  14. git-ref/src/fullname.rs +71 −0
  15. git-ref/src/lib.rs +22 −6
  16. git-ref/src/mutable.rs +0 −162
  17. git-ref/src/name.rs +19 −19
  18. git-ref/src/namespace.rs +2 −2
  19. git-ref/src/store/file/find.rs +19 −16
  20. git-ref/src/store/file/log/iter.rs +6 −5
  21. git-ref/src/store/file/log/line.rs +71 −9
  22. git-ref/src/store/file/log/mod.rs +22 −86
  23. git-ref/src/store/file/loose/iter.rs +1 −1
  24. git-ref/src/store/file/loose/mod.rs +3 −3
  25. git-ref/src/store/file/loose/reference/decode.rs +8 −10
  26. git-ref/src/store/file/loose/reference/logiter.rs +4 −4
  27. git-ref/src/store/file/loose/reference/peel.rs +2 −2
  28. git-ref/src/store/file/loose/reflog.rs +8 −8
  29. git-ref/src/store/file/loose/reflog/create_or_update/tests.rs +6 −6
  30. git-ref/src/store/file/overlay.rs +1 −1
  31. git-ref/src/store/file/reference.rs +12 −13
  32. git-ref/src/store/file/transaction/commit.rs +2 −2
  33. git-ref/src/store/file/transaction/prepare.rs +6 −6
  34. git-ref/src/store/packed/decode.rs +1 −1
  35. git-ref/src/store/packed/decode/tests.rs +3 −3
  36. git-ref/src/store/packed/find.rs +6 −6
  37. git-ref/src/store/packed/mod.rs +2 −2
  38. git-ref/src/store/packed/transaction.rs +2 −4
  39. git-ref/src/target.rs +83 −8
  40. git-ref/src/transaction.rs +7 −7
  41. git-ref/tests/file/log.rs +5 −5
  42. git-ref/tests/file/reference.rs +16 −16
  43. git-ref/tests/file/store/find.rs +6 −6
  44. git-ref/tests/file/store/iter.rs +2 −2
  45. git-ref/tests/file/transaction/mod.rs +6 −5
  46. git-ref/tests/file/transaction/prepare_and_commit/create_or_update.rs +27 −28
  47. git-ref/tests/file/transaction/prepare_and_commit/delete.rs +31 −29
  48. git-ref/tests/packed/find.rs +25 −21
  49. git-ref/tests/packed/open.rs +1 −1
  50. git-ref/tests/transaction/mod.rs +5 −7
  51. git-repository/Cargo.toml +1 −1
  52. git-repository/src/easy/ext/reference.rs +4 −5
  53. git-repository/src/easy/reference.rs +5 −5
  54. git-repository/src/path/is_git.rs +1 −1
  55. git-repository/tests/reference/mod.rs +1 −1
  56. gitoxide-core/src/hours.rs +1 −1
  57. gitoxide-core/src/pack/create.rs +1 −1
Cargo.lock+1−1
@@ -985,7 +985,7 @@ dependencies = [ · 984 unmodified lines
985985
986986 [[package]]
987987 name = "git-actor"
988−version = "0.4.0"
988+version = "0.5.0"
989989 dependencies = [
990990 "bstr",
991991 "btoi",
cargo-smart-release/src/command/release/git.rs+2−5
@@ -141,7 +141,7 @@ pub(in crate::command::release_impl) fn create_version_tag<'repo>( · 140 unmodified lines
141141 skip_tag,
142142 ..
143143 }: Options,
144−) -> anyhow::Result<Option<refs::mutable::FullName>> {
144+) -> anyhow::Result<Option<refs::FullName>> {
145145 if skip_tag {
146146 return Ok(None);
147147 }
@@ -170,10 +170,7 @@ pub(in crate::command::release_impl) fn create_version_tag<'repo>( · 22 unmodified lines
170170 }
171171
172172 // TODO: Make this gitoxide
173−pub fn push_tags_and_head(
174− tag_names: impl IntoIterator<Item = refs::mutable::FullName>,
175− options: Options,
176−) -> anyhow::Result<()> {
173+pub fn push_tags_and_head(tag_names: impl IntoIterator<Item = refs::FullName>, options: Options) -> anyhow::Result<()> {
177174 if options.skip_push {
178175 return Ok(());
179176 }
experiments/diffing/src/main.rs+1−1
@@ -32,7 +32,7 @@ fn main() -> anyhow::Result<()> { · 31 unmodified lines
3232 let packed = repo.refs.packed_buffer()?;
3333 let commit_id = repo
3434 .refs
35− .find_existing(&name, packed.as_ref())?
35+ .find(&name, packed.as_ref())?
3636 .peel_to_id_in_place(&repo.refs, packed.as_ref(), peel::none)?
3737 .to_owned();
3838 let db = &repo.odb;
experiments/traversal/src/main.rs+1−1
@@ -28,7 +28,7 @@ fn main() -> anyhow::Result<()> { · 27 unmodified lines
2828 let packed = repo.refs.packed_buffer()?;
2929 let commit_id = repo
3030 .refs
31− .find_existing(&name, packed.as_ref())?
31+ .find(&name, packed.as_ref())?
3232 .peel_to_id_in_place(&repo.refs, packed.as_ref(), peel::none)?
3333 .to_owned();
3434 (repo, commit_id)
git-actor/Cargo.toml+1−1
@@ -1,6 +1,6 @@
11 [package]
22 name = "git-actor"
3−version = "0.4.0"
3+version = "0.5.0"
44 description = "A way to identify git actors"
55 authors = ["Sebastian Thiel <sebastian.thiel@icloud.com>"]
66 repository = "https://github.com/Byron/gitoxide"
git-actor/src/lib.rs+0−2
@@ -5,8 +5,6 @@ use bstr::{BStr, BString}; · 4 unmodified lines
55
66 ///
77 pub mod signature;
8−///
9−pub mod signature_ref;
108
119 const SPACE: &[u8; 1] = b" ";
1210
git-actor/src/signature/decode.rsrenamed from git-actor/src/signature_ref/decode.rs+2−5
@@ -68,13 +68,10 @@ mod tests { · 67 unmodified lines
6868 use git_testtools::to_bstr_err;
6969 use nom::IResult;
7070
71− use crate::{
72− signature_ref::{self, SignatureRef},
73− Sign, Time,
74− };
71+ use crate::{signature, Sign, SignatureRef, Time};
7572
7673 fn decode(i: &[u8]) -> IResult<&[u8], SignatureRef<'_>, nom::error::VerboseError<&[u8]>> {
77− signature_ref::decode(i)
74+ signature::decode(i)
7875 }
7976
8077 fn signature(
git-actor/src/signature/mod.rsrenamed from git-actor/src/signature.rs+17−0
@@ -1,3 +1,16 @@
1+mod _ref {
2+ use crate::{signature::decode, SignatureRef};
3+
4+ impl<'a> SignatureRef<'a> {
5+ /// Deserialize a signature from the given `data`.
6+ pub fn from_bytes<E: nom::error::ParseError<&'a [u8]> + nom::error::ContextError<&'a [u8]>>(
7+ data: &'a [u8],
8+ ) -> Result<SignatureRef<'a>, nom::Err<E>> {
9+ decode(data).map(|(_, t)| t)
10+ }
11+ }
12+}
13+
114 mod convert {
215 use crate::{Sign, Signature, SignatureRef, Time};
316
@@ -85,3 +98,7 @@ mod write { · 81 unmodified lines
8598 Ok(name)
8699 }
87100 }
101+
102+///
103+mod decode;
104+pub use decode::decode;
git-actor/src/signature_ref/mod.rs+0−14
@@ -1,14 +0,0 @@
1−use crate::SignatureRef;
2−
3−impl<'a> SignatureRef<'a> {
4− /// Deserialize a signature from the given `data`.
5− pub fn from_bytes<E: nom::error::ParseError<&'a [u8]> + nom::error::ContextError<&'a [u8]>>(
6− data: &'a [u8],
7− ) -> Result<SignatureRef<'a>, nom::Err<E>> {
8− decode(data).map(|(_, t)| t)
9− }
10−}
11−
12−///
13−mod decode;
14−pub use decode::decode;
git-object/Cargo.toml+1−1
@@ -21,7 +21,7 @@ all-features = true · 20 unmodified lines
2121 [dependencies]
2222 git-hash = { version = "^0.5.0", path = "../git-hash" }
2323 git-validate = { version = "^0.5.0", path = "../git-validate" }
24−git-actor = { version ="^0.4.0", path = "../git-actor" }
24+git-actor = { version ="^0.5.0", path = "../git-actor" }
2525
2626 quick-error = "2.0.0"
2727 hex = "0.4.2"
git-object/src/immutable/parse.rs+1−1
@@ -77,5 +77,5 @@ pub fn hex_hash<'a, E: ParseError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], & · 76 unmodified lines
7777 pub(crate) fn signature<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(
7878 i: &'a [u8],
7979 ) -> IResult<&'a [u8], git_actor::SignatureRef<'a>, E> {
80− git_actor::signature_ref::decode(i)
80+ git_actor::signature::decode(i)
8181 }
git-object/src/types.rs+1−1
@@ -56,7 +56,7 @@ impl fmt::Display for Kind { · 55 unmodified lines
5656 pub mod tree {
5757 /// The mode of items storable in a tree, similar to the file mode on a unix file system.
5858 ///
59− /// Used in [mutable::Entry][crate::mutable::tree::Entry] and [signature_ref::Entry][crate::immutable::tree::Entry].
59+ /// Used in [mutable::Entry][crate::mutable::tree::Entry] and [tree::Entry][crate::immutable::tree::Entry].
6060 #[derive(Clone, Copy, PartialEq, Eq, Debug, Ord, PartialOrd, Hash)]
6161 #[repr(u16)]
6262 #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
git-ref/Cargo.toml+1−1
@@ -28,7 +28,7 @@ git-features = { version = "^0.16.0", path = "../git-features", features = ["wal · 27 unmodified lines
2828 git-hash = { version = "^0.5.0", path = "../git-hash" }
2929 git-object = { version ="0.12.0", path = "../git-object" }
3030 git-validate = { version = "^0.5.0", path = "../git-validate" }
31−git-actor = { version ="^0.4.0", path = "../git-actor" }
31+git-actor = { version ="^0.5.0", path = "../git-actor" }
3232 git-lock = { version ="^1.0.0", path = "../git-lock" }
3333 git-tempfile = { version ="^1.0.0", path = "../git-tempfile" }
3434
git-ref/src/fullname.rs+71−0
@@ -0,0 +1,71 @@
1+use std::{borrow::Cow, convert::TryFrom, path::Path};
2+
3+use bstr::{BStr, BString, ByteSlice};
4+
5+use crate::FullName;
6+
7+impl TryFrom<&str> for FullName {
8+ type Error = git_validate::refname::Error;
9+
10+ fn try_from(value: &str) -> Result<Self, Self::Error> {
11+ Ok(FullName(git_validate::refname(value.as_bytes().as_bstr())?.into()))
12+ }
13+}
14+
15+impl TryFrom<String> for FullName {
16+ type Error = git_validate::refname::Error;
17+
18+ fn try_from(value: String) -> Result<Self, Self::Error> {
19+ git_validate::refname(value.as_bytes().as_bstr())?;
20+ Ok(FullName(value.into()))
21+ }
22+}
23+
24+impl TryFrom<&BStr> for FullName {
25+ type Error = git_validate::refname::Error;
26+
27+ fn try_from(value: &BStr) -> Result<Self, Self::Error> {
28+ Ok(FullName(git_validate::refname(value)?.into()))
29+ }
30+}
31+
32+impl TryFrom<BString> for FullName {
33+ type Error = git_validate::refname::Error;
34+
35+ fn try_from(value: BString) -> Result<Self, Self::Error> {
36+ git_validate::refname(value.as_ref())?;
37+ Ok(FullName(value))
38+ }
39+}
40+
41+impl<'a> From<crate::FullNameRef<'a>> for FullName {
42+ fn from(value: crate::FullNameRef<'a>) -> Self {
43+ FullName(value.as_bstr().into())
44+ }
45+}
46+
47+impl FullName {
48+ /// Interpret this fully qualified reference name as partial name.
49+ pub fn to_partial(&self) -> crate::PartialNameRef<'_> {
50+ crate::PartialNameRef(self.0.as_bstr())
51+ }
52+
53+ /// Interpret this fully qualified reference as shared full name
54+ pub fn to_ref(&self) -> crate::FullNameRef<'_> {
55+ crate::FullNameRef(self.0.as_bstr())
56+ }
57+
58+ /// Convert this name into the relative path, lossily, identifying the reference location relative to a repository
59+ pub fn to_path(&self) -> Cow<'_, Path> {
60+ self.0.to_path().expect("UTF-8 conversion always succeeds").into()
61+ }
62+
63+ /// Dissolve this instance and return the buffer.
64+ pub fn into_inner(self) -> BString {
65+ self.0
66+ }
67+ /// Return ourselves as byte string which is a valid refname
68+ pub fn as_bstr(&self) -> &BStr {
69+ self.0.as_bstr()
70+ }
71+}
git-ref/src/lib.rs+22−6
@@ -19,12 +19,12 @@ · 18 unmodified lines
1919 #![forbid(unsafe_code)]
2020 #![deny(missing_docs, rust_2018_idioms)]
2121 use bstr::{BStr, BString};
22−use git_hash::oid;
22+use git_hash::{oid, ObjectId};
2323
2424 mod store;
2525 pub use store::{file, packed};
26−///
27−pub mod mutable;
26+
27+mod fullname;
2828 ///
2929 pub mod name;
3030 ///
@@ -32,12 +32,17 @@ pub mod namespace; · 1 unmodified line
3232 ///
3333 pub mod transaction;
3434
35+/// Indicate that the given BString is a validate reference name or path that can be used as path on disk or written as target
36+/// of a symbolic reference
37+#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
38+pub struct FullName(pub(crate) BString);
39+
3540 /// A validated and potentially partial reference name - it can safely be used for common operations.
3641 #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
37−pub struct FullName<'a>(&'a BStr);
42+pub struct FullNameRef<'a>(&'a BStr);
3843 /// A validated complete and fully qualified reference name, safe to use for all operations.
3944 #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
40−pub struct PartialName<'a>(&'a BStr);
45+pub struct PartialNameRef<'a>(&'a BStr);
4146
4247 /// A validated prefix for references to act as a namespace.
4348 #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
@@ -55,9 +60,20 @@ pub enum Kind { · 11 unmodified lines
5560 Symbolic,
5661 }
5762
63+/// Denotes a ref target, equivalent to [`Kind`], but with mutable data.
64+#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
65+pub enum Target {
66+ /// A ref that points to an object id
67+ Peeled(ObjectId),
68+ /// A ref that points to another reference by its validated name, adding a level of indirection.
69+ ///
70+ /// Note that this is an extension of gitoxide which will be helpful in logging all reference changes.
71+ Symbolic(FullName),
72+}
73+
5874 /// Denotes a ref target, equivalent to [`Kind`], but with signature_ref data.
5975 #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
60−pub enum Target<'a> {
76+pub enum TargetRef<'a> {
6177 /// A ref that points to an object id
6278 Peeled(&'a oid),
6379 /// A ref that points to another reference by its validated name, adding a level of indirection.
git-ref/src/mutable.rs+0−162
@@ -1,162 +0,0 @@
1−use std::{borrow::Cow, convert::TryFrom, fmt, path::Path};
2−
3−use bstr::{BStr, BString, ByteSlice};
4−use git_hash::{oid, ObjectId};
5−
6−use crate::Kind;
7−
8−/// Indicate that the given BString is a validate reference name or path that can be used as path on disk or written as target
9−/// of a symbolic reference
10−#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
11−pub struct FullName(pub(crate) BString);
12−
13−impl TryFrom<&str> for FullName {
14− type Error = git_validate::refname::Error;
15−
16− fn try_from(value: &str) -> Result<Self, Self::Error> {
17− Ok(FullName(git_validate::refname(value.as_bytes().as_bstr())?.into()))
18− }
19−}
20−
21−impl TryFrom<String> for FullName {
22− type Error = git_validate::refname::Error;
23−
24− fn try_from(value: String) -> Result<Self, Self::Error> {
25− git_validate::refname(value.as_bytes().as_bstr())?;
26− Ok(FullName(value.into()))
27− }
28−}
29−
30−impl TryFrom<&BStr> for FullName {
31− type Error = git_validate::refname::Error;
32−
33− fn try_from(value: &BStr) -> Result<Self, Self::Error> {
34− Ok(FullName(git_validate::refname(value)?.into()))
35− }
36−}
37−
38−impl TryFrom<BString> for FullName {
39− type Error = git_validate::refname::Error;
40−
41− fn try_from(value: BString) -> Result<Self, Self::Error> {
42− git_validate::refname(value.as_ref())?;
43− Ok(FullName(value))
44− }
45−}
46−
47−impl<'a> From<crate::FullName<'a>> for FullName {
48− fn from(value: crate::FullName<'a>) -> Self {
49− FullName(value.as_bstr().into())
50− }
51−}
52−
53−impl FullName {
54− /// Interpret this fully qualified reference name as partial name.
55− pub fn to_partial(&self) -> crate::PartialName<'_> {
56− crate::PartialName(self.0.as_bstr())
57− }
58−
59− /// Interpret this fully qualified reference as shared full name
60− pub fn borrow(&self) -> crate::FullName<'_> {
61− crate::FullName(self.0.as_bstr())
62− }
63−
64− /// Convert this name into the relative path, lossily, identifying the reference location relative to a repository
65− pub fn to_path(&self) -> Cow<'_, Path> {
66− self.0.to_path().expect("UTF-8 conversion always succeeds").into()
67− }
68−
69− /// Dissolve this instance and return the buffer.
70− pub fn into_inner(self) -> BString {
71− self.0
72− }
73− /// Return ourselves as byte string which is a valid refname
74− pub fn as_bstr(&self) -> &BStr {
75− self.0.as_bstr()
76− }
77−}
78−
79−/// Denotes a ref target, equivalent to [`Kind`][super::Kind], but with mutable data.
80−#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
81−pub enum Target {
82− /// A ref that points to an object id
83− Peeled(ObjectId),
84− /// A ref that points to another reference by its validated name, adding a level of indirection.
85− ///
86− /// Note that this is an extension of gitoxide which will be helpful in logging all reference changes.
87− Symbolic(FullName),
88−}
89−
90−impl Target {
91− /// Returns the kind of the target the ref is pointing to.
92− pub fn kind(&self) -> Kind {
93− match self {
94− Target::Symbolic(_) => Kind::Symbolic,
95− Target::Peeled(_) => Kind::Peeled,
96− }
97− }
98−
99− /// Return true if this is a peeled target with a null hash
100− pub fn is_null(&self) -> bool {
101− match self {
102− Target::Peeled(oid) => oid.is_null(),
103− Target::Symbolic(_) => false,
104− }
105− }
106−
107− /// Interpret this owned Target as shared Target
108− pub fn borrow(&self) -> crate::Target<'_> {
109− match self {
110− Target::Peeled(oid) => crate::Target::Peeled(oid),
111− Target::Symbolic(name) => crate::Target::Symbolic(name.0.as_bstr()),
112− }
113− }
114−
115− /// Interpret this target as object id which maybe `None` if it is symbolic.
116− pub fn as_id(&self) -> Option<&oid> {
117− match self {
118− Target::Symbolic(_) => None,
119− Target::Peeled(oid) => Some(oid),
120− }
121− }
122− /// Interpret this target as name of the reference it points to which maybe `None` if it an object id.
123− pub fn as_name(&self) -> Option<&BStr> {
124− match self {
125− Target::Symbolic(name) => Some(name.as_bstr()),
126− Target::Peeled(_) => None,
127− }
128− }
129−
130− /// Create an instance that signals that a reference should exist if this value is used in a [`Change`][crate::transaction::Change].
131− pub fn must_exist() -> Self {
132− Target::Peeled(ObjectId::null_sha1())
133− }
134−}
135−
136−impl<'a> From<crate::Target<'a>> for Target {
137− fn from(src: crate::Target<'a>) -> Self {
138− match src {
139− crate::Target::Peeled(oid) => Target::Peeled(oid.to_owned()),
140− crate::Target::Symbolic(name) => Target::Symbolic(FullName(name.to_owned())),
141− }
142− }
143−}
144−
145−impl<'a> PartialEq<crate::Target<'a>> for Target {
146− fn eq(&self, other: &crate::Target<'a>) -> bool {
147− match (self, other) {
148− (Target::Peeled(lhs), crate::Target::Peeled(rhs)) => lhs == rhs,
149− (Target::Symbolic(lhs), crate::Target::Symbolic(rhs)) => lhs.as_bstr() == *rhs,
150− _ => false,
151− }
152− }
153−}
154−
155−impl fmt::Display for Target {
156− fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
157− match self {
158− Target::Peeled(oid) => oid.fmt(f),
159− Target::Symbolic(name) => write!(f, "ref: {}", name.as_bstr()),
160− }
161− }
162−}
git-ref/src/name.rs+19−19
@@ -6,12 +6,12 @@ use std::{ · 5 unmodified lines
66
77 use bstr::{BStr, ByteSlice};
88
9−use crate::{FullName, PartialName};
9+use crate::{FullNameRef, PartialNameRef};
1010
11−/// The error used in the [`PartialName`][super::PartialName]::try_from(…) implementations.
11+/// The error used in the [`PartialNameRef`][super::PartialNameRef]::try_from(…) implementations.
1212 pub type Error = git_validate::reference::name::Error;
1313
14−impl<'a> FullName<'a> {
14+impl<'a> FullNameRef<'a> {
1515 /// Convert this name into the relative path identifying the reference location.
1616 pub fn to_path(self) -> Cow<'a, Path> {
1717 self.0.to_path().expect("UTF-8 conversion always succeeds").into()
@@ -23,7 +23,7 @@ impl<'a> FullName<'a> { · 5 unmodified lines
2323 }
2424 }
2525
26−impl<'a> PartialName<'a> {
26+impl<'a> PartialNameRef<'a> {
2727 /// Convert this name into the relative path possibly identifying the reference location.
2828 /// Note that it may be only a partial path though.
2929 pub fn to_partial_path(self) -> Cow<'a, Path> {
@@ -36,62 +36,62 @@ impl<'a> PartialName<'a> { · 6 unmodified lines
3636 }
3737 }
3838
39−impl<'a> TryFrom<&'a BStr> for FullName<'a> {
39+impl<'a> TryFrom<&'a BStr> for FullNameRef<'a> {
4040 type Error = Error;
4141
4242 fn try_from(v: &'a BStr) -> Result<Self, Self::Error> {
43− Ok(FullName(git_validate::reference::name(v)?))
43+ Ok(FullNameRef(git_validate::reference::name(v)?))
4444 }
4545 }
4646
47−impl<'a> TryFrom<FullName<'a>> for PartialName<'a> {
47+impl<'a> TryFrom<FullNameRef<'a>> for PartialNameRef<'a> {
4848 type Error = Infallible;
4949
50− fn try_from(v: FullName<'a>) -> Result<Self, Self::Error> {
51− Ok(PartialName(v.0))
50+ fn try_from(v: FullNameRef<'a>) -> Result<Self, Self::Error> {
51+ Ok(PartialNameRef(v.0))
5252 }
5353 }
5454
55−impl<'a> TryFrom<&'a BStr> for PartialName<'a> {
55+impl<'a> TryFrom<&'a BStr> for PartialNameRef<'a> {
5656 type Error = Error;
5757
5858 fn try_from(v: &'a BStr) -> Result<Self, Self::Error> {
59− Ok(PartialName(git_validate::reference::name_partial(v)?))
59+ Ok(PartialNameRef(git_validate::reference::name_partial(v)?))
6060 }
6161 }
6262
63−impl<'a> TryFrom<&'a str> for FullName<'a> {
63+impl<'a> TryFrom<&'a str> for FullNameRef<'a> {
6464 type Error = Error;
6565
6666 fn try_from(v: &'a str) -> Result<Self, Self::Error> {
6767 let v = v.as_bytes().as_bstr();
68− Ok(FullName(git_validate::reference::name(v)?))
68+ Ok(FullNameRef(git_validate::reference::name(v)?))
6969 }
7070 }
7171
72−impl<'a> TryFrom<&'a str> for PartialName<'a> {
72+impl<'a> TryFrom<&'a str> for PartialNameRef<'a> {
7373 type Error = Error;
7474
7575 fn try_from(v: &'a str) -> Result<Self, Self::Error> {
7676 let v = v.as_bytes().as_bstr();
77− Ok(PartialName(git_validate::reference::name_partial(v)?))
77+ Ok(PartialNameRef(git_validate::reference::name_partial(v)?))
7878 }
7979 }
8080
81−impl<'a> TryFrom<&'a String> for FullName<'a> {
81+impl<'a> TryFrom<&'a String> for FullNameRef<'a> {
8282 type Error = Error;
8383
8484 fn try_from(v: &'a String) -> Result<Self, Self::Error> {
8585 let v = v.as_bytes().as_bstr();
86− Ok(FullName(git_validate::reference::name(v)?))
86+ Ok(FullNameRef(git_validate::reference::name(v)?))
8787 }
8888 }
8989
90−impl<'a> TryFrom<&'a String> for PartialName<'a> {
90+impl<'a> TryFrom<&'a String> for PartialNameRef<'a> {
9191 type Error = Error;
9292
9393 fn try_from(v: &'a String) -> Result<Self, Self::Error> {
9494 let v = v.as_bytes().as_bstr();
95− Ok(PartialName(git_validate::reference::name_partial(v)?))
95+ Ok(PartialNameRef(git_validate::reference::name_partial(v)?))
9696 }
9797 }
git-ref/src/namespace.rs+2−2
@@ -2,7 +2,7 @@ use std::{borrow::Cow, convert::TryInto, path::Path}; · 1 unmodified line
22
33 use bstr::{BStr, BString, ByteSlice, ByteVec};
44
5−use crate::{Namespace, PartialName};
5+use crate::{Namespace, PartialNameRef};
66
77 impl Namespace {
88 /// Dissolve ourselves into the interior representation
@@ -24,7 +24,7 @@ impl Namespace { · 15 unmodified lines
2424 /// For more information, consult the [git namespace documentation](https://git-scm.com/docs/gitnamespaces).
2525 pub fn expand<'a, Name, E>(namespace: Name) -> Result<Namespace, git_validate::refname::Error>
2626 where
27− Name: TryInto<PartialName<'a>, Error = E>,
27+ Name: TryInto<PartialNameRef<'a>, Error = E>,
2828 git_validate::refname::Error: From<E>,
2929 {
3030 let namespace = namespace.try_into()?.0;
git-ref/src/store/file/find.rs+19−16
@@ -9,12 +9,11 @@ pub use error::Error; · 8 unmodified lines
99
1010 use crate::{
1111 file,
12− mutable::FullName,
1312 store::{
1413 file::{loose, path_to_name},
1514 packed,
1615 },
17− PartialName,
16+ FullName, PartialNameRef,
1817 };
1918
2019 enum Transform {
@@ -35,13 +34,13 @@ impl file::Store { · 14 unmodified lines
3534 /// The lookup algorithm follows the one in [the git documentation][git-lookup-docs].
3635 ///
3736 /// [git-lookup-docs]: https://github.com/git/git/blob/5d5b1473453400224ebb126bf3947e0a3276bdf5/Documentation/revisions.txt#L34-L46
38− pub fn find<'a, 'p, 's, Name, E>(
37+ pub fn try_find<'a, 'p, 's, Name, E>(
3938 &'s self,
4039 partial: Name,
4140 packed: Option<&'p packed::Buffer>,
4241 ) -> Result<Option<file::Reference<'p>>, Error>
4342 where
44− Name: TryInto<PartialName<'a>, Error = E>,
43+ Name: TryInto<PartialNameRef<'a>, Error = E>,
4544 Error: From<E>,
4645 {
4746 let path = partial.try_into()?;
@@ -49,12 +48,16 @@ impl file::Store { · 1 unmodified line
4948 }
5049
5150 /// Similar to [`file::Store::find()`] but a non-existing ref is treated as error.
52− pub fn loose_find<'a, Name, E>(&self, partial: Name) -> Result<Option<loose::Reference>, Error>
51+ ///
52+ /// Find only loose references, that is references that aren't in the packed-refs buffer.
53+ /// All symbolic references are loose references.
54+ /// `HEAD` is always a loose reference.
55+ pub fn try_find_loose<'a, Name, E>(&self, partial: Name) -> Result<Option<loose::Reference>, Error>
5356 where
54− Name: TryInto<PartialName<'a>, Error = E>,
57+ Name: TryInto<PartialNameRef<'a>, Error = E>,
5558 Error: From<E>,
5659 {
57− self.find(partial, None)
60+ self.try_find(partial, None)
5861 .map(|r| r.map(|r| r.try_into().expect("only loose refs are found without pack")))
5962 }
6063
@@ -116,8 +119,8 @@ impl file::Store { · 55 unmodified lines
116119 if is_definitely_absolute {
117120 if let Some(packed) = packed {
118121 let full_name = path_to_name(relative_path);
119− let full_name = PartialName((*full_name).as_bstr());
120− if let Some(packed_ref) = packed.find(full_name)? {
122+ let full_name = PartialNameRef((*full_name).as_bstr());
123+ if let Some(packed_ref) = packed.try_find(full_name)? {
121124 return Ok(Some(file::Reference::Packed(packed_ref)));
122125 };
123126 }
@@ -173,18 +176,18 @@ pub mod existing { · 49 unmodified lines
173176 file::{find, loose},
174177 packed,
175178 },
176− PartialName,
179+ PartialNameRef,
177180 };
178181
179182 impl file::Store {
180− /// Similar to [`file::Store::find_existing()`] but a non-existing ref is treated as error.
181− pub fn find_existing<'a, 'p, 's, Name, E>(
183+ /// Similar to [`file::Store::find()`] but a non-existing ref is treated as error.
184+ pub fn find<'a, 'p, 's, Name, E>(
182185 &'s self,
183186 partial: Name,
184187 packed: Option<&'p packed::Buffer>,
185188 ) -> Result<file::Reference<'p>, Error>
186189 where
187− Name: TryInto<PartialName<'a>, Error = E>,
190+ Name: TryInto<PartialNameRef<'a>, Error = E>,
188191 crate::name::Error: From<E>,
189192 {
190193 let path = partial
@@ -198,12 +201,12 @@ pub mod existing { · 7 unmodified lines
198201 }
199202
200203 /// Similar to [`file::Store::find()`] won't handle packed-refs.
201− pub fn loose_find_existing<'a, Name, E>(&self, partial: Name) -> Result<loose::Reference, Error>
204+ pub fn find_loose<'a, Name, E>(&self, partial: Name) -> Result<loose::Reference, Error>
202205 where
203− Name: TryInto<PartialName<'a>, Error = E>,
206+ Name: TryInto<PartialNameRef<'a>, Error = E>,
204207 crate::name::Error: From<E>,
205208 {
206− self.find_existing(partial, None)
209+ self.find(partial, None)
207210 .map(|r| r.try_into().expect("always loose without packed"))
208211 }
209212 }
git-ref/src/store/file/log/iter.rs+6−5
@@ -1,5 +1,6 @@
11 use bstr::ByteSlice;
22
3+use crate::store::file;
34 use crate::store::file::{log, log::iter::decode::LineNumber};
45
56 ///
@@ -51,9 +52,9 @@ pub mod decode { · 45 unmodified lines
5152 /// This iterator is useful when the ref log file is going to be rewritten which forces processing of the entire file.
5253 /// It will continue parsing even if individual log entries failed to parse, leaving it to the driver to decide whether to
5354 /// abort or continue.
54−pub fn forward(lines: &[u8]) -> impl Iterator<Item = Result<log::Line<'_>, decode::Error>> {
55+pub fn forward(lines: &[u8]) -> impl Iterator<Item = Result<log::LineRef<'_>, decode::Error>> {
5556 lines.as_bstr().lines().enumerate().map(|(ln, line)| {
56− log::Line::from_bytes(line).map_err(|err| decode::Error::new(err, decode::LineNumber::FromStart(ln)))
57+ log::LineRef::from_bytes(line).map_err(|err| decode::Error::new(err, decode::LineNumber::FromStart(ln)))
5758 })
5859 }
5960
@@ -93,7 +94,7 @@ impl<'a, F> Iterator for Reverse<'a, F> · 33 unmodified lines
9394 where
9495 F: std::io::Read + std::io::Seek,
9596 {
96− type Item = std::io::Result<Result<log::mutable::Line, decode::Error>>;
97+ type Item = std::io::Result<Result<file::log::Line, decode::Error>>;
9798
9899 fn next(&mut self) -> Option<Self::Item> {
99100 match (self.last_nl_pos.take(), self.read_and_pos.take()) {
@@ -124,7 +125,7 @@ where · 24 unmodified lines
124125 self.read_and_pos = Some(read_and_pos);
125126 self.last_nl_pos = Some(start);
126127 let buf = &self.buf[start + 1..end];
127− let res = Some(Ok(log::Line::from_bytes(buf)
128+ let res = Some(Ok(log::LineRef::from_bytes(buf)
128129 .map_err(|err| decode::Error::new(err, LineNumber::FromEnd(self.count)))
129130 .map(Into::into)));
130131 self.count += 1;
@@ -134,7 +135,7 @@ where · 3 unmodified lines
134135 let (mut read, last_read_pos) = read_and_pos;
135136 if last_read_pos == 0 {
136137 let buf = &self.buf[..end];
137− Some(Ok(log::Line::from_bytes(buf)
138+ Some(Ok(log::LineRef::from_bytes(buf)
138139 .map_err(|err| decode::Error::new(err, LineNumber::FromEnd(self.count)))
139140 .map(Into::into)))
140141 } else {
git-ref/src/store/file/log/line.rs+71−9
@@ -1,8 +1,59 @@
11 use git_hash::ObjectId;
22
33 use crate::store::file::log::Line;
4+use crate::store::file::log::LineRef;
45
5−impl<'a> Line<'a> {
6+impl<'a> LineRef<'a> {
7+ /// Convert this instance into its mutable counterpart
8+ pub fn to_owned(&self) -> Line {
9+ self.clone().into()
10+ }
11+}
12+
13+mod write {
14+ use std::io;
15+
16+ use bstr::{BStr, ByteSlice};
17+ use quick_error::quick_error;
18+
19+ use crate::store::file::log::Line;
20+
21+ quick_error! {
22+ /// The Error produced by [`Line::write_to()`] (but wrapped in an io error).
23+ #[derive(Debug)]
24+ #[allow(missing_docs)]
25+ enum Error {
26+ IllegalCharacter {
27+ display("Messages must not contain newlines\\n")
28+ }
29+ }
30+ }
31+
32+ impl From<Error> for io::Error {
33+ fn from(err: Error) -> Self {
34+ io::Error::new(io::ErrorKind::Other, err)
35+ }
36+ }
37+
38+ /// Output
39+ impl Line {
40+ /// Serialize this instance to `out` in the git serialization format for ref log lines.
41+ pub fn write_to(&self, mut out: impl io::Write) -> io::Result<()> {
42+ write!(out, "{} {} ", self.previous_oid, self.new_oid)?;
43+ self.signature.write_to(&mut out)?;
44+ writeln!(out, "\t{}", check_newlines(self.message.as_ref())?)
45+ }
46+ }
47+
48+ fn check_newlines(input: &BStr) -> Result<&BStr, Error> {
49+ if input.find_byte(b'\n').is_some() {
50+ return Err(Error::IllegalCharacter);
51+ }
52+ Ok(input)
53+ }
54+}
55+
56+impl<'a> LineRef<'a> {
657 /// The previous object id of the ref. It will be a null hash if there was no previous id as
758 /// this ref is being created.
859 pub fn previous_oid(&self) -> ObjectId {
@@ -14,6 +65,17 @@ impl<'a> Line<'a> { · 5 unmodified lines
1465 }
1566 }
1667
68+impl<'a> From<LineRef<'a>> for Line {
69+ fn from(v: LineRef<'a>) -> Self {
70+ Line {
71+ previous_oid: v.previous_oid(),
72+ new_oid: v.new_oid(),
73+ signature: v.signature.into(),
74+ message: v.message.into(),
75+ }
76+ }
77+}
78+
1779 ///
1880 pub mod decode {
1981 use bstr::{BStr, ByteSlice};
@@ -25,7 +87,7 @@ pub mod decode { · 5 unmodified lines
2587 IResult,
2688 };
2789
28− use crate::{file::log::Line, parse::hex_hash};
90+ use crate::{file::log::LineRef, parse::hex_hash};
2991
3092 ///
3193 mod error {
@@ -59,9 +121,9 @@ pub mod decode { · 27 unmodified lines
59121 }
60122 pub use error::Error;
61123
62− impl<'a> Line<'a> {
124+ impl<'a> LineRef<'a> {
63125 /// Decode a line from the given bytes which are expected to start at a hex sha.
64− pub fn from_bytes(input: &'a [u8]) -> Result<Line<'a>, Error> {
126+ pub fn from_bytes(input: &'a [u8]) -> Result<LineRef<'a>, Error> {
65127 one::<()>(input).map(|(_, l)| l).map_err(|_| Error::new(input))
66128 }
67129 }
@@ -74,13 +136,13 @@ pub mod decode { · 6 unmodified lines
74136 }
75137 }
76138
77− fn one<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(bytes: &'a [u8]) -> IResult<&[u8], Line<'a>, E> {
139+ fn one<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(bytes: &'a [u8]) -> IResult<&[u8], LineRef<'a>, E> {
78140 let (i, (old, new, signature, message_sep, message)) = context(
79141 "<old-hexsha> <new-hexsha> <name> <<email>> <timestamp> <tz>\\t<message>",
80142 tuple((
81143 context("<old-hexsha>", terminated(hex_hash, tag(b" "))),
82144 context("<new-hexsha>", terminated(hex_hash, tag(b" "))),
83− context("<name> <<email>> <timestamp>", git_actor::signature_ref::decode),
145+ context("<name> <<email>> <timestamp>", git_actor::signature::decode),
84146 opt(tag(b"\t")),
85147 context("<optional message>", message),
86148 )),
@@ -100,7 +162,7 @@ pub mod decode { · 13 unmodified lines
100162
101163 Ok((
102164 i,
103− Line {
165+ LineRef {
104166 previous_oid: old,
105167 new_oid: new,
106168 signature,
@@ -161,7 +223,7 @@ pub mod decode { · 54 unmodified lines
161223 for input in &[line_without_nl, line_with_nl] {
162224 assert_eq!(
163225 one::<nom::error::Error<_>>(input).expect("successful parsing").1,
164− Line {
226+ LineRef {
165227 previous_oid: NULL_SHA1.as_bstr(),
166228 new_oid: NULL_SHA1.as_bstr(),
167229 signature: git_actor::SignatureRef {
@@ -187,7 +249,7 @@ pub mod decode { · 19 unmodified lines
187249 for input in &[line_without_nl, line_with_nl] {
188250 let (remaining, res) = one::<nom::error::Error<_>>(input).expect("successful parsing");
189251 assert!(remaining.is_empty(), "all consuming even without trailing newline");
190− let actual = Line {
252+ let actual = LineRef {
191253 previous_oid: b"a5828ae6b52137b913b978e16cd2334482eb4c1f".as_bstr(),
192254 new_oid: b"89b43f80a514aee58b662ad606e6352e03eaeee4".as_bstr(),
193255 signature: git_actor::SignatureRef {
git-ref/src/store/file/log/mod.rs+22−86
@@ -1,15 +1,22 @@
11 use bstr::BStr;
22
3+use git_hash::ObjectId;
4+use git_object::bstr::BString;
5+
36 pub use super::loose::reflog::{create_or_update, Error};
47
8+///
9+pub mod iter;
10+mod line;
11+
512 /// A parsed ref log line.
613 #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
714 #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
815 #[non_exhaustive]
9−pub struct Line<'a> {
10− /// The previous object id in hexadecimal. Use [`Line::previous_oid()`] to get a more usable form.
16+pub struct LineRef<'a> {
17+ /// The previous object id in hexadecimal. Use [`LineRef::previous_oid()`] to get a more usable form.
1118 pub previous_oid: &'a BStr,
12− /// The new object id in hexadecimal. Use [`Line::new_oid()`] to get a more usable form.
19+ /// The new object id in hexadecimal. Use [`LineRef::new_oid()`] to get a more usable form.
1320 pub new_oid: &'a BStr,
1421 /// The signature of the currently configured committer.
1522 #[cfg_attr(feature = "serde1", serde(borrow))]
@@ -18,87 +25,16 @@ pub struct Line<'a> { · 2 unmodified lines
1825 pub message: &'a BStr,
1926 }
2027
21−///
22−pub mod mutable {
23− use bstr::BString;
24− use git_hash::ObjectId;
25−
26− /// A parsed ref log line that can be changed
27− #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
28− #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
29− pub struct Line {
30− /// The previous object id. Can be a null-sha to indicate this is a line for a new ref.
31− pub previous_oid: ObjectId,
32− /// The new object id. Can be a null-sha to indicate this ref is being deleted.
33− pub new_oid: ObjectId,
34− /// The signature of the currently configured committer.
35− pub signature: git_actor::Signature,
36− /// The message providing details about the operation performed in this log line.
37− pub message: BString,
38− }
39−
40− impl<'a> From<super::Line<'a>> for Line {
41− fn from(v: super::Line<'a>) -> Self {
42− Line {
43− previous_oid: v.previous_oid(),
44− new_oid: v.new_oid(),
45− signature: v.signature.into(),
46− message: v.message.into(),
47− }
48− }
49− }
50−
51− impl<'a> super::Line<'a> {
52− /// Convert this instance into its mutable counterpart
53− pub fn to_mutable(&self) -> Line {
54− self.clone().into()
55− }
56− }
57−
58− mod write {
59− use std::io;
60−
61− use bstr::{BStr, ByteSlice};
62− use quick_error::quick_error;
63−
64− use super::Line;
65−
66− quick_error! {
67− /// The Error produced by [`Line::write_to()`] (but wrapped in an io error).
68− #[derive(Debug)]
69− #[allow(missing_docs)]
70− enum Error {
71− IllegalCharacter {
72− display("Messages must not contain newlines\\n")
73− }
74− }
75− }
76−
77− impl From<Error> for io::Error {
78− fn from(err: Error) -> Self {
79− io::Error::new(io::ErrorKind::Other, err)
80− }
81− }
82−
83− /// Output
84− impl Line {
85− /// Serialize this instance to `out` in the git serialization format for ref log lines.
86− pub fn write_to(&self, mut out: impl io::Write) -> io::Result<()> {
87− write!(out, "{} {} ", self.previous_oid, self.new_oid)?;
88− self.signature.write_to(&mut out)?;
89− writeln!(out, "\t{}", check_newlines(self.message.as_ref())?)
90− }
91− }
92−
93− fn check_newlines(input: &BStr) -> Result<&BStr, Error> {
94− if input.find_byte(b'\n').is_some() {
95− return Err(Error::IllegalCharacter);
96− }
97− Ok(input)
98− }
99− }
28+/// A parsed ref log line that can be changed
29+#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
30+#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
31+pub struct Line {
32+ /// The previous object id. Can be a null-sha to indicate this is a line for a new ref.
33+ pub previous_oid: ObjectId,
34+ /// The new object id. Can be a null-sha to indicate this ref is being deleted.
35+ pub new_oid: ObjectId,
36+ /// The signature of the currently configured committer.
37+ pub signature: git_actor::Signature,
38+ /// The message providing details about the operation performed in this log line.
39+ pub message: BString,
10040 }
101−
102−///
103−pub mod iter;
104−mod line;
git-ref/src/store/file/loose/iter.rs+1−1
@@ -8,8 +8,8 @@ use git_features::fs::walkdir::DirEntryIter; · 7 unmodified lines
88 use os_str_bytes::OsStrBytes;
99
1010 use crate::{
11− mutable::FullName,
1211 store::file::{self, loose::Reference},
12+ FullName,
1313 };
1414
1515 /// An iterator over all valid loose reference paths as seen from a particular base directory.
git-ref/src/store/file/loose/mod.rs+3−3
@@ -1,12 +1,12 @@
1−use crate::{mutable, Kind};
1+use crate::{FullName, Kind, Target};
22
33 /// A git _ref_ which is stored in a file.
44 #[derive(Debug, PartialOrd, PartialEq, Ord, Eq, Hash, Clone)]
55 pub struct Reference {
66 /// The path to uniquely identify this ref within its store.
7− pub name: mutable::FullName,
7+ pub name: FullName,
88 /// The target of the reference, either a symbolic reference by full name or an object by its id.
9− pub target: mutable::Target,
9+ pub target: Target,
1010 }
1111
1212 impl Reference {
git-ref/src/store/file/loose/reference/decode.rs+8−10
@@ -11,9 +11,9 @@ use nom::{ · 10 unmodified lines
1111 use quick_error::quick_error;
1212
1313 use crate::{
14− mutable,
1514 parse::{hex_hash, newline},
1615 store::file::loose::Reference,
16+ FullName, Target,
1717 };
1818
1919 enum MaybeUnsafeState {
@@ -36,18 +36,16 @@ quick_error! { · 16 unmodified lines
3636 }
3737 }
3838
39−impl TryFrom<MaybeUnsafeState> for mutable::Target {
39+impl TryFrom<MaybeUnsafeState> for Target {
4040 type Error = Error;
4141
4242 fn try_from(v: MaybeUnsafeState) -> Result<Self, Self::Error> {
4343 Ok(match v {
44− MaybeUnsafeState::Id(id) => mutable::Target::Peeled(id),
45− MaybeUnsafeState::UnvalidatedPath(name) => {
46− mutable::Target::Symbolic(match git_validate::refname(name.as_ref()) {
47− Ok(_) => mutable::FullName(name),
48− Err(err) => return Err(Error::RefnameValidation { err, path: name }),
49− })
50− }
44+ MaybeUnsafeState::Id(id) => Target::Peeled(id),
45+ MaybeUnsafeState::UnvalidatedPath(name) => Target::Symbolic(match git_validate::refname(name.as_ref()) {
46+ Ok(_) => FullName(name),
47+ Err(err) => return Err(Error::RefnameValidation { err, path: name }),
48+ }),
5149 })
5250 }
5351 }
@@ -55,7 +53,7 @@ impl TryFrom<MaybeUnsafeState> for mutable::Target { · 1 unmodified line
5553 impl Reference {
5654 /// Create a new reference of the given `parent` store with `relative_path` service as unique identifier
5755 /// at which the `path_contents` was read to obtain the refs value.
58− pub fn try_from_path(name: mutable::FullName, path_contents: &[u8]) -> Result<Self, Error> {
56+ pub fn try_from_path(name: FullName, path_contents: &[u8]) -> Result<Self, Error> {
5957 Ok(Reference {
6058 name,
6159 target: parse(path_contents)
git-ref/src/store/file/loose/reference/logiter.rs+4−4
@@ -18,7 +18,7 @@ impl Reference { · 17 unmodified lines
1818 /// If the caller needs to know if it's readable, try to read the log instead with a reverse or forward iterator.
1919 pub fn log_exists(&self, store: &file::Store) -> bool {
2020 store
21− .reflog_exists(self.name.borrow())
21+ .reflog_exists(self.name.to_ref())
2222 .expect("name conversion infallible")
2323 }
2424 /// Return a reflog reverse iterator for this ref, reading chunks from the back into the fixed buffer `buf`, in the given `store`.
@@ -30,7 +30,7 @@ impl Reference { · 5 unmodified lines
3030 store: &file::Store,
3131 buf: &'b mut [u8],
3232 ) -> std::io::Result<Option<log::iter::Reverse<'b, std::fs::File>>> {
33− store.reflog_iter_rev(self.name.borrow(), buf).map_err(must_be_io_err)
33+ store.reflog_iter_rev(self.name.to_ref(), buf).map_err(must_be_io_err)
3434 }
3535
3636 /// Return a reflog forward iterator for this ref and write its file contents into `buf`, in the given `store`.
@@ -41,7 +41,7 @@ impl Reference { · 4 unmodified lines
4141 &'a self,
4242 store: &file::Store,
4343 buf: &'b mut Vec<u8>,
44− ) -> std::io::Result<Option<impl Iterator<Item = Result<log::Line<'b>, log::iter::decode::Error>> + 'a>> {
45− store.reflog_iter(self.name.borrow(), buf).map_err(must_be_io_err)
44+ ) -> std::io::Result<Option<impl Iterator<Item = Result<log::LineRef<'b>, log::iter::decode::Error>> + 'a>> {
45+ store.reflog_iter(self.name.to_ref(), buf).map_err(must_be_io_err)
4646 }
4747 }
git-ref/src/store/file/loose/reference/peel.rs+2−2
@@ -2,11 +2,11 @@ use quick_error::quick_error; · 1 unmodified line
22
33 use crate::{
44 file,
5− mutable::Target,
65 store::{
76 file::{find, loose},
87 packed,
98 },
9+ Target,
1010 };
1111
1212 quick_error! {
@@ -67,8 +67,8 @@ pub mod to_id { · 54 unmodified lines
6767 use quick_error::quick_error;
6868
6969 use crate::{
70− mutable::{FullName, Target},
7170 store::{file, file::loose, packed},
71+ FullName, Target,
7272 };
7373
7474 quick_error! {
git-ref/src/store/file/loose/reflog.rs+8−8
@@ -2,7 +2,7 @@ use std::{convert::TryInto, io::Read, path::PathBuf}; · 1 unmodified line
22
33 use crate::{
44 store::{file, file::log},
5− FullName,
5+ FullNameRef,
66 };
77
88 impl file::Store {
@@ -13,7 +13,7 @@ impl file::Store { · 4 unmodified lines
1313 /// If the caller needs to know if it's readable, try to read the log instead with a reverse or forward iterator.
1414 pub fn reflog_exists<'a, Name, E>(&self, name: Name) -> Result<bool, E>
1515 where
16− Name: TryInto<FullName<'a>, Error = E>,
16+ Name: TryInto<FullNameRef<'a>, Error = E>,
1717 crate::name::Error: From<E>,
1818 {
1919 Ok(self.reflog_path(name.try_into()?).is_file())
@@ -29,10 +29,10 @@ impl file::Store { · 9 unmodified lines
2929 buf: &'b mut [u8],
3030 ) -> Result<Option<log::iter::Reverse<'b, std::fs::File>>, Error>
3131 where
32− Name: TryInto<FullName<'a>, Error = E>,
32+ Name: TryInto<FullNameRef<'a>, Error = E>,
3333 crate::name::Error: From<E>,
3434 {
35− let name: FullName<'_> = name.try_into().map_err(|err| Error::RefnameValidation(err.into()))?;
35+ let name: FullNameRef<'_> = name.try_into().map_err(|err| Error::RefnameValidation(err.into()))?;
3636 let path = self.reflog_path(name);
3737 if path.is_dir() {
3838 return Ok(None);
@@ -52,12 +52,12 @@ impl file::Store { · 13 unmodified lines
5252 &self,
5353 name: Name,
5454 buf: &'b mut Vec<u8>,
55− ) -> Result<Option<impl Iterator<Item = Result<log::Line<'b>, log::iter::decode::Error>>>, Error>
55+ ) -> Result<Option<impl Iterator<Item = Result<log::LineRef<'b>, log::iter::decode::Error>>>, Error>
5656 where
57− Name: TryInto<FullName<'a>, Error = E>,
57+ Name: TryInto<FullNameRef<'a>, Error = E>,
5858 crate::name::Error: From<E>,
5959 {
60− let name: FullName<'_> = name.try_into().map_err(|err| Error::RefnameValidation(err.into()))?;
60+ let name: FullNameRef<'_> = name.try_into().map_err(|err| Error::RefnameValidation(err.into()))?;
6161 let path = self.reflog_path(name);
6262 match std::fs::File::open(&path) {
6363 Ok(mut file) => {
@@ -77,7 +77,7 @@ impl file::Store { · 13 unmodified lines
7777
7878 impl file::Store {
7979 /// Implements the logic required to transform a fully qualified refname into its log name
80− pub(crate) fn reflog_path(&self, name: FullName<'_>) -> PathBuf {
80+ pub(crate) fn reflog_path(&self, name: FullNameRef<'_>) -> PathBuf {
8181 self.reflog_path_inner(&name.to_path())
8282 }
8383 }
git-ref/src/store/file/loose/reflog/create_or_update/tests.rs+6−6
@@ -1,5 +1,5 @@
11 use super::*;
2−use crate::{file::WriteReflog, store::file::log, FullName};
2+use crate::{file::WriteReflog, store::file::log, FullNameRef};
33 use bstr::ByteSlice;
44 use git_actor::{Sign, Signature, Time};
55 use git_lock::acquire::Fail;
@@ -16,7 +16,7 @@ fn empty_store(writemode: WriteReflog) -> Result<(TempDir, file::Store)> { · 10 unmodified lines
1616 }
1717
1818 fn reflock(store: &file::Store, full_name: &str) -> Result<git_lock::Marker> {
19− let full_name: FullName<'_> = full_name.try_into()?;
19+ let full_name: FullNameRef<'_> = full_name.try_into()?;
2020 git_lock::Marker::acquire_to_hold_resource(
2121 store.reference_path(&full_name.to_path()),
2222 Fail::Immediately,
@@ -25,11 +25,11 @@ fn reflock(store: &file::Store, full_name: &str) -> Result<git_lock::Marker> { · 2 unmodified lines
2525 .map_err(Into::into)
2626 }
2727
28−fn reflog_lines(store: &file::Store, name: &str, buf: &mut Vec<u8>) -> Result<Vec<log::mutable::Line>> {
28+fn reflog_lines(store: &file::Store, name: &str, buf: &mut Vec<u8>) -> Result<Vec<log::Line>> {
2929 store
3030 .reflog_iter(name, buf)?
3131 .expect("existing reflog")
32− .map(|l| l.map(log::mutable::Line::from))
32+ .map(|l| l.map(log::Line::from))
3333 .collect::<std::result::Result<Vec<_>, _>>()
3434 .map_err(Into::into)
3535 }
@@ -83,7 +83,7 @@ fn missing_reflog_creates_it_even_if_similarly_named_empty_dir_exists_and_append · 47 unmodified lines
8383 WriteReflog::Normal => {
8484 assert_eq!(
8585 reflog_lines(&store, full_name, &mut buf)?,
86− vec![log::mutable::Line {
86+ vec![log::Line {
8787 previous_oid: ObjectId::null_sha1(),
8888 new_oid: new,
8989 signature: committer.clone(),
@@ -104,7 +104,7 @@ fn missing_reflog_creates_it_even_if_similarly_named_empty_dir_exists_and_append · 14 unmodified lines
104104 assert_eq!(lines.len(), 2, "now there is another line");
105105 assert_eq!(
106106 lines.last().expect("non-empty"),
107− &log::mutable::Line {
107+ &log::Line {
108108 previous_oid: previous,
109109 new_oid: new,
110110 signature: committer.clone(),
git-ref/src/store/file/overlay.rs+1−1
@@ -7,8 +7,8 @@ use std::{ · 6 unmodified lines
77
88 use crate::{
99 file::{loose, path_to_name, Reference},
10− mutable::FullName,
1110 store::{file, packed},
11+ FullName,
1212 };
1313
1414 /// An iterator stepping through sorted input of loose references and packed references, preferring loose refs over otherwise
git-ref/src/store/file/reference.rs+12−13
@@ -5,13 +5,12 @@ use git_hash::ObjectId; · 4 unmodified lines
55
66 use crate::{
77 file::loose::reference::logiter::must_be_io_err,
8− mutable,
98 store::{
109 file,
1110 file::{log, loose},
1211 packed,
1312 },
14− FullName, Namespace,
13+ FullNameRef, Namespace, Target,
1514 };
1615
1716 /// Either a loose or packed reference, depending on where it was found.
@@ -82,7 +81,7 @@ impl<'p> Reference<'p> { · 64 unmodified lines
8281 match self {
8382 Reference::Loose(r) => r.follow_symbolic(store, packed),
8483 Reference::Packed(p) => packed
85− .and_then(|packed| packed.find(p.name).ok().flatten()) // needed to get data with 'p2 lifetime
84+ .and_then(|packed| packed.try_find(p.name).ok().flatten()) // needed to get data with 'p2 lifetime
8685 .and_then(|np| {
8786 p.object.and(np.object).map(|peeled| {
8887 Ok(Reference::Packed(packed::Reference {
@@ -112,9 +111,9 @@ impl<'p> Reference<'p> { · 23 unmodified lines
112111 &'a self,
113112 store: &file::Store,
114113 buf: &'b mut Vec<u8>,
115− ) -> std::io::Result<Option<impl Iterator<Item = Result<log::Line<'b>, log::iter::decode::Error>> + 'a>> {
114+ ) -> std::io::Result<Option<impl Iterator<Item = Result<log::LineRef<'b>, log::iter::decode::Error>> + 'a>> {
116115 match self {
117− Reference::Loose(r) => store.reflog_iter(r.name.borrow(), buf).map_err(must_be_io_err),
116+ Reference::Loose(r) => store.reflog_iter(r.name.to_ref(), buf).map_err(must_be_io_err),
118117 Reference::Packed(p) => store.reflog_iter(p.name, buf).map_err(must_be_io_err),
119118 }
120119 }
@@ -128,9 +127,9 @@ impl<'p> Reference<'p> { · 7 unmodified lines
128127 }
129128
130129 /// Transform this reference into an owned `Target`
131− pub fn into_target(self) -> mutable::Target {
130+ pub fn into_target(self) -> Target {
132131 match self {
133− Reference::Packed(p) => mutable::Target::Peeled(p.object()),
132+ Reference::Packed(p) => Target::Peeled(p.object()),
134133 Reference::Loose(r) => r.target,
135134 }
136135 }
@@ -144,28 +143,28 @@ impl<'p> Reference<'p> { · 7 unmodified lines
144143 }
145144
146145 /// Return the full validated name of the reference, which may include a namespace.
147− pub fn name(&self) -> FullName<'_> {
146+ pub fn name(&self) -> FullNameRef<'_> {
148147 match self {
149148 Reference::Packed(p) => p.name,
150− Reference::Loose(l) => l.name.borrow(),
149+ Reference::Loose(l) => l.name.to_ref(),
151150 }
152151 }
153152
154153 /// Return the full validated name of the reference, with the given namespace stripped if possible.
155154 ///
156155 /// If the reference name wasn't prefixed with `namespace`, `None` is returned instead.
157− pub fn name_without_namespace(&self, namespace: &Namespace) -> Option<FullName<'_>> {
156+ pub fn name_without_namespace(&self, namespace: &Namespace) -> Option<FullNameRef<'_>> {
158157 self.name()
159158 .0
160159 .as_bstr()
161160 .strip_prefix(namespace.0.as_bstr().as_ref())
162− .map(|stripped| FullName(stripped.as_bstr()))
161+ .map(|stripped| FullNameRef(stripped.as_bstr()))
163162 }
164163
165164 /// Return the target to which the reference points to.
166− pub fn target(&self) -> mutable::Target {
165+ pub fn target(&self) -> Target {
167166 match self {
168− Reference::Packed(p) => mutable::Target::Peeled(p.target()),
167+ Reference::Packed(p) => Target::Peeled(p.target()),
169168 Reference::Loose(l) => l.target.clone(),
170169 }
171170 }
git-ref/src/store/file/transaction/commit.rs+2−2
@@ -1,7 +1,7 @@
11 use crate::{
2− mutable::Target,
32 store::file::{transaction::PackedRefs, Transaction},
43 transaction::{Change, LogChange, RefEdit, RefLog},
4+ Target,
55 };
66
77 impl<'s> Transaction<'s> {
@@ -102,7 +102,7 @@ impl<'s> Transaction<'s> { · 94 unmodified lines
102102 Change::Delete { .. } => {
103103 // Reflog deletion happens first in case it fails a ref without log is less terrible than
104104 // a log without a reference.
105− let reflog_path = self.store.reflog_path(change.update.name.borrow());
105+ let reflog_path = self.store.reflog_path(change.update.name.to_ref());
106106 if let Err(err) = std::fs::remove_file(&reflog_path) {
107107 if err.kind() != std::io::ErrorKind::NotFound {
108108 return Err(Error::DeleteReflog {
git-ref/src/store/file/transaction/prepare.rs+6−6
@@ -1,5 +1,4 @@
11 use crate::{
2− mutable::Target,
32 packed,
43 store::{
54 file,
@@ -10,6 +9,7 @@ use crate::{ · 4 unmodified lines
109 },
1110 },
1211 transaction::{Change, Create, LogChange, RefEdit, RefEditsExt, RefLog},
12+ Target,
1313 };
1414
1515 impl<'s> Transaction<'s> {
@@ -44,7 +44,7 @@ impl<'s> Transaction<'s> { · 28 unmodified lines
4444 })
4545 .and_then(|maybe_loose| match (maybe_loose, packed) {
4646 (None, Some(packed)) => packed
47− .find(change.update.name.borrow())
47+ .try_find(change.update.name.to_ref())
4848 .map(|opt| opt.map(file::Reference::Packed))
4949 .map_err(Error::from),
5050 (None, None) => Ok(None),
@@ -104,7 +104,7 @@ impl<'s> Transaction<'s> { · 53 unmodified lines
104104
105105 let existing_ref = existing_ref?;
106106 match (&previous, &existing_ref) {
107− (Create::Only, Some(existing)) if existing.target() != new.borrow() => {
107+ (Create::Only, Some(existing)) if existing.target() != new.to_ref() => {
108108 let new = new.clone();
109109 return Err(Error::MustNotExist {
110110 full_name: change.name(),
@@ -191,7 +191,7 @@ impl<'s> Transaction<'s> { · 80 unmodified lines
191191 |name| {
192192 let symbolic_refs_are_never_packed = None;
193193 store
194− .find_existing(name, symbolic_refs_are_never_packed)
194+ .find(name, symbolic_refs_are_never_packed)
195195 .map(|r| r.into_target())
196196 .ok()
197197 },
@@ -321,7 +321,7 @@ impl<'s> Transaction<'s> { · 123 unmodified lines
321321
322322 // traverse parent chain from leaf/peeled ref and set the leaf previous oid accordingly
323323 // to help with their reflog entries
324− if let (Some(crate::Target::Peeled(oid)), Some(parent_idx)) =
324+ if let (Some(crate::TargetRef::Peeled(oid)), Some(parent_idx)) =
325325 (change.update.change.previous_value(), change.parent_index)
326326 {
327327 let oid = oid.to_owned();
@@ -342,8 +342,8 @@ mod error { · 14 unmodified lines
342342 use quick_error::quick_error;
343343
344344 use crate::{
345− mutable::Target,
346345 store::{file, packed},
346+ Target,
347347 };
348348
349349 quick_error! {
git-ref/src/store/packed/decode.rs+1−1
@@ -73,7 +73,7 @@ pub fn reference<'a, E: ParseError<&'a [u8]> + FromExternalError<&'a [u8], crate · 72 unmodified lines
7373 ) -> IResult<&'a [u8], packed::Reference<'a>, E> {
7474 let (input, (target, name)) = tuple((
7575 terminated(hex_hash, tag(b" ")),
76− map_res(until_newline, crate::FullName::try_from),
76+ map_res(until_newline, crate::FullNameRef::try_from),
7777 ))(input)?;
7878 let (rest, object) = opt(delimited(tag(b"^"), hex_hash, newline))(input)?;
7979 Ok((rest, packed::Reference { name, target, object }))
git-ref/src/store/packed/decode/tests.rs+3−3
@@ -7,7 +7,7 @@ mod reference { · 6 unmodified lines
77 use super::Result;
88 use crate::{
99 store::{packed, packed::decode},
10− FullName,
10+ FullNameRef,
1111 };
1212
1313 #[test]
@@ -28,7 +28,7 @@ mod reference { · 14 unmodified lines
2828 assert_eq!(
2929 parsed,
3030 packed::Reference {
31− name: FullName("refs/heads/alternates-after-packs-and-loose".into()),
31+ name: FullNameRef("refs/heads/alternates-after-packs-and-loose".into()),
3232 target: "d53c4b0f91f1b29769c9430f2d1c0bcab1170c75".into(),
3333 object: Some("e9cdc958e7ce2290e2d7958cdb5aa9323ef35d37".into())
3434 }
@@ -38,7 +38,7 @@ mod reference { · 3 unmodified lines
3838
3939 let (input, parsed) = decode::reference::<VerboseError<_>>(input)?;
4040 assert!(input.is_empty(), "exhausted");
41− assert_eq!(parsed.name, FullName("refs/heads/avoid-double-lookup".into()));
41+ assert_eq!(parsed.name, FullNameRef("refs/heads/avoid-double-lookup".into()));
4242 assert_eq!(parsed.target, "eaae9c1bc723209d793eb93f5587fa2604d5cd92");
4343 assert!(parsed.object.is_none());
4444 Ok(())
git-ref/src/store/packed/find.rs+6−6
@@ -2,14 +2,14 @@ use std::{borrow::Cow, convert::TryInto}; · 1 unmodified line
22
33 use bstr::{BStr, BString, ByteSlice};
44
5−use crate::{store::packed, PartialName};
5+use crate::{store::packed, PartialNameRef};
66
77 /// packed-refs specific functionality
88 impl packed::Buffer {
99 /// Find a reference with the given `name` and return it.
10− pub fn find<'a, Name, E>(&self, name: Name) -> Result<Option<packed::Reference<'_>>, Error>
10+ pub fn try_find<'a, Name, E>(&self, name: Name) -> Result<Option<packed::Reference<'_>>, Error>
1111 where
12− Name: TryInto<PartialName<'a>, Error = E>,
12+ Name: TryInto<PartialNameRef<'a>, Error = E>,
1313 Error: From<E>,
1414 {
1515 let name = name.try_into()?;
@@ -52,12 +52,12 @@ impl packed::Buffer { · 36 unmodified lines
5252 }
5353
5454 /// Find a reference with the given `name` and return it.
55− pub fn find_existing<'a, Name, E>(&self, name: Name) -> Result<packed::Reference<'_>, existing::Error>
55+ pub fn find<'a, Name, E>(&self, name: Name) -> Result<packed::Reference<'_>, existing::Error>
5656 where
57− Name: TryInto<PartialName<'a>, Error = E>,
57+ Name: TryInto<PartialNameRef<'a>, Error = E>,
5858 Error: From<E>,
5959 {
60− match self.find(name) {
60+ match self.try_find(name) {
6161 Ok(Some(r)) => Ok(r),
6262 Ok(None) => Err(existing::Error::NotFound),
6363 Err(err) => Err(existing::Error::Find(err)),
git-ref/src/store/packed/mod.rs+2−2
@@ -4,7 +4,7 @@ use bstr::{BStr, BString}; · 3 unmodified lines
44 use filebuffer::FileBuffer;
55 use git_hash::ObjectId;
66
7−use crate::{transaction::RefEdit, FullName};
7+use crate::{transaction::RefEdit, FullNameRef};
88
99 enum Backing {
1010 /// The buffer is loaded entirely in memory, along with the `offset` to the first record past the header.
@@ -42,7 +42,7 @@ pub(crate) struct Transaction { · 31 unmodified lines
4242 #[derive(Debug, PartialEq, Eq)]
4343 pub struct Reference<'a> {
4444 /// The validated full name of the reference.
45− pub name: FullName<'a>,
45+ pub name: FullNameRef<'a>,
4646 /// The target object id of the reference, hex encoded.
4747 pub target: &'a BStr,
4848 /// The fully peeled object id, hex encoded, that the ref is ultimately pointing to
git-ref/src/store/packed/transaction.rs+2−4
@@ -1,9 +1,9 @@
11 use std::io::Write;
22
33 use crate::{
4− mutable::Target,
54 store::{file::transaction::FindObjectFn, packed, packed::Edit},
65 transaction::{Change, RefEdit},
6+ Target,
77 };
88
99 pub(crate) const HEADER_LINE: &[u8] = b"# pack-refs with: peeled fully-peeled sorted \n";
@@ -54,9 +54,7 @@ impl packed::Transaction { · 44 unmodified lines
5454 .into_iter()
5555 .filter(|edit| {
5656 if let Change::Delete { .. } = edit.change {
57− buffer
58− .as_ref()
59− .map_or(true, |b| b.find_existing(edit.name.borrow()).is_ok())
57+ buffer.as_ref().map_or(true, |b| b.find(edit.name.to_ref()).is_ok())
6058 } else {
6159 true
6260 }
git-ref/src/target.rs+83−8
@@ -1,9 +1,38 @@
1−use bstr::BStr;
2−use git_hash::oid;
1+use bstr::{BStr, ByteSlice};
2+use git_hash::{oid, ObjectId};
3+use std::fmt;
34
4−use crate::{Kind, Target};
5+use crate::{FullName, Kind, Target, TargetRef};
56
6−impl<'a> Target<'a> {
7+impl<'a> TargetRef<'a> {
8+ /// Returns the kind of the target the ref is pointing to.
9+ pub fn kind(&self) -> Kind {
10+ match self {
11+ TargetRef::Symbolic(_) => Kind::Symbolic,
12+ TargetRef::Peeled(_) => Kind::Peeled,
13+ }
14+ }
15+ /// Interpret this target as object id which maybe `None` if it is symbolic.
16+ pub fn as_id(&self) -> Option<&oid> {
17+ match self {
18+ TargetRef::Symbolic(_) => None,
19+ TargetRef::Peeled(oid) => Some(oid),
20+ }
21+ }
22+ /// Interpret this target as name of the reference it points to which maybe `None` if it an object id.
23+ pub fn as_name(&self) -> Option<&BStr> {
24+ match self {
25+ TargetRef::Symbolic(path) => Some(path),
26+ TargetRef::Peeled(_) => None,
27+ }
28+ }
29+ /// Convert this instance into an owned version, without consuming it.
30+ pub fn into_owned(self) -> crate::Target {
31+ self.into()
32+ }
33+}
34+
35+impl Target {
736 /// Returns the kind of the target the ref is pointing to.
837 pub fn kind(&self) -> Kind {
938 match self {
@@ -11,6 +40,23 @@ impl<'a> Target<'a> { · 1 unmodified line
1140 Target::Peeled(_) => Kind::Peeled,
1241 }
1342 }
43+
44+ /// Return true if this is a peeled target with a null hash
45+ pub fn is_null(&self) -> bool {
46+ match self {
47+ Target::Peeled(oid) => oid.is_null(),
48+ Target::Symbolic(_) => false,
49+ }
50+ }
51+
52+ /// Interpret this owned Target as shared Target
53+ pub fn to_ref(&self) -> crate::TargetRef<'_> {
54+ match self {
55+ Target::Peeled(oid) => crate::TargetRef::Peeled(oid),
56+ Target::Symbolic(name) => crate::TargetRef::Symbolic(name.0.as_bstr()),
57+ }
58+ }
59+
1460 /// Interpret this target as object id which maybe `None` if it is symbolic.
1561 pub fn as_id(&self) -> Option<&oid> {
1662 match self {
@@ -21,12 +67,41 @@ impl<'a> Target<'a> { · 4 unmodified lines
2167 /// Interpret this target as name of the reference it points to which maybe `None` if it an object id.
2268 pub fn as_name(&self) -> Option<&BStr> {
2369 match self {
24− Target::Symbolic(path) => Some(path),
70+ Target::Symbolic(name) => Some(name.as_bstr()),
2571 Target::Peeled(_) => None,
2672 }
2773 }
28− /// Convert this instance into an owned version, without consuming it.
29− pub fn to_owned(self) -> crate::mutable::Target {
30− self.into()
74+
75+ /// Create an instance that signals that a reference should exist if this value is used in a [`Change`][crate::transaction::Change].
76+ pub fn must_exist() -> Self {
77+ Target::Peeled(ObjectId::null_sha1())
78+ }
79+}
80+
81+impl<'a> From<crate::TargetRef<'a>> for Target {
82+ fn from(src: crate::TargetRef<'a>) -> Self {
83+ match src {
84+ crate::TargetRef::Peeled(oid) => Target::Peeled(oid.to_owned()),
85+ crate::TargetRef::Symbolic(name) => Target::Symbolic(FullName(name.to_owned())),
86+ }
87+ }
88+}
89+
90+impl<'a> PartialEq<crate::TargetRef<'a>> for Target {
91+ fn eq(&self, other: &crate::TargetRef<'a>) -> bool {
92+ match (self, other) {
93+ (Target::Peeled(lhs), crate::TargetRef::Peeled(rhs)) => lhs == rhs,
94+ (Target::Symbolic(lhs), crate::TargetRef::Symbolic(rhs)) => lhs.as_bstr() == *rhs,
95+ _ => false,
96+ }
97+ }
98+}
99+
100+impl fmt::Display for Target {
101+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
102+ match self {
103+ Target::Peeled(oid) => oid.fmt(f),
104+ Target::Symbolic(name) => write!(f, "ref: {}", name.as_bstr()),
105+ }
31106 }
32107 }
git-ref/src/transaction.rs+7−7
@@ -15,7 +15,7 @@ · 14 unmodified lines
1515 use bstr::BString;
1616 use git_hash::ObjectId;
1717
18−use crate::mutable::{FullName, Target};
18+use crate::{FullName, Target};
1919
2020 /// A change to the reflog.
2121 #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
@@ -101,14 +101,14 @@ pub enum Change { · 79 unmodified lines
101101
102102 impl Change {
103103 /// Return references to values that are in common between all variants.
104− pub fn previous_value(&self) -> Option<crate::Target<'_>> {
104+ pub fn previous_value(&self) -> Option<crate::TargetRef<'_>> {
105105 match self {
106106 Change::Update { mode: Create::Only, .. } => None,
107107 Change::Update {
108108 mode: Create::OrUpdate { previous },
109109 ..
110110 }
111− | Change::Delete { previous, .. } => previous.as_ref().map(|t| t.borrow()),
111+ | Change::Delete { previous, .. } => previous.as_ref().map(|t| t.to_ref()),
112112 }
113113 }
114114 }
@@ -139,7 +139,7 @@ mod ext { · 24 unmodified lines
139139
140140 use crate::{
141141 transaction::{Change, LogChange, RefEdit, RefLog, Target},
142− Namespace, PartialName,
142+ Namespace, PartialNameRef,
143143 };
144144
145145 /// An extension trait to perform commonly used operations on edits across different ref stores.
@@ -155,7 +155,7 @@ mod ext { · 9 unmodified lines
155155 /// Note no action is performed if deref isn't specified.
156156 fn extend_with_splits_of_symbolic_refs(
157157 &mut self,
158− find: impl FnMut(PartialName<'_>) -> Option<Target>,
158+ find: impl FnMut(PartialNameRef<'_>) -> Option<Target>,
159159 make_entry: impl FnMut(usize, RefEdit) -> T,
160160 ) -> Result<(), std::io::Error>;
161161
@@ -168,7 +168,7 @@ mod ext { · 6 unmodified lines
168168 /// Users call this to assure derefs are honored and duplicate checks are done.
169169 fn pre_process(
170170 &mut self,
171− find: impl FnMut(PartialName<'_>) -> Option<Target>,
171+ find: impl FnMut(PartialNameRef<'_>) -> Option<Target>,
172172 make_entry: impl FnMut(usize, RefEdit) -> T,
173173 namespace: impl Into<Option<Namespace>>,
174174 ) -> Result<(), std::io::Error> {
@@ -198,7 +198,7 @@ mod ext { · 23 unmodified lines
198198
199199 fn extend_with_splits_of_symbolic_refs(
200200 &mut self,
201− mut find: impl FnMut(PartialName<'_>) -> Option<Target>,
201+ mut find: impl FnMut(PartialNameRef<'_>) -> Option<Target>,
202202 mut make_entry: impl FnMut(usize, RefEdit) -> E,
203203 ) -> Result<(), std::io::Error> {
204204 let mut new_edits = Vec::new();
git-ref/tests/file/log.rs+5−5
@@ -6,7 +6,7 @@ mod line { · 5 unmodified lines
66 #[test]
77 fn newlines_in_message_of_the_input_fails_and_we_trust_signature_writing_validation() -> crate::Result {
88 let line = "0000000000000000000000000000000000000000 134385f6d781b7e97062102c6a483440bfda2a03 committer <committer@example.com> 946771200 +0000 commit (initial): c1";
9− let mut line = log::Line::from_bytes(line.as_bytes())?.to_mutable();
9+ let mut line = log::LineRef::from_bytes(line.as_bytes())?.to_owned();
1010 line.message.push_str("and here come\nthe newline");
1111 let err = line
1212 .write_to(&mut Vec::new())
@@ -20,10 +20,10 @@ mod line { · 7 unmodified lines
2020 let lines = &["0000000000000000000000000000000000000000 134385f6d781b7e97062102c6a483440bfda2a03 committer <committer@example.com> 946771200 +0000 commit (initial): c1\n",
2121 "0000000000000000000000000000000000000000 134385f6d781b7e97062102c6a483440bfda2a03 committer <committer@example.com> 946771200 +0000 \n"];
2222 for line in lines {
23− let line = log::Line::from_bytes(line.as_bytes())?;
23+ let line = log::LineRef::from_bytes(line.as_bytes())?;
2424 let mut buf = Vec::new();
25− line.to_mutable().write_to(&mut buf)?;
26− let same_line = log::Line::from_bytes(&buf)?;
25+ line.to_owned().write_to(&mut buf)?;
26+ let same_line = log::LineRef::from_bytes(&buf)?;
2727 assert_eq!(line, same_line);
2828 }
2929 Ok(())
@@ -75,7 +75,7 @@ mod iter { · 45 unmodified lines
7575 }
7676
7777 mod with_buffer_big_enough_for_largest_line {
78− use git_ref::file::log::mutable::Line;
78+ use git_ref::file::log::Line;
7979 use git_testtools::hex_to_id;
8080
8181 #[test]
git-ref/tests/file/reference.rs+16−16
@@ -6,7 +6,7 @@ mod reflog { · 5 unmodified lines
66 fn iter() -> crate::Result {
77 let store = file::store_with_packed_refs()?;
88 let packed = store.packed_buffer()?;
9− let r = store.find_existing("main", packed.as_ref())?;
9+ let r = store.find("main", packed.as_ref())?;
1010 let mut buf = Vec::new();
1111 assert_eq!(r.log_iter(&store, &mut buf)?.expect("log exists").count(), 1);
1212 assert!(r.log_exists(&store), "it exists if its readable");
@@ -17,7 +17,7 @@ mod reflog { · 4 unmodified lines
1717 fn iter_rev() -> crate::Result {
1818 let store = file::store_with_packed_refs()?;
1919 let packed = store.packed_buffer()?;
20− let r = store.find_existing("main", packed.as_ref())?;
20+ let r = store.find("main", packed.as_ref())?;
2121 let mut buf = [0u8; 256];
2222 assert_eq!(r.log_iter_rev(&store, &mut buf)?.expect("log exists").count(), 1);
2323 Ok(())
@@ -30,7 +30,7 @@ mod reflog { · 6 unmodified lines
3030 #[test]
3131 fn iter() -> crate::Result {
3232 let store = file::store()?;
33− let r = store.loose_find_existing("HEAD")?;
33+ let r = store.find_loose("HEAD")?;
3434 let mut buf = Vec::new();
3535 assert_eq!(r.log_iter(&store, &mut buf)?.expect("log exists").count(), 1);
3636 assert!(r.log_exists(&store), "it exists if its readable");
@@ -40,7 +40,7 @@ mod reflog { · 3 unmodified lines
4040 #[test]
4141 fn iter_rev() -> crate::Result {
4242 let store = file::store()?;
43− let r = store.loose_find_existing("HEAD")?;
43+ let r = store.find_loose("HEAD")?;
4444 let mut buf = [0u8; 256];
4545 assert_eq!(r.log_iter_rev(&store, &mut buf)?.expect("log exists").count(), 1);
4646 Ok(())
@@ -60,7 +60,7 @@ mod peel { · 13 unmodified lines
6060 #[test]
6161 fn one_level() -> crate::Result {
6262 let store = file::store()?;
63− let r = store.loose_find_existing("HEAD")?;
63+ let r = store.find_loose("HEAD")?;
6464 assert_eq!(r.kind(), git_ref::Kind::Symbolic, "there is something to peel");
6565
6666 let nr = git_ref::file::loose::Reference::try_from(
@@ -68,13 +68,13 @@ mod peel { · 1 unmodified line
6868 )
6969 .expect("loose ref");
7070 assert!(
71− matches!(nr.target.borrow(), git_ref::Target::Peeled(_)),
71+ matches!(nr.target.to_ref(), git_ref::TargetRef::Peeled(_)),
7272 "iteration peels a single level"
7373 );
7474 assert!(nr.follow_symbolic(&store, None).is_none(), "end of iteration");
7575 assert_eq!(
76− nr.target.borrow(),
77− git_ref::Target::Peeled(&hex_to_id("134385f6d781b7e97062102c6a483440bfda2a03")),
76+ nr.target.to_ref(),
77+ git_ref::TargetRef::Peeled(&hex_to_id("134385f6d781b7e97062102c6a483440bfda2a03")),
7878 "we still have the peeled target"
7979 );
8080 Ok(())
@@ -83,13 +83,13 @@ mod peel { · 2 unmodified lines
8383 #[test]
8484 fn peel_with_packed_involvement() -> crate::Result {
8585 let store = store_with_packed_refs()?;
86− let mut head = store.loose_find_existing("HEAD")?;
86+ let mut head = store.find_loose("HEAD")?;
8787 let packed = store.packed_buffer()?;
8888 let expected = hex_to_id("134385f6d781b7e97062102c6a483440bfda2a03");
8989 assert_eq!(head.peel_to_id_in_place(&store, packed.as_ref(), peel::none)?, expected);
9090 assert_eq!(head.target.as_id().map(ToOwned::to_owned), Some(expected));
9191
92− let mut head = store.find_existing("dt1", packed.as_ref())?;
92+ let mut head = store.find("dt1", packed.as_ref())?;
9393 assert_eq!(head.peel_to_id_in_place(&store, packed.as_ref(), peel::none)?, expected);
9494 assert_eq!(head.target().as_id().map(ToOwned::to_owned), Some(expected));
9595 Ok(())
@@ -100,7 +100,7 @@ mod peel { · 4 unmodified lines
100100 let store = store_with_packed_refs()?;
101101 let packed = store.packed_buffer()?;
102102
103− let head = store.find_existing("dt1", packed.as_ref())?;
103+ let head = store.find("dt1", packed.as_ref())?;
104104 assert!(head.is_packed());
105105 assert_eq!(
106106 head.target().as_id().map(ToOwned::to_owned),
@@ -128,14 +128,14 @@ mod peel { · 21 unmodified lines
128128 #[test]
129129 fn to_id_multi_hop() -> crate::Result {
130130 let store = file::store()?;
131− let mut r = store.loose_find_existing("multi-link")?;
131+ let mut r = store.find_loose("multi-link")?;
132132 assert_eq!(r.kind(), git_ref::Kind::Symbolic, "there is something to peel");
133133
134134 let commit = hex_to_id("134385f6d781b7e97062102c6a483440bfda2a03");
135135 assert_eq!(r.peel_to_id_in_place(&store, None, peel::none)?, commit);
136136 assert_eq!(r.name.as_bstr(), "refs/remotes/origin/multi-link-target3");
137137
138− let mut r = store.loose_find_existing("dt1")?;
138+ let mut r = store.find_loose("dt1")?;
139139 assert_eq!(
140140 r.peel_to_id_in_place(&store, None, peel::none)?,
141141 hex_to_id("4c3f4cce493d7beb45012e478021b5f65295e5a3"),
@@ -158,7 +158,7 @@ mod peel { · 16 unmodified lines
158158 #[test]
159159 fn to_id_cycle() -> crate::Result {
160160 let store = file::store()?;
161− let mut r = store.loose_find_existing("loop-a")?;
161+ let mut r = store.find_loose("loop-a")?;
162162 assert_eq!(r.kind(), git_ref::Kind::Symbolic, "there is something to peel");
163163 assert_eq!(r.name.as_bstr(), "refs/loop-a");
164164
@@ -203,8 +203,8 @@ mod parse { · 38 unmodified lines
203203 let reference =
204204 Reference::try_from_path("HEAD".try_into().expect("valid static name"), $input).unwrap();
205205 assert_eq!(reference.kind(), $kind);
206− assert_eq!(reference.target.borrow().as_id(), $id);
207− assert_eq!(reference.target.borrow().as_name(), $ref);
206+ assert_eq!(reference.target.to_ref().as_id(), $id);
207+ assert_eq!(reference.target.to_ref().as_name(), $ref);
208208 }
209209 };
210210 }
git-ref/tests/file/store/find.rs+6−6
@@ -8,8 +8,8 @@ mod existing { · 7 unmodified lines
88 let store = store_at("make_packed_ref_repository_for_overlay.sh")?;
99 let c1 = hex_to_id("134385f6d781b7e97062102c6a483440bfda2a03");
1010 let packed = store.packed_buffer()?;
11− let r = store.find_existing("main", packed.as_ref())?;
12− assert_eq!(r.target().borrow().as_id().expect("peeled"), c1);
11+ let r = store.find("main", packed.as_ref())?;
12+ assert_eq!(r.target().to_ref().as_id().expect("peeled"), c1);
1313 assert_eq!(r.name().as_bstr(), "refs/heads/main");
1414 Ok(())
1515 }
@@ -27,7 +27,7 @@ mod loose { · 11 unmodified lines
2727 fn success_and_failure() -> crate::Result {
2828 let store = store()?;
2929 for (partial_name, expected_path) in &[("main", Some("refs/heads/main")), ("does-not-exist", None)] {
30− let reference = store.loose_find_existing(*partial_name);
30+ let reference = store.find_loose(*partial_name);
3131 match expected_path {
3232 Some(expected_path) => assert_eq!(reference?.name.as_bstr(), expected_path),
3333 None => match reference {
@@ -60,9 +60,9 @@ mod loose { · 26 unmodified lines
6060 ("heads/main", "refs/heads/main", git_ref::Kind::Peeled),
6161 ("refs/heads/main", "refs/heads/main", git_ref::Kind::Peeled),
6262 ] {
63− let reference = store.loose_find(*partial_name)?.expect("exists");
63+ let reference = store.try_find_loose(*partial_name)?.expect("exists");
6464 assert_eq!(reference.name.as_bstr(), expected_path);
65− assert_eq!(reference.target.borrow().kind(), *expected_ref_kind);
65+ assert_eq!(reference.target.to_ref().kind(), *expected_ref_kind);
6666 }
6767 Ok(())
6868 }
@@ -75,7 +75,7 @@ mod loose { · 6 unmodified lines
7575 ("broken", "does not parse", true),
7676 ("../escaping", "an invalid ref name", true),
7777 ] {
78− let reference = store.loose_find(*partial_name);
78+ let reference = store.try_find_loose(*partial_name);
7979 if *is_err {
8080 assert!(reference.is_err(), "{}", reason);
8181 } else {
git-ref/tests/file/store/iter.rs+2−2
@@ -202,7 +202,7 @@ fn loose_iter_with_prefix() -> crate::Result { · 201 unmodified lines
202202
203203 #[test]
204204 fn overlay_iter() -> crate::Result {
205− use git_ref::mutable::Target::*;
205+ use git_ref::Target::*;
206206
207207 let store = store_at("make_packed_ref_repository_for_overlay.sh")?;
208208 let ref_names = store
@@ -249,7 +249,7 @@ fn overlay_iter_with_prefix_wont_allow_absolute_paths() -> crate::Result { · 40 unmodified lines
249249
250250 #[test]
251251 fn overlay_prefixed_iter() -> crate::Result {
252− use git_ref::mutable::Target::*;
252+ use git_ref::Target::*;
253253
254254 let store = store_at("make_packed_ref_repository_for_overlay.sh")?;
255255 let ref_names = store
git-ref/tests/file/transaction/mod.rs+6−5
@@ -1,15 +1,16 @@
11 mod prepare_and_commit {
22 use bstr::BString;
3+
34 use git_actor::{Sign, Time};
45 use git_hash::ObjectId;
5− use git_ref::{file, file::log};
6+ use git_ref::file;
67
7− fn reflog_lines(store: &file::Store, name: &str) -> crate::Result<Vec<log::mutable::Line>> {
8+ fn reflog_lines(store: &file::Store, name: &str) -> crate::Result<Vec<file::log::Line>> {
89 let mut buf = Vec::new();
910 let res = store
1011 .reflog_iter(name, &mut buf)?
1112 .expect("existing reflog")
12− .map(|l| l.map(log::mutable::Line::from))
13+ .map(|l| l.map(file::log::Line::from))
1314 .collect::<std::result::Result<Vec<_>, _>>()?;
1415 Ok(res)
1516 }
@@ -32,8 +33,8 @@ mod prepare_and_commit { · 16 unmodified lines
3233 }
3334 }
3435
35− fn log_line(previous: ObjectId, new: ObjectId, message: impl Into<BString>) -> log::mutable::Line {
36− log::mutable::Line {
36+ fn log_line(previous: ObjectId, new: ObjectId, message: impl Into<BString>) -> file::log::Line {
37+ file::log::Line {
3738 previous_oid: previous,
3839 new_oid: new,
3940 signature: committer(),
git-ref/tests/file/transaction/prepare_and_commit/create_or_update.rs+27−28
@@ -11,8 +11,8 @@ use git_ref::{ · 10 unmodified lines
1111 transaction::{self, PackedRefs},
1212 WriteReflog,
1313 },
14− mutable::Target,
1514 transaction::{Change, Create, LogChange, RefEdit, RefLog},
15+ Target,
1616 };
1717 use git_testtools::hex_to_id;
1818 use std::convert::TryInto;
@@ -46,7 +46,7 @@ fn reference_with_equally_named_empty_or_non_empty_directory_already_in_place_ca · 27 unmodified lines
4646 if *is_empty {
4747 let edits = edits?;
4848 assert!(
49− store.loose_find(edits[0].name.to_partial())?.is_some(),
49+ store.try_find_loose(edits[0].name.to_partial())?.is_some(),
5050 "HEAD was created despite a directory being in the way"
5151 );
5252 } else {
@@ -96,7 +96,7 @@ fn reference_with_old_value_must_exist_when_creating_it() -> crate::Result { · 43 unmodified lines
9696 #[test]
9797 fn reference_with_explicit_value_must_match_the_value_on_update() -> crate::Result {
9898 let (_keep, store) = store_writable("make_repo_for_reflog.sh")?;
99− let head = store.loose_find("HEAD")?.expect("head exists already");
99+ let head = store.try_find_loose("HEAD")?.expect("head exists already");
100100 let target = head.target;
101101
102102 let res = store.transaction().prepare(
@@ -126,7 +126,7 @@ fn reference_with_explicit_value_must_match_the_value_on_update() -> crate::Resu · 23 unmodified lines
126126 #[test]
127127 fn reference_with_create_only_must_not_exist_already_when_creating_it_if_the_value_does_not_match() -> crate::Result {
128128 let (_keep, store) = store_writable("make_repo_for_reflog.sh")?;
129− let head = store.loose_find("HEAD")?.expect("head exists already");
129+ let head = store.try_find_loose("HEAD")?.expect("head exists already");
130130 let target = head.target;
131131
132132 let res = store.transaction().prepare(
@@ -211,7 +211,7 @@ fn namespaced_updates_or_deletions_cause_reference_names_to_be_rewritten_and_obs · 78 unmodified lines
211211 #[test]
212212 fn reference_with_create_only_must_not_exist_already_when_creating_it_unless_the_value_matches() -> crate::Result {
213213 let (_keep, store) = store_writable("make_repo_for_reflog.sh")?;
214− let head = store.loose_find("HEAD")?.expect("head exists already");
214+ let head = store.try_find_loose("HEAD")?.expect("head exists already");
215215 let target = head.target;
216216 let previous_reflog_count = reflog_lines(&store, "HEAD")?.len();
217217
@@ -289,7 +289,10 @@ fn symbolic_head_missing_referent_then_update_referent() -> crate::Result { · 71 unmodified lines
289289 let (_keep, mut store) = empty_store()?;
290290 store.write_reflog = *reflog_writemode;
291291 let referent = "refs/heads/alt-main";
292− assert!(store.loose_find(referent)?.is_none(), "the reference does not exist");
292+ assert!(
293+ store.try_find_loose(referent)?.is_none(),
294+ "the reference does not exist"
295+ );
293296 let log_ignored = LogChange {
294297 mode: RefLog::AndReference,
295298 force_create_reflog: false,
@@ -325,12 +328,12 @@ fn symbolic_head_missing_referent_then_update_referent() -> crate::Result { · 29 unmodified lines
325328 "no split was performed"
326329 );
327330
328− let head = store.loose_find_existing(edits[0].name.to_partial())?;
331+ let head = store.find_loose(edits[0].name.to_partial())?;
329332 assert_eq!(head.name.as_bstr(), "HEAD");
330333 assert_eq!(head.kind(), git_ref::Kind::Symbolic);
331− assert_eq!(head.target.borrow().as_name(), Some(referent.as_bytes().as_bstr()));
334+ assert_eq!(head.target.to_ref().as_name(), Some(referent.as_bytes().as_bstr()));
332335 assert!(!head.log_exists(&store), "no reflog is written for symbolic ref");
333− assert!(store.loose_find(referent)?.is_none(), "referent wasn't created");
336+ assert!(store.try_find_loose(referent)?.is_none(), "referent wasn't created");
334337
335338 let new_oid = hex_to_id("28ce6a8b26aa170e1de65536fe8abe1832bd3242");
336339 let new = Target::Peeled(new_oid);
@@ -386,22 +389,22 @@ fn symbolic_head_missing_referent_then_update_referent() -> crate::Result { · 49 unmodified lines
386389 ]
387390 );
388391
389− let head = store.loose_find_existing("HEAD")?;
392+ let head = store.find_loose("HEAD")?;
390393 assert_eq!(
391394 head.kind(),
392395 git_ref::Kind::Symbolic,
393396 "head is still symbolic, not detached"
394397 );
395398 assert_eq!(
396− head.target.borrow().as_name(),
399+ head.target.to_ref().as_name(),
397400 Some(referent.as_bytes().as_bstr()),
398401 "it still points to the referent"
399402 );
400403
401− let referent_ref = store.loose_find_existing(referent)?;
404+ let referent_ref = store.find_loose(referent)?;
402405 assert_eq!(referent_ref.kind(), git_ref::Kind::Peeled, "referent is a peeled ref");
403406 assert_eq!(
404− referent_ref.target.borrow().as_id(),
407+ referent_ref.target.to_ref().as_id(),
405408 Some(new_oid.as_ref()),
406409 "referent points to desired hash"
407410 );
@@ -430,8 +433,8 @@ fn symbolic_head_missing_referent_then_update_referent() -> crate::Result { · 22 unmodified lines
430433 /// be needed to keep the reflog consistent
431434 fn write_reference_to_which_head_points_to_does_not_update_heads_reflog_even_though_it_should() -> crate::Result {
432435 let (_keep, store) = store_writable("make_repo_for_reflog.sh")?;
433− let head = store.loose_find_existing("HEAD")?;
434− let referent = head.target.borrow().as_name().expect("symbolic ref").to_owned();
436+ let head = store.find_loose("HEAD")?;
437+ let referent = head.target.to_ref().as_name().expect("symbolic ref").to_owned();
435438 let previous_head_reflog = reflog_lines(&store, "HEAD")?;
436439
437440 let new_id = hex_to_id("01dd4e2a978a9f5bd773dae6da7aa4a5ac1cdbbc");
@@ -497,7 +500,7 @@ fn write_reference_to_which_head_points_to_does_not_update_heads_reflog_even_tho · 59 unmodified lines
497500 fn packed_refs_are_looked_up_when_checking_existing_values() -> crate::Result {
498501 let (_keep, store) = store_writable("make_packed_ref_repository.sh")?;
499502 assert!(
500− store.loose_find("main")?.is_none(),
503+ store.try_find_loose("main")?.is_none(),
501504 "no loose main available, it's packed"
502505 );
503506 let new_id = hex_to_id("0000000000000000000000000000000000000001");
@@ -528,12 +531,12 @@ fn packed_refs_are_looked_up_when_checking_existing_values() -> crate::Result { · 24 unmodified lines
528531
529532 let packed = store.packed_buffer().unwrap().expect("packed refs is available");
530533 assert_eq!(
531− packed.find_existing("main")?.target(),
532− old_id,
533− "packed refs aren't rewritten, the change goes into the loose ref instead which shadows packed refs of same name"
534+ packed.find("main")?.target(),
535+ old_id,
536+ "packed refs aren't rewritten, the change goes into the loose ref instead which shadows packed refs of same name"
534537 );
535538 assert_eq!(
536− store.loose_find_existing("main")?.target.as_id(),
539+ store.find_loose("main")?.target.as_id(),
537540 Some(new_id.as_ref()),
538541 "the new id was written to the loose ref"
539542 );
@@ -608,10 +611,10 @@ fn packed_refs_creation_with_packed_refs_mode_prune_removes_original_loose_refs( · 68 unmodified lines
608611 #[test]
609612 fn packed_refs_creation_with_packed_refs_mode_leave_keeps_original_loose_refs() -> crate::Result {
610613 let (_keep, store) = store_writable("make_packed_ref_repository_for_overlay.sh")?;
611− let branch = store.find_existing("newer-as-loose", None)?;
614+ let branch = store.find("newer-as-loose", None)?;
612615 let packed = store.packed_buffer()?.expect("packed-refs");
613616 assert_ne!(
614− packed.find_existing("newer-as-loose")?.target(),
617+ packed.find("newer-as-loose")?.target(),
615618 branch.target().as_id().expect("peeled"),
616619 "the packed ref is outdated"
617620 );
@@ -662,12 +665,8 @@ fn packed_refs_creation_with_packed_refs_mode_leave_keeps_original_loose_refs() · 44 unmodified lines
662665 "the amount of packed refs doesn't change"
663666 );
664667 assert_eq!(
665− packed.find_existing("newer-as-loose")?.target(),
666− store
667− .find_existing("newer-as-loose", None)?
668− .target()
669− .as_id()
670− .expect("peeled"),
668+ packed.find("newer-as-loose")?.target(),
669+ store.find("newer-as-loose", None)?.target().as_id().expect("peeled"),
671670 "the packed ref is now up to date and the loose ref definitely still exists"
672671 );
673672 Ok(())
git-ref/tests/file/transaction/prepare_and_commit/delete.rs+31−29
@@ -4,8 +4,8 @@ use crate::file::{ · 3 unmodified lines
44 };
55 use git_lock::acquire::Fail;
66 use git_ref::{
7− mutable::Target,
87 transaction::{Change, RefEdit, RefLog},
8+ Target,
99 };
1010 use git_testtools::hex_to_id;
1111 use std::convert::TryInto;
@@ -58,9 +58,9 @@ fn delete_a_ref_which_is_gone_but_must_exist_fails() -> crate::Result { · 46 unmodified lines
5858 #[test]
5959 fn delete_ref_and_reflog_on_symbolic_no_deref() -> crate::Result {
6060 let (_keep, store) = store_writable("make_repo_for_reflog.sh")?;
61− let head = store.loose_find_existing("HEAD")?;
61+ let head = store.find_loose("HEAD")?;
6262 assert!(head.log_exists(&store));
63− let _main = store.loose_find_existing("main")?;
63+ let _main = store.find_loose("main")?;
6464
6565 let edits = store
6666 .transaction()
@@ -93,15 +93,15 @@ fn delete_ref_and_reflog_on_symbolic_no_deref() -> crate::Result { · 26 unmodified lines
9393 store.reflog_iter_rev("HEAD", &mut [0u8; 128])?.is_none(),
9494 "reflog was deleted"
9595 );
96− assert!(store.loose_find("HEAD")?.is_none(), "ref was deleted");
97− assert!(store.loose_find("main")?.is_some(), "referent still exists");
96+ assert!(store.try_find_loose("HEAD")?.is_none(), "ref was deleted");
97+ assert!(store.try_find_loose("main")?.is_some(), "referent still exists");
9898 Ok(())
9999 }
100100
101101 #[test]
102102 fn delete_ref_with_incorrect_previous_value_fails() -> crate::Result {
103103 let (_keep, store) = store_writable("make_repo_for_reflog.sh")?;
104− let head = store.loose_find_existing("HEAD")?;
104+ let head = store.find_loose("HEAD")?;
105105 assert!(head.log_exists(&store));
106106
107107 let res = store.transaction().prepare(
@@ -123,9 +123,9 @@ fn delete_ref_with_incorrect_previous_value_fails() -> crate::Result { · 15 unmodified lines
123123 Ok(_) => unreachable!("must be err"),
124124 }
125125 // everything stays as is
126− let head = store.loose_find_existing("HEAD")?;
126+ let head = store.find_loose("HEAD")?;
127127 assert!(head.log_exists(&store));
128− let main = store.loose_find_existing("main").expect("referent still exists");
128+ let main = store.find_loose("main").expect("referent still exists");
129129 assert!(main.log_exists(&store));
130130 Ok(())
131131 }
@@ -133,7 +133,7 @@ fn delete_ref_with_incorrect_previous_value_fails() -> crate::Result { · 1 unmodified line
133133 #[test]
134134 fn delete_reflog_only_of_symbolic_no_deref() -> crate::Result {
135135 let (_keep, store) = store_writable("make_repo_for_reflog.sh")?;
136− let head = store.loose_find_existing("HEAD")?;
136+ let head = store.find_loose("HEAD")?;
137137 assert!(head.log_exists(&store));
138138
139139 let edits = store
@@ -152,9 +152,9 @@ fn delete_reflog_only_of_symbolic_no_deref() -> crate::Result { · 12 unmodified lines
152152 .commit(&committer())?;
153153
154154 assert_eq!(edits.len(), 1);
155− let head = store.loose_find_existing("HEAD")?;
155+ let head = store.find_loose("HEAD")?;
156156 assert!(!head.log_exists(&store));
157− let main = store.loose_find_existing("main").expect("referent still exists");
157+ let main = store.find_loose("main").expect("referent still exists");
158158 assert!(main.log_exists(&store), "log is untouched, too");
159159 assert_eq!(
160160 main.target,
@@ -167,7 +167,7 @@ fn delete_reflog_only_of_symbolic_no_deref() -> crate::Result { · 6 unmodified lines
167167 #[test]
168168 fn delete_reflog_only_of_symbolic_with_deref() -> crate::Result {
169169 let (_keep, store) = store_writable("make_repo_for_reflog.sh")?;
170− let head = store.loose_find_existing("HEAD")?;
170+ let head = store.find_loose("HEAD")?;
171171 assert!(head.log_exists(&store));
172172
173173 let edits = store
@@ -186,9 +186,9 @@ fn delete_reflog_only_of_symbolic_with_deref() -> crate::Result { · 12 unmodified lines
186186 .commit(&committer())?;
187187
188188 assert_eq!(edits.len(), 2);
189− let head = store.loose_find_existing("HEAD")?;
189+ let head = store.find_loose("HEAD")?;
190190 assert!(!head.log_exists(&store));
191− let main = store.loose_find_existing("main").expect("referent still exists");
191+ let main = store.find_loose("main").expect("referent still exists");
192192 assert!(!main.log_exists(&store), "log is removed");
193193 assert_eq!(
194194 main.target,
@@ -203,7 +203,7 @@ fn delete_reflog_only_of_symbolic_with_deref() -> crate::Result { · 8 unmodified lines
203203 fn delete_broken_ref_that_must_exist_fails_as_it_is_no_valid_ref() -> crate::Result {
204204 let (_keep, store) = empty_store()?;
205205 std::fs::write(store.base.join("HEAD"), &b"broken")?;
206− assert!(store.loose_find("HEAD").is_err(), "the ref is truly broken");
206+ assert!(store.try_find_loose("HEAD").is_err(), "the ref is truly broken");
207207
208208 let res = store.transaction().prepare(
209209 Some(RefEdit {
@@ -233,7 +233,7 @@ fn delete_broken_ref_that_must_exist_fails_as_it_is_no_valid_ref() -> crate::Res · 23 unmodified lines
233233 fn delete_broken_ref_that_may_not_exist_works_even_in_deref_mode() -> crate::Result {
234234 let (_keep, store) = empty_store()?;
235235 std::fs::write(store.base.join("HEAD"), &b"broken")?;
236− assert!(store.loose_find("HEAD").is_err(), "the ref is truly broken");
236+ assert!(store.try_find_loose("HEAD").is_err(), "the ref is truly broken");
237237
238238 let edits = store
239239 .transaction()
@@ -250,7 +250,7 @@ fn delete_broken_ref_that_may_not_exist_works_even_in_deref_mode() -> crate::Res · 10 unmodified lines
250250 )?
251251 .commit(&committer())?;
252252
253− assert!(store.loose_find("HEAD")?.is_none(), "the ref was deleted");
253+ assert!(store.try_find_loose("HEAD")?.is_none(), "the ref was deleted");
254254 assert_eq!(
255255 edits,
256256 vec![RefEdit {
@@ -270,7 +270,7 @@ fn store_write_mode_has_no_effect_and_reflogs_are_always_deleted() -> crate::Res · 13 unmodified lines
270270 for reflog_writemode in &[git_ref::file::WriteReflog::Normal, git_ref::file::WriteReflog::Disable] {
271271 let (_keep, mut store) = store_writable("make_repo_for_reflog.sh")?;
272272 store.write_reflog = *reflog_writemode;
273− assert!(store.loose_find_existing("HEAD")?.log_exists(&store));
273+ assert!(store.find_loose("HEAD")?.log_exists(&store));
274274 assert!(store.packed_buffer()?.is_none(), "there is no pack");
275275
276276 let edits = store
@@ -288,10 +288,7 @@ fn store_write_mode_has_no_effect_and_reflogs_are_always_deleted() -> crate::Res · 11 unmodified lines
288288 )?
289289 .commit(&committer())?;
290290 assert_eq!(edits.len(), 1);
291− assert!(
292− !store.loose_find_existing("HEAD")?.log_exists(&store),
293− "log was deleted"
294− );
291+ assert!(!store.find_loose("HEAD")?.log_exists(&store), "log was deleted");
295292 assert!(store.packed_buffer()?.is_none(), "there still is no pack");
296293 }
297294 Ok(())
@@ -302,11 +299,11 @@ fn packed_refs_are_consulted_when_determining_previous_value_of_ref_to_be_delete · 4 unmodified lines
302299 ) -> crate::Result {
303300 let (_keep, store) = store_writable("make_packed_ref_repository.sh")?;
304301 assert!(
305− store.loose_find("main")?.is_none(),
302+ store.try_find_loose("main")?.is_none(),
306303 "no loose main available, it's packed"
307304 );
308305 assert!(
309− store.packed_buffer()?.expect("packed").find("main")?.is_some(),
306+ store.packed_buffer()?.expect("packed").try_find("main")?.is_some(),
310307 "packed main is available"
311308 );
312309
@@ -328,7 +325,7 @@ fn packed_refs_are_consulted_when_determining_previous_value_of_ref_to_be_delete · 15 unmodified lines
328325
329326 assert_eq!(edits.len(), 1, "an edit was performed in the packed refs store");
330327 let packed = store.packed_buffer()?.expect("packed ref present");
331− assert!(packed.find("main")?.is_none(), "no main present after deletion");
328+ assert!(packed.try_find("main")?.is_none(), "no main present after deletion");
332329 Ok(())
333330 }
334331
@@ -336,10 +333,10 @@ fn packed_refs_are_consulted_when_determining_previous_value_of_ref_to_be_delete · 1 unmodified line
336333 fn a_loose_ref_with_old_value_check_and_outdated_packed_refs_value_deletes_both_refs() -> crate::Result {
337334 let (_keep, store) = store_writable("make_packed_ref_repository_for_overlay.sh")?;
338335 let packed = store.packed_buffer()?.expect("packed-refs");
339− let branch = store.find_existing("newer-as-loose", Some(&packed))?;
336+ let branch = store.find("newer-as-loose", Some(&packed))?;
340337 let branch_id = branch.target().as_id().map(ToOwned::to_owned).expect("peeled");
341338 assert_ne!(
342− packed.find_existing("newer-as-loose")?.target(),
339+ packed.find("newer-as-loose")?.target(),
343340 branch_id,
344341 "the packed ref is outdated"
345342 );
@@ -365,7 +362,9 @@ fn a_loose_ref_with_old_value_check_and_outdated_packed_refs_value_deletes_both_ · 19 unmodified lines
365362 "only one edit even though technically two places were changed"
366363 );
367364 assert!(
368− store.find("newer-as-loose", store.packed_buffer()?.as_ref())?.is_none(),
365+ store
366+ .try_find("newer-as-loose", store.packed_buffer()?.as_ref())?
367+ .is_none(),
369368 "reference is deleted everywhere"
370369 );
371370 Ok(())
@@ -407,7 +406,10 @@ fn all_contained_references_deletes_the_packed_ref_file_too() { · 35 unmodified lines
407406 assert!(packed.is_none(), "it won't make up packed refs");
408407 for edit in edits {
409408 assert!(
410− store.find(edit.name.to_partial(), packed.as_ref()).unwrap().is_none(),
409+ store
410+ .try_find(edit.name.to_partial(), packed.as_ref())
411+ .unwrap()
412+ .is_none(),
411413 "delete ref cannot be found"
412414 );
413415 }
git-ref/tests/packed/find.rs+25−21
@@ -1,6 +1,6 @@
11 use std::convert::{TryFrom, TryInto};
22
3−use git_ref::{packed, PartialName};
3+use git_ref::{packed, PartialNameRef};
44 use git_testtools::fixture_path;
55
66 use crate::{
@@ -11,7 +11,7 @@ use crate::{ · 4 unmodified lines
1111 #[test]
1212 fn a_lock_file_would_not_be_a_valid_partial_name() {
1313 // doesn't really belong here but want to make sure refname validation works as expected.
14− let err = PartialName::try_from("heads/hello.lock").expect_err("this should fail");
14+ let err = PartialNameRef::try_from("heads/hello.lock").expect_err("this should fail");
1515 assert_eq!(err.to_string(), "A reference must be a valid tag name as well");
1616 }
1717
@@ -22,9 +22,9 @@ fn all_iterable_refs_can_be_found() -> crate::Result { · 4 unmodified lines
2222
2323 for reference in packed_refs.iter()? {
2424 let reference = reference?;
25− let found = packed_refs.find(reference.name)?.expect("reference exists");
25+ let found = packed_refs.try_find(reference.name)?.expect("reference exists");
2626 assert_eq!(reference, found, "both refs are exactly the same");
27− let found = packed_refs.find_existing(reference.name)?;
27+ let found = packed_refs.find(reference.name)?;
2828 assert_eq!(reference, found);
2929 }
3030 Ok(())
@@ -33,7 +33,7 @@ fn all_iterable_refs_can_be_found() -> crate::Result { · 2 unmodified lines
3333 #[test]
3434 fn binary_search_a_name_past_the_end_of_the_packed_refs_file() -> crate::Result {
3535 let packed_refs = packed::Buffer::open(fixture_path("packed-refs").join("triggers-out-of-bounds"), 32)?;
36− assert!(packed_refs.find("v0.0.1")?.is_none());
36+ assert!(packed_refs.try_find("v0.0.1")?.is_none());
3737 Ok(())
3838 }
3939
@@ -49,7 +49,7 @@ c4cebba92af964f2d126be90b8a6298c4cf84d45 refs/tags/git-actor-v0.1.0 · 9 unmodified lines
4949 let buf = packed::Buffer::open(path, 1024)?;
5050 let name = "refs/tags/TEST-0.0.1";
5151 assert_eq!(
52− buf.find(name)?.expect("reference exists"),
52+ buf.try_find(name)?.expect("reference exists"),
5353 packed::Reference {
5454 name: name.try_into()?,
5555 target: "916840c0e2f67d370291042cb5274a597f4fa9bc".into(),
@@ -58,7 +58,7 @@ c4cebba92af964f2d126be90b8a6298c4cf84d45 refs/tags/git-actor-v0.1.0 · 2 unmodified lines
5858 );
5959 let name = "refs/tags/git-actor-v0.1.0";
6060 assert_eq!(
61− buf.find(name)?.expect("reference exists"),
61+ buf.try_find(name)?.expect("reference exists"),
6262 packed::Reference {
6363 name: name.try_into()?,
6464 target: "c4cebba92af964f2d126be90b8a6298c4cf84d45".into(),
@@ -67,7 +67,7 @@ c4cebba92af964f2d126be90b8a6298c4cf84d45 refs/tags/git-actor-v0.1.0 · 2 unmodified lines
6767 );
6868 let name = "refs/tags/git-actor-v0.1.1";
6969 assert_eq!(
70− buf.find(name)?.expect("reference exists"),
70+ buf.try_find(name)?.expect("reference exists"),
7171 packed::Reference {
7272 name: name.try_into()?,
7373 target: "0b92c8a256ae06c189e3b9c30b646d62ac8f7d10".into(),
@@ -83,50 +83,50 @@ fn partial_name_to_full_name_conversion_rules_are_applied() -> crate::Result { · 9 unmodified lines
8383 let packed = store.packed_buffer()?.expect("packed-refs exists");
8484
8585 assert_eq!(
86− store.loose_find_existing("origin")?.name.as_bstr(),
86+ store.find_loose("origin")?.name.as_bstr(),
8787 "refs/remotes/origin/HEAD",
8888 "a special that only applies to loose refs"
8989 );
9090 assert!(
91− packed.find("origin")?.is_none(),
91+ packed.try_find("origin")?.is_none(),
9292 "packed refs don't have this special case as they don't store HEADs or symrefs"
9393 );
9494 assert_eq!(
95− store.loose_find_existing("HEAD")?.name.as_bstr(),
95+ store.find_loose("HEAD")?.name.as_bstr(),
9696 "HEAD",
9797 "HEAD can be found in loose stores"
9898 );
9999 assert!(
100− packed.find("HEAD")?.is_none(),
100+ packed.try_find("HEAD")?.is_none(),
101101 "packed refs definitely don't contain HEAD"
102102 );
103103 assert_eq!(
104− packed.find("head-or-tag")?.expect("present").name.as_bstr(),
104+ packed.try_find("head-or-tag")?.expect("present").name.as_bstr(),
105105 "refs/tags/head-or-tag",
106106 "it finds tags first"
107107 );
108108 assert_eq!(
109− packed.find("heads/head-or-tag")?.expect("present").name.as_bstr(),
109+ packed.try_find("heads/head-or-tag")?.expect("present").name.as_bstr(),
110110 "refs/heads/head-or-tag",
111111 "it finds heads when disambiguated"
112112 );
113113 assert_eq!(
114− packed.find("main")?.expect("present").name.as_bstr(),
114+ packed.try_find("main")?.expect("present").name.as_bstr(),
115115 "refs/heads/main",
116116 "it finds local heads before remote ones"
117117 );
118118 assert_eq!(
119− packed.find("origin/main")?.expect("present").name.as_bstr(),
119+ packed.try_find("origin/main")?.expect("present").name.as_bstr(),
120120 "refs/remotes/origin/main",
121121 "it finds remote heads when disambiguated"
122122 );
123123 assert_eq!(
124− packed.find("remotes/origin/main")?.expect("present").name.as_bstr(),
124+ packed.try_find("remotes/origin/main")?.expect("present").name.as_bstr(),
125125 "refs/remotes/origin/main",
126126 "more specification is possible, too"
127127 );
128128 assert_eq!(
129− packed.find("tag-object")?.expect("present"),
129+ packed.try_find("tag-object")?.expect("present"),
130130 packed::Reference {
131131 name: "refs/tags/tag-object".try_into()?,
132132 target: "b3109a7e51fc593f85b145a76c70ddd1d133fafd".into(),
@@ -150,7 +150,7 @@ bogus refs/tags/git-actor-v0.1.0 · 17 unmodified lines
150150
151151 let name = "refs/tags/git-actor-v0.1.1";
152152 assert_eq!(
153− buf.find(name)?.expect("reference exists"),
153+ buf.try_find(name)?.expect("reference exists"),
154154 packed::Reference {
155155 name: name.try_into()?,
156156 target: "0b92c8a256ae06c189e3b9c30b646d62ac8f7d10".into(),
@@ -160,7 +160,7 @@ bogus refs/tags/git-actor-v0.1.0 · 3 unmodified lines
160160
161161 for failing_name in &["refs/tags/TEST-0.0.1", "refs/tags/git-actor-v0.1.0"] {
162162 assert_eq!(
163− buf.find(*failing_name)
163+ buf.try_find(*failing_name)
164164 .expect_err("it should detect an err")
165165 .to_string(),
166166 "The reference could not be parsed"
@@ -178,7 +178,11 @@ fn find_speed() -> crate::Result { · 11 unmodified lines
178178 for r in packed.iter()?.take(10_000) {
179179 num_refs += 1;
180180 let r = r?;
181− assert_eq!(packed.find(r.name)?.expect("ref was found"), r, "the refs are the same");
181+ assert_eq!(
182+ packed.try_find(r.name)?.expect("ref was found"),
183+ r,
184+ "the refs are the same"
185+ );
182186 }
183187 let elapsed = start.elapsed().as_secs_f32();
184188 eprintln!(
git-ref/tests/packed/open.rs+1−1
@@ -27,7 +27,7 @@ fn unsorted_buffers_or_those_without_a_header_can_be_opened_and_searched() { · 26 unmodified lines
2727 .unwrap();
2828 for packed_ref in buffer.iter().unwrap().map(Result::unwrap) {
2929 let found_ref = buffer
30− .find_existing(packed_ref.name)
30+ .find(packed_ref.name)
3131 .expect("ref can be found as buffer is sorted");
3232 assert_eq!(
3333 found_ref, packed_ref,
git-ref/tests/transaction/mod.rs+5−7
@@ -3,9 +3,8 @@ mod refedit_ext { · 2 unmodified lines
33
44 use bstr::{BString, ByteSlice};
55 use git_ref::{
6− mutable::Target,
76 transaction::{Change, Create, RefEdit, RefEditsExt, RefLog},
8− PartialName,
7+ PartialNameRef, Target,
98 };
109
1110 #[derive(Default)]
@@ -26,7 +25,7 @@ mod refedit_ext { · 14 unmodified lines
2625 },
2726 }
2827 }
29− fn find_existing(&self, name: PartialName<'_>) -> Option<Target> {
28+ fn find_existing(&self, name: PartialNameRef<'_>) -> Option<Target> {
3029 self.targets.borrow_mut().remove(name.as_bstr())
3130 }
3231 }
@@ -149,16 +148,15 @@ mod refedit_ext { · 116 unmodified lines
149148
150149 use git_hash::ObjectId;
151150 use git_ref::{
152− mutable::Target,
153151 transaction::{Change, Create, LogChange, RefEdit, RefEditsExt, RefLog},
154− FullName, PartialName,
152+ FullNameRef, PartialNameRef, Target,
155153 };
156154 use git_testtools::hex_to_id;
157155
158156 use crate::transaction::refedit_ext::MockStore;
159157
160158 fn find<'a>(edits: &'a [RefEdit], name: &str) -> &'a RefEdit {
161− let name: FullName = name.try_into().unwrap();
159+ let name: FullNameRef = name.try_into().unwrap();
162160 edits
163161 .iter()
164162 .find(|e| e.name.as_bstr() == name.as_bstr())
@@ -229,7 +227,7 @@ mod refedit_ext { · 64 unmodified lines
229227 next_item: Cell<bool>,
230228 }
231229 impl Cycler {
232− fn find_existing(&self, _name: PartialName<'_>) -> Option<Target> {
230+ fn find_existing(&self, _name: PartialNameRef<'_>) -> Option<Target> {
233231 let item: bool = self.next_item.get();
234232 self.next_item.set(!item);
235233 Some(Target::Symbolic(
git-repository/Cargo.toml+1−1
@@ -42,7 +42,7 @@ git-validate = { version = "^0.5.0", path = "../git-validate" } · 41 unmodified lines
4242 git-odb = { version ="0.20.0", path = "../git-odb" }
4343 git-hash = { version = "^0.5.0", path = "../git-hash" }
4444 git-object = { version ="0.12.0", path = "../git-object" }
45−git-actor = { version ="^0.4.0", path = "../git-actor" }
45+git-actor = { version ="^0.5.0", path = "../git-actor" }
4646 git-pack = { version ="^0.9.0", path = "../git-pack" }
4747
4848 git-url = { version = "0.3.0", path = "../git-url", optional = true }
git-repository/src/easy/ext/reference.rs+4−5
@@ -10,9 +10,8 @@ use git_actor as actor; · 9 unmodified lines
1010 use git_lock as lock;
1111 use git_ref::{
1212 file::find::Error,
13− mutable::Target,
1413 transaction::{Change, Create, RefEdit},
15− PartialName,
14+ PartialNameRef, Target,
1615 };
1716
1817 /// Obtain and alter references comfortably
@@ -77,7 +76,7 @@ pub trait ReferenceAccessExt: easy::Access + Sized { · 58 unmodified lines
7776
7877 fn find_reference<'a, Name, E>(&self, name: Name) -> Result<Reference<'_, Self>, reference::find::existing::Error>
7978 where
80− Name: TryInto<PartialName<'a>, Error = E>,
79+ Name: TryInto<PartialNameRef<'a>, Error = E>,
8180 Error: From<E>,
8281 {
8382 self.try_find_reference(name)?
@@ -86,14 +85,14 @@ pub trait ReferenceAccessExt: easy::Access + Sized { · 2 unmodified lines
8685
8786 fn try_find_reference<'a, Name, E>(&self, name: Name) -> Result<Option<Reference<'_, Self>>, reference::find::Error>
8887 where
89− Name: TryInto<PartialName<'a>, Error = E>,
88+ Name: TryInto<PartialNameRef<'a>, Error = E>,
9089 Error: From<E>,
9190 {
9291 let state = self.state();
9392 let repo = self.repo()?;
9493 match repo
9594 .refs
96− .find(name, state.assure_packed_refs_uptodate(&repo.refs)?.as_ref())
95+ .try_find(name, state.assure_packed_refs_uptodate(&repo.refs)?.as_ref())
9796 {
9897 Ok(r) => match r {
9998 Some(r) => Ok(Some(Reference::from_file_ref(r, self))),
git-repository/src/easy/reference.rs+5−5
@@ -12,7 +12,7 @@ use git_ref as refs; · 11 unmodified lines
1212 pub(crate) enum Backing {
1313 OwnedPacked {
1414 /// The validated full name of the reference.
15− name: refs::mutable::FullName,
15+ name: refs::FullName,
1616 /// The target object id of the reference, hex encoded.
1717 target: ObjectId,
1818 /// The fully peeled object id, hex encoded, that the ref is ultimately pointing to
@@ -107,19 +107,19 @@ where · 88 unmodified lines
107107 access,
108108 }
109109 }
110− pub fn target(&self) -> refs::mutable::Target {
110+ pub fn target(&self) -> refs::Target {
111111 match self.backing.as_ref().expect("always set") {
112− Backing::OwnedPacked { target, .. } => refs::mutable::Target::Peeled(target.to_owned()),
112+ Backing::OwnedPacked { target, .. } => refs::Target::Peeled(target.to_owned()),
113113 Backing::LooseFile(r) => r.target.clone(),
114114 }
115115 }
116116
117− pub fn name(&self) -> refs::FullName<'_> {
117+ pub fn name(&self) -> refs::FullNameRef<'_> {
118118 match self.backing.as_ref().expect("always set") {
119119 Backing::OwnedPacked { name, .. } => name,
120120 Backing::LooseFile(r) => &r.name,
121121 }
122− .borrow()
122+ .to_ref()
123123 }
124124
125125 pub fn peel_to_oid_in_place(&mut self) -> Result<Oid<'repo, A>, peel_to_oid_in_place::Error> {
git-repository/src/path/is_git.rs+1−1
@@ -42,7 +42,7 @@ pub fn is_git(git_dir: impl AsRef<Path>) -> Result<crate::Kind, Error> { · 41 unmodified lines
4242
4343 {
4444 let refs = git_ref::file::Store::at(&dot_git, Default::default());
45− let head = refs.loose_find_existing("HEAD")?;
45+ let head = refs.find_loose("HEAD")?;
4646 if head.name.as_bstr() != "HEAD" {
4747 return Err(Error::MisplacedHead(head.name.into_inner()));
4848 }
git-repository/tests/reference/mod.rs+1−1
@@ -19,7 +19,7 @@ mod find { · 18 unmodified lines
1919
2020 assert_eq!(
2121 packed_tag_ref.target(),
22− refs::mutable::Target::Peeled(hex_to_id("4c3f4cce493d7beb45012e478021b5f65295e5a3")),
22+ refs::Target::Peeled(hex_to_id("4c3f4cce493d7beb45012e478021b5f65295e5a3")),
2323 "it points to a tag object"
2424 );
2525
gitoxide-core/src/hours.rs+1−1
@@ -49,7 +49,7 @@ where · 48 unmodified lines
4949 let packed = repo.refs.packed_buffer()?;
5050 let commit_id = repo
5151 .refs
52− .find_existing(refname.to_string_lossy().as_ref(), packed.as_ref())?
52+ .find(refname.to_string_lossy().as_ref(), packed.as_ref())?
5353 .peel_to_id_in_place(&repo.refs, packed.as_ref(), |oid, buf| {
5454 repo.odb
5555 .find(oid, buf, &mut pack::cache::Never)
gitoxide-core/src/pack/create.rs+1−1
@@ -117,7 +117,7 @@ where · 116 unmodified lines
117117 let refs = &repo.refs;
118118 let repo = Arc::clone(&repo);
119119 move |_| {
120− refs.find_existing(tip.as_ref().to_string_lossy().as_ref(), packed.as_ref())
120+ refs.find(tip.as_ref().to_string_lossy().as_ref(), packed.as_ref())
121121 .map_err(anyhow::Error::from)
122122 .and_then(|mut r| {
123123 r.peel_to_id_in_place(refs, packed.as_ref(), |oid, buf| {