Harness the power of signify(1) to sign arbitrary git objects
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

print sigs in json fmt

+68 -21
+62 -19
src/list_signatures.rs
··· 8 8 use super::utils; 9 9 10 10 /// List signatures stored in this repository. 11 - pub fn command() -> Result<()> { 11 + pub fn command(output_json: bool) -> Result<()> { 12 12 let repo = utils::open_repository()?; 13 13 14 - for (oid, signers) in find_signers(&repo)? { 15 - let object = repo 16 - .find_object(oid, None) 17 - .context("Failed to find signed object")?; 14 + if !output_json { 15 + output_signers_human(&repo) 16 + } else { 17 + output_signers_json(&repo) 18 + } 19 + } 18 20 19 - let signed_rev = { 20 - let opts = { 21 - let mut opts = git2::DescribeOptions::new(); 22 - opts.describe_all(); 23 - opts.show_commit_oid_as_fallback(true); 24 - opts 25 - }; 26 - object 27 - .describe(&opts) 28 - .with_context(|| format!("Failed to describe oid={oid}"))? 29 - .format(None) 30 - .with_context(|| format!("Failed to format description of oid={oid}"))? 31 - }; 32 - 21 + fn output_signers_human(repo: &Repository) -> Result<()> { 22 + for (oid, signers) in find_signers(repo)? { 23 + let signed_rev = describe_object(repo, oid)?; 33 24 println!("Signers of {signed_rev}:"); 34 25 35 26 for signer in signers { 36 27 println!(" - {signer}"); 37 28 } 38 29 } 30 + Ok(()) 31 + } 32 + 33 + fn output_signers_json(repo: &Repository) -> Result<()> { 34 + fn print_signers(signers: Vec<Oid>) { 35 + let mut signers_iter = signers.into_iter(); 36 + 37 + print!("["); 38 + if let Some(signer) = signers_iter.next() { 39 + print!("\"{signer}\""); 40 + } 41 + for signer in signers_iter { 42 + print!(",\"{signer}\""); 43 + } 44 + print!("]"); 45 + } 46 + 47 + let mut objs_iter = find_signers(repo)?.into_iter(); 48 + 49 + print!("{{"); 50 + if let Some((oid, signers)) = objs_iter.next() { 51 + let signed_rev = describe_object(repo, oid)?; 52 + print!("\"{signed_rev}\":"); 53 + print_signers(signers); 54 + } 55 + for (oid, signers) in objs_iter { 56 + let signed_rev = describe_object(repo, oid)?; 57 + print!(",\"{signed_rev}\":"); 58 + print_signers(signers); 59 + } 60 + print!("}}"); 39 61 40 62 Ok(()) 63 + } 64 + 65 + fn describe_object(repo: &Repository, oid: Oid) -> Result<String> { 66 + let object = repo 67 + .find_object(oid, None) 68 + .context("Failed to find signed object")?; 69 + 70 + let opts = { 71 + let mut opts = git2::DescribeOptions::new(); 72 + opts.describe_all(); 73 + opts.show_commit_oid_as_fallback(true); 74 + opts 75 + }; 76 + 77 + let description = object 78 + .describe(&opts) 79 + .with_context(|| format!("Failed to describe oid={oid}"))?; 80 + 81 + description 82 + .format(None) 83 + .with_context(|| format!("Failed to format description of oid={oid}")) 41 84 } 42 85 43 86 fn find_signers(repo: &Repository) -> Result<BTreeMap<Oid, Vec<Oid>>> {
+6 -2
src/main.rs
··· 62 62 remote: Option<Cow<'static, str>>, 63 63 }, 64 64 /// List signatures stored in this repository 65 - ListSignatures, 65 + ListSignatures { 66 + /// Output JSON 67 + #[arg(long)] 68 + json: bool, 69 + }, 66 70 } 67 71 68 72 #[derive(Subcommand)] ··· 115 119 } => verify::command(public_key, rev), 116 120 Action::Push { remote } => push::command(&remote.unwrap_or(Cow::Borrowed("origin"))), 117 121 Action::Pull { remote } => pull::command(&remote.unwrap_or(Cow::Borrowed("origin"))), 118 - Action::ListSignatures => list_signatures::command(), 122 + Action::ListSignatures { json } => list_signatures::command(json), 119 123 } 120 124 }