From 1ddf5aaa0e2c391e13643ba5950a845d6dbfa533 Mon Sep 17 00:00:00 2001 From: Stefan Filip Date: Wed, 2 Sep 2020 17:17:23 -0700 Subject: [PATCH] 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 --- .../lib/edenapi/tools/make_req/src/main.rs | 2 +- .../lib/edenapi/tools/read_res/src/main.rs | 34 +++++++++++++++++-- eden/scm/lib/edenapi/types/src/commit.rs | 14 +++++++- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/eden/scm/lib/edenapi/tools/make_req/src/main.rs b/eden/scm/lib/edenapi/tools/make_req/src/main.rs index 6e81913f10..c1e517172c 100644 --- a/eden/scm/lib/edenapi/tools/make_req/src/main.rs +++ b/eden/scm/lib/edenapi/tools/make_req/src/main.rs @@ -54,8 +54,8 @@ fn main() -> Result<()> { Command::Tree(args) => make_req::(args), Command::History(args) => make_req::(args), Command::CompleteTree(args) => make_req::(args), - Command::CommitLocationToHash(args) => make_req::(args), Command::CommitRevlogData(args) => make_req::(args), + Command::CommitLocationToHash(args) => make_req::(args), } } diff --git a/eden/scm/lib/edenapi/tools/read_res/src/main.rs b/eden/scm/lib/edenapi/tools/read_res/src/main.rs index 8e013b6321..9fbfdeecdc 100644 --- a/eden/scm/lib/edenapi/tools/read_res/src/main.rs +++ b/eden/scm/lib/edenapi/tools/read_res/src/main.rs @@ -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, } +#[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, + #[structopt(long, short, help = "Output file (stdout used if omitted)")] + output: Option, + #[structopt(long, short, help = "Look at items starting with index start")] + start: Option, + #[structopt(long, short, help = "Only look at N entries")] + limit: Option, +} + 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 = 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, ) -> BTreeMap> { diff --git a/eden/scm/lib/edenapi/types/src/commit.rs b/eden/scm/lib/edenapi/types/src/commit.rs index 7f3981b84e..eb8eef11a8 100644 --- a/eden/scm/lib/edenapi/types/src/commit.rs +++ b/eden/scm/lib/edenapi/types/src/commit.rs @@ -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)]