Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 2 additions & 59 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 12 additions & 17 deletions src/CLI2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <Color.h>
#include <Context.h>
#include <Lexer.h>
#include <TaskRef.h>
#include <format.h>
#include <shared.h>
#include <stdlib.h>
Expand Down Expand Up @@ -1293,21 +1294,14 @@ void CLI2::desugarFilterPatterns() {
// a single prefix: a1b2c3d4
// a comma-separated list: a1b2c3d4,e5f6a7b8
//
static bool looksLikeHexPrefix(const std::string& s) {
if (s.length() != 8) return false;
for (char c : s)
if (!std::isxdigit(static_cast<unsigned char>(c))) return false;
return true;
}

// Pushes all hex-prefix elements from a comma-separated string into _uuid_list.
// Pushes all task-ref elements from a comma-separated string into _uuid_list.
// Returns true if any were added.
static bool pushHexPrefixesFromSet(const std::string& raw,
std::vector<std::string>& uuid_list) {
auto elements = split(raw, ',');
bool any = false;
for (auto& element : elements) {
if (looksLikeHexPrefix(element)) {
if (taskref::looksLikeTaskRef(element)) {
uuid_list.push_back(element);
any = true;
}
Expand All @@ -1328,11 +1322,12 @@ void CLI2::findIDs() {

std::string raw = a.attribute("raw");

// A hex-only word/identifier token is treated as a UUID prefix.
// Numeric short IDs and hex-only words are treated as task refs.
bool isWordOrIdent = (a._lextype == Lexer::Type::word ||
a._lextype == Lexer::Type::identifier);
a._lextype == Lexer::Type::identifier ||
a._lextype == Lexer::Type::number);
if (isWordOrIdent && !previousFilterArgWasAnOperator &&
looksLikeHexPrefix(raw)) {
taskref::looksLikeTaskRef(raw)) {
changes = true;
_uuid_list.push_back(raw);
} else if (a._lextype == Lexer::Type::set) {
Expand All @@ -1354,8 +1349,9 @@ void CLI2::findIDs() {
if (a.hasTag("MODIFICATION")) {
std::string raw = a.attribute("raw");

if ((a._lextype == Lexer::Type::word || a._lextype == Lexer::Type::identifier) &&
looksLikeHexPrefix(raw)) {
if ((a._lextype == Lexer::Type::word || a._lextype == Lexer::Type::identifier ||
a._lextype == Lexer::Type::number) &&
taskref::looksLikeTaskRef(raw)) {
changes = true;
a.unTag("MODIFICATION");
a.tag("FILTER");
Expand Down Expand Up @@ -1494,16 +1490,15 @@ void CLI2::insertIDExpr() {
A2 opSimilar("=", Lexer::Type::op);
opSimilar.tag("FILTER");

A2 argUUID("uuid", Lexer::Type::dom);
argUUID.tag("FILTER");

reconstructed.push_back(openParen);

// Add all UUID prefix items.
for (auto u = _uuid_list.begin(); u != _uuid_list.end(); ++u) {
if (u != _uuid_list.begin()) reconstructed.push_back(opOr);

reconstructed.push_back(openParen);
A2 argUUID(taskref::looksLikeNumericShortId(*u) ? "id" : "uuid", Lexer::Type::dom);
argUUID.tag("FILTER");
reconstructed.push_back(argUUID);
reconstructed.push_back(opSimilar);

Expand Down
18 changes: 16 additions & 2 deletions src/TDB2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <Datetime.h>
#include <TDB2.h>
#include <Table.h>
#include <TaskRef.h>
#include <format.h>
#include <shared.h>
#include <stdlib.h>
Expand Down Expand Up @@ -74,10 +75,11 @@ void apply_depmap(Task& t, tc::DependencyMapWrapper& depmap) {
} // namespace

// Keys that must never be written to TaskChampion storage:
// uuid/id — synthetic keys managed by tch itself
// uuid/id/short_id — synthetic keys managed by tch or the backing database
// tags — legacy comma-separated representation; tch-native tag_* keys carry the same data
// depends — legacy comma-separated representation; tch-native dep_* keys carry the same data
static const std::unordered_set<std::string> kTCSkippedKeys = {"uuid", "id", "tags", "depends"};
static const std::unordered_set<std::string> kTCSkippedKeys = {"uuid", "id", "short_id", "tags",
"depends"};

////////////////////////////////////////////////////////////////////////////////
void TDB2::open_replica(const std::string& db_path) {
Expand Down Expand Up @@ -339,6 +341,18 @@ void TDB2::invalidate_cached_info() {
bool TDB2::get(const std::string& uuid, Task& task) {
auto depmap = replica()->dependency_map();

// Numeric task refs are per-user short IDs. Prefer them over numeric UUID
// prefixes; if no short ID matches, keep the historical UUID-prefix fallback.
if (taskref::looksLikeNumericShortId(uuid)) {
auto maybe = replica()->get_task_data_by_ref(uuid);
if (maybe.is_some()) {
auto tctask = maybe.take();
task = Task{std::move(tctask)};
apply_depmap(task, *depmap);
return true;
}
}

// Tier 1: full-UUID PK fast path.
if (looksLikeFullUuid(uuid)) {
auto maybe = replica()->get_task_data(tc::uuid_from_string(uuid));
Expand Down
7 changes: 6 additions & 1 deletion src/Task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,12 @@ void Task::parseTC(rust::Box<tc::TaskData> task) {
}

data["uuid"] = static_cast<std::string>(task->get_uuid().to_string());
id = (data["uuid"].length() >= 8) ? data["uuid"].substr(0, 8) : "";
if (has("short_id")) {
id = get("short_id");
remove("short_id");
} else {
id = (data["uuid"].length() >= 8) ? data["uuid"].substr(0, 8) : "";
}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
56 changes: 56 additions & 0 deletions src/TaskRef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2006 - 2021, Tomas Babej, Paul Beckingham, Federico Hernandez.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// https://www.opensource.org/licenses/mit-license.php
//
////////////////////////////////////////////////////////////////////////////////

#ifndef INCLUDED_TASK_REF
#define INCLUDED_TASK_REF

#include <cctype>
#include <string>

namespace taskref {

inline bool looksLikeHexPrefix(const std::string& s) {
if (s.length() != 8) return false;
for (char c : s)
if (!std::isxdigit(static_cast<unsigned char>(c))) return false;
return true;
}

inline bool looksLikeNumericShortId(const std::string& s) {
if (s.empty()) return false;
for (char c : s)
if (!std::isdigit(static_cast<unsigned char>(c))) return false;
return true;
}

inline bool looksLikeTaskRef(const std::string& s) {
return looksLikeNumericShortId(s) || looksLikeHexPrefix(s);
}

} // namespace taskref

#endif
////////////////////////////////////////////////////////////////////////////////
2 changes: 1 addition & 1 deletion src/columns/ColID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ColumnID::ColumnID() {
_label = "ID";
_modifiable = false;
_styles = {"short"};
_examples = {"a1b2c3d4"};
_examples = {"42", "a1b2c3d4"};
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions src/taskchampion-cpp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ rust-version = "1.91.1" # MSRV (taskchampion@3.0.2-pre requirement)
crate-type = ["staticlib"]

[dependencies]
taskchampion = { git = "https://github.com/GuionAI/taskchampion.git", tag = "v3.0.2-guion.49", features = ["storage-powersync", "storage-pgwire", "test-utils"] }
taskchampion = { git = "https://github.com/GuionAI/taskchampion.git", tag = "v3.0.2-guion.58", features = ["storage-powersync", "storage-pgwire", "test-utils"] }
anyhow = "1"
async-trait = "0.1"
cxx = "1.0.133"
Expand All @@ -21,4 +21,4 @@ tokio = { version = "1", features = [ "rt" ] }
cxx-build = "1.0.133"

[dev-dependencies]
taskchampion = { git = "https://github.com/GuionAI/taskchampion.git", tag = "v3.0.2-guion.49", features = ["storage-powersync", "storage-pgwire", "test-utils"] }
taskchampion = { git = "https://github.com/GuionAI/taskchampion.git", tag = "v3.0.2-guion.58", features = ["storage-powersync", "storage-pgwire", "test-utils"] }
12 changes: 12 additions & 0 deletions src/taskchampion-cpp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ mod ffi {
/// Get an existing task by its UUID.
fn get_task_data(&mut self, uuid: Uuid) -> Result<OptionTaskData>;

/// Get an existing task by its full UUID or numeric short ID.
fn get_task_data_by_ref(&mut self, task_ref: String) -> Result<OptionTaskData>;

/// Get the operations for a task task by its UUID.
fn get_task_operations(&mut self, uuid: Uuid) -> Result<Vec<Operation>>;

Expand Down Expand Up @@ -696,6 +699,15 @@ impl Replica {
rt().block_on(async { Ok(self.0.get_task_data(uuid.into()).await?.into()) })
}

fn get_task_data_by_ref(&mut self, task_ref: String) -> Result<ffi::OptionTaskData, CppError> {
rt().block_on(async {
let Some(uuid) = self.0.resolve_task_ref(&task_ref).await? else {
return Ok(None.into());
};
Ok(self.0.get_task_data(uuid).await?.into())
})
}

fn get_task_operations(&mut self, uuid: ffi::Uuid) -> Result<Vec<Operation>, CppError> {
rt().block_on(async {
Ok(from_tc_operations(
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ set (pythonTests
reports.test.py
search.test.py
sequence.test.py
short_id.test.py
shell.test.py
show.test.py
sorting.test.py
Expand Down
Loading