`Reference::log_iter(…)` now is a platform instead of a forward iterator, which requires a call to `.all()` to return the forward iterator like previously. `Reference::log_iter_rev(…)` was removed in favor of `Reference::log_iter(…).rev()`.
Unified · Split
| @@ -75,6 +75,7 @@ impl<'a> Iterator for Forward<'a> { · 74 unmodified lines | |||
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | /// A platform to store a buffer to hold ref log lines for iteration. | 77 | /// A platform to store a buffer to hold ref log lines for iteration. |
| 78 | #[must_use = "Iterators should be obtained from this platform"] | ||
| 78 | pub struct Platform<'a, 's> { | 79 | pub struct Platform<'a, 's> { |
| 79 | pub(crate) store: &'s file::Store, | 80 | pub(crate) store: &'s file::Store, |
| 80 | pub(crate) name: FullNameRef<'a>, | 81 | pub(crate) name: FullNameRef<'a>, |
| @@ -84,8 +85,8 @@ pub struct Platform<'a, 's> { · 3 unmodified lines | |||
| 84 | impl<'a, 's> Platform<'a, 's> { | 85 | impl<'a, 's> Platform<'a, 's> { |
| 85 | /// Return a forward iterator over all log-lines, most recent to oldest. | 86 | /// Return a forward iterator over all log-lines, most recent to oldest. |
| 86 | pub fn rev(&mut self) -> std::io::Result<Option<log::iter::Reverse<'_, std::fs::File>>> { | 87 | pub fn rev(&mut self) -> std::io::Result<Option<log::iter::Reverse<'_, std::fs::File>>> { |
| 87 | self.buf.resize(512, 0); | ||
| 88 | self.buf.clear(); | 88 | self.buf.clear(); |
| 89 | self.buf.resize(512, 0); | ||
| 89 | self.store | 90 | self.store |
| 90 | .reflog_iter_rev(self.name, &mut self.buf) | 91 | .reflog_iter_rev(self.name, &mut self.buf) |
| 91 | .map_err(must_be_io_err) | 92 | .map_err(must_be_io_err) |
| @@ -24,6 +24,7 @@ pub struct LooseThenPacked<'p, 's> { · 23 unmodified lines | |||
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | /// An intermediate structure to hold shared state alive long enough for iteration to happen. | 26 | /// An intermediate structure to hold shared state alive long enough for iteration to happen. |
| 27 | #[must_use = "Iterators should be obtained from this platform"] | ||
| 27 | pub struct Platform<'s> { | 28 | pub struct Platform<'s> { |
| 28 | store: &'s file::Store, | 29 | store: &'s file::Store, |
| 29 | packed: Option<OwnShared<packed::Buffer>>, | 30 | packed: Option<OwnShared<packed::Buffer>>, |
| @@ -5,10 +5,7 @@ use git_hash::ObjectId; · 4 unmodified lines | |||
| 5 | use crate::{ | 5 | use crate::{ |
| 6 | peel, | 6 | peel, |
| 7 | raw::Reference, | 7 | raw::Reference, |
| 8 | store_impl::{ | 8 | store_impl::{file, file::log}, |
| 9 | file, | ||
| 10 | file::{log, loose::reference::logiter::must_be_io_err}, | ||
| 11 | }, | ||
| 12 | Target, | 9 | Target, |
| 13 | }; | 10 | }; |
| 14 | 11 | ||
| @@ -18,21 +15,7 @@ impl Sealed for crate::Reference {} · 3 unmodified lines | |||
| 18 | /// A trait to extend [Reference][crate::Reference] with functionality requiring a [file::Store]. | 15 | /// A trait to extend [Reference][crate::Reference] with functionality requiring a [file::Store]. |
| 19 | pub trait ReferenceExt: Sealed { | 16 | pub trait ReferenceExt: Sealed { |
| 20 | /// A step towards obtaining forward or reverse iterators on reference logs. | 17 | /// A step towards obtaining forward or reverse iterators on reference logs. |
| 21 | fn log_iter_platform<'a, 's>(&'a self, store: &'s file::Store) -> log::iter::Platform<'a, 's>; | 18 | fn log_iter<'a, 's>(&'a self, store: &'s file::Store) -> log::iter::Platform<'a, 's>; |
| 22 | |||
| 23 | /// Obtain a reverse iterator over logs of this reference. See [crate::file::loose::Reference::log_iter_rev()] for details. | ||
| 24 | fn log_iter_rev<'b>( | ||
| 25 | &self, | ||
| 26 | store: &file::Store, | ||
| 27 | buf: &'b mut [u8], | ||
| 28 | ) -> std::io::Result<Option<log::iter::Reverse<'b, std::fs::File>>>; | ||
| 29 | |||
| 30 | /// Obtain an iterator over logs of this reference. See [crate::file::loose::Reference::log_iter()] for details. | ||
| 31 | fn log_iter<'a, 'b: 'a>( | ||
| 32 | &'a self, | ||
| 33 | store: &file::Store, | ||
| 34 | buf: &'b mut Vec<u8>, | ||
| 35 | ) -> std::io::Result<Option<log::iter::Forward<'b>>>; | ||
| 36 | 19 | ||
| 37 | /// For details, see [Reference::log_exists()]. | 20 | /// For details, see [Reference::log_exists()]. |
| 38 | fn log_exists(&self, store: &file::Store) -> bool; | 21 | fn log_exists(&self, store: &file::Store) -> bool; |
| @@ -52,7 +35,7 @@ pub trait ReferenceExt: Sealed { · 13 unmodified lines | |||
| 52 | } | 35 | } |
| 53 | 36 | ||
| 54 | impl ReferenceExt for Reference { | 37 | impl ReferenceExt for Reference { |
| 55 | fn log_iter_platform<'a, 's>(&'a self, store: &'s file::Store) -> log::iter::Platform<'a, 's> { | 38 | fn log_iter<'a, 's>(&'a self, store: &'s file::Store) -> log::iter::Platform<'a, 's> { |
| 56 | log::iter::Platform { | 39 | log::iter::Platform { |
| 57 | store, | 40 | store, |
| 58 | name: self.name.to_ref(), | 41 | name: self.name.to_ref(), |
| @@ -60,22 +43,6 @@ impl ReferenceExt for Reference { · 1 unmodified line | |||
| 60 | } | 43 | } |
| 61 | } | 44 | } |
| 62 | 45 | ||
| 63 | fn log_iter_rev<'b>( | ||
| 64 | &self, | ||
| 65 | store: &file::Store, | ||
| 66 | buf: &'b mut [u8], | ||
| 67 | ) -> std::io::Result<Option<log::iter::Reverse<'b, std::fs::File>>> { | ||
| 68 | store.reflog_iter_rev(self.name.to_ref(), buf).map_err(must_be_io_err) | ||
| 69 | } | ||
| 70 | |||
| 71 | fn log_iter<'a, 'b: 'a>( | ||
| 72 | &'a self, | ||
| 73 | store: &file::Store, | ||
| 74 | buf: &'b mut Vec<u8>, | ||
| 75 | ) -> std::io::Result<Option<log::iter::Forward<'b>>> { | ||
| 76 | store.reflog_iter(self.name.to_ref(), buf).map_err(must_be_io_err) | ||
| 77 | } | ||
| 78 | |||
| 79 | fn log_exists(&self, store: &file::Store) -> bool { | 46 | fn log_exists(&self, store: &file::Store) -> bool { |
| 80 | store | 47 | store |
| 81 | .reflog_exists(self.name.to_ref()) | 48 | .reflog_exists(self.name.to_ref()) |
| @@ -8,8 +8,7 @@ mod reflog { · 7 unmodified lines | |||
| 8 | fn iter() -> crate::Result { | 8 | fn iter() -> crate::Result { |
| 9 | let store = file::store_with_packed_refs()?; | 9 | let store = file::store_with_packed_refs()?; |
| 10 | let r = store.find("main")?; | 10 | let r = store.find("main")?; |
| 11 | let mut buf = Vec::new(); | 11 | assert_eq!(r.log_iter(&store).all()?.expect("log exists").count(), 1); |
| 12 | assert_eq!(r.log_iter(&store, &mut buf)?.expect("log exists").count(), 1); | ||
| 13 | assert!(r.log_exists(&store), "it exists if its readable"); | 12 | assert!(r.log_exists(&store), "it exists if its readable"); |
| 14 | Ok(()) | 13 | Ok(()) |
| 15 | } | 14 | } |
| @@ -18,8 +17,7 @@ mod reflog { · 2 unmodified lines | |||
| 18 | fn iter_rev() -> crate::Result { | 17 | fn iter_rev() -> crate::Result { |
| 19 | let store = file::store_with_packed_refs()?; | 18 | let store = file::store_with_packed_refs()?; |
| 20 | let r = store.find("main")?; | 19 | let r = store.find("main")?; |
| 21 | let mut buf = [0u8; 256]; | 20 | assert_eq!(r.log_iter(&store).rev()?.expect("log exists").count(), 1); |
| 22 | assert_eq!(r.log_iter_rev(&store, &mut buf)?.expect("log exists").count(), 1); | ||
| 23 | Ok(()) | 21 | Ok(()) |
| 24 | } | 22 | } |
| 25 | } | 23 | } |
| @@ -720,8 +720,7 @@ fn packed_refs_creation_with_packed_refs_mode_leave_keeps_original_loose_refs() · 719 unmodified lines | |||
| 720 | branch.target.as_id().expect("peeled"), | 720 | branch.target.as_id().expect("peeled"), |
| 721 | "the packed ref is outdated" | 721 | "the packed ref is outdated" |
| 722 | ); | 722 | ); |
| 723 | let mut buf = Vec::new(); | 723 | let previous_reflog_entries = branch.log_iter(&store).all()?.expect("log").count(); |
| 724 | let previous_reflog_entries = branch.log_iter(&store, &mut buf)?.expect("log").count(); | ||
| 725 | let previous_packed_refs = packed.iter()?.filter_map(Result::ok).count(); | 724 | let previous_packed_refs = packed.iter()?.filter_map(Result::ok).count(); |
| 726 | 725 | ||
| 727 | let edits = store.loose_iter()?.map(|r| r.expect("valid ref")).map(|r| RefEdit { | 726 | let edits = store.loose_iter()?.map(|r| r.expect("valid ref")).map(|r| RefEdit { |
| @@ -753,7 +752,7 @@ fn packed_refs_creation_with_packed_refs_mode_leave_keeps_original_loose_refs() · 25 unmodified lines | |||
| 753 | "the amount of loose refs didn't change and having symbolic ones isn't a problem" | 752 | "the amount of loose refs didn't change and having symbolic ones isn't a problem" |
| 754 | ); | 753 | ); |
| 755 | assert_eq!( | 754 | assert_eq!( |
| 756 | branch.log_iter(&store, &mut buf)?.expect("log").count(), | 755 | branch.log_iter(&store).all()?.expect("log").count(), |
| 757 | previous_reflog_entries, | 756 | previous_reflog_entries, |
| 758 | "reflog isn't adjusted as there is no change" | 757 | "reflog isn't adjusted as there is no change" |
| 759 | ); | 758 | ); |