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
|
|
|
*/
|
2017-07-28 04:00:19 +03:00
|
|
|
|
2019-12-07 03:26:57 +03:00
|
|
|
use anyhow::{bail, Result};
|
2017-07-28 04:00:19 +03:00
|
|
|
use clap::App;
|
2019-08-14 13:58:11 +03:00
|
|
|
use mercurial_revlog::revlog::{RevIdx, Revlog};
|
|
|
|
use std::str::FromStr;
|
2017-07-28 04:00:19 +03:00
|
|
|
|
|
|
|
fn run() -> Result<()> {
|
|
|
|
// Define command line args and parse command line
|
|
|
|
let matches = App::new("idxdump")
|
|
|
|
.about("dump index entries")
|
|
|
|
.args_from_usage(concat!(
|
|
|
|
"<IDXFILE> 'index file'\n",
|
|
|
|
"[<REV>] 'revision index'"
|
|
|
|
))
|
|
|
|
.get_matches();
|
|
|
|
|
|
|
|
// get path to index file
|
|
|
|
let idxpath = matches.value_of("IDXFILE").unwrap();
|
|
|
|
|
|
|
|
// Get optional index of entry within index file to start dumping from
|
|
|
|
let revidx: Option<RevIdx> = match matches.value_of("REV").map(FromStr::from_str) {
|
|
|
|
Some(Ok(v)) => Some(v),
|
2019-12-05 21:10:52 +03:00
|
|
|
Some(Err(err)) => bail!("idx malformed: {:?}", err),
|
2017-07-28 04:00:19 +03:00
|
|
|
None => None,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Construct a `Revlog` from the index file
|
2018-03-20 21:42:43 +03:00
|
|
|
let revlog = match Revlog::from_idx_no_data(idxpath) {
|
2017-07-28 04:00:19 +03:00
|
|
|
Ok(revlog) => revlog,
|
2019-12-05 21:10:52 +03:00
|
|
|
Err(err) => bail!("failed to load idx {}: {:?}", idxpath, err),
|
2017-07-28 04:00:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Print the header, using its `Debug` implementation
|
|
|
|
println!("Header: {:?}", revlog.get_header());
|
|
|
|
|
|
|
|
// Construct an iterator over the revlog index
|
|
|
|
let iter = &mut revlog.into_iter();
|
|
|
|
|
|
|
|
// If we're not starting at the first version, seek to the starting point
|
|
|
|
if let Some(revidx) = revidx {
|
|
|
|
iter.seek(revidx)
|
|
|
|
}
|
|
|
|
|
|
|
|
// for each entry, get a parsed index entry, and the sequence number in the iteration
|
|
|
|
// (`enumerate()` takes an iterator returning T and turns it into an iterator returning
|
|
|
|
// `(usize, T)` tuples)
|
|
|
|
for (idx, entry) in iter.enumerate() {
|
|
|
|
println!("{:?}: {:?}", revidx.unwrap_or(RevIdx::zero()) + idx, entry)
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
if let Err(ref e) = run() {
|
|
|
|
println!("Failed: {}", e);
|
|
|
|
|
2019-11-22 19:55:54 +03:00
|
|
|
for e in e.chain() {
|
2017-07-28 04:00:19 +03:00
|
|
|
println!("caused by: {}", e);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
}
|