Skip to content

Commit

Permalink
Merge pull request #258 from Ivanbeethoven/main
Browse files Browse the repository at this point in the history
(git & delta) Renaming the function signature of delta and formally relying on the delta module for git's delta operation
  • Loading branch information
genedna authored Nov 21, 2023
2 parents 5087ce0 + fc46de3 commit c70e75f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 19 deletions.
6 changes: 3 additions & 3 deletions delta/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> {
pub fn encode(old_data: & [u8], new_data: & [u8]) -> Vec<u8> {
let differ = DeltaDiff::new(old_data, new_data);
differ.encode()
}
Expand Down
1 change: 1 addition & 0 deletions git/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions git/src/internal/diff/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 0 additions & 1 deletion git/src/internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
pub mod object;
pub mod pack;
pub mod zlib;
pub mod diff;
use std::fmt::Display;

use crate::errors::GitError;
Expand Down
13 changes: 4 additions & 9 deletions git/src/internal/pack/encode.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down
9 changes: 5 additions & 4 deletions git/src/internal/pack/preload.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{counter::GitTypeCounter, delta::undelta, EntryHeader, Pack};
use super::{counter::GitTypeCounter, EntryHeader, Pack};
use crate::{
errors::GitError,
internal::{
Expand All @@ -24,6 +24,7 @@ use std::{
time::Instant
};
use tokio::sync::{RwLock, RwLockReadGuard};
use delta;

///
/// One Pre loading Git object in memory
Expand Down Expand Up @@ -370,7 +371,7 @@ async fn produce_object<TC>(
}
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!");},
}
Expand Down Expand Up @@ -492,7 +493,7 @@ fn delta_offset_obj<T>(
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;
}
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit c70e75f

Please sign in to comment.