From 199b258e51381d4610517a93a6c7af5e28d933bf Mon Sep 17 00:00:00 2001 From: Xiaoyang Han Date: Tue, 21 Nov 2023 14:19:55 +0800 Subject: [PATCH] (git & delta) Renaming the function signature of delta and formally relying on the delta module for git's delta operation Signed-off-by: Xiaoyang Han --- delta/src/lib.rs | 6 +++--- git/Cargo.toml | 1 + git/src/internal/diff/mod.rs | 4 ++-- git/src/internal/mod.rs | 1 - git/src/internal/pack/encode.rs | 13 ++++--------- git/src/internal/pack/preload.rs | 9 +++++---- 6 files changed, 15 insertions(+), 19 deletions(-) diff --git a/delta/src/lib.rs b/delta/src/lib.rs index b1c49a2f..c1bbdf84 100644 --- a/delta/src/lib.rs +++ b/delta/src/lib.rs @@ -7,12 +7,12 @@ mod utils; -pub use decode::delta_decode; -pub fn delta_encode_rate(old_data: & [u8], new_data: & [u8]) -> f64{ +pub use decode::delta_decode as decode; +pub fn encode_rate(old_data: & [u8], new_data: & [u8]) -> f64{ let differ = DeltaDiff::new(old_data, new_data); differ.get_ssam_rate() } -pub fn delta_encode(old_data: & [u8], new_data: & [u8]) -> Vec { +pub fn encode(old_data: & [u8], new_data: & [u8]) -> Vec { let differ = DeltaDiff::new(old_data, new_data); differ.encode() } diff --git a/git/Cargo.toml b/git/Cargo.toml index 30183f08..2b0ebf16 100644 --- a/git/Cargo.toml +++ b/git/Cargo.toml @@ -20,6 +20,7 @@ common = { path = "../common" } entity = { path = "../storage/entity" } storage = { path = "../storage" } kvcache = { path = "../kvcache" } +delta = { path = "../delta"} anyhow = "1.0.75" bstr = "1.7.0" chrono = "0.4.24" diff --git a/git/src/internal/diff/mod.rs b/git/src/internal/diff/mod.rs index 98f7f44b..644d99bd 100644 --- a/git/src/internal/diff/mod.rs +++ b/git/src/internal/diff/mod.rs @@ -1,9 +1,9 @@ //! //! +//! # This sub module has been enabled and all its functions have been moved to the "delta" module //! //! -//! -//! + #[cfg(feature="diff_mydrs")] use diffs::myers; use diffs::Diff; diff --git a/git/src/internal/mod.rs b/git/src/internal/mod.rs index d010882c..4fec8d39 100644 --- a/git/src/internal/mod.rs +++ b/git/src/internal/mod.rs @@ -6,7 +6,6 @@ pub mod object; pub mod pack; pub mod zlib; -pub mod diff; use std::fmt::Display; use crate::errors::GitError; diff --git a/git/src/internal/pack/encode.rs b/git/src/internal/pack/encode.rs index 7eb6aab7..f3243b48 100644 --- a/git/src/internal/pack/encode.rs +++ b/git/src/internal/pack/encode.rs @@ -1,16 +1,13 @@ use entity::objects; use sha1::{Digest, Sha1}; -use std::io::{Cursor, Write}; +use std::io::{Cursor, Write,Error}; use std::sync::Arc; -use crate::internal::diff::DeltaDiff; use crate::internal::object::ObjectT; use crate::internal::zlib::stream::deflate::Write as Writer; - -use std::io::Error; - use super::header::EntryHeader; +use delta; const SLID_WINDWOS: usize = 20; #[allow(unused)] @@ -55,8 +52,7 @@ where if !obj_vec[pos].object_type.eq(&obj_vec[i].object_type) { break; } - let differ = DeltaDiff::new(&obj_vec[i - j].data, &obj_vec[i].data); - let diff_rate = differ.get_ssam_rate(); + let diff_rate = delta::encode_rate(&obj_vec[i - j].data, &obj_vec[i].data); if (diff_rate > best_ssam_rate) && diff_rate > 0.5 { best_ssam_rate = diff_rate; best_j = j; @@ -69,8 +65,7 @@ where &obj_vec[i].data, ) } else { - let differ = DeltaDiff::new(&obj_vec[i - best_j].data, &obj_vec[i].data); - let after = differ.encode(); + let after = delta::encode(&obj_vec[i - best_j].data, &obj_vec[i].data); encode_one_ojbect(6, after.len(), &after) } .unwrap(); diff --git a/git/src/internal/pack/preload.rs b/git/src/internal/pack/preload.rs index e5aede71..b8487038 100644 --- a/git/src/internal/pack/preload.rs +++ b/git/src/internal/pack/preload.rs @@ -1,4 +1,4 @@ -use super::{counter::GitTypeCounter, delta::undelta, EntryHeader, Pack}; +use super::{counter::GitTypeCounter, EntryHeader, Pack}; use crate::{ errors::GitError, internal::{ @@ -24,6 +24,7 @@ use std::{ time::Instant }; use tokio::sync::{RwLock, RwLockReadGuard}; +use delta; /// /// One Pre loading Git object in memory @@ -370,7 +371,7 @@ async fn produce_object( } let mut base_obj = stack.pop().unwrap(); while let Some(e) = stack.pop() { - base_obj.data = match undelta(&mut Cursor::new(&e.data), &base_obj.data){ + base_obj.data = match delta::decode(&mut Cursor::new(&e.data), &base_obj.data){ Ok(a) => a, Err(err) => {tracing::error!("thread id:{} err:{}",thread_id,err); panic!("err!");}, } @@ -492,7 +493,7 @@ fn delta_offset_obj( counter.lock().unwrap().count_depth(stack.len()); } while let Some(e) = stack.pop() { - b_obj.data = undelta(&mut Cursor::new(&e.data), &b_obj.data).unwrap(); + b_obj.data = delta::decode(&mut Cursor::new(&e.data), &b_obj.data).unwrap(); } return b_obj; } @@ -546,7 +547,7 @@ async fn get_ref_object_fromdb( counter.lock().unwrap().count(DB); } base_data = db_obj.data; - let re = undelta(&mut Cursor::new(e.data.clone()), &base_data); + let re = delta::decode(&mut Cursor::new(e.data.clone()), &base_data); if re.is_err(){ tracing::error!("REF_DELTA ERROR:{}",re.err().unwrap()); return None}