summaryrefslogtreecommitdiff
path: root/server/common/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/common/src')
-rw-r--r--server/common/src/git.rs77
-rw-r--r--server/common/src/git_socket.rs6
2 files changed, 77 insertions, 6 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;
diff --git a/server/common/src/git_socket.rs b/server/common/src/git_socket.rs
index a4805be..6e1c7d4 100644
--- a/server/common/src/git_socket.rs
+++ b/server/common/src/git_socket.rs
@@ -5,16 +5,14 @@ pub struct GitReceive {
pub old_value: String,
pub new_value: String,
pub reference: String,
- // Only set for pre hooks, because server can't read the objects the pre-hook has not yet
- // accepted, so to be able to validate the commiter, send them. Also only set if new_value
- // is not empty.
- pub commiter: Option<String>,
}
#[derive(Deserialize, Serialize)]
pub struct GitHookRequest {
pub pre: bool,
pub receive: Vec<GitReceive>,
+ pub object_dir: Option<String>,
+ pub alt_object_dirs: Option<String>,
}
#[derive(Deserialize, Serialize)]