gitscope
← rgit / Diff · 53166e7 → 53166e7
Changes 53166e7..53166e7
Patch commit
diff --git a/src/git.rs b/src/git.rs
index 0f5ef48..8c38314 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -7,7 +7,7 @@ use std::{
};
use arc_swap::ArcSwapOption;
-use git2::{ObjectType, Oid, Repository, Signature};
+use git2::{Oid, Repository, Signature};
use moka::future::Cache;
use time::OffsetDateTime;
@@ -59,16 +59,16 @@ impl Git {
.await
}
- pub async fn get_refs<'a>(&'a self, repo: PathBuf) -> Arc<Refs> {
+ pub async fn get_refs(&self, repo: PathBuf) -> Arc<Refs> {
self.refs
.get_with(repo.clone(), async {
tokio::task::spawn_blocking(move || {
let repo = git2::Repository::open_bare(repo).unwrap();
- let refs = repo.references().unwrap();
+ let ref_iter = repo.references().unwrap();
let mut built_refs = Refs::default();
- for ref_ in refs {
+ for ref_ in ref_iter {
let ref_ = ref_.unwrap();
if ref_.is_branch() {
@@ -120,7 +120,7 @@ impl Git {
.await
}
- pub async fn get_latest_commit<'a>(&'a self, repo: PathBuf) -> Commit {
+ pub async fn get_latest_commit(&self, repo: PathBuf) -> Commit {
tokio::task::spawn_blocking(move || {
let repo = Repository::open_bare(repo).unwrap();
let head = repo.head().unwrap();
@@ -134,7 +134,7 @@ impl Git {
pub async fn fetch_repository_metadata(&self) -> Arc<RepositoryMetadataList> {
if let Some(metadata) = self.repository_metadata.load().as_ref() {
- return Arc::clone(&metadata);
+ return Arc::clone(metadata);
}
let start = Path::new("../test-git").canonicalize().unwrap();
@@ -153,13 +153,25 @@ impl Git {
repos
}
- pub async fn get_commits(&self, repo: PathBuf, offset: usize) -> (Vec<Commit>, Option<usize>) {
+ pub async fn get_commits(
+ &self,
+ repo: PathBuf,
+ branch: Option<&str>,
+ offset: usize,
+ ) -> (Vec<Commit>, Option<usize>) {
const AMOUNT: usize = 200;
+ let ref_name = branch.map(|branch| format!("refs/heads/{}", branch));
+
tokio::task::spawn_blocking(move || {
let repo = Repository::open_bare(repo).unwrap();
let mut revs = repo.revwalk().unwrap();
- revs.push_head().unwrap();
+
+ if let Some(ref_name) = ref_name.as_deref() {
+ revs.push_ref(ref_name).unwrap();
+ } else {
+ revs.push_head().unwrap();
+ }
let mut commits: Vec<Commit> = revs
.skip(offset)
diff --git a/src/methods/repo.rs b/src/methods/repo.rs
index 1de00d8..cd5b8fc 100644
--- a/src/methods/repo.rs
+++ b/src/methods/repo.rs
@@ -93,6 +93,8 @@ pub async fn handle_summary(Extension(repo): Extension<Repository>) -> Html<Stri
pub struct LogQuery {
#[serde(rename = "ofs")]
offset: Option<usize>,
+ #[serde(rename = "h")]
+ branch: Option<String>,
}
#[allow(clippy::unused_async)]
@@ -108,10 +110,15 @@ pub async fn handle_log(
repo: Repository,
commits: Vec<Commit>,
next_offset: Option<usize>,
+ branch: Option<String>,
}
let (commits, next_offset) = git
- .get_commits(repository_path, query.offset.unwrap_or(0))
+ .get_commits(
+ repository_path,
+ query.branch.as_deref(),
+ query.offset.unwrap_or(0),
+ )
.await;
Html(
@@ -119,6 +126,7 @@ pub async fn handle_log(
repo,
commits,
next_offset,
+ branch: query.branch,
}
.render()
.unwrap(),
diff --git a/templates/repo/log.html b/templates/repo/log.html
index ce9dd7a..1f06e7d 100644
--- a/templates/repo/log.html
+++ b/templates/repo/log.html
@@ -28,7 +28,11 @@
{% if let Some(next_offset) = next_offset %}
<div class="mt-2 text-center">
- <a href="?ofs={{ next_offset }}">[next]</a>
+ {% if let Some(branch) = branch %}
+ <a href="?h={{ branch }}&ofs={{ next_offset }}">[next]</a>
+ {% else %}
+ <a href="?ofs={{ next_offset }}">[next]</a>
+ {% endif %}
</div>
{% endif %}
{% endblock %}
\ No newline at end of file