aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-04-23 00:14:45 -0600
committerMelody Horn <melody@boringcactus.com>2021-04-23 00:14:45 -0600
commit60e05b91d812fea839f9acc949d98f12039af765 (patch)
tree4dbf573f5da803169e1eca239d61c68217a1263c /src
parent518025bee1982bad954e3640b693f1a0a747adc0 (diff)
downloadgityeet-canon.tar.gz
gityeet-canon.zip
open the repo when handling the requestHEADcanon
it would be smart to not keep the Vec<Repository> around, but nobody's ever accused me of smart
Diffstat (limited to 'src')
-rw-r--r--src/main.rs11
-rw-r--r--src/state.rs5
2 files changed, 10 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs
index d85a1d3..604a745 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -66,11 +66,10 @@ async fn repo_tree_path(req: Request) -> tide::Result {
async fn view_tree_path(state: &Arc<Mutex<State>>, repo_rel_path: &str, tree_rel_path: &str) -> tide::Result {
let state = state.lock_arc().await;
- let repo = state.data.iter()
- .find(|repo| state.relative_path(repo.path()) == Path::new(repo_rel_path));
+ let repo = state.open(repo_rel_path);
let repo = match repo {
- Some(x) => x,
- None => return Ok("bruh that's not a real repo".into()),
+ Ok(x) => x,
+ Err(err) => return Ok(format!("couldn't open repo: {}", err).into()),
};
let head = repo.head();
@@ -94,7 +93,7 @@ async fn view_tree_path(state: &Arc<Mutex<State>>, repo_rel_path: &str, tree_rel
Err(err) => return Ok(format!("bruh that path doesn't exist: {}", err).into()),
};
- let selected_object = selected_tree_entry.to_object(repo);
+ let selected_object = selected_tree_entry.to_object(&repo);
let selected_object = match selected_object {
Ok(x) => x,
Err(err) => return Ok(format!("bruh that path doesn't exist: {}", err).into()),
@@ -106,7 +105,7 @@ async fn view_tree_path(state: &Arc<Mutex<State>>, repo_rel_path: &str, tree_rel
if let Some(selected_tree) = selected_object.as_tree() {
let template = templates::RepoFolder {
- repo,
+ repo: &repo,
repo_path: repo_rel_path,
title: repo_rel_path,
rel_path: &tree_rel_path,
diff --git a/src/state.rs b/src/state.rs
index 004d3e2..deb7c9c 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -60,4 +60,9 @@ impl State {
pub fn relative_path<'a>(&'a self, subdir: &'a Path) -> &'a Path {
subdir.strip_prefix(&self.root).unwrap_or(subdir)
}
+
+ pub fn open(&self, path: impl AsRef<Path>) -> Result<Repository> {
+ let path = self.root.join(path);
+ Ok(Repository::open_bare(path)?)
+ }
}