diff options
Diffstat (limited to 'server/common/src/git.rs')
| -rw-r--r-- | server/common/src/git.rs | 77 |
1 files changed, 75 insertions, 2 deletions
diff --git a/server/common/src/git.rs b/server/common/src/git.rs index e396d8a..37995b3 100644 --- a/server/common/src/git.rs +++ b/server/common/src/git.rs @@ -83,6 +83,22 @@ pub struct GitFile { cursor: Cursor<Vec<u8>>, } +pub struct Env { + pub object_dir: Option<String>, + pub alt_object_dirs: Option<String>, +} + +impl Env { + fn apply(&self, cmd: &mut Command) { + if let Some(value) = &self.object_dir { + cmd.env("GIT_OBJECT_DIRECTORY", value); + } + if let Some(value) = &self.alt_object_dirs { + cmd.env("GIT_ALTERNATE_OBJECT_DIRECTORIES", value); + } + } +} + impl GitFile { pub fn new(data: Vec<u8>) -> Self { GitFile { @@ -403,6 +419,22 @@ impl RepoData { self.check(&mut cmd).await } + async fn is_ancestor_with_env( + &self, + repo: &Repository, + ancestor: &str, + commit: &str, + env: &Env, + ) -> Result<bool, Error> { + let mut cmd = self.git_cmd(repo); + cmd.arg("merge-base") + .arg("--is-ancestor") + .arg(ancestor) + .arg(commit); + env.apply(&mut cmd); + self.check(&mut cmd).await + } + async fn is_equal_content( &self, repo: &Repository, @@ -419,13 +451,24 @@ impl RepoData { } async fn get_author(&self, repo: &Repository, commit: &str) -> Result<User, Error> { - self.get_log_format(repo, commit, "%an%x00%al%x00%ae") + self.get_log_format(repo, commit, "%an%x00%al%x00%ae", None) .map_ok(parse_user) .await } async fn get_commiter(&self, repo: &Repository, commit: &str) -> Result<User, Error> { - self.get_log_format(repo, commit, "%cn%x00%cl%x00%ce") + self.get_log_format(repo, commit, "%cn%x00%cl%x00%ce", None) + .map_ok(parse_user) + .await + } + + async fn get_commiter_with_env( + &self, + repo: &Repository, + commit: &str, + env: &Env, + ) -> Result<User, Error> { + self.get_log_format(repo, commit, "%cn%x00%cl%x00%ce", Some(env)) .map_ok(parse_user) .await } @@ -473,6 +516,7 @@ impl RepoData { repo: &Repository, commit: &str, format: &str, + maybe_env: Option<&Env>, ) -> Result<String, Error> { let mut cmd = self.git_cmd(repo); cmd.arg("log") @@ -481,6 +525,9 @@ impl RepoData { .arg("--no-mailmap") .arg(format!("--pretty=format:{format}")) .arg(commit); + if let Some(env) = maybe_env { + env.apply(&mut cmd); + } self.output(&mut cmd).await } @@ -693,6 +740,21 @@ impl Repository { .await } + pub async fn is_ancestor_with_env( + &self, + ancestor: impl Into<String>, + commit: impl Into<String>, + env: &Env, + ) -> Result<bool, Error> { + let ancestor = ancestor.into(); + let commit = commit.into(); + + let data = self.lock.read().await; + + data.is_ancestor_with_env(self, ancestor.as_str(), commit.as_str(), env) + .await + } + pub async fn is_equal_content( &self, commit1: impl Into<String>, @@ -720,6 +782,17 @@ impl Repository { data.get_commiter(self, commit.as_str()).await } + pub async fn get_commiter_with_env( + &self, + commit: impl Into<String>, + env: &Env, + ) -> Result<User, Error> { + let commit = commit.into(); + let data = self.lock.read().await; + + data.get_commiter_with_env(self, commit.as_str(), env).await + } + pub async fn delete_branch(&self, branch: impl Into<String>) -> Result<(), Error> { let branch = branch.into(); let data = self.lock.read().await; |
