🏡 index : ~doyle/packfile.git

author Jordan Doyle <jordan@doyle.la> 2023-07-04 20:16:54.0 +00:00:00
committer Jordan Doyle <jordan@doyle.la> 2023-07-04 20:16:54.0 +00:00:00
commit
33d76f2ceb837f673e2a74768c8cf2dc7032c072 [patch]
tree
955d630df395b2798e40356f82ecc18a56f8ac3b
parent
55938bb8888a89723e60517d9367cec83e0e18d4
download
33d76f2ceb837f673e2a74768c8cf2dc7032c072.tar.gz

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(-)

diff --git a/Cargo.toml b/Cargo.toml
index 4e4f004..9f07e28 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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"]
diff --git a/src/codec.rs b/src/codec.rs
index f0dd2ed..78af676 100644
--- a/src/codec.rs
+++ b/src/codec.rs
@@ -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 {
diff --git a/src/high_level.rs b/src/high_level.rs
index 94b6472..2f46e9d 100644
--- a/src/high_level.rs
+++ b/src/high_level.rs
@@ -8,7 +8,6 @@

use bytes::Bytes;
use indexmap::IndexMap;
use tracing::instrument;

use crate::{
    low_level::{
@@ -38,7 +37,10 @@ impl GitRepository {
    /// Inserts a file into the repository, writing a file to the path
    /// `path/to/my-file` would require a `path` of `["path", "to"]`
    /// and a `file` of `"my-file"`.
    #[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 {
    /// Finalises this `GitRepository` by writing a commit to the `packfile_entries`,
    /// all the files currently in the `tree`, returning all the packfile entries
    /// and also the commit hash so it can be referred to by `ls-ref`s.
    #[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 {
    /// Recursively writes the the whole tree out to the given `pack_file`,
    /// the tree contains pointers to (hashes of) files contained within a
    /// directory, and pointers to other directories.
    #[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>,
diff --git a/src/low_level.rs b/src/low_level.rs
index 37d9ad5..4a36227 100644
--- a/src/low_level.rs
+++ b/src/low_level.rs
@@ -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 {

// `[mode] [name]\0[hash]`
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); // TODO: this needs space reserving for it

@@ -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();

diff --git a/src/packet_line.rs b/src/packet_line.rs
index 5556760..1a37c10 100644
--- a/src/packet_line.rs
+++ b/src/packet_line.rs
@@ -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) => {