History

[ref] refactor

Sebastian Thiel committed 5 years ago

Commit 49fc2121 parent 8ed391613 files · +61 −52Browse files

Showing the changes to git-ref/src (12 of 13 files). Show all

Unified · Split

12 files
  1. git-ref/src/store/file/find.rs +12 −7
  2. git-ref/src/store/file/loose/iter.rs +6 −3
  3. git-ref/src/store/file/loose/mod.rs +19 −0
  4. git-ref/src/store/file/loose/reference/decode.rs +2 −1
  5. git-ref/src/store/file/loose/reference/logiter.rs +1 −1
  6. git-ref/src/store/file/loose/reference/mod.rs +0 −9
  7. git-ref/src/store/file/loose/reference/peel.rs +6 −4
  8. git-ref/src/store/file/mod.rs +0 −12
  9. git-ref/src/store/file/overlay/iter.rs +4 −5
  10. git-ref/src/store/file/overlay/mod.rs +3 −3
  11. git-ref/src/store/file/overlay/reference.rs +1 −1
  12. git-ref/src/store/file/transaction.rs +2 −2
git-ref/src/store/file/find.rs+12−7
@@ -8,10 +8,13 @@ use bstr::ByteSlice; · 7 unmodified lines
8 8
9pub use error::Error;9pub use error::Error;
10 10
11use crate::mutable::FullName;
12use crate::{11use 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 where54 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 where203 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>,
git-ref/src/store/file/loose/iter.rs+6−3
@@ -1,4 +1,7 @@
1use crate::{mutable::FullName, store::file};1use crate::{
2 mutable::FullName,
3 store::file::{self, loose::Reference},
4};
2use bstr::ByteSlice;5use bstr::ByteSlice;
3use git_features::fs::walkdir::DirEntryIter;6use git_features::fs::walkdir::DirEntryIter;
4use os_str_bytes::OsStrBytes;7use os_str_bytes::OsStrBytes;
@@ -78,7 +81,7 @@ impl<'a> Loose<'a> { · 73 unmodified lines
78}81}
79 82
80impl<'a> Iterator for Loose<'a> {83impl<'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_path96 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(),
git-ref/src/store/file/loose/mod.rs+19−0
@@ -1,3 +1,22 @@
1use 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)]
5pub 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
13impl<'a> Reference<'a> {
14 /// Return the kind of ref.
15 pub fn kind(&self) -> Kind {
16 self.target.kind()
17 }
18}
19
1///20///
2pub(crate) mod reflog;21pub(crate) mod reflog;
3 22
git-ref/src/store/file/loose/reference/decode.rs+2−1
@@ -1,7 +1,8 @@
1use crate::{1use 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};
6use bstr::BString;7use bstr::BString;
7use git_hash::ObjectId;8use git_hash::ObjectId;
git-ref/src/store/file/loose/reference/logiter.rs+1−1
@@ -1,4 +1,4 @@
1use crate::store::file::{log, loose, Reference};1use crate::store::file::{log, loose, loose::Reference};
2use std::io::Read;2use std::io::Read;
3 3
4impl<'a> Reference<'a> {4impl<'a> Reference<'a> {
git-ref/src/store/file/loose/reference/mod.rs+0−9
@@ -1,12 +1,3 @@
1use crate::{file::Reference, Kind};
2
3impl<'a> Reference<'a> {
4 /// Return the kind of ref.
5 pub fn kind(&self) -> Kind {
6 self.target.kind()
7 }
8}
9
10mod logiter;1mod logiter;
11 2
12///3///
git-ref/src/store/file/loose/reference/peel.rs+6−4
@@ -1,10 +1,12 @@
1use quick_error::quick_error;1use quick_error::quick_error;
2 2
3use crate::store::file::find;
4use crate::{3use 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
10quick_error! {12quick_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 };
git-ref/src/store/file/mod.rs+0−12
@@ -1,7 +1,5 @@
1use std::path::PathBuf;1use std::path::PathBuf;
2 2
3use crate::mutable;
4
5/// The way a file store handles the reflog3/// 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)]
7pub enum WriteReflog {5pub 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)]
22pub 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 path20/// Each ref is represented as a single file on disk in a folder structure that follows the relative path
git-ref/src/store/file/overlay/iter.rs+4−5
@@ -1,6 +1,6 @@
1use super::{LooseThenPacked, Reference};1use super::{LooseThenPacked, Reference};
2use crate::{2use crate::{
3 file::path_to_name,3 file::{loose, path_to_name},
4 store::{file, packed},4 store::{file, packed},
5};5};
6use std::{6use 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: refpath40 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 })
git-ref/src/store/file/overlay/mod.rs+3−3
@@ -1,4 +1,4 @@
1use crate::store::{file, packed};1use crate::store::{file, file::loose, packed};
2use std::iter::Peekable;2use std::iter::Peekable;
3 3
4/// An iterator stepping through sorted input of loose references and packed references, preferring loose refs over otherwise4/// 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
8pub struct LooseThenPacked<'p, 's> {8pub 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 pack17 /// A reference originating in a pack
18 Packed(packed::Reference<'p>),18 Packed(packed::Reference<'p>),
19 /// A reference from the filesystem19 /// A reference from the filesystem
20 Loose(file::Reference<'s>),20 Loose(loose::Reference<'s>),
21}21}
22 22
23mod reference;23mod reference;
git-ref/src/store/file/overlay/reference.rs+1−1
@@ -10,7 +10,7 @@ use crate::{ · 9 unmodified lines
10use git_hash::oid;10use git_hash::oid;
11use std::convert::TryFrom;11use std::convert::TryFrom;
12 12
13impl<'p, 's> TryFrom<Reference<'p, 's>> for crate::file::Reference<'s> {13impl<'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> {
git-ref/src/store/file/transaction.rs+2−2
@@ -1,6 +1,6 @@
1use crate::{1use 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};
6use bstr::BString;6use 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 })

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t