// Copyright (c) 2004-present, Facebook, Inc. // All Rights Reserved. // // This software may be used and distributed according to the terms of the // GNU General Public License version 2 or any later version. #![deny(warnings)] extern crate clap; extern crate mercurial; extern crate mercurial_types; use std::path::PathBuf; use std::str::FromStr; use clap::{App, SubCommand}; use mercurial::{RevlogChangeset, revlog::Revlog}; use mercurial_types::HgNodeHash; fn setup_app<'a, 'b>() -> App<'a, 'b> { App::new("read revlog repo content") .version("0.0.0") .about("read revlogs") .args_from_usage( r#" 'path to .hg folder with revlogs' "#, ) .subcommand( SubCommand::with_name("changeset") .about("reads changesets") .args_from_usage( r#" 'sha1 hash to read' -p, --parsed 'parse blob as RevlogChangeset' "#, ), ) } fn main() { let matches = setup_app().get_matches(); let base: PathBuf = matches.value_of("PATH").unwrap().into(); let store = base.as_path().join("store"); match matches.subcommand() { ("changeset", Some(sub_m)) => { let changelog = Revlog::from_idx_with_data(store.join("00changelog.i"), None as Option) .expect("Failed to load changelog"); let hash = sub_m.value_of("HASH").unwrap(); let hash = HgNodeHash::from_str(hash).expect("Incorrect Sha1 hash provided"); let raw = changelog .get_idx_by_nodeid(&hash) .and_then(|idx| changelog.get_rev(idx)) .expect("Changeset not found"); println!("RAW: {:?}", raw); let changeset = RevlogChangeset::new(raw.clone()).expect("Failed to deserialize CS"); if sub_m.is_present("parsed") { println!(""); println!("PAR: {:?}", changeset); } let encoded = changeset.get_node().expect("Failed to serialize CS"); if raw != encoded { println!(""); println!("POTENTIAL PROBLEM: {:?}", encoded); } } _ => { println!("{}", matches.usage()); ::std::process::exit(1); } } }