Repositories

grarr

(mirrored on github)

Wim Looman <wim@nemo157.com>
b3f64e Add dumb protocol head support
Wim Looman committed at 2016-03-13 16:06:10

Added src/handler/git/protocols/dumb/head.rs

@@ -0,0 +1,32 @@
use handler::base::*;
#[derive(Clone)]
pub struct Head;
impl Handler for Head {
fn handle(&self, req: &mut Request) -> IronResult<Response> {
let context = itry!(req.extensions.get::<RepositoryContext>().ok_or(Error::MissingExtension), status::InternalServerError);
let head = itry!(
context.repository
.find_reference("HEAD")
.map_err(Error::from)
.and_then(|head|
head.symbolic_target()
.ok_or(Error::from("HEAD should be a symbolic ref"))
.map(|target| format!("ref: {}", target))),
status::InternalServerError);
Ok(Response::with((status::Ok, mime!(Text/Plain; Charset=Utf8), head)))
}
}
impl Route for Head {
fn method() -> Method {
Method::Get
}
fn route() -> Cow<'static, str> {
"/HEAD".into()
}
}

Modified src/handler/git/protocols/dumb/mod.rs

@@ -1,2 +1,5 @@
mod refs;
mod head;
pub use self::refs::Refs;
pub use self::head::Head;

Modified src/main.rs

@@ -91,6 +91,7 @@ fn main() {
.register(inject_repository_context(&config.repos.root, handler::Pages))
.register(inject_repository_context(&config.repos.root, handler::Compare))
.register(inject_repository_context(&config.repos.root, handler::git::protocols::dumb::Refs))
.register(inject_repository_context(&config.repos.root, handler::git::protocols::dumb::Head))
.register(statics![
prefix: "./static/";
"./static/js/highlight.js",