Skip to content

Commit c99039f

Browse files
committed
chore: Address pedantic clippy lints
1 parent eb8a86d commit c99039f

38 files changed

+219
-205
lines changed

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn main() {
3939
.ok();
4040
let git_hash = git_output
4141
.as_ref()
42-
.and_then(|output| std::str::from_utf8(&output.stdout).ok().map(|s| s.trim()))
42+
.and_then(|output| std::str::from_utf8(&output.stdout).ok().map(str::trim))
4343
// E.g. "v2.0.0-beta.2-7-g12ab34cd56*"
4444
// ttttttttttttt N hhhhhhhhhhhD
4545
// t => last matching annotated tag

src/alias.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fn split_command_line(line: &str) -> Result<Vec<String>, String> {
145145
argv.push(completed_word);
146146
skip_spaces = true;
147147
} else {
148-
word.push(c)
148+
word.push(c);
149149
}
150150
}
151151
} else {

src/argset.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub(crate) fn parse_branch_name(name: &str) -> anyhow::Result<String> {
6969
/// since that function returns `Option<&String>` which often needs to be mapped to
7070
/// `Option<&str>`.
7171
pub(crate) fn get_one_str<'a>(matches: &'a clap::ArgMatches, id: &str) -> Option<&'a str> {
72-
matches.get_one::<String>(id).map(|s| s.as_str())
72+
matches.get_one::<String>(id).map(String::as_str)
7373
}
7474

