Unified · Split
| @@ -1633,6 +1633,7 @@ dependencies = [ · 1632 unmodified lines | |||
| 1633 | "gix-quote 0.4.7", | 1633 | "gix-quote 0.4.7", |
| 1634 | "gix-testtools", | 1634 | "gix-testtools", |
| 1635 | "gix-trace 0.1.3", | 1635 | "gix-trace 0.1.3", |
| 1636 | "gix-utils 0.1.5", | ||
| 1636 | "gix-worktree 0.27.0", | 1637 | "gix-worktree 0.27.0", |
| 1637 | "once_cell", | 1638 | "once_cell", |
| 1638 | "smallvec", | 1639 | "smallvec", |
| @@ -18,6 +18,7 @@ gix-trace = { version = "^0.1.3", path = "../gix-trace" } · 17 unmodified lines | |||
| 18 | gix-object = { version = "^0.38.0", path = "../gix-object" } | 18 | gix-object = { version = "^0.38.0", path = "../gix-object" } |
| 19 | gix-command = { version = "^0.2.10", path = "../gix-command" } | 19 | gix-command = { version = "^0.2.10", path = "../gix-command" } |
| 20 | gix-quote = { version = "^0.4.7", path = "../gix-quote" } | 20 | gix-quote = { version = "^0.4.7", path = "../gix-quote" } |
| 21 | gix-utils = { version = "^0.1.5", path = "../gix-utils" } | ||
| 21 | gix-path = { version = "^0.10.0", path = "../gix-path" } | 22 | gix-path = { version = "^0.10.0", path = "../gix-path" } |
| 22 | gix-packetline = { package = "gix-packetline-blocking", version = "^0.16.6", path = "../gix-packetline-blocking" } | 23 | gix-packetline = { package = "gix-packetline-blocking", version = "^0.16.6", path = "../gix-packetline-blocking" } |
| 23 | gix-attributes = { version = "^0.20.0", path = "../gix-attributes" } | 24 | gix-attributes = { version = "^0.20.0", path = "../gix-attributes" } |
| @@ -43,7 +43,7 @@ pub struct Pipeline { · 42 unmodified lines | |||
| 43 | /// State needed to keep running filter processes. | 43 | /// State needed to keep running filter processes. |
| 44 | processes: driver::State, | 44 | processes: driver::State, |
| 45 | /// A utility to handle multiple buffers to keep results of various filters. | 45 | /// A utility to handle multiple buffers to keep results of various filters. |
| 46 | bufs: pipeline::util::Buffers, | 46 | bufs: gix_utils::Buffers, |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | /// A declaration of a driver program. | 49 | /// A declaration of a driver program. |
| @@ -190,7 +190,7 @@ impl Pipeline { · 189 unmodified lines | |||
| 190 | self.options.eol_config, | 190 | self.options.eol_config, |
| 191 | )?; | 191 | )?; |
| 192 | 192 | ||
| 193 | let mut bufs = self.bufs.with_src(src); | 193 | let mut bufs = self.bufs.use_foreign_src(src); |
| 194 | let (src, dest) = bufs.src_and_dest(); | 194 | let (src, dest) = bufs.src_and_dest(); |
| 195 | if apply_ident_filter && ident::apply(src, self.options.object_hash, dest) { | 195 | if apply_ident_filter && ident::apply(src, self.options.object_hash, dest) { |
| 196 | bufs.swap(); | 196 | bufs.swap(); |
| @@ -114,6 +114,3 @@ impl Pipeline { · 113 unmodified lines | |||
| 114 | pub mod convert; | 114 | pub mod convert; |
| 115 | 115 | ||
| 116 | pub(crate) mod util; | 116 | pub(crate) mod util; |
| 117 | |||
| 118 | #[cfg(test)] | ||
| 119 | mod tests; | ||
| @@ -1,39 +0,0 @@ | |||
| 1 | mod buffers { | ||
| 2 | use bstr::ByteSlice; | ||
| 3 | |||
| 4 | use crate::pipeline::util::Buffers; | ||
| 5 | |||
| 6 | #[test] | ||
| 7 | fn usage() { | ||
| 8 | let mut backing = Buffers::default(); | ||
| 9 | let mut bufs = backing.with_src(b"a"); | ||
| 10 | |||
| 11 | { | ||
| 12 | let (src, dest) = bufs.src_and_dest(); | ||
| 13 | assert_eq!(src.as_bstr(), "a"); | ||
| 14 | assert!(dest.is_empty()); | ||
| 15 | dest.push(b'b'); | ||
| 16 | } | ||
| 17 | assert!(bufs.ro_src.is_some(), "read-only source remains until swap"); | ||
| 18 | bufs.swap(); | ||
| 19 | assert!( | ||
| 20 | bufs.ro_src.is_none(), | ||
| 21 | "after swap it's not used anymore as recent data is in owned buffers" | ||
| 22 | ); | ||
| 23 | |||
| 24 | let (src, dest) = bufs.src_and_dest(); | ||
| 25 | assert_eq!(src.as_bstr(), "b", "buffers were swapped"); | ||
| 26 | assert_eq!(dest.as_bstr(), "", "destination is new and cleared"); | ||
| 27 | dest.push(b'c'); | ||
| 28 | bufs.swap(); | ||
| 29 | |||
| 30 | let (src, dest) = bufs.src_and_dest(); | ||
| 31 | assert_eq!(src.as_bstr(), "c"); | ||
| 32 | assert_eq!(dest.as_bstr(), "", "destination is cleared"); | ||
| 33 | |||
| 34 | let mut bufs = backing.with_src(b"z"); | ||
| 35 | let (src, dest) = bufs.src_and_dest(); | ||
| 36 | assert_eq!(src.as_bstr(), "z"); | ||
| 37 | assert_eq!(dest.as_bstr(), "", "output buffer was cleared by `with_src()`") | ||
| 38 | } | ||
| 39 | } | ||
| @@ -11,54 +11,6 @@ use crate::{ · 10 unmodified lines | |||
| 11 | Driver, | 11 | Driver, |
| 12 | }; | 12 | }; |
| 13 | 13 | ||
| 14 | /// A utility to do buffer-swapping with. | ||
| 15 | #[derive(Default, Clone)] | ||
| 16 | pub(crate) struct Buffers { | ||
| 17 | pub src: Vec<u8>, | ||
| 18 | pub dest: Vec<u8>, | ||
| 19 | } | ||
| 20 | |||
| 21 | /// A utility to do buffer-swapping with. | ||
| 22 | pub(crate) struct BuffersWithSource<'src, 'bufs> { | ||
| 23 | pub ro_src: Option<&'src [u8]>, | ||
| 24 | pub src: &'bufs mut Vec<u8>, | ||
| 25 | pub dest: &'bufs mut Vec<u8>, | ||
| 26 | } | ||
| 27 | |||
| 28 | impl Buffers { | ||
| 29 | pub fn with_src<'a, 'src>(&'a mut self, src: &'src [u8]) -> BuffersWithSource<'src, 'a> { | ||
| 30 | self.clear(); | ||
| 31 | BuffersWithSource { | ||
| 32 | ro_src: Some(src), | ||
| 33 | src: &mut self.src, | ||
| 34 | dest: &mut self.dest, | ||
| 35 | } | ||
| 36 | } | ||
| 37 | pub fn clear(&mut self) { | ||
| 38 | self.src.clear(); | ||
| 39 | self.dest.clear(); | ||
| 40 | } | ||
| 41 | |||
| 42 | pub fn swap(&mut self) { | ||
| 43 | std::mem::swap(&mut self.src, &mut self.dest); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | impl BuffersWithSource<'_, '_> { | ||
| 48 | /// Must be called after every change (i.e. when it's known that `dest` was written. | ||
| 49 | pub fn swap(&mut self) { | ||
| 50 | self.ro_src.take(); | ||
| 51 | std::mem::swap(&mut self.src, &mut self.dest); | ||
| 52 | self.dest.clear(); | ||
| 53 | } | ||
| 54 | pub fn src_and_dest(&mut self) -> (&[u8], &mut Vec<u8>) { | ||
| 55 | match self.ro_src { | ||
| 56 | Some(src) => (src, &mut self.dest), | ||
| 57 | None => (self.src, &mut self.dest), | ||
| 58 | } | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | pub(crate) struct Configuration<'a> { | 14 | pub(crate) struct Configuration<'a> { |
| 63 | pub(crate) driver: Option<&'a Driver>, | 15 | pub(crate) driver: Option<&'a Driver>, |
| 64 | /// What attributes say about CRLF handling. | 16 | /// What attributes say about CRLF handling. |