Move tracing to behind a feature flag
Diff
Cargo.toml | 4 ++--
src/codec.rs | 3 +--
src/high_level.rs | 13 +++++++++----
src/low_level.rs | 21 +++++++++++++--------
src/packet_line.rs | 3 +--
5 files changed, 26 insertions(+), 18 deletions(-)
@@ -22,11 +22,11 @@ sha1 = "0.10"
thiserror = "1.0"
time = "0.3.15"
tokio-util = { version = "0.7", features = ["codec"], optional = true }
tracing = "0.1"
tracing = { version = "0.1", optional = true }
[dev-dependencies]
insta = { version = "1.29", features = ["filters"] }
tempfile = "3.5"
[features]
default = ["tokio-util"]
default = ["tokio-util", "tracing"]
@@ -8,7 +8,6 @@ use std::ops::RangeInclusive;
use bytes::{Buf, Bytes, BytesMut};
use tokio_util::codec;
use tracing::instrument;
use crate::{packet_line::PktLine, Error};
@@ -40,7 +39,7 @@ impl codec::Decoder for GitCodec {
type Item = GitCommand;
type Error = Error;
#[instrument(skip(self, src), err)]
#[cfg_attr(feature = "tracing", tracing::instrument(skip(self, src), err))]
fn decode(&mut self, src: &mut bytes::BytesMut) -> Result<Option<Self::Item>, Self::Error> {
loop {
if src.len() < 4 {
@@ -8,7 +8,6 @@
use bytes::Bytes;
use indexmap::IndexMap;
use tracing::instrument;
use crate::{
low_level::{
@@ -38,7 +37,10 @@ impl GitRepository {
#[instrument(skip(self, file, content), err)]
#[cfg_attr(
feature = "tracing",
tracing::instrument(skip(self, file, content), err)
)]
pub fn insert(
&mut self,
path: &[&'static str],
@@ -83,7 +85,10 @@ impl GitRepository {
#[instrument(skip(self, name, email, message), err)]
#[cfg_attr(
feature = "tracing",
tracing::instrument(skip(self, name, email, message), err)
)]
pub fn commit(
mut self,
name: &'static str,
@@ -128,7 +133,7 @@ impl Tree {
#[instrument(skip(self, pack_file), err)]
#[cfg_attr(feature = "tracing", tracing::instrument(skip(self, pack_file), err))]
fn into_packfile_entries(
self,
pack_file: &mut IndexMap<HashOutput, PackFileEntry>,
@@ -12,7 +12,6 @@ use std::{
use bytes::{BufMut, Bytes, BytesMut};
use flate2::{write::ZlibEncoder, Compression};
use sha1::Digest;
use tracing::instrument;
use crate::{util::ArcOrCowStr, Error};
@@ -44,7 +43,10 @@ impl<'a> PackFile<'a> {
20
}
#[instrument(skip(self, original_buf), err)]
#[cfg_attr(
feature = "tracing",
tracing::instrument(skip(self, original_buf), err)
)]
pub fn encode_to(&self, original_buf: &mut BytesMut) -> Result<(), Error> {
let mut buf = original_buf.split_off(original_buf.len());
buf.reserve(Self::header_size() + Self::footer_size());
@@ -84,7 +86,7 @@ pub struct Commit {
}
impl Commit {
#[instrument(skip(self, out), err)]
#[cfg_attr(feature = "tracing", tracing::instrument(skip(self, out), err))]
fn encode_to(&self, out: &mut BytesMut) -> Result<(), Error> {
let mut tree_hex = [0_u8; 20 * 2];
hex::encode_to_slice(self.tree, &mut tree_hex).map_err(Error::EncodeTreeHash)?;
@@ -170,7 +172,7 @@ pub struct TreeItem {
impl TreeItem {
#[instrument(skip(self, out), err)]
#[cfg_attr(feature = "tracing", tracing::instrument(skip(self, out), err))]
fn encode_to(&self, out: &mut BytesMut) -> Result<(), Error> {
out.write_str(self.kind.mode())?;
write!(out, " {}\0", self.name)?;
@@ -223,7 +225,7 @@ pub enum PackFileEntry {
}
impl PackFileEntry {
#[instrument(skip(self, buf))]
#[cfg_attr(feature = "tracing", tracing::instrument(skip(self, buf)))]
fn write_header(&self, buf: &mut BytesMut) {
let mut size = self.uncompressed_size();
@@ -271,7 +273,10 @@ impl PackFileEntry {
}
}
#[instrument(skip(self, original_out), err)]
#[cfg_attr(
feature = "tracing",
tracing::instrument(skip(self, original_out), err)
)]
pub fn encode_to(&self, original_out: &mut BytesMut) -> Result<(), Error> {
self.write_header(original_out);
@@ -309,7 +314,7 @@ impl PackFileEntry {
Ok(())
}
#[instrument(skip(self))]
#[cfg_attr(feature = "tracing", tracing::instrument(skip(self)))]
#[must_use]
pub fn uncompressed_size(&self) -> usize {
match self {
@@ -319,7 +324,7 @@ impl PackFileEntry {
}
}
#[instrument(skip(self), err)]
#[cfg_attr(feature = "tracing", tracing::instrument(skip(self), err))]
pub fn hash(&self) -> Result<HashOutput, Error> {
let size = self.uncompressed_size();
@@ -1,7 +1,6 @@
use std::fmt::Write;
use bytes::{BufMut, BytesMut};
use tracing::instrument;
use crate::{low_level::PackFile, Error};
@@ -24,7 +23,7 @@ pub enum PktLine<'a> {
}
impl PktLine<'_> {
#[instrument(skip(self, buf), err)]
#[cfg_attr(feature = "tracing", tracing::instrument(skip(self, buf), err))]
pub fn encode_to(&self, buf: &mut BytesMut) -> Result<(), Error> {
match self {
Self::Data(data) => {