From 52b7379a20fb2ca60152046dbfe678adf03e8e81 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Sat, 09 Jul 2022 01:52:19 +0100 Subject: [PATCH] Allow looking up a tree by id --- src/git.rs | 10 +++++++++- statics/style.css | 4 ++++ src/methods/repo.rs | 8 ++++++++ templates/repo/commit.html | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/git.rs b/src/git.rs index 1ec4f27..597174f 100644 --- a/src/git.rs +++ a/src/git.rs @@ -97,12 +97,16 @@ } impl OpenRepository { - pub async fn path(self: Arc, path: Option) -> PathDestination { + pub async fn path(self: Arc, path: Option, tree_id: Option) -> PathDestination { tokio::task::spawn_blocking(move || { let repo = self.repo.lock(); - let head = repo.head().unwrap(); - let mut tree = head.peel_to_tree().unwrap(); + let mut tree = if let Some(tree_id) = tree_id { + repo.find_tree(Oid::from_str(&tree_id).unwrap()).unwrap() + } else { + let head = repo.head().unwrap(); + head.peel_to_tree().unwrap() + }; if let Some(path) = path.as_ref() { let item = tree.get_path(&path).unwrap(); diff --git a/statics/style.css b/statics/style.css index 1018024..77321c2 100644 --- a/statics/style.css +++ a/statics/style.css @@ -25,6 +25,10 @@ color: blue; } +a.no-style { + color: inherit; +} + a:hover { text-decoration: underline; } diff --git a/src/methods/repo.rs b/src/methods/repo.rs index ecf9df9..ef3bd08 100644 --- a/src/methods/repo.rs +++ a/src/methods/repo.rs @@ -245,11 +245,17 @@ into_response(&CommitView { repo, commit }) } +#[derive(Deserialize)] +pub struct TreeQuery { + id: Option, +} + pub async fn handle_tree( Extension(repo): Extension, Extension(RepositoryPath(repository_path)): Extension, Extension(ChildPath(child_path)): Extension, Extension(git): Extension>, + Query(query): Query, ) -> Response { #[derive(Template)] #[template(path = "repo/tree.html")] @@ -267,7 +273,7 @@ let open_repo = git.repo(repository_path).await; - match open_repo.path(child_path).await { + match open_repo.path(child_path, query.id).await { PathDestination::Tree(items) => into_response(&TreeView { repo, items }), PathDestination::File(file) => into_response(&FileView { repo, file }), } diff --git a/templates/repo/commit.html b/templates/repo/commit.html index 647a32e..be35019 100644 --- a/templates/repo/commit.html +++ a/templates/repo/commit.html @@ -25,7 +25,7 @@ tree -
{{ commit.tree() }}
+
{{ commit.tree() }}
{% for parent in commit.parents() %} -- rgit 0.1.3