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 | 9 | pub use error::Error; |
| 10 | 10 | |
| 11 | −use crate::mutable::FullName; | |
| 12 | 11 | use crate::{ |
| 13 | 12 | file, |
| 14 | − store::{file::path_to_name, packed}, | |
| 13 | + mutable::FullName, | |
| 14 | + store::{ | |
| 15 | + file::{loose, path_to_name}, | |
| 16 | + packed, | |
| 17 | + }, | |
| 15 | 18 | PartialName, |
| 16 | 19 | }; |
| 17 | 20 | |
| @@ -47,7 +50,7 @@ impl file::Store { · 29 unmodified lines | ||
| 47 | 50 | } |
| 48 | 51 | |
| 49 | 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 | 54 | where |
| 52 | 55 | Name: TryInto<PartialName<'a>, Error = E>, |
| 53 | 56 | Error: From<E>, |
| @@ -126,7 +129,7 @@ impl file::Store { · 72 unmodified lines | ||
| 126 | 129 | }; |
| 127 | 130 | Ok(Some({ |
| 128 | 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 | 133 | .map(file::loose_then_packed::Reference::Loose) |
| 131 | 134 | .map_err(|err| Error::ReferenceCreation { err, relative_path })? |
| 132 | 135 | })) |
| @@ -165,10 +168,12 @@ pub mod existing { · 32 unmodified lines | ||
| 165 | 168 | |
| 166 | 169 | pub use error::Error; |
| 167 | 170 | |
| 168 | − use crate::store::file::find; | |
| 169 | 171 | use crate::{ |
| 170 | 172 | file::{self}, |
| 171 | − store::packed, | |
| 173 | + store::{ | |
| 174 | + file::{find, loose}, | |
| 175 | + packed, | |
| 176 | + }, | |
| 172 | 177 | PartialName, |
| 173 | 178 | }; |
| 174 | 179 | |
| @@ -194,7 +199,7 @@ pub mod existing { · 19 unmodified lines | ||
| 194 | 199 | } |
| 195 | 200 | |
| 196 | 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 | 203 | where |
| 199 | 204 | Name: TryInto<PartialName<'a>, Error = E>, |
| 200 | 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 | 5 | use bstr::ByteSlice; |
| 3 | 6 | use git_features::fs::walkdir::DirEntryIter; |
| 4 | 7 | use os_str_bytes::OsStrBytes; |
| @@ -78,7 +81,7 @@ impl<'a> Loose<'a> { · 73 unmodified lines | ||
| 78 | 81 | } |
| 79 | 82 | |
| 80 | 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 | 86 | fn next(&mut self) -> Option<Self::Item> { |
| 84 | 87 | self.ref_paths.next().map(|res| { |
| @@ -93,7 +96,7 @@ impl<'a> Iterator for Loose<'a> { · 8 unmodified lines | ||
| 93 | 96 | let relative_path = validated_path |
| 94 | 97 | .strip_prefix(&self.ref_paths.base) |
| 95 | 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 | 100 | loose::Error::ReferenceCreation { |
| 98 | 101 | err, |
| 99 | 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 | 21 | pub(crate) mod reflog; |
| 3 | 22 | |
| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | use crate::{ |
| 2 | − file::{Reference, Store}, | |
| 2 | + file::Store, | |
| 3 | 3 | mutable, |
| 4 | 4 | parse::{hex_hash, newline}, |
| 5 | + store::file::loose::Reference, | |
| 5 | 6 | }; |
| 6 | 7 | use bstr::BString; |
| 7 | 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 | 2 | use std::io::Read; |
| 3 | 3 | |
| 4 | 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 | 1 | mod logiter; |
| 11 | 2 | |
| 12 | 3 | /// |
| @@ -1,10 +1,12 @@ | ||
| 1 | 1 | use quick_error::quick_error; |
| 2 | 2 | |
| 3 | −use crate::store::file::find; | |
| 4 | 3 | use crate::{ |
| 5 | − file::{self, Reference}, | |
| 4 | + file::{self}, | |
| 6 | 5 | mutable::Target, |
| 7 | − store::packed, | |
| 6 | + store::{ | |
| 7 | + file::{find, loose::Reference}, | |
| 8 | + packed, | |
| 9 | + }, | |
| 8 | 10 | }; |
| 9 | 11 | |
| 10 | 12 | quick_error! { |
| @@ -54,8 +56,8 @@ pub mod to_id { · 43 unmodified lines | ||
| 54 | 56 | use std::{collections::BTreeSet, path::PathBuf}; |
| 55 | 57 | |
| 56 | 58 | use crate::store::file::loose::reference; |
| 59 | + use crate::store::file::loose::Reference; | |
| 57 | 60 | use crate::{ |
| 58 | − file::Reference, | |
| 59 | 61 | mutable::{FullName, Target}, |
| 60 | 62 | store::{file::loose_then_packed, packed}, |
| 61 | 63 | }; |
| @@ -1,7 +1,5 @@ | ||
| 1 | 1 | use std::path::PathBuf; |
| 2 | 2 | |
| 3 | −use crate::mutable; | |
| 4 | − | |
| 5 | 3 | /// The way a file store handles the reflog |
| 6 | 4 | #[derive(Debug, PartialOrd, PartialEq, Ord, Eq, Hash, Clone, Copy)] |
| 7 | 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 | 18 | /// A store for reference which uses plain files. |
| 31 | 19 | /// |
| 32 | 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 | 1 | use super::{LooseThenPacked, Reference}; |
| 2 | 2 | use crate::{ |
| 3 | − file::path_to_name, | |
| 3 | + file::{loose, path_to_name}, | |
| 4 | 4 | store::{file, packed}, |
| 5 | 5 | }; |
| 6 | 6 | use std::{ |
| @@ -34,7 +34,7 @@ impl<'p, 's> LooseThenPacked<'p, 's> { · 27 unmodified lines | ||
| 34 | 34 | f.read_to_end(&mut self.buf) |
| 35 | 35 | }) |
| 36 | 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 | 38 | .map_err(|err| Error::ReferenceCreation { |
| 39 | 39 | err, |
| 40 | 40 | relative_path: refpath |
| @@ -97,8 +97,7 @@ impl file::Store { · 56 unmodified lines | ||
| 97 | 97 | .iter() |
| 98 | 98 | .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))? |
| 99 | 99 | .peekable(), |
| 100 | − loose: file::loose::iter::SortedLoosePaths::at_root_with_names(self.refs_dir(), self.base.clone()) | |
| 101 | − .peekable(), | |
| 100 | + loose: loose::iter::SortedLoosePaths::at_root_with_names(self.refs_dir(), self.base.clone()).peekable(), | |
| 102 | 101 | buf: Vec::new(), |
| 103 | 102 | }) |
| 104 | 103 | } |
| @@ -118,7 +117,7 @@ impl file::Store { · 13 unmodified lines | ||
| 118 | 117 | .iter_prefixed(packed_prefix) |
| 119 | 118 | .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))? |
| 120 | 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 | 121 | .peekable(), |
| 123 | 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 | 2 | use std::iter::Peekable; |
| 3 | 3 | |
| 4 | 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 | 8 | pub struct LooseThenPacked<'p, 's> { |
| 9 | 9 | parent: &'s file::Store, |
| 10 | 10 | packed: Peekable<packed::Iter<'p>>, |
| 11 | − loose: Peekable<file::loose::iter::SortedLoosePaths>, | |
| 11 | + loose: Peekable<loose::iter::SortedLoosePaths>, | |
| 12 | 12 | buf: Vec<u8>, |
| 13 | 13 | } |
| 14 | 14 | |
| @@ -17,7 +17,7 @@ pub enum Reference<'p, 's> { · 2 unmodified lines | ||
| 17 | 17 | /// A reference originating in a pack |
| 18 | 18 | Packed(packed::Reference<'p>), |
| 19 | 19 | /// A reference from the filesystem |
| 20 | − Loose(file::Reference<'s>), | |
| 20 | + Loose(loose::Reference<'s>), | |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | mod reference; |
| @@ -10,7 +10,7 @@ use crate::{ · 9 unmodified lines | ||
| 10 | 10 | use git_hash::oid; |
| 11 | 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 | 14 | type Error = (); |
| 15 | 15 | |
| 16 | 16 | fn try_from(value: Reference<'p, 's>) -> Result<Self, Self::Error> { |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | use crate::{ |
| 2 | 2 | mutable::Target, |
| 3 | − store::file, | |
| 3 | + store::{file, file::loose}, | |
| 4 | 4 | transaction::{Change, Create, RefEdit, RefEditsExt, RefLog}, |
| 5 | 5 | }; |
| 6 | 6 | use bstr::BString; |
| @@ -61,7 +61,7 @@ impl<'a> Transaction<'a> { · 54 unmodified lines | ||
| 61 | 61 | .map_err(Error::from) |
| 62 | 62 | .and_then(|opt| { |
| 63 | 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 | 66 | .transpose() |
| 67 | 67 | }) |