mirror of
https://github.com/facebook/sapling.git
synced 2024-12-25 14:05:00 +03:00
tools: add location-to-hash command to read_res
Summary: There aren't too many thigs that we can do with the responses that we get back from the server. Thigs are somewhat application specific for this endpoint. One option that is not available right now and might make sense to add is limiting the number of entries that are printed for a given location. Reviewed By: kulshrax Differential Revision: D23456220 fbshipit-source-id: eb24602c3dea39b568859b82fc27b7f6acc77600
This commit is contained in:
parent
932450fb15
commit
1ddf5aaa0e
@ -54,8 +54,8 @@ fn main() -> Result<()> {
|
||||
Command::Tree(args) => make_req::<TreeRequest>(args),
|
||||
Command::History(args) => make_req::<HistoryRequest>(args),
|
||||
Command::CompleteTree(args) => make_req::<CompleteTreeRequest>(args),
|
||||
Command::CommitLocationToHash(args) => make_req::<CommitLocationToHashRequest>(args),
|
||||
Command::CommitRevlogData(args) => make_req::<CommitRevlogDataRequest>(args),
|
||||
Command::CommitLocationToHash(args) => make_req::<CommitLocationToHashRequest>(args),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,8 @@ use sha1::{Digest, Sha1};
|
||||
use structopt::StructOpt;
|
||||
|
||||
use edenapi_types::{
|
||||
CommitRevlogData, FileEntry, FileError, HistoryResponseChunk, TreeEntry, TreeError,
|
||||
WireHistoryEntry,
|
||||
CommitLocationToHash, CommitRevlogData, FileEntry, FileError, HistoryResponseChunk, TreeEntry,
|
||||
TreeError, WireHistoryEntry,
|
||||
};
|
||||
use types::{HgId, Key, Parents, RepoPathBuf};
|
||||
|
||||
@ -36,6 +36,7 @@ enum Args {
|
||||
File(FileArgs),
|
||||
History(HistoryArgs),
|
||||
CommitRevlogData(CommitRevlogDataArgs),
|
||||
CommitLocationToHash(CommitLocationToHashArgs),
|
||||
}
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
@ -157,12 +158,26 @@ struct CommitRevlogDataCheckArgs {
|
||||
limit: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
#[structopt(about = "Read the contents of a commit location-to-hash request")]
|
||||
struct CommitLocationToHashArgs {
|
||||
#[structopt(help = "Input CBOR file (stdin is used if omitted)")]
|
||||
input: Option<PathBuf>,
|
||||
#[structopt(long, short, help = "Output file (stdout used if omitted)")]
|
||||
output: Option<PathBuf>,
|
||||
#[structopt(long, short, help = "Look at items starting with index start")]
|
||||
start: Option<usize>,
|
||||
#[structopt(long, short, help = "Only look at N entries")]
|
||||
limit: Option<usize>,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
match Args::from_args() {
|
||||
Args::Tree(args) => cmd_tree(args),
|
||||
Args::File(args) => cmd_file(args),
|
||||
Args::History(args) => cmd_history(args),
|
||||
Args::CommitRevlogData(args) => cmd_commit_revlog_data(args),
|
||||
Args::CommitLocationToHash(args) => cmd_commit_location_to_hash(args),
|
||||
}
|
||||
}
|
||||
|
||||
@ -341,6 +356,21 @@ fn cmd_commit_revlog_data_check(args: CommitRevlogDataCheckArgs) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn cmd_commit_location_to_hash(args: CommitLocationToHashArgs) -> Result<()> {
|
||||
let commit_location_to_hash_list: Vec<CommitLocationToHash> = read_input(args.input, None)?;
|
||||
let iter = commit_location_to_hash_list
|
||||
.iter()
|
||||
.skip(args.start.unwrap_or(0))
|
||||
.take(args.limit.unwrap_or(usize::MAX));
|
||||
for clh in iter {
|
||||
println!("{:?}", clh.location);
|
||||
for hgid in clh.hgids.iter() {
|
||||
println!(" {}", hgid);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn make_history_map(
|
||||
chunks: impl IntoIterator<Item = HistoryResponseChunk>,
|
||||
) -> BTreeMap<String, Vec<WireHistoryEntry>> {
|
||||
|
@ -5,6 +5,8 @@
|
||||
* GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use bytes::Bytes;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
@ -29,7 +31,7 @@ use types::hgid::HgId;
|
||||
///
|
||||
/// Notes.
|
||||
/// * We expect the default or master bookmark to be a known commit.
|
||||
#[derive(Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||
#[derive(Clone, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct CommitLocation {
|
||||
pub known_descendant: HgId,
|
||||
@ -37,6 +39,16 @@ pub struct CommitLocation {
|
||||
pub count: u64,
|
||||
}
|
||||
|
||||
impl fmt::Debug for CommitLocation {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"CommitLocation(known=\"{}\", dist={}, count={})",
|
||||
self.known_descendant, self.distance_to_descendant, self.count
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// A LocationToHashRequest consists of a set of locations that we want to retrieve the hashe for.
|
||||
#[derive(Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
|
Loading…
Reference in New Issue
Block a user