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
88
99 pub use error::Error;
1010
11−use crate::mutable::FullName;
1211 use crate::{
1312 file,
14− store::{file::path_to_name, packed},
13+ mutable::FullName,
14+ store::{
15+ file::{loose, path_to_name},
16+ packed,
17+ },
1518 PartialName,
1619 };
1720
@@ -47,7 +50,7 @@ impl file::Store { · 29 unmodified lines
4750 }
4851
4952 /// 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>
5154 where
5255 Name: TryInto<PartialName<'a>, Error = E>,
5356 Error: From<E>,
@@ -126,7 +129,7 @@ impl file::Store { · 72 unmodified lines
126129 };
127130 Ok(Some({
128131 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)
130133 .map(file::loose_then_packed::Reference::Loose)
131134 .map_err(|err| Error::ReferenceCreation { err, relative_path })?
132135 }))
@@ -165,10 +168,12 @@ pub mod existing { · 32 unmodified lines
165168
166169 pub use error::Error;
167170
168− use crate::store::file::find;
169171 use crate::{
170172 file::{self},
171− store::packed,
173+ store::{
174+ file::{find, loose},
175+ packed,
176+ },
172177 PartialName,
173178 };
174179
@@ -194,7 +199,7 @@ pub mod existing { · 19 unmodified lines
194199 }
195200
196201 /// 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>
198203 where
199204 Name: TryInto<PartialName<'a>, Error = E>,
200205 crate::name::Error: From<E>,
git-ref/src/store/file/loose/iter.rs+6−3
@@ -1,4 +1,7 @@
1−use crate::{mutable::FullName, store::file};
1+use crate::{
2+ mutable::FullName,
3+ store::file::{self, loose::Reference},
4+};
25 use bstr::ByteSlice;
36 use git_features::fs::walkdir::DirEntryIter;
47 use os_str_bytes::OsStrBytes;
@@ -78,7 +81,7 @@ impl<'a> Loose<'a> { · 73 unmodified lines
7881 }
7982
8083 impl<'a> Iterator for Loose<'a> {
81− type Item = Result<file::Reference<'a>, loose::Error>;
84+ type Item = Result<Reference<'a>, loose::Error>;
8285
8386 fn next(&mut self) -> Option<Self::Item> {
8487 self.ref_paths.next().map(|res| {
@@ -93,7 +96,7 @@ impl<'a> Iterator for Loose<'a> { · 8 unmodified lines
9396 let relative_path = validated_path
9497 .strip_prefix(&self.ref_paths.base)
9598 .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| {
97100 loose::Error::ReferenceCreation {
98101 err,
99102 relative_path: relative_path.into(),
git-ref/src/store/file/loose/mod.rs+19−0
@@ -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+
120 ///
221 pub(crate) mod reflog;
322
git-ref/src/store/file/loose/reference/decode.rs+2−1
@@ -1,7 +1,8 @@
11 use crate::{
2− file::{Reference, Store},
2+ file::Store,
33 mutable,
44 parse::{hex_hash, newline},
5+ store::file::loose::Reference,
56 };
67 use bstr::BString;
78 use git_hash::ObjectId;
git-ref/src/store/file/loose/reference/logiter.rs+1−1
@@ -1,4 +1,4 @@
1−use crate::store::file::{log, loose, Reference};
1+use crate::store::file::{log, loose, loose::Reference};
22 use std::io::Read;
33
44 impl<'a> Reference<'a> {
git-ref/src/store/file/loose/reference/mod.rs+0−9
@@ -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−
101 mod logiter;
112
123 ///
git-ref/src/store/file/loose/reference/peel.rs+6−4
@@ -1,10 +1,12 @@
11 use quick_error::quick_error;
22
3−use crate::store::file::find;
43 use crate::{
5− file::{self, Reference},
4+ file::{self},
65 mutable::Target,
7− store::packed,
6+ store::{
7+ file::{find, loose::Reference},
8+ packed,
9+ },
810 };
911
1012 quick_error! {
@@ -54,8 +56,8 @@ pub mod to_id { · 43 unmodified lines
5456 use std::{collections::BTreeSet, path::PathBuf};
5557
5658 use crate::store::file::loose::reference;
59+ use crate::store::file::loose::Reference;
5760 use crate::{
58− file::Reference,
5961 mutable::{FullName, Target},
6062 store::{file::loose_then_packed, packed},
6163 };
git-ref/src/store/file/mod.rs+0−12
@@ -1,7 +1,5 @@
11 use std::path::PathBuf;
22
3−use crate::mutable;
4−
53 /// The way a file store handles the reflog
64 #[derive(Debug, PartialOrd, PartialEq, Ord, Eq, Hash, Clone, Copy)]
75 pub enum WriteReflog {
@@ -17,16 +15,6 @@ impl Default for WriteReflog { · 9 unmodified lines
1715 }
1816 }
1917
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−
3018 /// A store for reference which uses plain files.
3119 ///
3220 /// 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 @@
11 use super::{LooseThenPacked, Reference};
22 use crate::{
3− file::path_to_name,
3+ file::{loose, path_to_name},
44 store::{file, packed},
55 };
66 use std::{
@@ -34,7 +34,7 @@ impl<'p, 's> LooseThenPacked<'p, 's> { · 27 unmodified lines
3434 f.read_to_end(&mut self.buf)
3535 })
3636 .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)
3838 .map_err(|err| Error::ReferenceCreation {
3939 err,
4040 relative_path: refpath
@@ -97,8 +97,7 @@ impl file::Store { · 56 unmodified lines
9797 .iter()
9898 .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?
9999 .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(),
102101 buf: Vec::new(),
103102 })
104103 }
@@ -118,7 +117,7 @@ impl file::Store { · 13 unmodified lines
118117 .iter_prefixed(packed_prefix)
119118 .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?
120119 .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())
122121 .peekable(),
123122 buf: Vec::new(),
124123 })
git-ref/src/store/file/overlay/mod.rs+3−3
@@ -1,4 +1,4 @@
1−use crate::store::{file, packed};
1+use crate::store::{file, file::loose, packed};
22 use std::iter::Peekable;
33
44 /// 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
88 pub struct LooseThenPacked<'p, 's> {
99 parent: &'s file::Store,
1010 packed: Peekable<packed::Iter<'p>>,
11− loose: Peekable<file::loose::iter::SortedLoosePaths>,
11+ loose: Peekable<loose::iter::SortedLoosePaths>,
1212 buf: Vec<u8>,
1313 }
1414
@@ -17,7 +17,7 @@ pub enum Reference<'p, 's> { · 2 unmodified lines
1717 /// A reference originating in a pack
1818 Packed(packed::Reference<'p>),
1919 /// A reference from the filesystem
20− Loose(file::Reference<'s>),
20+ Loose(loose::Reference<'s>),
2121 }
2222
2323 mod reference;
git-ref/src/store/file/overlay/reference.rs+1−1
@@ -10,7 +10,7 @@ use crate::{ · 9 unmodified lines
1010 use git_hash::oid;
1111 use std::convert::TryFrom;
1212
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> {
1414 type Error = ();
1515
1616 fn try_from(value: Reference<'p, 's>) -> Result<Self, Self::Error> {
git-ref/src/store/file/transaction.rs+2−2
@@ -1,6 +1,6 @@
11 use crate::{
22 mutable::Target,
3− store::file,
3+ store::{file, file::loose},
44 transaction::{Change, Create, RefEdit, RefEditsExt, RefLog},
55 };
66 use bstr::BString;
@@ -61,7 +61,7 @@ impl<'a> Transaction<'a> { · 54 unmodified lines
6161 .map_err(Error::from)
6262 .and_then(|opt| {
6363 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)
6565 })
6666 .transpose()
6767 })

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