summaryrefslogtreecommitdiff
path: root/server/common/src/git.rs
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2025-06-22 22:57:08 +0200
committerJoel Klinghed <the_jk@spawned.biz>2025-06-22 22:57:08 +0200
commitf9b7c2a14c939d0bb7d1ac2fcca3116e38e37f74 (patch)
treecc20775f2d70416ef6414d265b7e1d44cce6fece /server/common/src/git.rs
parent9cb8a56b406c46244e936c2f40830d0e89dba785 (diff)
Add support for pushing changes to a translation review
Finally got around to fixing the pre-receive hook to include quarantined objects so the hook actually can run git commands on the not-yet-accepted commits. As part of that, had to make sure git hook and eyeballs server had the same path to the repo or confusion will appear.
Diffstat (limited to 'server/common/src/git.rs')
-rw-r--r--server/common/src/git.rs77
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;