mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
820395cb2a
Summary: Rust 2018 updates to: //scm/mononoke:admin-rust-build-info-lib //scm/mononoke:aliasverify //scm/mononoke:aliasverify-rust-build-info-lib //scm/mononoke:aliasverify-unittest //scm/mononoke:blobimport //scm/mononoke:blobimport-rust-build-info-lib //scm/mononoke:blobimport-unittest //scm/mononoke:blobstore_healer-rust-build-info-lib //scm/mononoke:bonsai_verify //scm/mononoke:bonsai_verify-rust-build-info-lib //scm/mononoke:configlint-rust-build-info-lib //scm/mononoke:dumprev //scm/mononoke:dumprev-rust-build-info-lib //scm/mononoke:idxdump //scm/mononoke:idxdump-rust-build-info-lib //scm/mononoke:mononoke-rust-build-info-lib //scm/mononoke:populate_healer-rust-build-info-lib //scm/mononoke:revlogrepo //scm/mononoke:revlogrepo-rust-build-info-lib //scm/mononoke:revlogrepo-unittest Reviewed By: fanzeyi Differential Revision: D15465530 fbshipit-source-id: 616db5cc0a8584ccb05f4c3c446b1b3ffd343695
84 lines
2.4 KiB
Rust
84 lines
2.4 KiB
Rust
// 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.
|
|
|
|
// declare dependencies on other crates
|
|
extern crate clap;
|
|
// mercurial stuff
|
|
#[macro_use]
|
|
extern crate failure_ext as failure;
|
|
// 3rd party command line parser
|
|
extern crate mercurial;
|
|
|
|
// Import symbols from std:: (standard library)
|
|
use std::str::FromStr;
|
|
|
|
// Just need `App` from clap
|
|
use crate::failure::Result;
|
|
use clap::App;
|
|
|
|
// Get `Revlog` and `RevIdx` from revlog module.
|
|
use mercurial::revlog::{RevIdx, Revlog};
|
|
|
|
fn run() -> Result<()> {
|
|
// Define command line args and parse command line
|
|
let matches = App::new("idxdump")
|
|
.version("0.0.0")
|
|
.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),
|
|
Some(Err(err)) => bail_msg!("idx malformed: {:?}", err),
|
|
None => None,
|
|
};
|
|
|
|
// Construct a `Revlog` from the index file
|
|
let revlog = match Revlog::from_idx_no_data(idxpath) {
|
|
Ok(revlog) => revlog,
|
|
Err(err) => bail_msg!("failed to load idx {}: {:?}", idxpath, err),
|
|
};
|
|
|
|
// 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);
|
|
|
|
for e in e.iter_chain() {
|
|
println!("caused by: {}", e);
|
|
}
|
|
|
|
std::process::exit(1);
|
|
}
|
|
}
|