🏡 index : ~doyle/rgit.git

author Jordan Doyle <jordan@doyle.la> 2022-07-09 1:52:19.0 +01:00:00
committer Jordan Doyle <jordan@doyle.la> 2022-07-09 1:52:19.0 +01:00:00
commit
52b7379a20fb2ca60152046dbfe678adf03e8e81 [patch]
tree
573d86d54cf75741c72c8f5f58173e255d6d68ab
parent
8fea2385e33999bf7dd71956f64568cba52d9064
download
52b7379a20fb2ca60152046dbfe678adf03e8e81.tar.gz

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(-)

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<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/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<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 }),
    }
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 @@
    </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>