Skip to content

Commit

Permalink
Add clone URL display
Browse files Browse the repository at this point in the history
  • Loading branch information
w4 committed Jan 3, 2025
1 parent 4118931 commit 84d0e86
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 13 deletions.
16 changes: 5 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/database/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ fn update_repository_metadata(scan_path: &Path, db: &rocksdb::DB) {
(r.unix_timestamp(), r.offset().whole_seconds())
},
default_branch: find_default_branch(&git_repository).ok().flatten(),
exported: repository_path.join("git-daemon-export-ok").exists(),
}
.insert(db, relative);

Expand Down
2 changes: 1 addition & 1 deletion src/database/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ pub mod tag;

pub type Yoked<T> = Yoke<T, Box<[u8]>>;

pub const SCHEMA_VERSION: &str = "2";
pub const SCHEMA_VERSION: &str = "3";
4 changes: 4 additions & 0 deletions src/database/schema/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ pub struct Repository {
pub last_modified: (i64, i32),
/// The default branch for Git operations
pub default_branch: Option<String>,
/// Whether the repository is available for HTTP(s) cloning
///
/// This is set to `true` based on the presence of `git-daemon-export-ok` in the repository
pub exported: bool,
}

pub type YokedRepository = Yoked<&'static <Repository as Archive>::Archived>;
Expand Down
7 changes: 6 additions & 1 deletion src/methods/repo/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{collections::BTreeMap, sync::Arc};

use anyhow::Context;
use askama::Template;
use axum::{response::IntoResponse, Extension};
use axum::{extract::Host, response::IntoResponse, Extension};
use rkyv::string::ArchivedString;

use crate::{
Expand All @@ -21,11 +21,14 @@ pub struct View {
refs: Refs,
commit_list: Vec<YokedCommit>,
branch: Option<Arc<str>>,
exported: bool,
host: String,
}

pub async fn handle(
Extension(repo): Extension<Repository>,
Extension(db): Extension<Arc<rocksdb::DB>>,
Host(host): Host,
) -> Result<impl IntoResponse> {
tokio::task::spawn_blocking(move || {
let repository = crate::database::schema::repository::Repository::open(&db, &*repo)?
Expand Down Expand Up @@ -57,6 +60,8 @@ pub async fn handle(
refs: Refs { heads, tags },
commit_list: commits,
branch: None,
exported: repository.get().exported,
host,
}))
})
.await
Expand Down
24 changes: 24 additions & 0 deletions templates/repo/summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,30 @@
</tr>
</tbody>
{%- endif %}

{% if exported %}
<tbody>
<tr class="separator">
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="no-background">
<th>Clone</th>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
<td colspan="4">
<a rel="vcs-git" href="/{{ repo.display() }}" title="{{ repo.display() }} Git repository">
https://{{ host }}/{{ repo.display() }}
</a>
</td>
</tr>
</tbody>
{%- endif %}
</table>
</div>
{% endblock %}

0 comments on commit 84d0e86

Please sign in to comment.