From 52b43cef2b7b3bb7c3cd6babc67058690eae4c32 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 11 Jan 2024 02:02:49 -0800 Subject: [PATCH] winner --- src/main.rs | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index fa68137..8722ce2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use std::io::{Read,Seek}; +use std::io::Read; use clap::{Args,Parser,Subcommand}; use anyhow::Result as AResult; use futures::StreamExt; @@ -49,6 +49,7 @@ enum Commands{ Upload, Compile, Decompile, + DecompileHistoryIntoGit, } #[derive(Args)] @@ -112,6 +113,14 @@ async fn main()->AResult<()>{ write_models:!cli.no_models.unwrap_or(false), write_scripts:!cli.no_scripts.unwrap_or(false), }), + Commands::DecompileHistoryIntoGit=>decompile_history_into_git(DecompileHistoryConfig{ + cookie:cookie.unwrap(), + asset_id:cli.asset_id.unwrap(), + output_folder:cli.output.unwrap(), + write_template:!cli.no_template.unwrap_or(false), + write_models:!cli.no_models.unwrap_or(false), + write_scripts:!cli.no_scripts.unwrap_or(false), + }).await, } } @@ -666,7 +675,7 @@ struct WriteCommitConfig{ write_scripts:bool, } -fn write_commit(config:WriteCommitConfig,b:AResult<(AssetVersion,DecompiledContext)>,repo:&git2::Repository,last_commit:Option<&git2::Commit>)->AResult{ +fn write_commit(config:WriteCommitConfig,b:AResult<(AssetVersion,DecompiledContext)>,repo:&git2::Repository)->AResult<()>{ let (asset_version,context)=b?; //clean output dir @@ -676,12 +685,12 @@ fn write_commit(config:WriteCommitConfig,b:AResult<(AssetVersion,DecompiledConte std::fs::remove_dir_all(src)?; let mut template=config.output_folder.clone(); template.push("template.rbxlx"); - std::fs::remove_file(template); + std::fs::remove_file(template)?; } //write files write_files(WriteConfig{ - output_folder:config.output_folder, + output_folder:config.output_folder.clone(), write_template:config.write_template, write_models:config.write_models, write_scripts:config.write_scripts, @@ -696,14 +705,15 @@ fn write_commit(config:WriteCommitConfig,b:AResult<(AssetVersion,DecompiledConte tree_index.write_tree()? }; let tree=repo.find_tree(tree_id)?; - let commit_id=match last_commit{ - Some(commit)=>repo.commit( + + match repo.revwalk().unwrap().next(){ + Some(Ok(commit_id))=>repo.commit( Some("HEAD"),//update_ref &sig,//author &sig,//commiter &format!("v{}", asset_version.assetVersionNumber),//message &tree,//tree (basically files) - &[commit],//parents + &[&repo.find_commit(commit_id)?],//parents ).expect("commit failed"), None=>repo.commit( Some("HEAD"),//update_ref @@ -713,10 +723,11 @@ fn write_commit(config:WriteCommitConfig,b:AResult<(AssetVersion,DecompiledConte &tree,//tree (basically files) &[],//parents ).expect("commit failed"), + Some(Err(e))=>Err(e)?, }; //commit - Ok(commit_id) + Ok(()) } struct DecompileHistoryConfig{ @@ -735,7 +746,6 @@ async fn decompile_history_into_git(config:DecompileHistoryConfig)->AResult<()>{ 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 mut commits=Vec::new(); //download all versions let asset_id_string=config.asset_id.to_string(); @@ -761,8 +771,8 @@ async fn decompile_history_into_git(config:DecompileHistoryConfig)->AResult<()>{ write_template:config.write_template, write_models:config.write_models, write_scripts:config.write_scripts, - },b,&repo,commits.last()){ - Ok(commit_id)=>commits.push(repo.find_commit(commit_id).expect("Failed to find commit")), + },b,&repo){ + Ok(())=>(), Err(e)=>println!("download/unzip/decompile/write error: {}",e), } }).await;