diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2025-01-29 00:34:30 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2025-01-29 00:34:30 +0100 |
| commit | 05b674190f26e2a58cc7b7288586c031552d50f3 (patch) | |
| tree | 452035e852a7012061c9424a9dc0f56fcad129ee /server/src/git.rs | |
| parent | 145b93302cbb7cb090c90fd07ed4ebabf742e453 (diff) | |
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.
Diffstat (limited to 'server/src/git.rs')
| -rw-r--r-- | server/src/git.rs | 34 |
1 files changed, 16 insertions, 18 deletions
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<String>, project_id: Option<String>, socket: Option<PathBuf>, + githook: Option<PathBuf>, // 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<impl Into<String>>, project_id: Option<impl Into<String>>, + githook: Option<impl Into<PathBuf>>, ) -> Self { let path = path.into(); let project_id = project_id.map(|x| x.into()); + let githook = githook.map(|x| x.into()); let socket: Option<PathBuf>; 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<PathBuf, Error> { - 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<PathBuf, Error> { - 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")) -} |
