Allow looking up a tree by id
Diff
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(-)
@@ -97,12 +97,16 @@
}
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();
@@ -25,6 +25,10 @@
color: blue;
}
a.no-style {
color: inherit;
}
a:hover {
text-decoration: underline;
}
@@ -245,11 +245,17 @@
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 @@
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 }),
}
@@ -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>