gitscope
← rgit / Diff · 2cbafe1 → 2cbafe1
Changes 2cbafe1..2cbafe1
Patch commit
diff --git a/src/git.rs b/src/git.rs
index 318cfbd..65d5fc2 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -7,9 +7,7 @@ use std::{
};
use arc_swap::ArcSwapOption;
-use git2::{
- DiffFormat, DiffLineType, DiffOptions, DiffStatsFormat, ObjectType, Oid, Repository, Signature,
-};
+use git2::{BranchType, DiffFormat, DiffLineType, DiffOptions, DiffStatsFormat, ObjectType, Oid, Repository, Signature};
use moka::future::Cache;
use parking_lot::Mutex;
use syntect::html::{ClassStyle, ClassedHTMLGenerator};
@@ -97,7 +95,7 @@ pub struct OpenRepository {
}
impl OpenRepository {
- pub async fn path(self: Arc<Self>, path: Option<PathBuf>, tree_id: Option<&str>) -> PathDestination {
+ pub async fn path(self: Arc<Self>, path: Option<PathBuf>, tree_id: Option<&str>, branch: Option<String>) -> PathDestination {
let tree_id = tree_id.map(Oid::from_str).transpose().unwrap();
tokio::task::spawn_blocking(move || {
@@ -105,6 +103,9 @@ impl OpenRepository {
let mut tree = if let Some(tree_id) = tree_id {
repo.find_tree(tree_id).unwrap()
+ } else if let Some(branch) = branch {
+ let branch = repo.find_branch(&branch, BranchType::Local).unwrap();
+ branch.get().peel_to_tree().unwrap()
} else {
let head = repo.head().unwrap();
head.peel_to_tree().unwrap()
diff --git a/src/methods/repo.rs b/src/methods/repo.rs
index 9f2e05a..afe96cb 100644
--- a/src/methods/repo.rs
+++ b/src/methods/repo.rs
@@ -249,12 +249,21 @@ pub async fn handle_commit(
#[derive(Deserialize)]
pub struct TreeQuery {
id: Option<String>,
+ #[serde(rename = "h")]
+ branch: Option<String>,
}
impl Display for TreeQuery {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ let mut prefix = "?";
+
if let Some(id) = self.id.as_deref() {
- write!(f, "?id={}", id)?;
+ write!(f, "{}id={}", prefix, id)?;
+ prefix = "&";
+ }
+
+ if let Some(branch) = self.branch.as_deref() {
+ write!(f, "{}h={}", prefix, branch)?;
}
Ok(())
@@ -285,7 +294,7 @@ pub async fn handle_tree(
let open_repo = git.repo(repository_path).await;
- match open_repo.path(child_path, query.id.as_deref()).await {
+ match open_repo.path(child_path, query.id.as_deref(), query.branch.clone()).await {
PathDestination::Tree(items) => into_response(&TreeView { repo, items, query }),
PathDestination::File(file) => into_response(&FileView { repo, file }),
}