From 5bb20e61665234c2dbf5f0cf706812fd6851b78f Mon Sep 17 00:00:00 2001 From: aaron-jack-manning Date: Sat, 10 Sep 2022 16:01:05 +1000 Subject: [PATCH] check all subdependencies when listing for no dependencies --- src/graph.rs | 15 +++++++++++++++ src/list.rs | 9 ++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/graph.rs b/src/graph.rs index 1c9c243..b9bba68 100755 --- a/src/graph.rs +++ b/src/graph.rs @@ -105,6 +105,21 @@ impl Graph { None } + /// Traverses a notes dependencies to get the set of all dependencies, direct and indirect. + pub fn get_nested_deps(&self, id : Id) -> HashSet { + fn helper(graph : &Graph, curr : &Id, output : &mut HashSet) { + for dep in graph.edges.get(curr).unwrap() { + output.insert(*dep); + helper(graph, dep, output) + } + } + + let mut output = HashSet::new(); + helper(self, &id, &mut output); + + output + } + fn find_cycle_local(&self, start : Id, unvisited : &mut BTreeSet, current_path_visited : &mut HashSet) -> Option> { // If already visited in the current path, then there is a cycle diff --git a/src/list.rs b/src/list.rs index 8204807..ae1a16a 100644 --- a/src/list.rs +++ b/src/list.rs @@ -7,7 +7,7 @@ use crate::tasks::Id; use std::cmp; use std::path; -use std::collections::{HashSet, HashMap}; +use std::collections::HashSet; use chrono::SubsecRound; impl args::ListOptions { @@ -128,10 +128,13 @@ pub fn list(mut options : args::ListOptions, vault_folder : &path::Path, state : })); } - // Checks that a task has no incomplete dependencies (these dependencies are direct only). + // Checks that a task has no incomplete dependencies. if options.no_dependencies { tasks = Box::new(tasks.filter(move |t| { - t.data.dependencies.iter().all(|d| completed_ids.contains(&d)) + // Get all dependencies (including indirect ones). + let all_dependencies = state.data.deps.get_nested_deps(t.data.id); + // Check that all of those dependencies are completed. + all_dependencies.iter().all(|d| completed_ids.contains(&d)) })); }