History

[ref] changing the ref type means a lot of breakage and some unsolved problems

Sebastian Thiel committed 5 years ago

Commit 407dc4d1 parent 2c4e45a4 files · +46 −19Browse files

Unified · Split

4 files
  1. git-ref/src/store/file/loose/find.rs +15 −14
  2. git-ref/src/store/file/overlay.rs +16 −0
  3. git-ref/src/store/file/reference/mod.rs +1 −0
  4. git-ref/src/store/file/reference/peel.rs +14 −5
git-ref/src/store/file/loose/find.rs+15−14
@@ -28,11 +28,11 @@ impl file::Store { · 27 unmodified lines
2828 /// The lookup algorithm follows the one in [the git documentation][git-lookup-docs].
2929 ///
3030 /// [git-lookup-docs]: https://github.com/git/git/blob/5d5b1473453400224ebb126bf3947e0a3276bdf5/Documentation/revisions.txt#L34-L46
31− pub fn find<'a, 'p, Name, E>(
32− &self,
31+ pub fn find<'a, 'p, 's, Name, E>(
32+ &'s self,
3333 partial: Name,
3434 packed: Option<&'p packed::Buffer>,
35− ) -> Result<Option<file::Reference<'_>>, Error>
35+ ) -> Result<Option<file::loose_then_packed::Reference<'p, 's>>, Error>
3636 where
3737 Name: TryInto<PartialName<'a>, Error = E>,
3838 Error: From<E>,
@@ -41,11 +41,11 @@ impl file::Store { · 2 unmodified lines
4141 self.find_one_with_verified_input(path.to_partial_path().as_ref(), packed)
4242 }
4343
44− pub(in crate::store::file) fn find_one_with_verified_input<'p>(
45− &self,
44+ pub(in crate::store::file) fn find_one_with_verified_input<'p, 's>(
45+ &'s self,
4646 relative_path: &Path,
4747 packed: Option<&'p packed::Buffer>,
48− ) -> Result<Option<file::Reference<'_>>, Error> {
48+ ) -> Result<Option<file::loose_then_packed::Reference<'p, 's>>, Error> {
4949 let is_all_uppercase = relative_path
5050 .to_string_lossy()
5151 .as_ref()
@@ -74,13 +74,13 @@ impl file::Store { · 22 unmodified lines
7474 )
7575 }
7676
77− fn find_inner<'p>(
78− &self,
77+ fn find_inner<'p, 's>(
78+ &'s self,
7979 inbetween: &str,
8080 relative_path: &Path,
8181 packed: Option<&'p packed::Buffer>,
8282 transform: Transform,
83− ) -> Result<Option<file::Reference<'_>>, Error> {
83+ ) -> Result<Option<file::loose_then_packed::Reference<'p, 's>>, Error> {
8484 let (base, is_definitely_absolute) = match transform {
8585 Transform::EnforceRefsPrefix => (
8686 if relative_path.starts_with("refs") {
@@ -100,8 +100,8 @@ impl file::Store { · 13 unmodified lines
100100 if let Some(packed) = packed {
101101 let full_name = path_to_name(relative_path);
102102 let full_name = PartialName((*full_name).as_bstr());
103− if let Some(_packed_ref) = packed.find(full_name)? {
104− todo!("transform packed ref into standard ref")
103+ if let Some(packed_ref) = packed.find(full_name)? {
104+ return Ok(Some(file::loose_then_packed::Reference::Packed(packed_ref)));
105105 };
106106 }
107107 }
@@ -111,6 +111,7 @@ impl file::Store { · 3 unmodified lines
111111 };
112112 Ok(Some(
113113 file::Reference::try_from_path(self, &relative_path, &contents)
114+ .map(file::loose_then_packed::Reference::Loose)
114115 .map_err(|err| Error::ReferenceCreation { err, relative_path })?,
115116 ))
116117 }
@@ -153,11 +154,11 @@ pub mod existing { · 36 unmodified lines
153154
154155 impl file::Store {
155156 /// Similar to [`file::Store::find()`] but a non-existing ref is treated as error.
156− pub fn find_existing<'a, 'p, Name, E>(
157− &self,
157+ pub fn find_existing<'a, 'p, 's, Name, E>(
158+ &'s self,
158159 partial: Name,
159160 packed: Option<&'p packed::Buffer>,
160− ) -> Result<file::Reference<'_>, Error>
161+ ) -> Result<file::loose_then_packed::Reference<'p, 's>, Error>
161162 where
162163 Name: TryInto<PartialName<'a>, Error = E>,
163164 crate::name::Error: From<E>,
git-ref/src/store/file/overlay.rs+16−0
@@ -32,6 +32,22 @@ pub enum Reference<'p, 's> { · 31 unmodified lines
3232 }
3333
3434 impl<'p, 's> Reference<'p, 's> {
35+ /// Returns the kind of reference
36+ pub fn kind(&self) -> crate::Kind {
37+ match self {
38+ Reference::Loose(r) => r.kind(),
39+ Reference::Packed(_) => crate::Kind::Peeled,
40+ }
41+ }
42+
43+ /// Transform this reference into an owned `Target`
44+ pub fn into_target(self) -> mutable::Target {
45+ match self {
46+ Reference::Packed(p) => mutable::Target::Peeled(p.object()),
47+ Reference::Loose(r) => r.into_target(),
48+ }
49+ }
50+
3551 /// Returns true if this ref is located in a packed ref buffer.
3652 pub fn is_packed(&self) -> bool {
3753 match self {
git-ref/src/store/file/reference/mod.rs+1−0
@@ -5,6 +5,7 @@ use std::path::{Path, PathBuf}; · 4 unmodified lines
55
66 #[derive(Debug, PartialOrd, PartialEq, Ord, Eq, Hash, Clone)]
77 #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
8+// TODO: replace with usage of Target, which is the same but with better typing
89 pub(in crate::file) enum State {
910 Id(ObjectId),
1011 ValidatedPath(BString),
git-ref/src/store/file/reference/peel.rs+14−5
@@ -21,11 +21,14 @@ quick_error! { · 20 unmodified lines
2121 }
2222 }
2323
24−impl<'a> Reference<'a> {
24+impl<'s> Reference<'s> {
2525 /// Follow this symbolic reference one level and return the ref it refers to, possibly providing access to `packed` references for lookup.
2626 ///
2727 /// Returns `None` if this is not a symbolic reference, hence the leaf of the chain.
28− pub fn peel_one_level(&self, packed: Option<&packed::Buffer>) -> Option<Result<Reference<'a>, Error>> {
28+ pub fn peel_one_level<'p>(
29+ &self,
30+ packed: Option<&'p packed::Buffer>,
31+ ) -> Option<Result<file::loose_then_packed::Reference<'p, 's>, Error>> {
2932 match &self.state {
3033 State::Id(_) => None,
3134 State::ValidatedPath(relative_path) => {
@@ -46,7 +49,7 @@ impl<'a> Reference<'a> { · 14 unmodified lines
4649 pub mod to_id {
4750 use crate::{
4851 file::{reference, Reference},
49− store::packed,
52+ store::{file::loose_then_packed, packed},
5053 };
5154 use git_hash::oid;
5255 use quick_error::quick_error;
@@ -84,11 +87,17 @@ pub mod to_id { · 31 unmodified lines
8487 while let Some(next) = cursor.peel_one_level(packed) {
8588 let next_ref = next?;
8689 if let crate::Kind::Peeled = next_ref.kind() {
87− *self = next_ref;
90+ match next_ref {
91+ loose_then_packed::Reference::Loose(r) => *self = r,
92+ loose_then_packed::Reference::Packed(_p) => todo!("assign state directly and convert path"),
93+ };
8894 return Ok(self.state.as_id().expect("it to be present"));
8995 }
9096 storage = next_ref;
91− cursor = &mut storage;
97+ cursor = match &mut storage {
98+ loose_then_packed::Reference::Loose(r) => r,
99+ loose_then_packed::Reference::Packed(_) => unreachable!("handled above - we are done"),
100+ };
92101 if seen.contains(&cursor.relative_path) {
93102 return Err(Error::Cycle(cursor.parent.base.join(&cursor.relative_path)));
94103 }