Skip to content

Commit e7de4c7

Browse files
committed
Merge branch 'trace-packetlines'
2 parents 16170d9 + c3edef1 commit e7de4c7

File tree

52 files changed

+375
-88
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+375
-88
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gitoxide-core/src/pack/receive.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ impl<W> protocol::fetch::DelegateBlocking for CloneDelegate<W> {
116116
mod blocking_io {
117117
use std::{io, io::BufRead, path::PathBuf};
118118

119+
use gix::config::tree::Key;
119120
use gix::{
120121
bstr::BString,
121122
protocol,
@@ -180,6 +181,12 @@ mod blocking_io {
180181
progress,
181182
protocol::FetchConnection::TerminateOnSuccessfulCompletion,
182183
gix::env::agent(),
184+
std::env::var_os(
185+
gix::config::tree::Gitoxide::TRACE_PACKET
186+
.environment_override()
187+
.expect("set"),
188+
)
189+
.is_some(),
183190
)?;
184191
Ok(())
185192
}
@@ -196,6 +203,7 @@ mod async_io {
196203

197204
use async_trait::async_trait;
198205
use futures_io::AsyncBufRead;
206+
use gix::config::tree::Key;
199207
use gix::{
200208
bstr::{BString, ByteSlice},
201209
odb::pack,
@@ -264,6 +272,12 @@ mod async_io {
264272
progress,
265273
protocol::FetchConnection::TerminateOnSuccessfulCompletion,
266274
gix::env::agent(),
275+
std::env::var_os(
276+
gix::config::tree::Gitoxide::TRACE_PACKET
277+
.environment_override()
278+
.expect("set"),
279+
)
280+
.is_some(),
267281
))
268282
})
269283
.await?;

gix-filter/src/driver/process/client.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ impl Client {
7676
let mut input = gix_packetline::StreamingPeekableIter::new(
7777
process.stdout.take().expect("configured stdout when spawning"),
7878
&[gix_packetline::PacketLineRef::Flush],
79+
false, /* packet tracing */
7980
);
8081
let mut read = input.as_read();
8182
let mut buf = String::new();

gix-filter/src/driver/process/server.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ impl Server {
6363
pick_version: &mut dyn FnMut(&[usize]) -> Option<usize>,
6464
available_capabilities: &[&str],
6565
) -> Result<Self, handshake::Error> {
66-
let mut input =
67-
gix_packetline::StreamingPeekableIter::new(stdin.lock(), &[gix_packetline::PacketLineRef::Flush]);
66+
let mut input = gix_packetline::StreamingPeekableIter::new(
67+
stdin.lock(),
68+
&[gix_packetline::PacketLineRef::Flush],
69+
false, /* packet tracing */
70+
);
6871
let mut read = input.as_read();
6972
let mut buf = String::new();
7073
read.read_line_to_string(&mut buf)?;

gix-packetline-blocking/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ blocking-io = []
2424
serde = ["dep:serde", "bstr/serde"]
2525

2626
[dependencies]
27+
gix-trace = { version = "^0.1.3", path = "../gix-trace" }
28+
2729
serde = { version = "1.0.114", optional = true, default-features = false, features = ["std", "derive"]}
2830
thiserror = "1.0.34"
2931
faster-hex = "0.8.0"

gix-packetline/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ path = "tests/blocking-packetline.rs"
3939
required-features = ["blocking-io", "maybe-async/is_sync"]
4040

4141
[dependencies]
42+
gix-trace = { version = "^0.1.3", path = "../gix-trace" }
43+
4244
serde = { version = "1.0.114", optional = true, default-features = false, features = ["std", "derive"]}
4345
thiserror = "1.0.34"
4446
faster-hex = "0.8.0"

gix-packetline/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ pub struct StreamingPeekableIter<T> {
9191
delimiters: &'static [PacketLineRef<'static>],
9292
is_done: bool,
9393
stopped_at: Option<PacketLineRef<'static>>,
94+
#[cfg_attr(all(not(feature = "async-io"), not(feature = "blocking-io")), allow(dead_code))]
95+
trace: bool,
9496
}
9597

9698
/// Utilities to help decoding packet lines

gix-packetline/src/read/async_io.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,30 @@ where
4444
delimiters: &[PacketLineRef<'static>],
4545
fail_on_err_lines: bool,
4646
buf_resize: bool,
47+
trace: bool,
4748
) -> ExhaustiveOutcome<'a> {
4849
(
4950
false,
5051
None,
5152
Some(match Self::read_line_inner(reader, buf).await {
5253
Ok(Ok(line)) => {
54+
if trace {
55+
match line {
56+
#[allow(unused_variables)]
57+
PacketLineRef::Data(d) => {
58+
gix_trace::trace!("<< {}", d.as_bstr().trim().as_bstr());
59+
}
60+
PacketLineRef::Flush => {
61+
gix_trace::trace!("<< FLUSH");
62+
}
63+
PacketLineRef::Delimiter => {
64+
gix_trace::trace!("<< DELIM");
65+
}
66+
PacketLineRef::ResponseEnd => {
67+
gix_trace::trace!("<< RESPONSE_END");
68+
}
69+
}
70+
}
5371
if delimiters.contains(&line) {
5472
let stopped_at = delimiters.iter().find(|l| **l == line).copied();
5573
buf.clear();
@@ -111,6 +129,7 @@ where
111129
self.delimiters,
112130
self.fail_on_err_lines,
113131
false,
132+
self.trace,
114133
)
115134
.await;
116135
self.is_done = is_done;
@@ -134,6 +153,7 @@ where
134153
self.delimiters,
135154
self.fail_on_err_lines,
136155
true,
156+
self.trace,
137157
)
138158
.await;
139159
self.is_done = is_done;

gix-packetline/src/read/blocking_io.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,30 @@ where
3838
delimiters: &[PacketLineRef<'static>],
3939
fail_on_err_lines: bool,
4040
buf_resize: bool,
41+
trace: bool,
4142
) -> ExhaustiveOutcome<'a> {
4243
(
4344
false,
4445
None,
4546
Some(match Self::read_line_inner(reader, buf) {
4647
Ok(Ok(line)) => {
48+
if trace {
49+
match line {
50+
#[allow(unused_variables)]
51+
PacketLineRef::Data(d) => {
52+
gix_trace::trace!("<< {}", d.as_bstr().trim().as_bstr());
53+
}
54+
PacketLineRef::Flush => {
55+
gix_trace::trace!("<< FLUSH");
56+
}
57+
PacketLineRef::Delimiter => {
58+
gix_trace::trace!("<< DELIM");
59+
}
60+
PacketLineRef::ResponseEnd => {
61+
gix_trace::trace!("<< RESPONSE_END");
62+
}
63+
}
64+
}
4765
if delimiters.contains(&line) {
4866
let stopped_at = delimiters.iter().find(|l| **l == line).copied();
4967
buf.clear();
@@ -66,6 +84,7 @@ where
6684
if buf_resize {
6785
buf.resize(len, 0);
6886
}
87+
// TODO(borrowchk): remove additional decoding of internal buffer which is needed only to make it past borrowchk
6988
Ok(Ok(crate::decode(buf).expect("only valid data here")))
7089
}
7190
Ok(Err(err)) => {
@@ -105,6 +124,7 @@ where
105124
self.delimiters,
106125
self.fail_on_err_lines,
107126
false,
127+
self.trace,
108128
);
109129
self.is_done = is_done;
110130
self.stopped_at = stopped_at;
@@ -127,6 +147,7 @@ where
127147
self.delimiters,
128148
self.fail_on_err_lines,
129149
true,
150+
self.trace,
130151
);
131152
self.is_done = is_done;
132153
self.stopped_at = stopped_at;

gix-packetline/src/read/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ pub use error::Error;
4343

4444
impl<T> StreamingPeekableIter<T> {
4545
/// Return a new instance from `read` which will stop decoding packet lines when receiving one of the given `delimiters`.
46-
pub fn new(read: T, delimiters: &'static [PacketLineRef<'static>]) -> Self {
46+
/// If `trace` is `true`, all packetlines received or sent will be passed to the facilities of the `gix-trace` crate.
47+
pub fn new(read: T, delimiters: &'static [PacketLineRef<'static>], trace: bool) -> Self {
4748
StreamingPeekableIter {
4849
read,
4950
#[cfg(any(feature = "blocking-io", feature = "async-io"))]
@@ -53,6 +54,7 @@ impl<T> StreamingPeekableIter<T> {
5354
fail_on_err_lines: false,
5455
is_done: false,
5556
stopped_at: None,
57+
trace,
5658
}
5759
}
5860

0 commit comments

Comments
 (0)