1
0
mirror of https://github.com/shimunn/gitredditor.git synced 2023-11-17 18:42:43 +01:00

applied clippy suggestions

This commit is contained in:
shimunn 2019-05-17 19:15:50 +02:00
parent e830ac588d
commit 166a4ba0de
2 changed files with 14 additions and 11 deletions

View File

@ -26,7 +26,7 @@ fn main() {
"Hello, world! {:?}", "Hello, world! {:?}",
update( update(
&opts.repo.unwrap(), &opts.repo.unwrap(),
comments.take(opts.fetch).filter_map(|c| c.ok()), comments.take(opts.fetch).flatten(),
&opts.redditor, &opts.redditor,
&("reddit.com/u/".to_owned() + &opts.redditor), &("reddit.com/u/".to_owned() + &opts.redditor),
(opts.threshold, opts.thresholdp) (opts.threshold, opts.thresholdp)
@ -34,7 +34,7 @@ fn main() {
); );
} }
fn update<'a>( fn update(
repo: &PathBuf, repo: &PathBuf,
current: impl IntoIterator<Item = Comment>, current: impl IntoIterator<Item = Comment>,
redditor: &str, redditor: &str,
@ -43,7 +43,7 @@ fn update<'a>(
) -> Result<usize, Box<Error>> { ) -> Result<usize, Box<Error>> {
let comment_path = |c: &Comment| { let comment_path = |c: &Comment| {
let mut p = repo.clone(); let mut p = repo.clone();
for s in c.permalink.split("/") { for s in c.permalink.split('/') {
p.push(s); p.push(s);
} }
p.set_extension("json"); p.set_extension("json");
@ -55,7 +55,7 @@ fn update<'a>(
let mut index = git.index()?; let mut index = git.index()?;
index.read(false)?; index.read(false)?;
let (threshold, threshold_percent) = threshold; let (threshold, threshold_percent) = threshold;
let threshold_percent = threshold_percent as f32; let threshold_percent = f32::from(threshold_percent);
let head = || dbg!(git.find_commit(git.head()?.target().unwrap())); let head = || dbg!(git.find_commit(git.head()?.target().unwrap()));
let mut parent = head()?; let mut parent = head()?;
for comment in current.into_iter() { for comment in current.into_iter() {
@ -81,9 +81,12 @@ fn update<'a>(
_ => true, _ => true,
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
if delta.len() > 0 { if !delta.is_empty() {
fs_write(&path, to_string_pretty(&comment)?)?; fs_write(&path, to_string_pretty(&comment)?)?;
commit_msg = delta.iter().map(|d| d.to_string()).collect::<Vec<_>>()[..].join("\n"); for msg in delta.iter() {
commit_msg.push_str(&msg.to_string());
commit_msg.push('\n');
}
//index.update_all(vec![&path], None)?; //index.update_all(vec![&path], None)?;
updated += 1; updated += 1;
true true
@ -103,7 +106,7 @@ fn update<'a>(
let tree_id = index.write_tree()?; let tree_id = index.write_tree()?;
let tree = git.find_tree(tree_id)?; let tree = git.find_tree(tree_id)?;
let time = commit_timestamp.unwrap_or(comment.last_update()); let time = commit_timestamp.unwrap_or_else(|| comment.last_update());
let sig_backdate = Signature::new(sig.name().unwrap(), sig.email().unwrap(), &{ let sig_backdate = Signature::new(sig.name().unwrap(), sig.email().unwrap(), &{
let dur = dbg!(time).duration_since(UNIX_EPOCH).unwrap(); let dur = dbg!(time).duration_since(UNIX_EPOCH).unwrap();

View File

@ -46,8 +46,8 @@ impl fmt::Display for CommentDelta {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use CommentDelta::*; use CommentDelta::*;
match self { match self {
Votes(d) if d > &0 => write!(f, "Received +{} upvotes", d), Votes(d) if *d > 0 => write!(f, "Received +{} upvotes", d),
Votes(d) if d < &0 => write!(f, "Received {} downvotes", d), Votes(d) if *d < 0 => write!(f, "Received {} downvotes", d),
Votes(_) => write!(f, "You shouln't see this one, if you do check the source"), Votes(_) => write!(f, "You shouln't see this one, if you do check the source"),
Content => write!(f, "Edited"), Content => write!(f, "Edited"),
New => write!(f, "Created"), New => write!(f, "Created"),
@ -103,7 +103,7 @@ impl Comments {
pub fn new<T: ToString>(url: T) -> Comments { pub fn new<T: ToString>(url: T) -> Comments {
let url = url.to_string(); let url = url.to_string();
Comments { Comments {
url: url, url,
continuation: None, continuation: None,
buffer: None, buffer: None,
no_it: 0, no_it: 0,
@ -127,7 +127,7 @@ impl Iterator for Comments {
let comment_json: Value = serde_json::from_str(&comment_json)?; let comment_json: Value = serde_json::from_str(&comment_json)?;
let data: &Value = &comment_json["data"]; let data: &Value = &comment_json["data"];
let continuation: Option<String> = match &data["after"] { let continuation: Option<String> = match &data["after"] {
Value::String(after) if after.len() > 0 => Some(after.clone()), Value::String(after) if !after.is_empty() => Some(after.clone()),
_ => None, _ => None,
}; };
//Kinda ugly .clone() //Kinda ugly .clone()