From a69552b873ec41debbfec0f45321cddc4fc319e2 Mon Sep 17 00:00:00 2001 From: Eric Petersen Date: Sat, 8 Jun 2024 15:48:22 -0700 Subject: [PATCH] Switch from json to serde_json; bump version to 0.6.2 --- Cargo.lock | 54 +++++++++++++++++++++++++++++++++++++++++++-------- Cargo.toml | 8 ++++++-- README.md | 2 ++ src/cli.rs | 12 ++++++------ src/repo.rs | 4 +++- src/report.rs | 30 +++++++++------------------- 6 files changed, 72 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2bd3c87..f2d6ec4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -175,14 +175,15 @@ dependencies = [ [[package]] name = "git-global" -version = "0.6.1" +version = "0.6.2" dependencies = [ "clap", "directories", "git2", - "json", "man", "regex", + "serde", + "serde_json", "tempfile", "walkdir", ] @@ -216,6 +217,12 @@ version = "1.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + [[package]] name = "jobserver" version = "0.1.31" @@ -225,12 +232,6 @@ dependencies = [ "libc", ] -[[package]] -name = "json" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd" - [[package]] name = "libc" version = "0.2.155" @@ -399,6 +400,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + [[package]] name = "same-file" version = "1.0.6" @@ -408,6 +415,37 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "serde" +version = "1.0.203" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.203" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +dependencies = [ + "itoa", + "ryu", + "serde", +] + [[package]] name = "strsim" version = "0.11.1" diff --git a/Cargo.toml b/Cargo.toml index 6a630c5..2d90967 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "git-global" -version = "0.6.1" +version = "0.6.2" authors = ["Eric Petersen "] description = "Keep track of all the git repositories on your machine." @@ -35,7 +35,7 @@ manpage = ["man"] [dependencies] directories = "5" -json = "0.12" # Unmaintained (RUSTSEC-2022-0081) +serde_json = "1" walkdir = "2" [dev-dependencies] @@ -53,3 +53,7 @@ default-features = false # don't need SSH/HTTPS [dependencies.man] version = "0.3" optional = true + +[dependencies.serde] +version = "1" +features = ["derive"] diff --git a/README.md b/README.md index 33892d3..41a7306 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,8 @@ The following are some ideas about future subcommands and features: ## Release Notes +* 0.6.2 (2024-06-08) + * Various dependency updates, including `json` --> `serde_json`. * 0.6.1 (2023-08-10) * Various dependency updates. * 0.6.0 (2023-05-10) diff --git a/src/cli.rs b/src/cli.rs index 06c793b..6ad3e06 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -3,7 +3,7 @@ use std::io::{stderr, stdout, Write}; use clap::{command, Arg, ArgAction, ArgMatches, Command}; -use json::object; +use serde_json::json; use crate::config::Config; use crate::subcommands; @@ -76,11 +76,11 @@ pub fn run_from_command_line() -> i32 { } Err(err) => { if use_json { - let json = object! { - "error" => true, - "message" => format!("{}", err) - }; - writeln!(&mut stderr(), "{:#}", json).unwrap(); + let out = json!({ + "error": true, + "message": format!("{}", err) + }); + writeln!(&mut stderr(), "{:#}", out).unwrap(); } else { writeln!(&mut stderr(), "{}", err).unwrap(); } diff --git a/src/repo.rs b/src/repo.rs index 212cd06..b4ec349 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -3,8 +3,10 @@ use std::fmt; use std::path::PathBuf; +use serde::Serialize; + /// A git repository, represented by the full path to its base directory. -#[derive(Clone, Eq, Hash, PartialEq)] +#[derive(Clone, Eq, Hash, PartialEq, Serialize)] pub struct Repo { path: PathBuf, } diff --git a/src/report.rs b/src/report.rs index d918786..e93bbd2 100644 --- a/src/report.rs +++ b/src/report.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use std::io::Write; -use json::{array, object}; +use serde_json::json; use crate::repo::Repo; @@ -73,28 +73,16 @@ impl Report { /// Writes all result messages to the given writer, as JSON. pub fn print_json(&self, writer: &mut W) { - let mut json = object! { - "error" => false, - "messages" => array![], - "repo_messages" => object!{} - }; - for msg in self.messages.iter() { - json["results"]["messages"] - .push(msg.to_string()) - .expect("Failing pushing message to JSON messages array."); - } + let mut repo_messages: HashMap> = HashMap::new(); for (repo, messages) in self.repo_messages.iter() { - json["repo_messages"][repo.path()] = array![]; - if !messages.is_empty() { - for line in messages.iter().filter(|l| !l.is_empty()) { - json["repo_messages"][repo.path()] - .push(line.to_string()) - .expect( - "Failed pushing line to JSON repo-messages array.", - ); - } - } + let msgs = messages.iter().filter(|l| !l.is_empty()); + repo_messages.insert(repo.path(), msgs.collect()); } + let json = json!({ + "error": false, + "messages": self.messages, + "repo_messages": repo_messages + }); writeln!(writer, "{:#}", json).unwrap(); } }