gitscope
← rgit / Diff · 52b7379 → 52b7379
Changes 52b7379..52b7379
Patch commit
diff --git a/src/git.rs b/src/git.rs
index 1ec4f27..597174f 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -97,12 +97,16 @@ pub struct OpenRepository {
}
impl OpenRepository {
- pub async fn path(self: Arc<Self>, path: Option<PathBuf>) -> PathDestination {
+ pub async fn path(self: Arc<Self>, path: Option<PathBuf>, tree_id: Option<String>) -> 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/src/methods/repo.rs b/src/methods/repo.rs
index ecf9df9..ef3bd08 100644
--- a/src/methods/repo.rs
+++ b/src/methods/repo.rs
@@ -245,11 +245,17 @@ pub async fn handle_commit(
into_response(&CommitView { repo, commit })
}
+#[derive(Deserialize)]
+pub struct TreeQuery {
+ id: Option<String>,
+}
+
pub async fn handle_tree(
Extension(repo): Extension<Repository>,
Extension(RepositoryPath(repository_path)): Extension<RepositoryPath>,
Extension(ChildPath(child_path)): Extension<ChildPath>,
Extension(git): Extension<Arc<Git>>,
+ Query(query): Query<TreeQuery>,
) -> Response {
#[derive(Template)]
#[template(path = "repo/tree.html")]
@@ -267,7 +273,7 @@ pub async fn handle_tree(
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/statics/style.css b/statics/style.css
index 1018024..77321c2 100644
--- a/statics/style.css
+++ b/statics/style.css
@@ -25,6 +25,10 @@ a {
color: blue;
}
+a.no-style {
+ color: inherit;
+}
+
a:hover {
text-decoration: underline;
}
diff --git a/templates/repo/commit.html b/templates/repo/commit.html
index 647a32e..be35019 100644
--- a/templates/repo/commit.html
+++ b/templates/repo/commit.html
@@ -25,7 +25,7 @@
</tr>
<tr>
<th>tree</th>
- <td colspan="2"><pre>{{ commit.tree() }}</pre></td>
+ <td colspan="2"><pre><a href="/{{ repo.display() }}/tree?id={{ commit.tree() }}" class="no-style">{{ commit.tree() }}</a></pre></td>
</tr>
{% for parent in commit.parents() %}
<tr>