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,
}
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??;
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,
},context).await?;
let date=asset_version.created;
//let sig=repo.signature()?; //this pulls default name and email
let sig=git2::Signature::new(config.git_committer_name.as_str(),config.git_committer_email.as_str(),&git2::Time::new(date.timestamp(),0)).unwrap();
let sig=gix::actor::Signature{
name:config.git_committer_name.into(),
email:config.git_committer_email.into(),
time:gix::date::Time::new(asset_version.created.timestamp(),0),
};
let tree_id={
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{
println!("tree_index.len()==0");
return Ok(());
@ -868,28 +870,28 @@ async fn write_commit(config:WriteCommitConfig,b:Result<AResult<(AssetVersion,De
match repo.head(){
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
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{
println!("no changes");
return Ok(());
}
parents.push(commit);
parents.push(commit.id());
},
Err(e)=>println!("repo head error {:?}",e),
};
repo.commit(
Some("HEAD"),//update_ref
&sig,//author
repo.commit_as(
&sig,//commiter
&sig,//author
"HEAD",
&format!("v{}",asset_version.assetVersionNumber),//message
&tree,//tree (basically files)
parents.iter().collect::<Vec<&git2::Commit<'_>>>().as_slice(),//parents
parents,//parents
)?;
//commit
@ -913,7 +915,14 @@ async fn decompile_history_into_git(config:DecompileHistoryConfig)->AResult<()>{
versions_path.push("versions.json");
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
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
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
let asset_id_string=config.asset_id.to_string();