fn browse(
    date: String,
    refname: String,
    db: Arc<Mutex<Connection>>,
    repository: Arc<PathBuf>,
    templates: Arc<Handlebars>,
) -> Result<impl Reply, warp::reject::Rejection> {
    let date = match percent_encoding::percent_decode(date.as_bytes())
        .decode_utf8()
    {
        Ok(s) => s,
        Err(_) => return Err(warp::reject::not_found()),
    };

    let mut db = db.lock().unwrap();

    // Load snapshot information
    let (current, prev_date, next_date) = match get_snapshot(&date, &mut db)
        .map_err(warp::reject::custom)?
    {
        (Some(current), prev, next) => {
            info!("Resolved date {} -> {}", date, current);
            (current, prev, next)
        }
        (None, _, _) => return Err(warp::reject::not_found()),
    };

    // Load branches
    let mut branches = get_branches(&current, &mut db)
        .map_err(warp::reject::custom)?;
    let current_sha = {
        let idx = branches.binary_search_by(|br| br.0.cmp(&refname))
            .map_err(|_| {
                warn!("Requested branch does not exist");
                warp::reject::not_found()
            })?;
        branches.remove(idx).1
    };

    // Load commits
    let commits = get_commits(&repository, &current_sha, 10)
        .map_err(warp::reject::custom)?;

    // Send response
    templates
        .render(
            "browse.html",
            &json!({
                "snapshot": {
                    "current": current, "prev": prev_date, "next": next_date,
                    "req": date,
                },
                "refname": refname,
                "branches": branches,
                "commits": commits,
            }),
        )
        .map_err(warp::reject::custom)
        .map(warp::reply::html)
}
/// Main view, showing information to the user
///
/// For a specific date and a specific branch, show the latest commits, other
/// branches in that snapshot, and link to the previous/next snapshots.
Main view, showing information to the user
For a specific date and a specific branch, show the latest commits, other
branches in that snapshot, and link to the previous/next snapshots.
Main view showing information to the user For a specific date and a specific branch show the latest commits other branches in that snapshot and link to the previous / next snapshots .
fn browse(
    date: String,
    refname: String,
    db: Arc<Mutex<Connection>>,
    repository: Arc<PathBuf>,
    templates: Arc<Handlebars>,
) -> Result<impl Reply, warp::reject::Rejection> {
    let date = match percent_encoding::percent_decode(date.as_bytes())
        .decode_utf8()
    {
        Ok(s) => s,
        Err(_) => return Err(warp::reject::not_found()),
    };
    let mut db = db.lock().unwrap();
    // Load snapshot information
    let (current, prev_date, next_date) = match get_snapshot(&date, &mut db)
        .map_err(warp::reject::custom)?
    {
        (Some(current), prev, next) => {
            info!("Resolved date {} -> {}", date, current);
            (current, prev, next)
        }
        (None, _, _) => return Err(warp::reject::not_found()),
    };
    // Load branches
    let mut branches = get_branches(&current, &mut db)
        .map_err(warp::reject::custom)?;
    let current_sha = {
        let idx = branches.binary_search_by(|br| br.0.cmp(&refname))
            .map_err(|_| {
                warn!("Requested branch does not exist");
                warp::reject::not_found()
            })?;
        branches.remove(idx).1
    };
    // Load commits
    let commits = get_commits(&repository, &current_sha, 10)
        .map_err(warp::reject::custom)?;
    // Send response
    templates
        .render(
            "browse.html",
            &json!({
                "snapshot": {
                    "current": current, "prev": prev_date, "next": next_date,
                    "req": date,
                },
                "refname": refname,
                "branches": branches,
                "commits": commits,
            }),
        )
        .map_err(warp::reject::custom)
        .map(warp::reply::html)
}
fn browse ( date : String , refname : String , db : Arc < Mutex < Connection > > , repository : Arc < PathBuf > , templates : Arc < Handlebars > , ) -> Result < impl Reply , warp :: reject :: Rejection > { let date = match percent_encoding :: percent_decode ( date . as_bytes ( ) ) . decode_utf8 ( ) { Ok ( s ) => s , Err ( _ ) => return Err ( warp :: reject :: not_found ( ) ) , } ; let mut db = db . lock ( ) . unwrap ( ) ; // Load snapshot information let ( current , prev_date , next_date ) = match get_snapshot ( & date , & mut db ) . map_err ( warp :: reject :: custom ) ? { ( Some ( current ) , prev , next ) => { info ! ( " " date current ) ; ( current , prev , next ) } ( None , _ , _ ) => return Err ( warp :: reject :: not_found ( ) ) , } ; // Load branches let mut branches = get_branches ( & current , & mut db ) . map_err ( warp :: reject :: custom ) ? ; let current_sha = { let idx = branches . binary_search_by ( | br | br . 0 . cmp ( & refname ) ) . map_err ( | _ | { warn ! ( " " ) ; warp :: reject :: not_found ( ) } ) ? ; branches . remove ( idx ) . 1 } ; // Load commits let commits = get_commits ( & repository , & current_sha , 10 ) . map_err ( warp :: reject :: custom ) ? ; // Send response templates . render ( " " , & json ! ( { " " { " " current " " prev_date " " next_date " " date } " " refname " " branches " " commits } ) , ) . map_err ( warp :: reject :: custom ) . map ( warp :: reply :: html ) }
Main view, showing information to the user
For a specific date and a specific branch, show the latest commits, other
branches in that snapshot, and link to the previous/next snapshots.
Main view showing information to the user For a specific date and a specific branch show the latest commits other branches in that snapshot and link to the previous / next snapshots .
date
String
refname
String
db
Arc<Mutex<Connection>>
repository
Arc<PathBuf>
templates
Arc<Handlebars>
date
String
refname
String
db
Arc<Mutex<Connection>>
repository
Arc<PathBuf>
templates
Arc<Handlebars>