diff options
Diffstat (limited to 'server/src/git_root.rs')
| -rw-r--r-- | server/src/git_root.rs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/server/src/git_root.rs b/server/src/git_root.rs index 71ad96f..f68ed92 100644 --- a/server/src/git_root.rs +++ b/server/src/git_root.rs @@ -9,6 +9,7 @@ use rocket_db_pools::{sqlx, Database, Pool}; use std::borrow::Cow; use std::collections::HashMap; use std::fs::Permissions; +use std::io::BufReader; use std::ops::Deref; use std::os::unix::fs::PermissionsExt; use std::path::{Path, PathBuf}; @@ -22,6 +23,7 @@ use crate::api_model; use crate::fs_utils; use crate::git; use crate::git_socket; +use crate::trans; use crate::Db; type DbPool = <Db as Database>::Pool; @@ -70,6 +72,71 @@ impl Roots { Ok(()) } + pub async fn new_translation_review( + &self, + db: &Db, + project_id: &str, + translation_reviewid: u64, + base: &str, + ) -> Result<(), anyhow::Error> { + let repo; + { + let data = self.data.lock().unwrap(); + if let Some(tmp_repo) = data.project_repo.get(project_id) { + repo = tmp_repo.clone(); + } else { + return Err(anyhow::Error::msg("No such repo")); + } + } + + let mut entries = repo + .ls_tree(base, true) + .await + .map_err(|e| anyhow::Error::new(e))?; + entries.retain(|e| e.object_type == git::ObjectType::BLOB); + let grits = entries + .iter() + .filter(|x| x.path.ends_with(".grd")) + .map(|x| x.path.to_string()) + .collect::<Vec<String>>(); + let entries = Arc::new(entries); + let strings = trans::collect_strings_with_opener(grits, move |path| { + for entry in &*entries { + if entry.path == path { + let rt = tokio::runtime::Handle::current(); + let object_name = entry.object_name.clone(); + let repo = repo.clone(); + return rt.block_on(async move { + repo.cat_file(git::ObjectType::BLOB, object_name) + .await + .map(|x| BufReader::new(x)) + .map_err(|e| anyhow::Error::new(e)) + }); + } + } + Err(anyhow::Error::msg(format!("No such file: {path}"))) + }) + .await?; + + trans::review_add_strings(db, translation_reviewid, strings, true).await?; + + Ok(()) + } + + pub async fn fetch_branch(&self, project_id: &str, branch: &str) -> anyhow::Result<String> { + let repo; + { + let data = self.data.lock().unwrap(); + if let Some(tmp_repo) = data.project_repo.get(project_id) { + repo = tmp_repo.clone(); + } else { + return Err(anyhow::Error::msg("No such repo")); + } + } + + repo.fetch(branch).await.map_err(|e| anyhow::Error::new(e)) + } + pub async fn del_branch(&self, project_id: &str, branch: &str) -> Result<(), git::Error> { let repo; { |
