fn snapshot(
    date: String,
    db: Arc<Mutex<Connection>>,
) -> Result<Response, 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 db = db.lock().unwrap();

    // First we have to find the main branch
    let head = (|| -> Result<String, rusqlite::Error> {
        // If "master" exists, use that
        let mut stmt = db.prepare(
            "
            SELECT name FROM refs
            WHERE name='master' AND tag=0
                AND from_date <= ?
                AND (to_date IS NULL OR to_date > ?);
            ",
        )?;
        let mut rows = stmt.query(&[&date, &date])?;
        if rows.next().is_some() {
            Ok("master".into())
        } else {
            // Otherwise, use whatever branch was last updated
            let mut stmt = db.prepare(
                "
                SELECT name FROM refs
                WHERE tag=0
                    AND from_date <= ?
                    AND (to_date IS NULL OR to_date >?)
                ORDER BY from_date DESC, name DESC;
                ",
            )?;
            let mut rows = stmt.query(&[&date, &date])?;
            if let Some(row) = rows.next() {
                Ok(row?.get(0))
            } else {
                panic!()
            }
        }
    })()
    .map_err(warp::reject::custom)?;
    info!("Redirecting to main branch at {}: {}", date, head);

    // Redirect
    http::response::Response::builder()
        .status(StatusCode::FOUND)
        .header("Location", format!("/_/{}/{}", date, head))
        .body(Body::empty())
        .map_err(warp::reject::custom)
}
/// Redirects to main branch in given snapshot
Redirects to main branch in given snapshot
Redirects to main branch in given snapshot
fn snapshot(
    date: String,
    db: Arc<Mutex<Connection>>,
) -> Result<Response, 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 db = db.lock().unwrap();
    // First we have to find the main branch
    let head = (|| -> Result<String, rusqlite::Error> {
        // If "master" exists, use that
        let mut stmt = db.prepare(
            "
            SELECT name FROM refs
            WHERE name='master' AND tag=0
                AND from_date <= ?
                AND (to_date IS NULL OR to_date > ?);
            ",
        )?;
        let mut rows = stmt.query(&[&date, &date])?;
        if rows.next().is_some() {
            Ok("master".into())
        } else {
            // Otherwise, use whatever branch was last updated
            let mut stmt = db.prepare(
                "
                SELECT name FROM refs
                WHERE tag=0
                    AND from_date <= ?
                    AND (to_date IS NULL OR to_date >?)
                ORDER BY from_date DESC, name DESC;
                ",
            )?;
            let mut rows = stmt.query(&[&date, &date])?;
            if let Some(row) = rows.next() {
                Ok(row?.get(0))
            } else {
                panic!()
            }
        }
    })()
    .map_err(warp::reject::custom)?;
    info!("Redirecting to main branch at {}: {}", date, head);
    // Redirect
    http::response::Response::builder()
        .status(StatusCode::FOUND)
        .header("Location", format!("/_/{}/{}", date, head))
        .body(Body::empty())
        .map_err(warp::reject::custom)
}
fn snapshot ( date : String , db : Arc < Mutex < Connection > > , ) -> Result < Response , 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 db = db . lock ( ) . unwrap ( ) ; // First we have to find the main branch let head = ( | | -> Result < String , rusqlite :: Error > { // If "master" exists, use that let mut stmt = db . prepare ( " " , ) ? ; let mut rows = stmt . query ( & [ & date , & date ] ) ? ; if rows . next ( ) . is_some ( ) { Ok ( " " . into ( ) ) } else { // Otherwise, use whatever branch was last updated let mut stmt = db . prepare ( " " , ) ? ; let mut rows = stmt . query ( & [ & date , & date ] ) ? ; if let Some ( row ) = rows . next ( ) { Ok ( row ? . get ( 0 ) ) } else { panic ! ( ) } } } ) ( ) . map_err ( warp :: reject :: custom ) ? ; info ! ( " " date head ) ; // Redirect http :: response :: Response :: builder ( ) . status ( StatusCode :: FOUND ) . header ( " " , format ! ( " " date head ) ) . body ( Body :: empty ( ) ) . map_err ( warp :: reject :: custom ) }
Redirects to main branch in given snapshot
Redirects to main branch in given snapshot
date
String
db
Arc<Mutex<Connection>>
date
String
db
Arc<Mutex<Connection>>