mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Replace NO_VERSION_ID with NIL_VERSION_ID
The docs refer to this as the "nil version ID" so let's do the same. This started out more ambitiously, to change this to `VersionId::NIL`, but that required making VersionId a newtype and all of the implicit conversions from VersionId to Uuid would have to be explicit. That didn't seem wortht the trouble.
This commit is contained in:
parent
f109056340
commit
536b88c8f4
4 changed files with 23 additions and 23 deletions
|
@ -1,5 +1,5 @@
|
||||||
use crate::api::{client_key_header, failure_to_ise, ServerState, SNAPSHOT_CONTENT_TYPE};
|
use crate::api::{client_key_header, failure_to_ise, ServerState, SNAPSHOT_CONTENT_TYPE};
|
||||||
use crate::server::{add_snapshot, VersionId, NO_VERSION_ID};
|
use crate::server::{add_snapshot, VersionId, NIL_VERSION_ID};
|
||||||
use actix_web::{error, post, web, HttpMessage, HttpRequest, HttpResponse, Result};
|
use actix_web::{error, post, web, HttpMessage, HttpRequest, HttpResponse, Result};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ pub(crate) async fn service(
|
||||||
let client = match txn.get_client(client_key).map_err(failure_to_ise)? {
|
let client = match txn.get_client(client_key).map_err(failure_to_ise)? {
|
||||||
Some(client) => client,
|
Some(client) => client,
|
||||||
None => {
|
None => {
|
||||||
txn.new_client(client_key, NO_VERSION_ID)
|
txn.new_client(client_key, NIL_VERSION_ID)
|
||||||
.map_err(failure_to_ise)?;
|
.map_err(failure_to_ise)?;
|
||||||
txn.get_client(client_key).map_err(failure_to_ise)?.unwrap()
|
txn.get_client(client_key).map_err(failure_to_ise)?.unwrap()
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ mod test {
|
||||||
{
|
{
|
||||||
let mut txn = storage.txn().unwrap();
|
let mut txn = storage.txn().unwrap();
|
||||||
txn.new_client(client_key, version_id).unwrap();
|
txn.new_client(client_key, version_id).unwrap();
|
||||||
txn.add_version(client_key, version_id, NO_VERSION_ID, vec![])?;
|
txn.add_version(client_key, version_id, NIL_VERSION_ID, vec![])?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let server = Server::new(storage);
|
let server = Server::new(storage);
|
||||||
|
@ -122,7 +122,7 @@ mod test {
|
||||||
// set up the storage contents..
|
// set up the storage contents..
|
||||||
{
|
{
|
||||||
let mut txn = storage.txn().unwrap();
|
let mut txn = storage.txn().unwrap();
|
||||||
txn.new_client(client_key, NO_VERSION_ID).unwrap();
|
txn.new_client(client_key, NIL_VERSION_ID).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let server = Server::new(storage);
|
let server = Server::new(storage);
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::api::{
|
||||||
client_key_header, failure_to_ise, ServerState, HISTORY_SEGMENT_CONTENT_TYPE,
|
client_key_header, failure_to_ise, ServerState, HISTORY_SEGMENT_CONTENT_TYPE,
|
||||||
PARENT_VERSION_ID_HEADER, SNAPSHOT_REQUEST_HEADER, VERSION_ID_HEADER,
|
PARENT_VERSION_ID_HEADER, SNAPSHOT_REQUEST_HEADER, VERSION_ID_HEADER,
|
||||||
};
|
};
|
||||||
use crate::server::{add_version, AddVersionResult, SnapshotUrgency, VersionId, NO_VERSION_ID};
|
use crate::server::{add_version, AddVersionResult, SnapshotUrgency, VersionId, NIL_VERSION_ID};
|
||||||
use actix_web::{error, post, web, HttpMessage, HttpRequest, HttpResponse, Result};
|
use actix_web::{error, post, web, HttpMessage, HttpRequest, HttpResponse, Result};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ pub(crate) async fn service(
|
||||||
let client = match txn.get_client(client_key).map_err(failure_to_ise)? {
|
let client = match txn.get_client(client_key).map_err(failure_to_ise)? {
|
||||||
Some(client) => client,
|
Some(client) => client,
|
||||||
None => {
|
None => {
|
||||||
txn.new_client(client_key, NO_VERSION_ID)
|
txn.new_client(client_key, NIL_VERSION_ID)
|
||||||
.map_err(failure_to_ise)?;
|
.map_err(failure_to_ise)?;
|
||||||
txn.get_client(client_key).map_err(failure_to_ise)?.unwrap()
|
txn.get_client(client_key).map_err(failure_to_ise)?.unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ pub(crate) async fn service(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::server::NO_VERSION_ID;
|
use crate::server::NIL_VERSION_ID;
|
||||||
use crate::storage::{InMemoryStorage, Storage};
|
use crate::storage::{InMemoryStorage, Storage};
|
||||||
use crate::Server;
|
use crate::Server;
|
||||||
use actix_web::{http::StatusCode, test, App};
|
use actix_web::{http::StatusCode, test, App};
|
||||||
|
@ -144,7 +144,7 @@ mod test {
|
||||||
// but the child of the nil parent_version_id is NOT FOUND, since
|
// but the child of the nil parent_version_id is NOT FOUND, since
|
||||||
// there is no snapshot. The tests in crate::server test more
|
// there is no snapshot. The tests in crate::server test more
|
||||||
// corner cases.
|
// corner cases.
|
||||||
let uri = format!("/v1/client/get-child-version/{}", NO_VERSION_ID);
|
let uri = format!("/v1/client/get-child-version/{}", NIL_VERSION_ID);
|
||||||
let req = test::TestRequest::get()
|
let req = test::TestRequest::get()
|
||||||
.uri(&uri)
|
.uri(&uri)
|
||||||
.header("X-Client-Key", client_key.to_string())
|
.header("X-Client-Key", client_key.to_string())
|
||||||
|
|
|
@ -6,7 +6,7 @@ use chrono::Utc;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
/// The distinguished value for "no version"
|
/// The distinguished value for "no version"
|
||||||
pub const NO_VERSION_ID: VersionId = Uuid::nil();
|
pub const NIL_VERSION_ID: VersionId = Uuid::nil();
|
||||||
|
|
||||||
/// Number of versions to search back from the latest to find the
|
/// Number of versions to search back from the latest to find the
|
||||||
/// version for a newly-added snapshot. Snapshots for versions older
|
/// version for a newly-added snapshot. Snapshots for versions older
|
||||||
|
@ -52,7 +52,7 @@ pub(crate) fn get_child_version<'a>(
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the requested parentVersionId is the nil UUID ..
|
// If the requested parentVersionId is the nil UUID ..
|
||||||
if parent_version_id == NO_VERSION_ID {
|
if parent_version_id == NIL_VERSION_ID {
|
||||||
return Ok(match client.snapshot {
|
return Ok(match client.snapshot {
|
||||||
// ..and snapshotVersionId is nil, the response is _not-found_ (the client has no
|
// ..and snapshotVersionId is nil, the response is _not-found_ (the client has no
|
||||||
// versions).
|
// versions).
|
||||||
|
@ -133,7 +133,7 @@ pub(crate) fn add_version<'a>(
|
||||||
);
|
);
|
||||||
|
|
||||||
// check if this version is acceptable, under the protection of the transaction
|
// check if this version is acceptable, under the protection of the transaction
|
||||||
if client.latest_version_id != NO_VERSION_ID && parent_version_id != client.latest_version_id {
|
if client.latest_version_id != NIL_VERSION_ID && parent_version_id != client.latest_version_id {
|
||||||
log::debug!("add_version request rejected: mismatched latest_version_id");
|
log::debug!("add_version request rejected: mismatched latest_version_id");
|
||||||
return Ok((
|
return Ok((
|
||||||
AddVersionResult::ExpectedParentVersion(client.latest_version_id),
|
AddVersionResult::ExpectedParentVersion(client.latest_version_id),
|
||||||
|
@ -206,7 +206,7 @@ pub(crate) fn add_snapshot<'a>(
|
||||||
let mut vid = client.latest_version_id;
|
let mut vid = client.latest_version_id;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if vid == version_id && version_id != NO_VERSION_ID {
|
if vid == version_id && version_id != NIL_VERSION_ID {
|
||||||
// the new snapshot is for a recent version, so proceed
|
// the new snapshot is for a recent version, so proceed
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ pub(crate) fn add_snapshot<'a>(
|
||||||
}
|
}
|
||||||
|
|
||||||
search_len -= 1;
|
search_len -= 1;
|
||||||
if search_len <= 0 || vid == NO_VERSION_ID {
|
if search_len <= 0 || vid == NIL_VERSION_ID {
|
||||||
// this should not happen in normal operation, so warn about it
|
// this should not happen in normal operation, so warn about it
|
||||||
log::warn!(
|
log::warn!(
|
||||||
"rejecting snapshot for version {}: version is too old or no such version",
|
"rejecting snapshot for version {}: version is too old or no such version",
|
||||||
|
@ -320,12 +320,12 @@ mod test {
|
||||||
let storage = InMemoryStorage::new();
|
let storage = InMemoryStorage::new();
|
||||||
let mut txn = storage.txn()?;
|
let mut txn = storage.txn()?;
|
||||||
let client_key = Uuid::new_v4();
|
let client_key = Uuid::new_v4();
|
||||||
txn.new_client(client_key, NO_VERSION_ID)?;
|
txn.new_client(client_key, NIL_VERSION_ID)?;
|
||||||
|
|
||||||
// when no snapshot exists, the first version is NotFound
|
// when no snapshot exists, the first version is NotFound
|
||||||
let client = txn.get_client(client_key)?.unwrap();
|
let client = txn.get_client(client_key)?.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_child_version(txn, client_key, client, NO_VERSION_ID)?,
|
get_child_version(txn, client_key, client, NIL_VERSION_ID)?,
|
||||||
GetVersionResult::NotFound
|
GetVersionResult::NotFound
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -353,7 +353,7 @@ mod test {
|
||||||
// when a snapshot exists, the first version is GONE
|
// when a snapshot exists, the first version is GONE
|
||||||
let client = txn.get_client(client_key)?.unwrap();
|
let client = txn.get_client(client_key)?.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_child_version(txn, client_key, client, NO_VERSION_ID)?,
|
get_child_version(txn, client_key, client, NIL_VERSION_ID)?,
|
||||||
GetVersionResult::Gone
|
GetVersionResult::Gone
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -370,7 +370,7 @@ mod test {
|
||||||
// add a parent version, but not the requested child version
|
// add a parent version, but not the requested child version
|
||||||
let parent_version_id = Uuid::new_v4();
|
let parent_version_id = Uuid::new_v4();
|
||||||
txn.new_client(client_key, parent_version_id)?;
|
txn.new_client(client_key, parent_version_id)?;
|
||||||
txn.add_version(client_key, parent_version_id, NO_VERSION_ID, vec![])?;
|
txn.add_version(client_key, parent_version_id, NIL_VERSION_ID, vec![])?;
|
||||||
|
|
||||||
let client = txn.get_client(client_key)?.unwrap();
|
let client = txn.get_client(client_key)?.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -660,7 +660,7 @@ mod test {
|
||||||
|
|
||||||
// set up a task DB with one version in it
|
// set up a task DB with one version in it
|
||||||
txn.new_client(client_key, version_id)?;
|
txn.new_client(client_key, version_id)?;
|
||||||
txn.add_version(client_key, version_id, NO_VERSION_ID, vec![])?;
|
txn.add_version(client_key, version_id, NIL_VERSION_ID, vec![])?;
|
||||||
|
|
||||||
// add a snapshot for that version
|
// add a snapshot for that version
|
||||||
let client = txn.get_client(client_key)?.unwrap();
|
let client = txn.get_client(client_key)?.unwrap();
|
||||||
|
@ -692,7 +692,7 @@ mod test {
|
||||||
|
|
||||||
// set up a task DB with two versions in it
|
// set up a task DB with two versions in it
|
||||||
txn.new_client(client_key, version_id_2)?;
|
txn.new_client(client_key, version_id_2)?;
|
||||||
txn.add_version(client_key, version_id_1, NO_VERSION_ID, vec![])?;
|
txn.add_version(client_key, version_id_1, NIL_VERSION_ID, vec![])?;
|
||||||
txn.add_version(client_key, version_id_2, version_id_1, vec![])?;
|
txn.add_version(client_key, version_id_2, version_id_1, vec![])?;
|
||||||
|
|
||||||
// add a snapshot for version 1
|
// add a snapshot for version 1
|
||||||
|
@ -725,7 +725,7 @@ mod test {
|
||||||
|
|
||||||
// set up a task DB with two versions in it
|
// set up a task DB with two versions in it
|
||||||
txn.new_client(client_key, version_id_2)?;
|
txn.new_client(client_key, version_id_2)?;
|
||||||
txn.add_version(client_key, version_id_1, NO_VERSION_ID, vec![])?;
|
txn.add_version(client_key, version_id_1, NIL_VERSION_ID, vec![])?;
|
||||||
txn.add_version(client_key, version_id_2, version_id_1, vec![])?;
|
txn.add_version(client_key, version_id_2, version_id_1, vec![])?;
|
||||||
|
|
||||||
// add a snapshot for unknown version
|
// add a snapshot for unknown version
|
||||||
|
@ -830,11 +830,11 @@ mod test {
|
||||||
let client_key = Uuid::new_v4();
|
let client_key = Uuid::new_v4();
|
||||||
|
|
||||||
// just set up the client
|
// just set up the client
|
||||||
txn.new_client(client_key, NO_VERSION_ID)?;
|
txn.new_client(client_key, NIL_VERSION_ID)?;
|
||||||
|
|
||||||
// add a snapshot for the nil version
|
// add a snapshot for the nil version
|
||||||
let client = txn.get_client(client_key)?.unwrap();
|
let client = txn.get_client(client_key)?.unwrap();
|
||||||
add_snapshot(txn, client_key, client, NO_VERSION_ID, vec![9, 9, 9])?;
|
add_snapshot(txn, client_key, client, NIL_VERSION_ID, vec![9, 9, 9])?;
|
||||||
|
|
||||||
// verify the snapshot does not exist
|
// verify the snapshot does not exist
|
||||||
let mut txn = storage.txn()?;
|
let mut txn = storage.txn()?;
|
||||||
|
@ -882,7 +882,7 @@ mod test {
|
||||||
let mut txn = storage.txn()?;
|
let mut txn = storage.txn()?;
|
||||||
let client_key = Uuid::new_v4();
|
let client_key = Uuid::new_v4();
|
||||||
|
|
||||||
txn.new_client(client_key, NO_VERSION_ID)?;
|
txn.new_client(client_key, NIL_VERSION_ID)?;
|
||||||
let client = txn.get_client(client_key)?.unwrap();
|
let client = txn.get_client(client_key)?.unwrap();
|
||||||
|
|
||||||
assert_eq!(get_snapshot(txn, client_key, client)?, None);
|
assert_eq!(get_snapshot(txn, client_key, client)?, None);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue