Skip to content

Commit

Permalink
Do not use CollectableRefs::into_refs() in gc subcommand
Browse files Browse the repository at this point in the history
We use a `FlatMap` instead. This also causes references to be
collected/printed in chunks, e.g. all references for each issue at a
time.
  • Loading branch information
neithernut committed Apr 30, 2018
1 parent 70df3e0 commit 3a76c37
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,30 +222,38 @@ fn fetch_impl(matches: &clap::ArgMatches) {
/// gc subcommand implementation
///
fn gc_impl(matches: &clap::ArgMatches) {
use libgitdit::gc::{ReferenceCollectionSpec, ReferenceCollector};
use libgitdit::gc::ReferenceCollectionSpec;
use libgitdit::iter::ReferenceDeletingIter;

let repo = util::open_dit_repo();

let collect_heads = if matches.is_present("collect-heads") {
ReferenceCollectionSpec::BackedByRemoteHead
} else {
ReferenceCollectionSpec::Never
let collect = {
let collect_heads = if matches.is_present("collect-heads") {
ReferenceCollectionSpec::BackedByRemoteHead
} else {
ReferenceCollectionSpec::Never
};
repo.collectable_refs()
.consider_remote_refs(matches.is_present("consider-remote"))
.collect_heads(collect_heads)
};

let refs = repo
.collectable_refs()
.consider_remote_refs(matches.is_present("consider-remote"))
.collect_heads(collect_heads)
.into_refs(repo.issues().unwrap_or_abort())
.unwrap_or_abort();
.issues()
.unwrap_or_abort()
.into_iter()
.map(|issue| collect.for_issue(&issue))
.abort_on_err()
.flat_map(|collector| collector)
.abort_on_err();

if matches.is_present("dry-run") {
refs.into_iter()
.map(|r| r.name().unwrap_or("Unknown ref").to_owned())
.print_lines()
.unwrap_or_abort();
} else {
ReferenceCollector::from(refs).print_lines().unwrap_or_abort();
ReferenceDeletingIter::from(refs).print_lines().unwrap_or_abort();
}
}

Expand Down

0 comments on commit 3a76c37

Please sign in to comment.