Compare commits

...

3 Commits
master ... gix

Author SHA1 Message Date
2d9b1024be gitoxide not ready yet 2024-01-13 15:29:31 -08:00
c8fe02160e wip 2024-01-12 23:47:58 -08:00
389943c361 gix deps 2024-01-12 23:00:23 -08:00
3 changed files with 1213 additions and 81 deletions

1231
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,7 @@ chrono = { version = "0.4.31", features = ["serde"] }
clap = { version = "4.4.2", features = ["derive"] } clap = { version = "4.4.2", features = ["derive"] }
flate2 = "1.0.28" flate2 = "1.0.28"
futures = "0.3.30" futures = "0.3.30"
git2 = "0.18.1" gix = "0.57.1"
lazy-regex = "3.1.0" lazy-regex = "3.1.0"
pollster = "0.3.0" pollster = "0.3.0"
rayon = "1.8.0" rayon = "1.8.0"

View File

@ -816,7 +816,7 @@ struct WriteCommitConfig{
write_scripts:bool, write_scripts:bool,
} }
async fn write_commit(config:WriteCommitConfig,b:Result<AResult<(AssetVersion,DecompiledContext)>,tokio::task::JoinError>,repo:&git2::Repository)->AResult<()>{ async fn write_commit(config:WriteCommitConfig,b:Result<AResult<(AssetVersion,DecompiledContext)>,tokio::task::JoinError>,repo:&gix::Repository)->AResult<()>{
let (asset_version,context)=b??; let (asset_version,context)=b??;
println!("writing files for version {}",asset_version.assetVersionNumber); println!("writing files for version {}",asset_version.assetVersionNumber);
@ -847,12 +847,16 @@ async fn write_commit(config:WriteCommitConfig,b:Result<AResult<(AssetVersion,De
write_scripts:config.write_scripts, write_scripts:config.write_scripts,
},context).await?; },context).await?;
let date=asset_version.created; let sig=gix::actor::Signature{
//let sig=repo.signature()?; //this pulls default name and email name:config.git_committer_name.into(),
let sig=git2::Signature::new(config.git_committer_name.as_str(),config.git_committer_email.as_str(),&git2::Time::new(date.timestamp(),0)).unwrap(); email:config.git_committer_email.into(),
time:gix::date::Time::new(asset_version.created.timestamp(),0),
};
let tree_id={ let tree_id={
let mut tree_index = repo.index()?; let mut tree = repo.index()?;
tree_index.add_all([config.output_folder.as_path()].iter(),git2::IndexAddOption::DEFAULT,None)?; tree.index()?.
tree.peel_to_entry(path);
tree_index.add_all([config.output_folder.as_path()].iter(),gix::IndexAddOption::DEFAULT,None)?;
if tree_index.len()==0{ if tree_index.len()==0{
println!("tree_index.len()==0"); println!("tree_index.len()==0");
return Ok(()); return Ok(());
@ -862,34 +866,35 @@ async fn write_commit(config:WriteCommitConfig,b:Result<AResult<(AssetVersion,De
tree_index.write()?; tree_index.write()?;
tree_index.write_tree()? tree_index.write_tree()?
}; };
let tree=repo.find_tree(tree_id)?; let tree=repo.tree(tree_id)?;
let mut parents=Vec::new(); let mut parents=Vec::new();
match repo.head(){ match repo.head_commit(){
Ok(reference)=>{ Ok(commit)=>{
let commit=reference.peel_to_commit()?;
//test tree against commit tree to see if there is any changes //test tree against commit tree to see if there is any changes
let commit_tree=commit.tree()?; let commit_tree=commit.tree()?;
let diff=repo.diff_tree_to_tree(Some(&commit_tree),Some(&tree),None)?; let diff=repo.diff_resource_cache(Some(&commit_tree),Some(&tree),None)?;
if diff.deltas().count()==0{ if diff.deltas().count()==0{
println!("no changes"); println!("no changes");
return Ok(()); return Ok(());
} }
parents.push(commit); parents.push(commit.id());
}, },
Err(e)=>println!("repo head error {:?}",e), //If the repo head is not found, great, continue and make the first commit
Err(gix::reference::head_commit::Error::Head(gix::reference::find::existing::Error::NotFound))=>(),
//for other errors
Err(e)=>Err(e)?,
}; };
repo.commit( repo.commit_as(
Some("HEAD"),//update_ref
&sig,//author
&sig,//commiter &sig,//commiter
&sig,//author
"HEAD",
&format!("v{}",asset_version.assetVersionNumber),//message &format!("v{}",asset_version.assetVersionNumber),//message
&tree,//tree (basically files) &tree,//tree (basically files)
parents.iter().collect::<Vec<&git2::Commit<'_>>>().as_slice(),//parents parents,//parents
)?; )?;
//commit //commit
@ -913,7 +918,14 @@ async fn decompile_history_into_git(config:DecompileHistoryConfig)->AResult<()>{
versions_path.push("versions.json"); versions_path.push("versions.json");
let asset_list:Vec<AssetVersion>=serde_json::from_reader(std::fs::File::open(versions_path)?)?; let asset_list:Vec<AssetVersion>=serde_json::from_reader(std::fs::File::open(versions_path)?)?;
let repo=git2::Repository::init(config.output_folder.clone())?; let repo=gix::discover(gix::create::into(
config.output_folder.as_path(),
gix::create::Kind::Bare,
gix::create::Options{
destination_must_be_empty:true,
fs_capabilities:None
}
)?)?;
//decompile all versions //decompile all versions
futures::stream::iter(asset_list.into_iter() futures::stream::iter(asset_list.into_iter()
@ -962,7 +974,14 @@ async fn download_and_decompile_history_into_git(config:DownloadAndDecompileHist
//poll paged list of all asset versions //poll paged list of all asset versions
let asset_list=get_version_history(&client,&config.cookie.as_str(),config.asset_id).await?; let asset_list=get_version_history(&client,&config.cookie.as_str(),config.asset_id).await?;
let repo=git2::Repository::init(config.output_folder.clone())?; let repo=gix::discover(gix::create::into(
config.output_folder.as_path(),
gix::create::Kind::Bare,
gix::create::Options{
destination_must_be_empty:true,
fs_capabilities:None
}
)?)?;
//download all versions //download all versions
let asset_id_string=config.asset_id.to_string(); let asset_id_string=config.asset_id.to_string();