diff --git a/integration-tests/src/bindings_tests/replica.c b/integration-tests/src/bindings_tests/replica.c index 88651fc45..639cf5f48 100644 --- a/integration-tests/src/bindings_tests/replica.c +++ b/integration-tests/src/bindings_tests/replica.c @@ -109,6 +109,8 @@ static void test_replica_working_set(void) { tc_working_set_free(ws); + TEST_ASSERT_EQUAL(19, tc_replica_num_local_operations(rep)); + tc_replica_free(rep); } diff --git a/lib/src/replica.rs b/lib/src/replica.rs index 6d9683959..9ad5f29db 100644 --- a/lib/src/replica.rs +++ b/lib/src/replica.rs @@ -360,6 +360,19 @@ pub unsafe extern "C" fn tc_replica_undo(rep: *mut TCReplica, undone_out: *mut i ) } +/// Get the number of local, un-synchronized operations, or -1 on error +#[no_mangle] +pub unsafe extern "C" fn tc_replica_num_local_operations(rep: *mut TCReplica) -> i64 { + wrap( + rep, + |rep| { + let count = rep.num_local_operations()? as i64; + Ok(count) + }, + -1, + ) +} + /// Add an UndoPoint, if one has not already been added by this Replica. This occurs automatically /// when a change is made. The `force` flag allows forcing a new UndoPoint even if one has already /// been created by this Replica, and may be useful when a Replica instance is held for a long time diff --git a/lib/taskchampion.h b/lib/taskchampion.h index a4ec0061e..c5a1eddf2 100644 --- a/lib/taskchampion.h +++ b/lib/taskchampion.h @@ -557,6 +557,11 @@ TCResult tc_replica_sync(struct TCReplica *rep, struct TCServer *server, bool av */ TCResult tc_replica_undo(struct TCReplica *rep, int32_t *undone_out); +/** + * Get the number of local, un-synchronized operations, or -1 on error + */ +int64_t tc_replica_num_local_operations(struct TCReplica *rep); + /** * Add an UndoPoint, if one has not already been added by this Replica. This occurs automatically * when a change is made. The `force` flag allows forcing a new UndoPoint even if one has already