Rename replica.gc to replica.rebuild_working_set

The command-line operation is still `gc`, but we'll break that down into
finer pieces in the replica.
This commit is contained in:
Dustin J. Mitchell 2021-01-02 13:23:48 -05:00
parent da63d77d9d
commit b62370c150
4 changed files with 9 additions and 8 deletions

View file

@ -3,7 +3,8 @@ use taskchampion::Replica;
use termcolor::WriteColor; use termcolor::WriteColor;
pub(crate) fn execute<W: WriteColor>(w: &mut W, replica: &mut Replica) -> Fallible<()> { pub(crate) fn execute<W: WriteColor>(w: &mut W, replica: &mut Replica) -> Fallible<()> {
replica.gc()?; log::debug!("rebuilding working set");
replica.rebuild_working_set()?;
writeln!(w, "garbage collected.")?; writeln!(w, "garbage collected.")?;
Ok(()) Ok(())
} }

View file

@ -184,7 +184,7 @@ mod test {
let t1 = replica.new_task(Status::Pending, s!("A")).unwrap(); let t1 = replica.new_task(Status::Pending, s!("A")).unwrap();
let t2 = replica.new_task(Status::Completed, s!("B")).unwrap(); let t2 = replica.new_task(Status::Completed, s!("B")).unwrap();
let _t = replica.new_task(Status::Pending, s!("C")).unwrap(); let _t = replica.new_task(Status::Pending, s!("C")).unwrap();
replica.gc().unwrap(); replica.rebuild_working_set().unwrap();
let t1uuid = *t1.get_uuid(); let t1uuid = *t1.get_uuid();
@ -210,7 +210,7 @@ mod test {
let t1 = replica.new_task(Status::Pending, s!("A")).unwrap(); let t1 = replica.new_task(Status::Pending, s!("A")).unwrap();
let t2 = replica.new_task(Status::Completed, s!("B")).unwrap(); let t2 = replica.new_task(Status::Completed, s!("B")).unwrap();
let _t = replica.new_task(Status::Pending, s!("C")).unwrap(); let _t = replica.new_task(Status::Pending, s!("C")).unwrap();
replica.gc().unwrap(); replica.rebuild_working_set().unwrap();
let t1uuid = *t1.get_uuid(); let t1uuid = *t1.get_uuid();
let t2uuid = t2.get_uuid().to_string(); let t2uuid = t2.get_uuid().to_string();
@ -238,7 +238,7 @@ mod test {
replica.new_task(Status::Pending, s!("A")).unwrap(); replica.new_task(Status::Pending, s!("A")).unwrap();
replica.new_task(Status::Completed, s!("B")).unwrap(); replica.new_task(Status::Completed, s!("B")).unwrap();
replica.new_task(Status::Deleted, s!("C")).unwrap(); replica.new_task(Status::Deleted, s!("C")).unwrap();
replica.gc().unwrap(); replica.rebuild_working_set().unwrap();
let filter = Filter { conditions: vec![] }; let filter = Filter { conditions: vec![] };
let mut filtered: Vec<_> = filtered_tasks(&mut replica, &filter) let mut filtered: Vec<_> = filtered_tasks(&mut replica, &filter)
@ -309,7 +309,7 @@ mod test {
replica.new_task(Status::Pending, s!("A")).unwrap(); replica.new_task(Status::Pending, s!("A")).unwrap();
replica.new_task(Status::Completed, s!("B")).unwrap(); replica.new_task(Status::Completed, s!("B")).unwrap();
replica.new_task(Status::Deleted, s!("C")).unwrap(); replica.new_task(Status::Deleted, s!("C")).unwrap();
replica.gc().unwrap(); replica.rebuild_working_set().unwrap();
let filter = Filter { let filter = Filter {
conditions: vec![Condition::Status(Status::Pending)], conditions: vec![Condition::Status(Status::Pending)],

View file

@ -163,7 +163,7 @@ mod test {
t2.set_status(Status::Completed).unwrap(); t2.set_status(Status::Completed).unwrap();
let t2 = t2.into_immut(); let t2 = t2.into_immut();
replica.gc().unwrap(); replica.rebuild_working_set().unwrap();
[*t1.get_uuid(), *t2.get_uuid(), *t3.get_uuid()] [*t1.get_uuid(), *t2.get_uuid(), *t3.get_uuid()]
} }

View file

@ -172,7 +172,7 @@ impl Replica {
/// Perform "garbage collection" on this replica. In particular, this renumbers the working /// Perform "garbage collection" on this replica. In particular, this renumbers the working
/// set to contain only pending tasks. /// set to contain only pending tasks.
pub fn gc(&mut self) -> Fallible<()> { pub fn rebuild_working_set(&mut self) -> Fallible<()> {
let pending = String::from(Status::Pending.to_taskmap()); let pending = String::from(Status::Pending.to_taskmap());
self.taskdb self.taskdb
.rebuild_working_set(|t| t.get("status") == Some(&pending))?; .rebuild_working_set(|t| t.get("status") == Some(&pending))?;
@ -251,7 +251,7 @@ mod tests {
assert_eq!(t.get_status(), Status::Deleted); assert_eq!(t.get_status(), Status::Deleted);
assert_eq!(t.get_description(), "gone"); assert_eq!(t.get_description(), "gone");
rep.gc().unwrap(); rep.rebuild_working_set().unwrap();
assert!(rep.get_working_set_index(t.get_uuid()).unwrap().is_none()); assert!(rep.get_working_set_index(t.get_uuid()).unwrap().is_none());
} }