Skip to content

Commit 03fe8a7

Browse files
committed
repository!: rename easy::reference::log::State to easy::reference::Logs (#164)
1 parent 0cd585e commit 03fe8a7

File tree

9 files changed

+43
-37
lines changed

9 files changed

+43
-37
lines changed

git-repository/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Change return value of `prelude::RepositoryAccessExt::committer()` from `git_actor::Signature` to `Result<git_actor::Signature, easy::borrow:repo::Error>`
44
- Change return value of `prelude::ReferenceAccessExt` from `Result<Vec<RefEdit>>, _>` to `Result<easy::Reference, _>`.
55
- Rename `State` structs that serve as platform for iterators or other dependent types into `Platform`. These are usually intermediate objects only.
6+
- Rename `easy::Reference::log()` into `easy::Reference::logs()`
67

78
### v0.9.1 (2021-09-10)
89

git-repository/src/easy/ext/reference.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ pub trait ReferenceAccessExt: easy::Access + Sized {
207207

208208
/// Return a platform for iterating references.
209209
///
210-
/// Common kinds of iteration are [all][easy::reference::iter::State::all()] or [prefixed][easy::reference::iter::State::prefixed()]
210+
/// Common kinds of iteration are [all][easy::reference::iter::Platform::all()] or [prefixed][easy::reference::iter::Platform::prefixed()]
211211
/// references.
212212
fn references(&self) -> Result<easy::reference::iter::Platform<'_, Self>, easy::reference::iter::Error> {
213213
let state = self.state();

git-repository/src/easy/head.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub mod log {
6969
easy::{ext::ReferenceAccessExt, Head},
7070
};
7171

72-
/// The error returned by [Head::log()].
72+
/// The error returned by [Head::logs()].
7373
#[derive(Debug, thiserror::Error)]
7474
#[allow(missing_docs)]
7575
pub enum Error {
@@ -84,8 +84,8 @@ pub mod log {
8484
A: easy::Access + Sized,
8585
{
8686
/// Return a platform for obtaining iterators on the reference log associated with the `HEAD` reference.
87-
pub fn log(&self) -> Result<easy::reference::log::Platform<'repo, A, easy::Reference<'repo, A>>, Error> {
88-
Ok(easy::reference::log::Platform {
87+
pub fn logs(&self) -> Result<easy::reference::Logs<'repo, A, easy::Reference<'repo, A>>, Error> {
88+
Ok(easy::reference::Logs {
8989
reference: self.access.find_reference("HEAD")?,
9090
buf: self.access.state().try_borrow_mut_buf()?,
9191
_phantom: PhantomData::default(),

git-repository/src/easy/oid.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,6 @@ pub mod ancestors {
9696
}
9797
}
9898

99-
/// The iterator returned by [`Ancestors::all()`].
100-
pub struct Iter<'a, 'repo, A>
101-
where
102-
A: easy::Access + Sized,
103-
{
104-
access: &'repo A,
105-
inner: Box<dyn Iterator<Item = Result<git_hash::ObjectId, git_traverse::commit::ancestors::Error>> + 'a>,
106-
}
107-
10899
impl<'repo, A> Ancestors<'repo, A>
109100
where
110101
A: easy::Access + Sized,
@@ -130,6 +121,15 @@ pub mod ancestors {
130121
}
131122
}
132123

124+
/// The iterator returned by [`Ancestors::all()`].
125+
pub struct Iter<'a, 'repo, A>
126+
where
127+
A: easy::Access + Sized,
128+
{
129+
access: &'repo A,
130+
inner: Box<dyn Iterator<Item = Result<git_hash::ObjectId, git_traverse::commit::ancestors::Error>> + 'a>,
131+
}
132+
133133
impl<'a, 'repo, A> Iterator for Iter<'a, 'repo, A>
134134
where
135135
A: easy::Access + Sized,

git-repository/src/easy/reference/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ where
6464

6565
///
6666
pub mod init {
67-
/// The error returned by [`State::all()`][super::State::all()] or [`State::prefixed()`][super::State::prefixed()].
67+
/// The error returned by [`Platform::all()`][super::Platform::all()] or [`Platform::prefixed()`][super::Platform::prefixed()].
6868
#[derive(Debug, thiserror::Error)]
6969
#[allow(missing_docs)]
7070
pub enum Error {

git-repository/src/easy/reference/log.rs renamed to git-repository/src/easy/reference/logs.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
11
//!
2-
use std::{borrow::Borrow, cell::RefMut, marker::PhantomData, ops::DerefMut};
2+
use std::{borrow::Borrow, ops::DerefMut};
33

44
use git_ref::file::ReferenceExt;
55

6-
use crate::{easy, easy::Reference};
7-
8-
/// A platform to obtain iterators over reference logs.
9-
#[must_use = "Iterators should be obtained from this log platform"]
10-
pub struct Platform<'repo, A: 'repo, R>
11-
where
12-
R: Borrow<Reference<'repo, A>>,
13-
{
14-
pub(crate) reference: R,
15-
pub(crate) buf: RefMut<'repo, Vec<u8>>,
16-
pub(crate) _phantom: PhantomData<A>,
17-
}
6+
use crate::{
7+
easy,
8+
easy::{reference::Logs, Reference},
9+
};
1810

1911
///
2012
pub mod init {
2113
use crate::easy;
2214

23-
/// The error returned by [State::iter()][super::State::iter()] and [State::iter_rev()][super::State::iter_rev()].
15+
/// The error returned by [Logs::iter()][super::Logs::iter()] and [Logs::iter_rev()][super::Logs::iter_rev()].
2416
#[derive(Debug, thiserror::Error)]
2517
#[allow(missing_docs)]
2618
pub enum Error {
@@ -37,7 +29,7 @@ pub type ReverseIter<'a> = git_ref::file::log::iter::Reverse<'a, std::fs::File>;
3729
/// An iterator over reference logs, oldest to newest.
3830
pub type ForwardIter<'a> = git_ref::file::log::iter::Forward<'a>;
3931

40-
impl<'repo, A, R> Platform<'repo, A, R>
32+
impl<'repo, A, R> Logs<'repo, A, R>
4133
where
4234
A: easy::Access + Sized,
4335
R: Borrow<Reference<'repo, A>>,
@@ -59,7 +51,7 @@ where
5951
/// Return an iterator over reference logs, from oldest to newest.
6052
///
6153
/// The iterator is optimized for rewriting the processing or rewriting the entire log.
62-
/// For accessing only the most recent entries, see [`iter_rev()`][State::iter_rev()].
54+
/// For accessing only the most recent entries, see [`iter_rev()`][Logs::iter_rev()].
6355
pub fn iter(&mut self) -> Result<Option<ForwardIter<'_>>, init::Error> {
6456
let buf = self.buf.deref_mut();
6557
Ok(self
@@ -75,8 +67,8 @@ where
7567
A: easy::Access + Sized,
7668
{
7769
/// Return a platform for obtaining iterators over reference logs.
78-
pub fn log(&self) -> Result<Platform<'repo, A, &'_ Reference<'repo, A>>, easy::borrow::state::Error> {
79-
Ok(Platform {
70+
pub fn logs(&self) -> Result<Logs<'repo, A, &'_ Reference<'repo, A>>, easy::borrow::state::Error> {
71+
Ok(Logs {
8072
reference: self,
8173
buf: self.access.state().try_borrow_mut_buf()?,
8274
_phantom: Default::default(),

git-repository/src/easy/reference/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ use crate::{
1212
pub mod iter;
1313

1414
mod errors;
15+
use std::{borrow::Borrow, cell::RefMut, marker::PhantomData};
16+
1517
pub use errors::{edit, find, namespace, peel};
1618

17-
pub mod log;
19+
pub mod logs;
1820
pub(crate) mod packed;
1921

2022
/// Access
@@ -35,6 +37,17 @@ impl<'repo, A> Reference<'repo, A> {
3537
}
3638
}
3739

40+
/// A platform to obtain iterators over reference logs.
41+
#[must_use = "Iterators should be obtained from this log platform"]
42+
pub struct Logs<'repo, A: 'repo, R>
43+
where
44+
R: Borrow<Reference<'repo, A>>,
45+
{
46+
pub(crate) reference: R,
47+
pub(crate) buf: RefMut<'repo, Vec<u8>>,
48+
pub(crate) _phantom: PhantomData<A>,
49+
}
50+
3851
impl<'repo, A> Reference<'repo, A>
3952
where
4053
A: easy::Access + Sized,

git-repository/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
//! However, other ways to adjust the `Repository` of long-running applications are possible. For instance, there could be a flag that
4848
//! indicates a new `Repository` should be created (for instance, after it was changed) which causes the next server connection to
4949
//! create a new one. This instance is the one to use when spawning new `EasyArc` instances.
50-
//! * `Platform` types are used to hold mutable or shared versions of required state for use in dependent objects they create, like iterators.
50+
//! * 'Platform' types are used to hold mutable or shared versions of required state for use in dependent objects they create, like iterators.
5151
//! These come with the benefit of allowing for nicely readable call chains.
5252
//!
5353
//! ### Terminology

git-repository/tests/easy/ext/object.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ mod commit {
6161
let head = repo.head()?.into_referent();
6262
assert_eq!(head.name().as_bstr(), "refs/heads/main", "'main' is the default name");
6363
assert_eq!(
64-
head.log()?
64+
head.logs()?
6565
.iter_rev()?
6666
.expect("log present")
6767
.next()
@@ -94,7 +94,7 @@ mod commit {
9494

9595
let head_log_entries: Vec<_> = repo
9696
.head()?
97-
.log()?
97+
.logs()?
9898
.iter_rev()?
9999
.expect("log present")
100100
.map(Result::unwrap)
@@ -127,7 +127,7 @@ mod commit {
127127
let current_commit = branch.peel_to_id_in_place()?;
128128
assert_eq!(current_commit, second_commit_id, "the commit was set");
129129

130-
let mut log = branch.log()?;
130+
let mut log = branch.logs()?;
131131
let mut log_iter = log.iter_rev()?.expect("log present");
132132
assert_eq!(
133133
log_iter.next().expect("one line")?.message,

0 commit comments

Comments
 (0)