This commit is contained in:
Quaternions 2024-01-12 23:00:34 -08:00
parent 389943c361
commit c8fe02160e

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,14 @@ 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_index = repo.index()?;
tree_index.add_all([config.output_folder.as_path()].iter(),git2::IndexAddOption::DEFAULT,None)?; 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(());
@ -868,28 +870,28 @@ async fn write_commit(config:WriteCommitConfig,b:Result<AResult<(AssetVersion,De
match repo.head(){ match repo.head(){
Ok(reference)=>{ Ok(reference)=>{
let commit=reference.peel_to_commit()?; let commit=reference.peel_to_commit_in_place()?;
//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), Err(e)=>println!("repo head error {:?}",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 +915,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 +971,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();