2019-10-11 23:51:17 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
|
|
*
|
|
|
|
* This software may be used and distributed according to the terms of the
|
2020-02-11 13:42:43 +03:00
|
|
|
* GNU General Public License version 2.
|
2019-10-11 23:51:17 +03:00
|
|
|
*/
|
2018-05-02 01:59:30 +03:00
|
|
|
|
|
|
|
#![deny(warnings)]
|
|
|
|
|
|
|
|
use clap::{App, SubCommand};
|
2019-08-14 13:58:11 +03:00
|
|
|
use mercurial_revlog::{revlog::Revlog, RevlogChangeset};
|
2018-06-07 23:12:16 +03:00
|
|
|
use mercurial_types::HgNodeHash;
|
2019-08-14 13:58:11 +03:00
|
|
|
use std::{path::PathBuf, str::FromStr};
|
2018-05-02 01:59:30 +03:00
|
|
|
|
|
|
|
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> 'path to .hg folder with revlogs'
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.subcommand(
|
|
|
|
SubCommand::with_name("changeset")
|
|
|
|
.about("reads changesets")
|
|
|
|
.args_from_usage(
|
|
|
|
r#"
|
|
|
|
<HASH> '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<String>)
|
|
|
|
.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
|
2019-02-07 01:58:25 +03:00
|
|
|
.get_idx_by_nodeid(hash)
|
2018-05-02 01:59:30 +03:00
|
|
|
.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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|