From 05b674190f26e2a58cc7b7288586c031552d50f3 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Wed, 29 Jan 2025 00:34:30 +0100 Subject: Add git-server to docker-compose To make a githook that can run on alpine images (using musl) they need to be cross-compiled. Then it became apparent that the githook binary was pulling in all the same dependencies as the server was. This is not good, but apparently also not something Rust/Cargo has figured out. RFC:s has been shutdown. workspace might be an option but then I probably need to also add a "code shared by both githook and server" library that both can link. Problem for another day. --- server/src/git.rs | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'server/src/git.rs') diff --git a/server/src/git.rs b/server/src/git.rs index 58d2fda..a05c670 100644 --- a/server/src/git.rs +++ b/server/src/git.rs @@ -46,6 +46,7 @@ pub struct Repository { remote: Option, project_id: Option, socket: Option, + githook: Option, // Lock for any repo task, 90% of all tasks are readers but there are some writers // where nothing else may be done. @@ -147,7 +148,14 @@ impl RepoData { } async fn sync_hooks(&mut self, repo: &Repository) -> Result<(), Error> { - let hook = get_githook_bin()?; + let hook = match repo.githook() { + Some(path) => PathBuf::from(path), + None => { + let server_exe = + std::env::current_exe().map_err(|e| io_err("unable to get current exe", e))?; + server_exe.parent().unwrap().join("eyeballs-githook") + } + }; let hooks = if repo.is_bare() { repo.path().join("hooks") @@ -409,9 +417,11 @@ impl Repository { bare: bool, remote: Option>, project_id: Option>, + githook: Option>, ) -> Self { let path = path.into(); let project_id = project_id.map(|x| x.into()); + let githook = githook.map(|x| x.into()); let socket: Option; if let Some(project_id) = &project_id { socket = Some( @@ -428,6 +438,7 @@ impl Repository { project_id, path, socket, + githook, bare, lock: RwLock::new(RepoData::new()), } @@ -449,6 +460,10 @@ impl Repository { self.socket.as_deref() } + fn githook(&self) -> Option<&Path> { + self.githook.as_deref() + } + pub fn is_bare(&self) -> bool { self.bare } @@ -520,20 +535,3 @@ impl Repository { data.get_commiter(self, commit.as_str()).await } } - -#[cfg(not(test))] -fn get_githook_bin() -> Result { - let server_exe = std::env::current_exe().map_err(|e| io_err("unable to get current exe", e))?; - Ok(server_exe.parent().unwrap().join("eyeballs-githook")) -} - -#[cfg(test)] -fn get_githook_bin() -> Result { - let test_exe = std::env::current_exe().map_err(|e| io_err("unable to get current exe", e))?; - Ok(test_exe - .parent() - .unwrap() - .parent() - .unwrap() - .join("eyeballs-githook")) -} -- cgit v1.2.3-70-g09d2