7575
/// For use with `clap::Arg::value_parser()` to parse a usize argument.
@@ -103,7 +103,7 @@ pub(crate) fn get_diff_opts(
103103

104104
if let Ok(value) = config.get_string("stgit.diff-opts") {
105105
for arg in value.split_ascii_whitespace() {
106-
opts.push(String::from(arg))
106+
opts.push(String::from(arg));
107107
}
108108
}
109109

@@ -112,7 +112,7 @@ pub(crate) fn get_diff_opts(
112112
}
113113

114114
if force_full_index {
115-
opts.push(String::from("--full-index"))
115+
opts.push(String::from("--full-index"));
116116
}
117117

118118
if force_binary {

src/cmd/branch.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,15 @@ fn run(matches: &ArgMatches) -> Result<()> {
231231
let repo = git2::Repository::open_from_env()?;
232232
if let Some((subname, submatches)) = matches.subcommand() {
233233
match subname {
234-
"--list" => list(repo, submatches),
235-
"--create" => create(repo, submatches),
236-
"--clone" => clone(repo, submatches),
237-
"--rename" => rename(repo, submatches),
238-
"--protect" => protect(repo, submatches),
239-
"--unprotect" => unprotect(repo, submatches),
240-
"--delete" => delete(repo, submatches),
241-
"--cleanup" => cleanup(repo, submatches),
242-
"--describe" => describe(repo, submatches),
234+
"--list" => list(&repo, submatches),
235+
"--create" => create(&repo, submatches),
236+
"--clone" => clone(&repo, submatches),
237+
"--rename" => rename(&repo, submatches),
238+
"--protect" => protect(&repo, submatches),
239+
"--unprotect" => unprotect(&repo, submatches),
240+
"--delete" => delete(&repo, submatches),
241+
"--cleanup" => cleanup(&repo, submatches),
242+
"--describe" => describe(&repo, submatches),
243243
s => panic!("unhandled branch subcommand {s}"),
244244
}
245245
} else {
@@ -316,7 +316,7 @@ fn set_stgit_parent(
316316
}
317317
}
318318

319-
fn list(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
319+
fn list(repo: &git2::Repository, matches: &ArgMatches) -> Result<()> {
320320
let mut branchnames = Vec::new();
321321
for branch_result in repo.branches(Some(git2::BranchType::Local))? {
322322
let (branch, _branch_type) = branch_result?;
@@ -328,13 +328,13 @@ fn list(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
328328
}
329329

330330
branchnames.sort();
331-
let branchname_width = branchnames.iter().map(|s| s.len()).max();
331+
let branchname_width = branchnames.iter().map(String::len).max();
332332

333333
let current_branchname = repo.get_branch(None).ok().and_then(|branch| {
334334
branch
335335
.name()
336336
.ok()
337-
.and_then(|name| name.map(|s| s.to_string()))
337+
.and_then(|name| name.map(ToString::to_string))
338338
});
339339

340340
let config = repo.config()?;
@@ -354,7 +354,7 @@ fn list(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
354354
write!(stdout, " ")?;
355355
};
356356

357-
if let Ok(stack) = Stack::from_branch(&repo, Some(branchname)) {
357+
if let Ok(stack) = Stack::from_branch(repo, Some(branchname)) {
358358
color_spec.set_fg(Some(termcolor::Color::Cyan));
359359
stdout.set_color(&color_spec)?;
360360
write!(stdout, "s")?;
@@ -401,7 +401,7 @@ fn list(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
401401
Ok(())
402402
}
403403

404-
fn create(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
404+
fn create(repo: &git2::Repository, matches: &ArgMatches) -> Result<()> {
405405
let new_branchname = get_one_str(matches, "new-branch").expect("required argument");
406406

407407
repo.check_repository_state()?;
@@ -441,7 +441,7 @@ fn create(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
441441
let target_commit = if let Some(parent_branch) = parent_branch.as_ref() {
442442
parent_branch.get().peel_to_commit()?
443443
} else if let Some(committish) = get_one_str(matches, "committish") {
444-
crate::revspec::parse_stgit_revision(&repo, Some(committish), None)?.peel_to_commit()?
444+
crate::revspec::parse_stgit_revision(repo, Some(committish), None)?.peel_to_commit()?
445445
} else {
446446
repo.head()?.peel_to_commit()?
447447
};
@@ -454,7 +454,7 @@ fn create(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
454454

455455
let mut config = repo.config()?;
456456
let mut new_branch = repo.branch(new_branchname, &target_commit, false)?;
457-
let stack = match Stack::initialize(&repo, Some(new_branchname)) {
457+
let stack = match Stack::initialize(repo, Some(new_branchname)) {
458458
Ok(stack) => stack,
459459
Err(e) => {
460460
new_branch.delete()?;
@@ -493,7 +493,7 @@ fn create(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
493493
}
494494
}
495495

496-
fn clone(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
496+
fn clone(repo: &git2::Repository, matches: &ArgMatches) -> Result<()> {
497497
let current_branch = repo.get_branch(None)?;
498498
let current_branchname = get_branch_name(&current_branch)?;
499499

@@ -510,7 +510,7 @@ fn clone(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
510510
repo.check_repository_state()?;
511511
statuses.check_conflicts()?;
512512

513-
if let Ok(stack) = Stack::from_branch(&repo, None) {
513+
if let Ok(stack) = Stack::from_branch(repo, None) {
514514
stack.check_head_top_mismatch()?;
515515
let state_ref = repo
516516
.find_reference(&stack.refname)
@@ -525,7 +525,7 @@ fn clone(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
525525
stupid.branch_copy(None, &new_branchname)?;
526526
} else {
527527
stupid.branch_copy(None, &new_branchname)?;
528-
Stack::initialize(&repo, Some(&new_branchname))?;
528+
Stack::initialize(repo, Some(&new_branchname))?;
529529
};
530530

531531
let mut config = repo.config()?;
@@ -542,11 +542,11 @@ fn clone(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
542542
stupid.checkout(new_branch.name().unwrap().unwrap())
543543
}
544544

545-
fn rename(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
545+
fn rename(repo: &git2::Repository, matches: &ArgMatches) -> Result<()> {
546546
let names: Vec<_> = matches
547547
.get_many::<String>("branch-any")
548548
.unwrap()
549-
.map(|s| s.as_str())
549+
.map(String::as_str)
550550
.collect();
551551
let current_branchname;
552552
let (old_branchname, new_branchname) = if names.len() == 2 {
@@ -562,7 +562,7 @@ fn rename(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
562562
let mut config = repo.config()?;
563563
let parent_branchname = get_stgit_parent(&config, old_branchname);
564564

565-
if let Ok(stack) = Stack::from_branch(&repo, Some(old_branchname)) {
565+
if let Ok(stack) = Stack::from_branch(repo, Some(old_branchname)) {
566566
let state_commit = repo
567567
.find_reference(&stack.refname)
568568
.expect("just found this stack state reference")
@@ -582,19 +582,19 @@ fn rename(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
582582
Ok(())
583583
}
584584

585-
fn protect(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
586-
let stack = Stack::from_branch(&repo, get_one_str(matches, "branch"))?;
585+
fn protect(repo: &git2::Repository, matches: &ArgMatches) -> Result<()> {
586+
let stack = Stack::from_branch(repo, get_one_str(matches, "branch"))?;
587587
let mut config = repo.config()?;
588588
stack.set_protected(&mut config, true)
589589
}
590590

591-
fn unprotect(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
592-
let stack = Stack::from_branch(&repo, get_one_str(matches, "branch"))?;
591+
fn unprotect(repo: &git2::Repository, matches: &ArgMatches) -> Result<()> {
592+
let stack = Stack::from_branch(repo, get_one_str(matches, "branch"))?;
593593
let mut config = repo.config()?;
594594
stack.set_protected(&mut config, false)
595595
}
596596

597-
fn delete(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
597+
fn delete(repo: &git2::Repository, matches: &ArgMatches) -> Result<()> {
598598
let target_branchname = get_one_str(matches, "branch-any").expect("required argument");
599599
let mut target_branch = repo.get_branch(Some(target_branchname))?;
600600
let current_branch = repo.get_branch(None).ok();
@@ -605,7 +605,7 @@ fn delete(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
605605

606606
let config = repo.config()?;
607607

608-
if let Ok(stack) = Stack::from_branch(&repo, Some(target_branchname)) {
608+
if let Ok(stack) = Stack::from_branch(repo, Some(target_branchname)) {
609609
if stack.is_protected(&config) {
610610
return Err(anyhow!("Delete not permitted: this branch is protected"));
611611
} else if !matches.get_flag("force") && stack.all_patches().count() > 0 {
@@ -620,8 +620,8 @@ fn delete(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
620620
Ok(())
621621
}
622622

623-
fn cleanup(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
624-
let stack = Stack::from_branch(&repo, get_one_str(matches, "branch"))?;
623+
fn cleanup(repo: &git2::Repository, matches: &ArgMatches) -> Result<()> {
624+
let stack = Stack::from_branch(repo, get_one_str(matches, "branch"))?;
625625
let config = repo.config()?;
626626
if stack.is_protected(&config) {
627627
return Err(anyhow!("Clean up not permitted: this branch is protected"));
@@ -634,7 +634,7 @@ fn cleanup(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
634634
Ok(())
635635
}
636636

637-
fn describe(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
637+
fn describe(repo: &git2::Repository, matches: &ArgMatches) -> Result<()> {
638638
let branch = repo.get_branch(get_one_str(matches, "branch-any"))?;
639639
let description = get_one_str(matches, "description").expect("required argument");
640640
let branchname = get_branch_name(&branch)?;

src/cmd/completion/bash.rs

Lines changed: 59 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(super) fn dispatch(matches: &clap::ArgMatches) -> Result<()> {
2929

3030
script.raw(HEADER);
3131

32-
let mut stg = crate::get_full_command(crate::alias::Aliases::new(), None);
32+
let mut stg = crate::get_full_command(&crate::alias::Aliases::new(), None);
3333
stg.build();
3434

3535
for command in stg.get_subcommands() {
@@ -210,34 +210,55 @@ fn insert_compreply(script: &mut ShStream, arg: &clap::Arg) {
210210
) {
211211
match arg.get_id().as_str() {
212212
"branch" | "ref-branch" => {
213-
script.line("mapfile -t COMPREPLY < <(compgen -W \"$(_stg_branches)\" -- \"$cur\")")
213+
script
214+
.line("mapfile -t COMPREPLY < <(compgen -W \"$(_stg_branches)\" -- \"$cur\")");
214215
}
215216

216217
"branch-any" => {
217-
script.line("mapfile -t COMPREPLY < <(compgen -W \"$(_all_branches)\" -- \"$cur\")")
218+
script
219+
.line("mapfile -t COMPREPLY < <(compgen -W \"$(_all_branches)\" -- \"$cur\")");
218220
}
219-
"committish" => script.line(
221+
"committish" => {
222+
script.line(
220223
"mapfile -t COMPREPLY < <(compgen -W \"$(_all_branches) $(_tags) $(_remotes)\")",
221-
),
222-
"git-diff-opt" => script
223-
.line("mapfile -t COMPREPLY < <(compgen -W \"$(_git_diff_opts)\" -- \"$cur\")"),
224-
"git-format-patch-opt" => script.line(
224+
);
225+
}
226+
"git-diff-opt" => {
227+
script
228+
.line("mapfile -t COMPREPLY < <(compgen -W \"$(_git_diff_opts)\" -- \"$cur\")");
229+
}
230+
"git-format-patch-opt" => {
231+
script.line(
225232
"mapfile -t COMPREPLY < <(compgen -W \"$(_git_format_patch_opts)\" -- \"$cur\")",
226-
),
227-
"git-send-email-opt" => script.line(
228-
"mapfile -t COMPREPLY < <(compgen -W \"$(_git_send_email_opts)\" -- \"$cur\")",
229-
),
230-
"patch" => script
231-
.line("mapfile -t COMPREPLY < <(compgen -W \"$(_visible_patches)\" -- \"$cur\")"),
232-
"patchranges" => script.line("_patch_range \"$(_visible_patches)\""),
233+
);
234+
}
235+
"git-send-email-opt" => {
236+
script.line(
237+
"mapfile -t COMPREPLY < <(compgen -W \"$(_git_send_email_opts)\" -- \"$cur\")",
238+
);
239+
}
240+
"patch" => {
241+
script.line(
242+
"mapfile -t COMPREPLY < <(compgen -W \"$(_visible_patches)\" -- \"$cur\")",
243+
);
244+
}
245+
"patchranges" => {
246+
script.line("_patch_range \"$(_visible_patches)\"");
247+
}
233248
"patchranges-all" | "set-tree" | "stgit-revision" => {
234-
script.line("_patch_range \"$(_all_patches)\"")
249+
script.line("_patch_range \"$(_all_patches)\"");
250+
}
251+
"patchranges-applied" => {
252+
script.line("_patch_range \"$(_applied_patches)\"");
253+
}
254+
"patchranges-hidden" => {
255+
script.line("_patch_range \"$(_hidden_patches)\"");
256+
}
257+
"patchranges-unapplied" => {
258+
script.line("_patch_range \"$(_unapplied_patches)\"");
235259
}
236-
"patchranges-applied" => script.line("_patch_range \"$(_applied_patches)\""),
237-
"patchranges-hidden" => script.line("_patch_range \"$(_hidden_patches)\""),
238-
"patchranges-unapplied" => script.line("_patch_range \"$(_unapplied_patches)\""),
239260
"pathspecs" => {
240-
script.line("mapfile -t COMPREPLY < <(compgen -o filenames -A file -- \"$cur\")")
261+
script.line("mapfile -t COMPREPLY < <(compgen -o filenames -A file -- \"$cur\")");
241262
}
242263
"subcommand" => {
243264
// N.B. the `$__subcommands` here refers to a variable in the *calling
@@ -260,28 +281,35 @@ fn insert_compreply(script: &mut ShStream, arg: &clap::Arg) {
260281
script.dedent();
261282
script.line("fi");
262283
}
263-
_ => script.line(":"),
284+
_ => {
285+
script.line(":");
286+
}
264287
};
265288
} else {
266289
match arg.get_value_hint() {
267290
clap::ValueHint::Unknown | clap::ValueHint::Other => panic!(),
268291
clap::ValueHint::AnyPath => {
269-
script.line("mapfile -t COMPREPLY < <(compgen -o default -- \"$cur\")")
292+
script.line("mapfile -t COMPREPLY < <(compgen -o default -- \"$cur\")");
270293
}
271294
clap::ValueHint::FilePath => {
272-
script.line("mapfile -t COMPREPLY < <(compgen -o filenames -A file -- \"$cur\")")
295+
script.line("mapfile -t COMPREPLY < <(compgen -o filenames -A file -- \"$cur\")");
296+
}
297+
clap::ValueHint::DirPath => {
298+
script.line(
299+
"mapfile -t COMPREPLY < <(compgen -o directory -A directory -- \"$cur\")",
300+
);
301+
}
302+
clap::ValueHint::EmailAddress => {
303+
script.line(":");
273304
}
274-
clap::ValueHint::DirPath => script
275-
.line("mapfile -t COMPREPLY < <(compgen -o directory -A directory -- \"$cur\")"),
276-
clap::ValueHint::EmailAddress => script.line(":"),
277305
clap::ValueHint::CommandName => {
278-
script.line("mapfile -t COMPREPLY < <(compgen -A command -- \"$cur\")")
306+
script.line("mapfile -t COMPREPLY < <(compgen -A command -- \"$cur\")");
279307
}
280308
clap::ValueHint::Username => {
281-
script.line("mapfile -t COMPREPLY < <(compgen -A user -- \"$cur\")")
309+
script.line("mapfile -t COMPREPLY < <(compgen -A user -- \"$cur\")");
282310
}
283311
clap::ValueHint::Hostname => {
284-
script.line("mapfile -t COMPREPLY < <(compgen -A hostname -- \"$cur\")")
312+
script.line("mapfile -t COMPREPLY < <(compgen -A hostname -- \"$cur\")");
285313
}
286314
clap::ValueHint::ExecutablePath => todo!(),
287315
clap::ValueHint::CommandString => todo!(),
@@ -307,8 +335,7 @@ fn get_flags(command: &clap::Command) -> (ShStream, ShStream) {
307335
for name in longs {
308336
if arg
309337
.get_num_args()
310-
.map(|value_range| value_range.takes_values())
311-
.unwrap_or(false)
338+
.map_or(false, |value_range| value_range.takes_values())
312339
{
313340
long_flags.word(&f!("--{name}="));
314341
} else {
@@ -341,7 +368,7 @@ fn get_flags(command: &clap::Command) -> (ShStream, ShStream) {
341368
}
342369
}
343370

344-
if command.get_positionals().any(|arg| arg.is_last_set()) {
371+
if command.get_positionals().any(clap::Arg::is_last_set) {
345372
long_flags.word("'-- '");
346373
}
347374

0 commit comments

Comments
 (0)