index : gitrs
A lightweight web interface for browsing Git repositories, implemented in Rust
about summary refs log tree commit diff
gitrs / src / git / refs.rs
-rw-r--r-- blob 8a2ef7aea04929a5ff82b07da25bb4ea01a5828f 565 bytes (plain)
1
use crate::{prelude::*, routes::PageQuery};
2
3
pub struct Ref {
4
    pub name: String,
5
    pub is_head: bool,
6
}
7
8
impl Ref {
9
    pub fn resolve(repo: &Repository, query: &PageQuery) -> Result<Ref, Error> {
10
        let head_branch_name = repo.head_branch_name()?;
11
        match &query.head {
12
            Some(h) if !h.is_empty() => Ok(Ref {
13
                name: h.clone(),
14
                is_head: *h == head_branch_name,
15
            }),
16
            _ => Ok(Ref {
17
                name: head_branch_name,
18
                is_head: true,
19
            }),
20
        }
21
    }
22
}