Showing the changes to git-ref/src (12 of 13 files). Show all
Unified · Split
| @@ -8,10 +8,13 @@ use bstr::ByteSlice; · 7 unmodified lines | |||
| 8 | 8 | ||
| 9 | pub use error::Error; | 9 | pub use error::Error; |
| 10 | 10 | ||
| 11 | use crate::mutable::FullName; | ||
| 12 | use crate::{ | 11 | use crate::{ |
| 13 | file, | 12 | file, |
| 14 | store::{file::path_to_name, packed}, | 13 | mutable::FullName, |
| 14 | store::{ | ||
| 15 | file::{loose, path_to_name}, | ||
| 16 | packed, | ||
| 17 | }, | ||
| 15 | PartialName, | 18 | PartialName, |
| 16 | }; | 19 | }; |
| 17 | 20 | ||
| @@ -47,7 +50,7 @@ impl file::Store { · 29 unmodified lines | |||
| 47 | } | 50 | } |
| 48 | 51 | ||
| 49 | /// Similar to [`file::Store::find()`] but a non-existing ref is treated as error. | 52 | /// Similar to [`file::Store::find()`] but a non-existing ref is treated as error. |
| 50 | pub fn loose_find<'a, Name, E>(&self, partial: Name) -> Result<Option<file::Reference<'_>>, Error> | 53 | pub fn loose_find<'a, Name, E>(&self, partial: Name) -> Result<Option<loose::Reference<'_>>, Error> |
| 51 | where | 54 | where |
| 52 | Name: TryInto<PartialName<'a>, Error = E>, | 55 | Name: TryInto<PartialName<'a>, Error = E>, |
| 53 | Error: From<E>, | 56 | Error: From<E>, |
| @@ -126,7 +129,7 @@ impl file::Store { · 72 unmodified lines | |||
| 126 | }; | 129 | }; |
| 127 | Ok(Some({ | 130 | Ok(Some({ |
| 128 | let full_name = path_to_name(&relative_path); | 131 | let full_name = path_to_name(&relative_path); |
| 129 | file::Reference::try_from_path(self, FullName(full_name), &contents) | 132 | loose::Reference::try_from_path(self, FullName(full_name), &contents) |
| 130 | .map(file::loose_then_packed::Reference::Loose) | 133 | .map(file::loose_then_packed::Reference::Loose) |
| 131 | .map_err(|err| Error::ReferenceCreation { err, relative_path })? | 134 | .map_err(|err| Error::ReferenceCreation { err, relative_path })? |
| 132 | })) | 135 | })) |
| @@ -165,10 +168,12 @@ pub mod existing { · 32 unmodified lines | |||
| 165 | 168 | ||
| 166 | pub use error::Error; | 169 | pub use error::Error; |
| 167 | 170 | ||
| 168 | use crate::store::file::find; | ||
| 169 | use crate::{ | 171 | use crate::{ |
| 170 | file::{self}, | 172 | file::{self}, |
| 171 | store::packed, | 173 | store::{ |
| 174 | file::{find, loose}, | ||
| 175 | packed, | ||
| 176 | }, | ||
| 172 | PartialName, | 177 | PartialName, |
| 173 | }; | 178 | }; |
| 174 | 179 | ||
| @@ -194,7 +199,7 @@ pub mod existing { · 19 unmodified lines | |||
| 194 | } | 199 | } |
| 195 | 200 | ||
| 196 | /// Similar to [`file::Store::find()`] won't handle packed-refs. | 201 | /// Similar to [`file::Store::find()`] won't handle packed-refs. |
| 197 | pub fn loose_find_existing<'a, Name, E>(&self, partial: Name) -> Result<file::Reference<'_>, Error> | 202 | pub fn loose_find_existing<'a, Name, E>(&self, partial: Name) -> Result<loose::Reference<'_>, Error> |
| 198 | where | 203 | where |
| 199 | Name: TryInto<PartialName<'a>, Error = E>, | 204 | Name: TryInto<PartialName<'a>, Error = E>, |
| 200 | crate::name::Error: From<E>, | 205 | crate::name::Error: From<E>, |
| @@ -1,4 +1,7 @@ | |||
| 1 | use crate::{mutable::FullName, store::file}; | 1 | use crate::{ |
| 2 | mutable::FullName, | ||
| 3 | store::file::{self, loose::Reference}, | ||
| 4 | }; | ||
| 2 | use bstr::ByteSlice; | 5 | use bstr::ByteSlice; |
| 3 | use git_features::fs::walkdir::DirEntryIter; | 6 | use git_features::fs::walkdir::DirEntryIter; |
| 4 | use os_str_bytes::OsStrBytes; | 7 | use os_str_bytes::OsStrBytes; |
| @@ -78,7 +81,7 @@ impl<'a> Loose<'a> { · 73 unmodified lines | |||
| 78 | } | 81 | } |
| 79 | 82 | ||
| 80 | impl<'a> Iterator for Loose<'a> { | 83 | impl<'a> Iterator for Loose<'a> { |
| 81 | type Item = Result<file::Reference<'a>, loose::Error>; | 84 | type Item = Result<Reference<'a>, loose::Error>; |
| 82 | 85 | ||
| 83 | fn next(&mut self) -> Option<Self::Item> { | 86 | fn next(&mut self) -> Option<Self::Item> { |
| 84 | self.ref_paths.next().map(|res| { | 87 | self.ref_paths.next().map(|res| { |
| @@ -93,7 +96,7 @@ impl<'a> Iterator for Loose<'a> { · 8 unmodified lines | |||
| 93 | let relative_path = validated_path | 96 | let relative_path = validated_path |
| 94 | .strip_prefix(&self.ref_paths.base) | 97 | .strip_prefix(&self.ref_paths.base) |
| 95 | .expect("root contains path"); | 98 | .expect("root contains path"); |
| 96 | file::Reference::try_from_path(self.parent, name, &self.buf).map_err(|err| { | 99 | Reference::try_from_path(self.parent, name, &self.buf).map_err(|err| { |
| 97 | loose::Error::ReferenceCreation { | 100 | loose::Error::ReferenceCreation { |
| 98 | err, | 101 | err, |
| 99 | relative_path: relative_path.into(), | 102 | relative_path: relative_path.into(), |
| @@ -1,3 +1,22 @@ | |||
| 1 | use crate::{file::Store, mutable, Kind}; | ||
| 2 | |||
| 3 | /// A git _ref_ which is stored in a file. | ||
| 4 | #[derive(Debug, PartialOrd, PartialEq, Ord, Eq, Hash, Clone)] | ||
| 5 | pub struct Reference<'a> { | ||
| 6 | parent: &'a Store, | ||
| 7 | /// The path to uniquely identify this ref within its store. | ||
| 8 | pub name: mutable::FullName, | ||
| 9 | /// The target of the reference, either a symbolic reference by full name or an object by its id. | ||
| 10 | pub target: mutable::Target, | ||
| 11 | } | ||
| 12 | |||
| 13 | impl<'a> Reference<'a> { | ||
| 14 | /// Return the kind of ref. | ||
| 15 | pub fn kind(&self) -> Kind { | ||
| 16 | self.target.kind() | ||
| 17 | } | ||
| 18 | } | ||
| 19 | |||
| 1 | /// | 20 | /// |
| 2 | pub(crate) mod reflog; | 21 | pub(crate) mod reflog; |
| 3 | 22 | ||
| @@ -1,7 +1,8 @@ | |||
| 1 | use crate::{ | 1 | use crate::{ |
| 2 | file::{Reference, Store}, | 2 | file::Store, |
| 3 | mutable, | 3 | mutable, |
| 4 | parse::{hex_hash, newline}, | 4 | parse::{hex_hash, newline}, |
| 5 | store::file::loose::Reference, | ||
| 5 | }; | 6 | }; |
| 6 | use bstr::BString; | 7 | use bstr::BString; |
| 7 | use git_hash::ObjectId; | 8 | use git_hash::ObjectId; |
| @@ -1,4 +1,4 @@ | |||
| 1 | use crate::store::file::{log, loose, Reference}; | 1 | use crate::store::file::{log, loose, loose::Reference}; |
| 2 | use std::io::Read; | 2 | use std::io::Read; |
| 3 | 3 | ||
| 4 | impl<'a> Reference<'a> { | 4 | impl<'a> Reference<'a> { |
| @@ -1,12 +1,3 @@ | |||
| 1 | use crate::{file::Reference, Kind}; | ||
| 2 | |||
| 3 | impl<'a> Reference<'a> { | ||
| 4 | /// Return the kind of ref. | ||
| 5 | pub fn kind(&self) -> Kind { | ||
| 6 | self.target.kind() | ||
| 7 | } | ||
| 8 | } | ||
| 9 | |||
| 10 | mod logiter; | 1 | mod logiter; |
| 11 | 2 | ||
| 12 | /// | 3 | /// |
| @@ -1,10 +1,12 @@ | |||
| 1 | use quick_error::quick_error; | 1 | use quick_error::quick_error; |
| 2 | 2 | ||
| 3 | use crate::store::file::find; | ||
| 4 | use crate::{ | 3 | use crate::{ |
| 5 | file::{self, Reference}, | 4 | file::{self}, |
| 6 | mutable::Target, | 5 | mutable::Target, |
| 7 | store::packed, | 6 | store::{ |
| 7 | file::{find, loose::Reference}, | ||
| 8 | packed, | ||
| 9 | }, | ||
| 8 | }; | 10 | }; |
| 9 | 11 | ||
| 10 | quick_error! { | 12 | quick_error! { |
| @@ -54,8 +56,8 @@ pub mod to_id { · 43 unmodified lines | |||
| 54 | use std::{collections::BTreeSet, path::PathBuf}; | 56 | use std::{collections::BTreeSet, path::PathBuf}; |
| 55 | 57 | ||
| 56 | use crate::store::file::loose::reference; | 58 | use crate::store::file::loose::reference; |
| 59 | use crate::store::file::loose::Reference; | ||
| 57 | use crate::{ | 60 | use crate::{ |
| 58 | file::Reference, | ||
| 59 | mutable::{FullName, Target}, | 61 | mutable::{FullName, Target}, |
| 60 | store::{file::loose_then_packed, packed}, | 62 | store::{file::loose_then_packed, packed}, |
| 61 | }; | 63 | }; |
| @@ -1,7 +1,5 @@ | |||
| 1 | use std::path::PathBuf; | 1 | use std::path::PathBuf; |
| 2 | 2 | ||
| 3 | use crate::mutable; | ||
| 4 | |||
| 5 | /// The way a file store handles the reflog | 3 | /// The way a file store handles the reflog |
| 6 | #[derive(Debug, PartialOrd, PartialEq, Ord, Eq, Hash, Clone, Copy)] | 4 | #[derive(Debug, PartialOrd, PartialEq, Ord, Eq, Hash, Clone, Copy)] |
| 7 | pub enum WriteReflog { | 5 | pub enum WriteReflog { |
| @@ -17,16 +15,6 @@ impl Default for WriteReflog { · 9 unmodified lines | |||
| 17 | } | 15 | } |
| 18 | } | 16 | } |
| 19 | 17 | ||
| 20 | /// A git _ref_ which is stored in a file. | ||
| 21 | #[derive(Debug, PartialOrd, PartialEq, Ord, Eq, Hash, Clone)] | ||
| 22 | pub struct Reference<'a> { | ||
| 23 | parent: &'a Store, | ||
| 24 | /// The path to uniquely identify this ref within its store. | ||
| 25 | pub name: mutable::FullName, | ||
| 26 | /// The target of the reference, either a symbolic reference by full name or an object by its id. | ||
| 27 | pub target: mutable::Target, | ||
| 28 | } | ||
| 29 | |||
| 30 | /// A store for reference which uses plain files. | 18 | /// A store for reference which uses plain files. |
| 31 | /// | 19 | /// |
| 32 | /// Each ref is represented as a single file on disk in a folder structure that follows the relative path | 20 | /// Each ref is represented as a single file on disk in a folder structure that follows the relative path |
| @@ -1,6 +1,6 @@ | |||
| 1 | use super::{LooseThenPacked, Reference}; | 1 | use super::{LooseThenPacked, Reference}; |
| 2 | use crate::{ | 2 | use crate::{ |
| 3 | file::path_to_name, | 3 | file::{loose, path_to_name}, |
| 4 | store::{file, packed}, | 4 | store::{file, packed}, |
| 5 | }; | 5 | }; |
| 6 | use std::{ | 6 | use std::{ |
| @@ -34,7 +34,7 @@ impl<'p, 's> LooseThenPacked<'p, 's> { · 27 unmodified lines | |||
| 34 | f.read_to_end(&mut self.buf) | 34 | f.read_to_end(&mut self.buf) |
| 35 | }) | 35 | }) |
| 36 | .map_err(Error::ReadFileContents)?; | 36 | .map_err(Error::ReadFileContents)?; |
| 37 | file::Reference::try_from_path(self.parent, name, &self.buf) | 37 | loose::Reference::try_from_path(self.parent, name, &self.buf) |
| 38 | .map_err(|err| Error::ReferenceCreation { | 38 | .map_err(|err| Error::ReferenceCreation { |
| 39 | err, | 39 | err, |
| 40 | relative_path: refpath | 40 | relative_path: refpath |
| @@ -97,8 +97,7 @@ impl file::Store { · 56 unmodified lines | |||
| 97 | .iter() | 97 | .iter() |
| 98 | .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))? | 98 | .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))? |
| 99 | .peekable(), | 99 | .peekable(), |
| 100 | loose: file::loose::iter::SortedLoosePaths::at_root_with_names(self.refs_dir(), self.base.clone()) | 100 | loose: loose::iter::SortedLoosePaths::at_root_with_names(self.refs_dir(), self.base.clone()).peekable(), |
| 101 | .peekable(), | ||
| 102 | buf: Vec::new(), | 101 | buf: Vec::new(), |
| 103 | }) | 102 | }) |
| 104 | } | 103 | } |
| @@ -118,7 +117,7 @@ impl file::Store { · 13 unmodified lines | |||
| 118 | .iter_prefixed(packed_prefix) | 117 | .iter_prefixed(packed_prefix) |
| 119 | .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))? | 118 | .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))? |
| 120 | .peekable(), | 119 | .peekable(), |
| 121 | loose: file::loose::iter::SortedLoosePaths::at_root_with_names(self.base.join(prefix), self.base.clone()) | 120 | loose: loose::iter::SortedLoosePaths::at_root_with_names(self.base.join(prefix), self.base.clone()) |
| 122 | .peekable(), | 121 | .peekable(), |
| 123 | buf: Vec::new(), | 122 | buf: Vec::new(), |
| 124 | }) | 123 | }) |
| @@ -1,4 +1,4 @@ | |||
| 1 | use crate::store::{file, packed}; | 1 | use crate::store::{file, file::loose, packed}; |
| 2 | use std::iter::Peekable; | 2 | use std::iter::Peekable; |
| 3 | 3 | ||
| 4 | /// An iterator stepping through sorted input of loose references and packed references, preferring loose refs over otherwise | 4 | /// An iterator stepping through sorted input of loose references and packed references, preferring loose refs over otherwise |
| @@ -8,7 +8,7 @@ use std::iter::Peekable; · 3 unmodified lines | |||
| 8 | pub struct LooseThenPacked<'p, 's> { | 8 | pub struct LooseThenPacked<'p, 's> { |
| 9 | parent: &'s file::Store, | 9 | parent: &'s file::Store, |
| 10 | packed: Peekable<packed::Iter<'p>>, | 10 | packed: Peekable<packed::Iter<'p>>, |
| 11 | loose: Peekable<file::loose::iter::SortedLoosePaths>, | 11 | loose: Peekable<loose::iter::SortedLoosePaths>, |
| 12 | buf: Vec<u8>, | 12 | buf: Vec<u8>, |
| 13 | } | 13 | } |
| 14 | 14 | ||
| @@ -17,7 +17,7 @@ pub enum Reference<'p, 's> { · 2 unmodified lines | |||
| 17 | /// A reference originating in a pack | 17 | /// A reference originating in a pack |
| 18 | Packed(packed::Reference<'p>), | 18 | Packed(packed::Reference<'p>), |
| 19 | /// A reference from the filesystem | 19 | /// A reference from the filesystem |
| 20 | Loose(file::Reference<'s>), | 20 | Loose(loose::Reference<'s>), |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | mod reference; | 23 | mod reference; |
| @@ -10,7 +10,7 @@ use crate::{ · 9 unmodified lines | |||
| 10 | use git_hash::oid; | 10 | use git_hash::oid; |
| 11 | use std::convert::TryFrom; | 11 | use std::convert::TryFrom; |
| 12 | 12 | ||
| 13 | impl<'p, 's> TryFrom<Reference<'p, 's>> for crate::file::Reference<'s> { | 13 | impl<'p, 's> TryFrom<Reference<'p, 's>> for crate::file::loose::Reference<'s> { |
| 14 | type Error = (); | 14 | type Error = (); |
| 15 | 15 | ||
| 16 | fn try_from(value: Reference<'p, 's>) -> Result<Self, Self::Error> { | 16 | fn try_from(value: Reference<'p, 's>) -> Result<Self, Self::Error> { |
| @@ -1,6 +1,6 @@ | |||
| 1 | use crate::{ | 1 | use crate::{ |
| 2 | mutable::Target, | 2 | mutable::Target, |
| 3 | store::file, | 3 | store::{file, file::loose}, |
| 4 | transaction::{Change, Create, RefEdit, RefEditsExt, RefLog}, | 4 | transaction::{Change, Create, RefEdit, RefEditsExt, RefLog}, |
| 5 | }; | 5 | }; |
| 6 | use bstr::BString; | 6 | use bstr::BString; |
| @@ -61,7 +61,7 @@ impl<'a> Transaction<'a> { · 54 unmodified lines | |||
| 61 | .map_err(Error::from) | 61 | .map_err(Error::from) |
| 62 | .and_then(|opt| { | 62 | .and_then(|opt| { |
| 63 | opt.map(|buf| { | 63 | opt.map(|buf| { |
| 64 | file::Reference::try_from_path(store, change.update.name.clone(), &buf).map_err(Error::from) | 64 | loose::Reference::try_from_path(store, change.update.name.clone(), &buf).map_err(Error::from) |
| 65 | }) | 65 | }) |
| 66 | .transpose() | 66 | .transpose() |
| 67 | }) | 67 | }) |