From 2584ecdb0a3891eeb8e89080507d44cb49c81327 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Mon, 23 Oct 2023 12:15:28 +0100 Subject: [PATCH] radicle: Pin timestamp for testing When testing the CLI, "since"-calculations will result in different values over time: now 1 month ago 2 months ago 10 months ago 1 year ago 10 years ago Initially, the solution was to use the wildcard match from `snapbox`, `[..]`, to match on these values. However, since these values change in length it means that they will affect the width of the tables produced by the CLI. To ensure the width is stable across runs over time it's possible to use a time that is the same as the commit time used at testing. To do this the `Timestamp` type is now a newtype which has a constructor `now` which will use the `RAD_COMMIT_TIME` env variable for construction, if it's available and in debug mode. This ensure that all "since"-calculations will result in `now`. Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- radicle-cli/examples/rad-cob.md | 20 ++-- radicle-cli/examples/rad-id-conflict.md | 32 +++---- radicle-cli/examples/rad-id-multi-delegate.md | 16 ++-- radicle-cli/examples/rad-issue.md | 24 ++--- radicle-cli/examples/rad-merge-via-push.md | 12 +-- .../examples/rad-patch-ahead-behind.md | 16 ++-- radicle-cli/examples/rad-patch-pull-update.md | 28 +++--- radicle-cli/examples/rad-patch-update.md | 32 +++---- radicle-cli/examples/rad-patch-via-push.md | 76 +++++++-------- radicle-cli/examples/rad-patch.md | 92 +++++++++---------- radicle-cli/examples/workflow/3-issues.md | 10 +- .../workflow/4-patching-contributor.md | 12 +-- .../workflow/5-patching-maintainer.md | 68 +++++++------- radicle/src/cob.rs | 10 +- radicle/src/cob/common.rs | 48 +++++++++- 15 files changed, 269 insertions(+), 227 deletions(-) diff --git a/radicle-cli/examples/rad-cob.md b/radicle-cli/examples/rad-cob.md index a1eb270e..1db4f697 100644 --- a/radicle-cli/examples/rad-cob.md +++ b/radicle-cli/examples/rad-cob.md @@ -18,11 +18,11 @@ The issue is now listed under our project. ``` $ rad issue list -╭─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ -│ ● ID Title Author Labels Assignees Opened │ -├─────────────────────────────────────────────────────────────────────────────────────────────────────────┤ -│ ● 9bf82c1 flux capacitor underpowered z6MknSL…StBU8Vi (you) [ .. ] │ -╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ +╭───────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ ● ID Title Author Labels Assignees Opened │ +├───────────────────────────────────────────────────────────────────────────────────────────────────┤ +│ ● 9bf82c1 flux capacitor underpowered z6MknSL…StBU8Vi (you) now │ +╰───────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` Let's create a patch, too. @@ -42,11 +42,11 @@ Patch can be listed. ``` $ rad patch -╭──────────────────────────────────────────────────────────────────────────────────────────────╮ -│ ● ID Title Author Head + - Updated │ -├──────────────────────────────────────────────────────────────────────────────────────────────┤ -│ ● a892664 Define power requirements z6MknSL…StBU8Vi (you) 3e674d1 +0 -0 [ ... ] │ -╰──────────────────────────────────────────────────────────────────────────────────────────────╯ +╭─────────────────────────────────────────────────────────────────────────────────────────╮ +│ ● ID Title Author Head + - Updated │ +├─────────────────────────────────────────────────────────────────────────────────────────┤ +│ ● a892664 Define power requirements z6MknSL…StBU8Vi (you) 3e674d1 +0 -0 now │ +╰─────────────────────────────────────────────────────────────────────────────────────────╯ ``` Both issue and patch COBs can be listed. diff --git a/radicle-cli/examples/rad-id-conflict.md b/radicle-cli/examples/rad-id-conflict.md index 342fc1f4..e74727db 100644 --- a/radicle-cli/examples/rad-id-conflict.md +++ b/radicle-cli/examples/rad-id-conflict.md @@ -31,14 +31,14 @@ $ rad sync --fetch rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji ✓ Fetching rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji from z6Mkt67…v4N1tRk.. ✓ Fetched repository from 1 seed(s) $ rad id list -╭──────────────────────────────────────────────────────────────────────────────────────╮ -│ ● ID Title Author Status Created │ -├──────────────────────────────────────────────────────────────────────────────────────┤ -│ ● fae22d0 Edit project name bob z6Mkt67…v4N1tRk active [ ... ] │ -│ ● 6c07e4e Edit project name alice (you) active [ ... ] │ -│ ● bd41a1c Add Bob alice (you) accepted [ ... ] │ -│ ● 2317f74 Initial revision alice (you) accepted [ ... ] │ -╰──────────────────────────────────────────────────────────────────────────────────────╯ +╭─────────────────────────────────────────────────────────────────────────────────╮ +│ ● ID Title Author Status Created │ +├─────────────────────────────────────────────────────────────────────────────────┤ +│ ● fae22d0 Edit project name bob z6Mkt67…v4N1tRk active now │ +│ ● 6c07e4e Edit project name alice (you) active now │ +│ ● bd41a1c Add Bob alice (you) accepted now │ +│ ● 2317f74 Initial revision alice (you) accepted now │ +╰─────────────────────────────────────────────────────────────────────────────────╯ ``` This isn't a problem as long as we don't try to accept both. So let's accept @@ -47,14 +47,14 @@ Bob's: ``` ~alice $ rad id accept fae22d0 -q $ rad id list -╭──────────────────────────────────────────────────────────────────────────────────────╮ -│ ● ID Title Author Status Created │ -├──────────────────────────────────────────────────────────────────────────────────────┤ -│ ● fae22d0 Edit project name bob z6Mkt67…v4N1tRk accepted [ ... ] │ -│ ● 6c07e4e Edit project name alice (you) stale [ ... ] │ -│ ● bd41a1c Add Bob alice (you) accepted [ ... ] │ -│ ● 2317f74 Initial revision alice (you) accepted [ ... ] │ -╰──────────────────────────────────────────────────────────────────────────────────────╯ +╭─────────────────────────────────────────────────────────────────────────────────╮ +│ ● ID Title Author Status Created │ +├─────────────────────────────────────────────────────────────────────────────────┤ +│ ● fae22d0 Edit project name bob z6Mkt67…v4N1tRk accepted now │ +│ ● 6c07e4e Edit project name alice (you) stale now │ +│ ● bd41a1c Add Bob alice (you) accepted now │ +│ ● 2317f74 Initial revision alice (you) accepted now │ +╰─────────────────────────────────────────────────────────────────────────────────╯ ``` Doing so voided the other conflicting revision, and it can no longer be diff --git a/radicle-cli/examples/rad-id-multi-delegate.md b/radicle-cli/examples/rad-id-multi-delegate.md index 12eee5ad..5f76b93d 100644 --- a/radicle-cli/examples/rad-id-multi-delegate.md +++ b/radicle-cli/examples/rad-id-multi-delegate.md @@ -75,14 +75,14 @@ We can list all revisions: ``` ~alice $ rad id list -╭─────────────────────────────────────────────────────────────────────────────────────╮ -│ ● ID Title Author Status Created │ -├─────────────────────────────────────────────────────────────────────────────────────┤ -│ ● 1483814 Make private alice (you) active [ ... ] │ -│ ● 9d90314 Add Eve bob z6Mkt67…v4N1tRk accepted [ ... ] │ -│ ● 5666f74 Add Bob alice (you) accepted [ ... ] │ -│ ● 2317f74 Initial revision alice (you) accepted [ ... ] │ -╰─────────────────────────────────────────────────────────────────────────────────────╯ +╭────────────────────────────────────────────────────────────────────────────────╮ +│ ● ID Title Author Status Created │ +├────────────────────────────────────────────────────────────────────────────────┤ +│ ● 1483814 Make private alice (you) active now │ +│ ● 9d90314 Add Eve bob z6Mkt67…v4N1tRk accepted now │ +│ ● 5666f74 Add Bob alice (you) accepted now │ +│ ● 2317f74 Initial revision alice (you) accepted now │ +╰────────────────────────────────────────────────────────────────────────────────╯ ``` Despite being a delegate, Bob can't edit or redact Alice's revision: diff --git a/radicle-cli/examples/rad-issue.md b/radicle-cli/examples/rad-issue.md index 733b9194..1fbf4379 100644 --- a/radicle-cli/examples/rad-issue.md +++ b/radicle-cli/examples/rad-issue.md @@ -19,11 +19,11 @@ The issue is now listed under our project. ``` $ rad issue list -╭─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ -│ ● ID Title Author Labels Assignees Opened │ -├─────────────────────────────────────────────────────────────────────────────────────────────────────────┤ -│ ● 9bf82c1 flux capacitor underpowered z6MknSL…StBU8Vi (you) [ .. ] │ -╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ +╭───────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ ● ID Title Author Labels Assignees Opened │ +├───────────────────────────────────────────────────────────────────────────────────────────────────┤ +│ ● 9bf82c1 flux capacitor underpowered z6MknSL…StBU8Vi (you) now │ +╰───────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` Show the issue information issue. @@ -56,11 +56,11 @@ It will now show in the list of issues assigned to us. ``` $ rad issue list --assigned -╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ -│ ● ID Title Author Labels Assignees Opened │ -├───────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ -│ ● 9bf82c1 flux capacitor underpowered z6MknSL…StBU8Vi (you) z6MknSL…StBU8Vi [ .. ] │ -╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ +╭─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ ● ID Title Author Labels Assignees Opened │ +├─────────────────────────────────────────────────────────────────────────────────────────────────────────┤ +│ ● 9bf82c1 flux capacitor underpowered z6MknSL…StBU8Vi (you) z6MknSL…StBU8Vi now │ +╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` Note: this can always be undone with the `unassign` subcommand. @@ -93,10 +93,10 @@ $ rad issue show 9bf82c141d5a9c54bb1d6b4517eb3bb7da8fb30d │ │ │ Flux capacitor power requirements exceed current supply │ ├─────────────────────────────────────────────────────────┤ -│ z6MknSL…StBU8Vi (you) [ ... ] 1a8e9d3 │ +│ z6MknSL…StBU8Vi (you) now 1a8e9d3 │ │ The flux capacitor needs 1.21 Gigawatts │ ├─────────────────────────────────────────────────────────┤ -│ z6MknSL…StBU8Vi (you) [ ... ] fb6ab7e │ +│ z6MknSL…StBU8Vi (you) now fb6ab7e │ │ More power! │ ╰─────────────────────────────────────────────────────────╯ ``` diff --git a/radicle-cli/examples/rad-merge-via-push.md b/radicle-cli/examples/rad-merge-via-push.md index 15e3bf9d..74419fab 100644 --- a/radicle-cli/examples/rad-merge-via-push.md +++ b/radicle-cli/examples/rad-merge-via-push.md @@ -68,12 +68,12 @@ To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkE ``` ``` $ rad patch --merged -╭─────────────────────────────────────────────────────────────────────────╮ -│ ● ID Title Author Head + - Updated │ -├─────────────────────────────────────────────────────────────────────────┤ -│ ✔ [ ... ] Second change alice (you) daf349f +0 -0 [ ... ] │ -│ ✔ [ ... ] First change alice (you) 20aa5dd +0 -0 [ ... ] │ -╰─────────────────────────────────────────────────────────────────────────╯ +╭────────────────────────────────────────────────────────────────────╮ +│ ● ID Title Author Head + - Updated │ +├────────────────────────────────────────────────────────────────────┤ +│ ✔ [ ... ] Second change alice (you) daf349f +0 -0 now │ +│ ✔ [ ... ] First change alice (you) 20aa5dd +0 -0 now │ +╰────────────────────────────────────────────────────────────────────╯ ``` We can verify that the remote tracking branches were also deleted: diff --git a/radicle-cli/examples/rad-patch-ahead-behind.md b/radicle-cli/examples/rad-patch-ahead-behind.md index fc7271c2..7450743a 100644 --- a/radicle-cli/examples/rad-patch-ahead-behind.md +++ b/radicle-cli/examples/rad-patch-ahead-behind.md @@ -45,11 +45,11 @@ To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkE When listing, we see that it has one addition: ``` $ rad patch list -╭─────────────────────────────────────────────────────────────────────────────╮ -│ ● ID Title Author Head + - Updated │ -├─────────────────────────────────────────────────────────────────────────────┤ -│ ● 71e51df Add Alan z6MknSL…StBU8Vi (you) 5c88a79 +1 -0 [ ... ] │ -╰─────────────────────────────────────────────────────────────────────────────╯ +╭────────────────────────────────────────────────────────────────────────╮ +│ ● ID Title Author Head + - Updated │ +├────────────────────────────────────────────────────────────────────────┤ +│ ● 71e51df Add Alan z6MknSL…StBU8Vi (you) 5c88a79 +1 -0 now │ +╰────────────────────────────────────────────────────────────────────────╯ ``` When showing the patch, we see that it is `ahead 1, behind 1`, since master has @@ -68,7 +68,7 @@ $ rad patch show -v -p 71e51df ├────────────────────────────────────────────────────┤ │ 5c88a79 Add Alan │ ├────────────────────────────────────────────────────┤ -│ ● opened by z6MknSL…StBU8Vi (you) [ ... ] │ +│ ● opened by z6MknSL…StBU8Vi (you) now │ ╰────────────────────────────────────────────────────╯ commit 5c88a79d75f5c2b4cc51ee6f163d2db91ee198d7 @@ -115,7 +115,7 @@ $ rad patch show -v 364cc2809f14c1bc74a8868159e87eb3844eb7e2 │ 7f63fcb Add Mel │ │ 5c88a79 Add Alan │ ├────────────────────────────────────────────────────┤ -│ ● opened by z6MknSL…StBU8Vi (you) [ ... ] │ +│ ● opened by z6MknSL…StBU8Vi (you) now │ ╰────────────────────────────────────────────────────╯ ``` @@ -149,6 +149,6 @@ $ rad patch show -v 11ab7fbec82c3aed393d7a696d6b3c7714735056 ├────────────────────────────────────────────────────┤ │ 7f63fcb Add Mel │ ├────────────────────────────────────────────────────┤ -│ ● opened by z6MknSL…StBU8Vi (you) [ ... ] │ +│ ● opened by z6MknSL…StBU8Vi (you) now │ ╰────────────────────────────────────────────────────╯ ``` diff --git a/radicle-cli/examples/rad-patch-pull-update.md b/radicle-cli/examples/rad-patch-pull-update.md index af6d8505..4ebece51 100644 --- a/radicle-cli/examples/rad-patch-pull-update.md +++ b/radicle-cli/examples/rad-patch-pull-update.md @@ -88,20 +88,20 @@ Alice pulls the update. ``` ~alice $ rad patch show 6d260fc -╭──────────────────────────────────────────────────────────────────────────────╮ -│ Title Bob's patch │ -│ Patch 6d260fc8388e74d8fefb5dabc5a798e125ec3cf9 │ -│ Author bob z6Mkt67…v4N1tRk │ -│ Head cad2666a8a2250e4dee175ed5044be2c251ff08b │ -│ Commits ahead 2, behind 0 │ -│ Status open │ -├──────────────────────────────────────────────────────────────────────────────┤ -│ cad2666 Bob's commit #2 │ -│ bdcdb30 Bob's commit #1 │ -├──────────────────────────────────────────────────────────────────────────────┤ -│ ● opened by bob z6Mkt67…v4N1tRk [ ... ] │ -│ ↑ updated to 750081b35a3f831f428653bd2240eb4674ccae71 (cad2666) [ ... ] │ -╰──────────────────────────────────────────────────────────────────────────────╯ +╭─────────────────────────────────────────────────────────────────────╮ +│ Title Bob's patch │ +│ Patch 6d260fc8388e74d8fefb5dabc5a798e125ec3cf9 │ +│ Author bob z6Mkt67…v4N1tRk │ +│ Head cad2666a8a2250e4dee175ed5044be2c251ff08b │ +│ Commits ahead 2, behind 0 │ +│ Status open │ +├─────────────────────────────────────────────────────────────────────┤ +│ cad2666 Bob's commit #2 │ +│ bdcdb30 Bob's commit #1 │ +├─────────────────────────────────────────────────────────────────────┤ +│ ● opened by bob z6Mkt67…v4N1tRk now │ +│ ↑ updated to 750081b35a3f831f428653bd2240eb4674ccae71 (cad2666) now │ +╰─────────────────────────────────────────────────────────────────────╯ $ git ls-remote rad f2de534b5e81d7c6e2dcaf58c3dd91573c0a0354 refs/heads/master cad2666a8a2250e4dee175ed5044be2c251ff08b refs/heads/patches/6d260fc8388e74d8fefb5dabc5a798e125ec3cf9 diff --git a/radicle-cli/examples/rad-patch-update.md b/radicle-cli/examples/rad-patch-update.md index 365a74c5..37c262f3 100644 --- a/radicle-cli/examples/rad-patch-update.md +++ b/radicle-cli/examples/rad-patch-update.md @@ -24,7 +24,7 @@ $ rad patch show 2541d346ba0b9377b3d38852dfded43f23833fc1 ├────────────────────────────────────────────────────┤ │ 51b2f0f Not a real change │ ├────────────────────────────────────────────────────┤ -│ ● opened by z6MknSL…StBU8Vi (you) [ ... ] │ +│ ● opened by z6MknSL…StBU8Vi (you) now │ ╰────────────────────────────────────────────────────╯ ``` @@ -54,19 +54,19 @@ The command outputs the new Revision ID, which we can now see here: ``` $ rad patch show 2541d346ba0b9377b3d38852dfded43f23833fc1 -╭──────────────────────────────────────────────────────────────────────────────╮ -│ Title Not a real change │ -│ Patch 2541d346ba0b9377b3d38852dfded43f23833fc1 │ -│ Author z6MknSL…StBU8Vi (you) │ -│ Head 4d272148458a17620541555b1f0905c01658aa9f │ -│ Branches feature/1 │ -│ Commits ahead 2, behind 0 │ -│ Status open │ -├──────────────────────────────────────────────────────────────────────────────┤ -│ 4d27214 Rename readme file │ -│ 51b2f0f Not a real change │ -├──────────────────────────────────────────────────────────────────────────────┤ -│ ● opened by z6MknSL…StBU8Vi (you) [ ... ] │ -│ ↑ updated to d9c9ef902f2957d746bb53e744e69a5c3aa564bc (4d27214) [ ... ] │ -╰──────────────────────────────────────────────────────────────────────────────╯ +╭─────────────────────────────────────────────────────────────────────╮ +│ Title Not a real change │ +│ Patch 2541d346ba0b9377b3d38852dfded43f23833fc1 │ +│ Author z6MknSL…StBU8Vi (you) │ +│ Head 4d272148458a17620541555b1f0905c01658aa9f │ +│ Branches feature/1 │ +│ Commits ahead 2, behind 0 │ +│ Status open │ +├─────────────────────────────────────────────────────────────────────┤ +│ 4d27214 Rename readme file │ +│ 51b2f0f Not a real change │ +├─────────────────────────────────────────────────────────────────────┤ +│ ● opened by z6MknSL…StBU8Vi (you) now │ +│ ↑ updated to d9c9ef902f2957d746bb53e744e69a5c3aa564bc (4d27214) now │ +╰─────────────────────────────────────────────────────────────────────╯ ``` diff --git a/radicle-cli/examples/rad-patch-via-push.md b/radicle-cli/examples/rad-patch-via-push.md index 611c1133..1d879ee7 100644 --- a/radicle-cli/examples/rad-patch-via-push.md +++ b/radicle-cli/examples/rad-patch-via-push.md @@ -30,7 +30,7 @@ $ rad patch show e49e64637ab4a29e5a16c73000dacd2afa918d9d ├────────────────────────────────────────────────────┤ │ 42d894a Add things │ ├────────────────────────────────────────────────────┤ -│ ● opened by z6MknSL…StBU8Vi (you) [ ... ] │ +│ ● opened by z6MknSL…StBU8Vi (you) now │ ╰────────────────────────────────────────────────────╯ ``` @@ -93,12 +93,12 @@ And both patches: ``` $ rad patch -╭────────────────────────────────────────────────────────────────────────────────────╮ -│ ● ID Title Author Head + - Updated │ -├────────────────────────────────────────────────────────────────────────────────────┤ -│ ● b1fd7b6 Add more things z6MknSL…StBU8Vi (you) 8b0ea80 +0 -0 [ ... ] │ -│ ● e49e646 Add things #1 z6MknSL…StBU8Vi (you) 42d894a +0 -0 [ ... ] │ -╰────────────────────────────────────────────────────────────────────────────────────╯ +╭───────────────────────────────────────────────────────────────────────────────╮ +│ ● ID Title Author Head + - Updated │ +├───────────────────────────────────────────────────────────────────────────────┤ +│ ● b1fd7b6 Add more things z6MknSL…StBU8Vi (you) 8b0ea80 +0 -0 now │ +│ ● e49e646 Add things #1 z6MknSL…StBU8Vi (you) 42d894a +0 -0 now │ +╰───────────────────────────────────────────────────────────────────────────────╯ ``` To update our patch, we simply push commits to the upstream branch: @@ -130,21 +130,21 @@ We can then see that the patch head has moved: ``` $ rad patch show b1fd7b6 -╭──────────────────────────────────────────────────────────────────────────────╮ -│ Title Add more things │ -│ Patch b1fd7b6883dca2ef11e0e486a7097e759ea90cdb │ -│ Author z6MknSL…StBU8Vi (you) │ -│ Head 02bef3fac41b2f98bb3c02b868a53ddfecb55b5f │ -│ Branches feature/2 │ -│ Commits ahead 2, behind 0 │ -│ Status open │ -├──────────────────────────────────────────────────────────────────────────────┤ -│ 02bef3f Improve code │ -│ 8b0ea80 Add more things │ -├──────────────────────────────────────────────────────────────────────────────┤ -│ ● opened by z6MknSL…StBU8Vi (you) [ ... ] │ -│ ↑ updated to c867846b9f294c271e8934820dfac2c5924ecd5a (02bef3f) [ ... ] │ -╰──────────────────────────────────────────────────────────────────────────────╯ +╭─────────────────────────────────────────────────────────────────────╮ +│ Title Add more things │ +│ Patch b1fd7b6883dca2ef11e0e486a7097e759ea90cdb │ +│ Author z6MknSL…StBU8Vi (you) │ +│ Head 02bef3fac41b2f98bb3c02b868a53ddfecb55b5f │ +│ Branches feature/2 │ +│ Commits ahead 2, behind 0 │ +│ Status open │ +├─────────────────────────────────────────────────────────────────────┤ +│ 02bef3f Improve code │ +│ 8b0ea80 Add more things │ +├─────────────────────────────────────────────────────────────────────┤ +│ ● opened by z6MknSL…StBU8Vi (you) now │ +│ ↑ updated to c867846b9f294c271e8934820dfac2c5924ecd5a (02bef3f) now │ +╰─────────────────────────────────────────────────────────────────────╯ ``` And we can check that all the refs are properly updated in our repository: @@ -206,22 +206,22 @@ That worked. We can see the new revision if we call `rad patch show`: ``` $ rad patch show b1fd7b6 -╭──────────────────────────────────────────────────────────────────────────────╮ -│ Title Add more things │ -│ Patch b1fd7b6883dca2ef11e0e486a7097e759ea90cdb │ -│ Author z6MknSL…StBU8Vi (you) │ -│ Head 9304dbc445925187994a7a93222a3f8bde73b785 │ -│ Branches feature/2 │ -│ Commits ahead 2, behind 0 │ -│ Status open │ -├──────────────────────────────────────────────────────────────────────────────┤ -│ 9304dbc Amended commit │ -│ 8b0ea80 Add more things │ -├──────────────────────────────────────────────────────────────────────────────┤ -│ ● opened by z6MknSL…StBU8Vi (you) [ ... ] │ -│ ↑ updated to c867846b9f294c271e8934820dfac2c5924ecd5a (02bef3f) [ ... ] │ -│ ↑ updated to cf4d8577a1ec8aaa21a7ccca67ad8627c3304024 (9304dbc) [ ... ] │ -╰──────────────────────────────────────────────────────────────────────────────╯ +╭─────────────────────────────────────────────────────────────────────╮ +│ Title Add more things │ +│ Patch b1fd7b6883dca2ef11e0e486a7097e759ea90cdb │ +│ Author z6MknSL…StBU8Vi (you) │ +│ Head 9304dbc445925187994a7a93222a3f8bde73b785 │ +│ Branches feature/2 │ +│ Commits ahead 2, behind 0 │ +│ Status open │ +├─────────────────────────────────────────────────────────────────────┤ +│ 9304dbc Amended commit │ +│ 8b0ea80 Add more things │ +├─────────────────────────────────────────────────────────────────────┤ +│ ● opened by z6MknSL…StBU8Vi (you) now │ +│ ↑ updated to c867846b9f294c271e8934820dfac2c5924ecd5a (02bef3f) now │ +│ ↑ updated to cf4d8577a1ec8aaa21a7ccca67ad8627c3304024 (9304dbc) now │ +╰─────────────────────────────────────────────────────────────────────╯ ``` ## Empty patch diff --git a/radicle-cli/examples/rad-patch.md b/radicle-cli/examples/rad-patch.md index 26f42566..904bea29 100644 --- a/radicle-cli/examples/rad-patch.md +++ b/radicle-cli/examples/rad-patch.md @@ -35,11 +35,11 @@ It will now be listed as one of the project's open patches. ``` $ rad patch -╭──────────────────────────────────────────────────────────────────────────────────────────────╮ -│ ● ID Title Author Head + - Updated │ -├──────────────────────────────────────────────────────────────────────────────────────────────┤ -│ ● a892664 Define power requirements z6MknSL…StBU8Vi (you) 3e674d1 +0 -0 [ ... ] │ -╰──────────────────────────────────────────────────────────────────────────────────────────────╯ +╭─────────────────────────────────────────────────────────────────────────────────────────╮ +│ ● ID Title Author Head + - Updated │ +├─────────────────────────────────────────────────────────────────────────────────────────┤ +│ ● a892664 Define power requirements z6MknSL…StBU8Vi (you) 3e674d1 +0 -0 now │ +╰─────────────────────────────────────────────────────────────────────────────────────────╯ ``` ``` $ rad patch show a8926643a8f6a65bc386b0131621994000485d4d -p @@ -56,7 +56,7 @@ $ rad patch show a8926643a8f6a65bc386b0131621994000485d4d -p ├────────────────────────────────────────────────────┤ │ 3e674d1 Define power requirements │ ├────────────────────────────────────────────────────┤ -│ ● opened by z6MknSL…StBU8Vi (you) [ ... ] │ +│ ● opened by z6MknSL…StBU8Vi (you) now │ ╰────────────────────────────────────────────────────╯ commit 3e674d1a1df90807e934f9ae5da2591dd6848a33 @@ -99,10 +99,10 @@ And let's leave a quick comment for our team: ``` $ rad patch comment a8926643a8f6a65bc386b0131621994000485d4d --message 'I cannot wait to get back to the 90s!' -╭────────────────────────────────────────────╮ -│ z6MknSL…StBU8Vi (you) [ ... ] b97a27f │ -│ I cannot wait to get back to the 90s! │ -╰────────────────────────────────────────────╯ +╭───────────────────────────────────────╮ +│ z6MknSL…StBU8Vi (you) now b97a27f │ +│ I cannot wait to get back to the 90s! │ +╰───────────────────────────────────────╯ $ rad patch comment a8926643a8f6a65bc386b0131621994000485d4d --message 'My favorite decade!' --reply-to b97a27f -q a3a462bc8ab52e2a6f3568c28a11ba53cf40bbc8 ``` @@ -126,24 +126,24 @@ Showing the patch list now will reveal the favorable verdict: ``` $ rad patch show a892664 -╭──────────────────────────────────────────────────────────────────────────────╮ -│ Title Define power requirements │ -│ Patch a8926643a8f6a65bc386b0131621994000485d4d │ -│ Author z6MknSL…StBU8Vi (you) │ -│ Head 27857ec9eb04c69cacab516e8bf4b5fd36090f66 │ -│ Branches flux-capacitor-power, patch/a892664 │ -│ Commits ahead 2, behind 0 │ -│ Status open │ -│ │ -│ See details. │ -├──────────────────────────────────────────────────────────────────────────────┤ -│ 27857ec Add README, just for the fun │ -│ 3e674d1 Define power requirements │ -├──────────────────────────────────────────────────────────────────────────────┤ -│ ● opened by z6MknSL…StBU8Vi (you) [ ... ] │ -│ ↑ updated to 8d8aa0887a11f2a37fa8ed0d5723efa96fd727ed (27857ec) [ ... ] │ -│ ✓ accepted by z6MknSL…StBU8Vi (you) [ ... ] │ -╰──────────────────────────────────────────────────────────────────────────────╯ +╭─────────────────────────────────────────────────────────────────────╮ +│ Title Define power requirements │ +│ Patch a8926643a8f6a65bc386b0131621994000485d4d │ +│ Author z6MknSL…StBU8Vi (you) │ +│ Head 27857ec9eb04c69cacab516e8bf4b5fd36090f66 │ +│ Branches flux-capacitor-power, patch/a892664 │ +│ Commits ahead 2, behind 0 │ +│ Status open │ +│ │ +│ See details. │ +├─────────────────────────────────────────────────────────────────────┤ +│ 27857ec Add README, just for the fun │ +│ 3e674d1 Define power requirements │ +├─────────────────────────────────────────────────────────────────────┤ +│ ● opened by z6MknSL…StBU8Vi (you) now │ +│ ↑ updated to 8d8aa0887a11f2a37fa8ed0d5723efa96fd727ed (27857ec) now │ +│ ✓ accepted by z6MknSL…StBU8Vi (you) now │ +╰─────────────────────────────────────────────────────────────────────╯ ``` If you make a mistake on the patch description, you can always change it! @@ -151,22 +151,22 @@ If you make a mistake on the patch description, you can always change it! ``` $ rad patch edit a892664 --message "Define power requirements" --message "Add requirements file" $ rad patch show a892664 -╭──────────────────────────────────────────────────────────────────────────────╮ -│ Title Define power requirements │ -│ Patch a8926643a8f6a65bc386b0131621994000485d4d │ -│ Author z6MknSL…StBU8Vi (you) │ -│ Head 27857ec9eb04c69cacab516e8bf4b5fd36090f66 │ -│ Branches flux-capacitor-power, patch/a892664 │ -│ Commits ahead 2, behind 0 │ -│ Status open │ -│ │ -│ Add requirements file │ -├──────────────────────────────────────────────────────────────────────────────┤ -│ 27857ec Add README, just for the fun │ -│ 3e674d1 Define power requirements │ -├──────────────────────────────────────────────────────────────────────────────┤ -│ ● opened by z6MknSL…StBU8Vi (you) [ ... ] │ -│ ↑ updated to 8d8aa0887a11f2a37fa8ed0d5723efa96fd727ed (27857ec) [ ... ] │ -│ ✓ accepted by z6MknSL…StBU8Vi (you) [ ... ] │ -╰──────────────────────────────────────────────────────────────────────────────╯ +╭─────────────────────────────────────────────────────────────────────╮ +│ Title Define power requirements │ +│ Patch a8926643a8f6a65bc386b0131621994000485d4d │ +│ Author z6MknSL…StBU8Vi (you) │ +│ Head 27857ec9eb04c69cacab516e8bf4b5fd36090f66 │ +│ Branches flux-capacitor-power, patch/a892664 │ +│ Commits ahead 2, behind 0 │ +│ Status open │ +│ │ +│ Add requirements file │ +├─────────────────────────────────────────────────────────────────────┤ +│ 27857ec Add README, just for the fun │ +│ 3e674d1 Define power requirements │ +├─────────────────────────────────────────────────────────────────────┤ +│ ● opened by z6MknSL…StBU8Vi (you) now │ +│ ↑ updated to 8d8aa0887a11f2a37fa8ed0d5723efa96fd727ed (27857ec) now │ +│ ✓ accepted by z6MknSL…StBU8Vi (you) now │ +╰─────────────────────────────────────────────────────────────────────╯ ``` diff --git a/radicle-cli/examples/workflow/3-issues.md b/radicle-cli/examples/workflow/3-issues.md index 9f9154c3..375e38c9 100644 --- a/radicle-cli/examples/workflow/3-issues.md +++ b/radicle-cli/examples/workflow/3-issues.md @@ -19,11 +19,11 @@ The issue is now listed under our project. ``` $ rad issue list -╭────────────────────────────────────────────────────────────────────────────────────────────────╮ -│ ● ID Title Author Labels Assignees Opened │ -├────────────────────────────────────────────────────────────────────────────────────────────────┤ -│ ● d457c20 flux capacitor underpowered bob (you) [ .. ] │ -╰────────────────────────────────────────────────────────────────────────────────────────────────╯ +╭──────────────────────────────────────────────────────────────────────────────────────────╮ +│ ● ID Title Author Labels Assignees Opened │ +├──────────────────────────────────────────────────────────────────────────────────────────┤ +│ ● d457c20 flux capacitor underpowered bob (you) now │ +╰──────────────────────────────────────────────────────────────────────────────────────────╯ ``` Great! Now we've documented the issue for ourselves and others. But wait, we've diff --git a/radicle-cli/examples/workflow/4-patching-contributor.md b/radicle-cli/examples/workflow/4-patching-contributor.md index 78e9be93..57f666a6 100644 --- a/radicle-cli/examples/workflow/4-patching-contributor.md +++ b/radicle-cli/examples/workflow/4-patching-contributor.md @@ -35,11 +35,11 @@ It will now be listed as one of the project's open patches. ``` $ rad patch -╭─────────────────────────────────────────────────────────────────────────────────────╮ -│ ● ID Title Author Head + - Updated │ -├─────────────────────────────────────────────────────────────────────────────────────┤ -│ ● 4bfb6fe Define power requirements bob (you) 3e674d1 +0 -0 [ ... ] │ -╰─────────────────────────────────────────────────────────────────────────────────────╯ +╭────────────────────────────────────────────────────────────────────────────────╮ +│ ● ID Title Author Head + - Updated │ +├────────────────────────────────────────────────────────────────────────────────┤ +│ ● 4bfb6fe Define power requirements bob (you) 3e674d1 +0 -0 now │ +╰────────────────────────────────────────────────────────────────────────────────╯ $ rad patch show 4bfb6fe940f815e3fcce6a2796e051df85db9fe1 ╭────────────────────────────────────────────────────╮ │ Title Define power requirements │ @@ -54,7 +54,7 @@ $ rad patch show 4bfb6fe940f815e3fcce6a2796e051df85db9fe1 ├────────────────────────────────────────────────────┤ │ 3e674d1 Define power requirements │ ├────────────────────────────────────────────────────┤ -│ ● opened by bob (you) [ ... ] │ +│ ● opened by bob (you) now │ ╰────────────────────────────────────────────────────╯ ``` diff --git a/radicle-cli/examples/workflow/5-patching-maintainer.md b/radicle-cli/examples/workflow/5-patching-maintainer.md index 18bcffb0..4ca70931 100644 --- a/radicle-cli/examples/workflow/5-patching-maintainer.md +++ b/radicle-cli/examples/workflow/5-patching-maintainer.md @@ -33,22 +33,22 @@ $ git branch -r bob/patches/4bfb6fe940f815e3fcce6a2796e051df85db9fe1 rad/master $ rad patch show 4bfb6fe -╭──────────────────────────────────────────────────────────────────────────────╮ -│ Title Define power requirements │ -│ Patch 4bfb6fe940f815e3fcce6a2796e051df85db9fe1 │ -│ Author bob z6Mkt67…v4N1tRk │ -│ Head 27857ec9eb04c69cacab516e8bf4b5fd36090f66 │ -│ Commits ahead 2, behind 0 │ -│ Status open │ -│ │ -│ See details. │ -├──────────────────────────────────────────────────────────────────────────────┤ -│ 27857ec Add README, just for the fun │ -│ 3e674d1 Define power requirements │ -├──────────────────────────────────────────────────────────────────────────────┤ -│ ● opened by bob z6Mkt67…v4N1tRk [ ... ] │ -│ ↑ updated to 7782e60eb51b6e852abb184b092249327354c625 (27857ec) [ ... ] │ -╰──────────────────────────────────────────────────────────────────────────────╯ +╭─────────────────────────────────────────────────────────────────────╮ +│ Title Define power requirements │ +│ Patch 4bfb6fe940f815e3fcce6a2796e051df85db9fe1 │ +│ Author bob z6Mkt67…v4N1tRk │ +│ Head 27857ec9eb04c69cacab516e8bf4b5fd36090f66 │ +│ Commits ahead 2, behind 0 │ +│ Status open │ +│ │ +│ See details. │ +├─────────────────────────────────────────────────────────────────────┤ +│ 27857ec Add README, just for the fun │ +│ 3e674d1 Define power requirements │ +├─────────────────────────────────────────────────────────────────────┤ +│ ● opened by bob z6Mkt67…v4N1tRk now │ +│ ↑ updated to 7782e60eb51b6e852abb184b092249327354c625 (27857ec) now │ +╰─────────────────────────────────────────────────────────────────────╯ ``` Wait! There's a mistake. The REQUIREMENTS should be a markdown file. Let's @@ -99,24 +99,24 @@ The patch is now merged and closed :). ``` $ rad patch show 4bfb6fe -╭──────────────────────────────────────────────────────────────────────────────╮ -│ Title Define power requirements │ -│ Patch 4bfb6fe940f815e3fcce6a2796e051df85db9fe1 │ -│ Author bob z6Mkt67…v4N1tRk │ -│ Head 27857ec9eb04c69cacab516e8bf4b5fd36090f66 │ -│ Commits ahead 0, behind 1 │ -│ Status merged │ -│ │ -│ See details. │ -├──────────────────────────────────────────────────────────────────────────────┤ -│ 27857ec Add README, just for the fun │ -│ 3e674d1 Define power requirements │ -├──────────────────────────────────────────────────────────────────────────────┤ -│ ● opened by bob z6Mkt67…v4N1tRk [ ... ] │ -│ ↑ updated to 7782e60eb51b6e852abb184b092249327354c625 (27857ec) [ ... ] │ -│ * revised by alice (you) in fab4fdd (f567f69) [ ... ] │ -│ ✓ merged by alice (you) at revision fab4fdd (f567f69) [ ... ] │ -╰──────────────────────────────────────────────────────────────────────────────╯ +╭─────────────────────────────────────────────────────────────────────╮ +│ Title Define power requirements │ +│ Patch 4bfb6fe940f815e3fcce6a2796e051df85db9fe1 │ +│ Author bob z6Mkt67…v4N1tRk │ +│ Head 27857ec9eb04c69cacab516e8bf4b5fd36090f66 │ +│ Commits ahead 0, behind 1 │ +│ Status merged │ +│ │ +│ See details. │ +├─────────────────────────────────────────────────────────────────────┤ +│ 27857ec Add README, just for the fun │ +│ 3e674d1 Define power requirements │ +├─────────────────────────────────────────────────────────────────────┤ +│ ● opened by bob z6Mkt67…v4N1tRk now │ +│ ↑ updated to 7782e60eb51b6e852abb184b092249327354c625 (27857ec) now │ +│ * revised by alice (you) in fab4fdd (f567f69) now │ +│ ✓ merged by alice (you) at revision fab4fdd (f567f69) now │ +╰─────────────────────────────────────────────────────────────────────╯ ``` To publish our new state to the network, we simply push: diff --git a/radicle/src/cob.rs b/radicle/src/cob.rs index cbb9ce68..2e77d2d2 100644 --- a/radicle/src/cob.rs +++ b/radicle/src/cob.rs @@ -10,13 +10,11 @@ pub mod thread; #[cfg(test)] pub mod test; -pub use cob::{ +pub use common::*; +pub use op::{ActorId, Op}; +pub use radicle_cob::{ change, history::EntryId, object, object::collaboration::error, CollaborativeObject, Contents, Create, Embed, Entry, Evaluate, History, Manifest, ObjectId, Store, TypeName, Update, Updated, Version, }; -pub use cob::{create, get, list, remove, update}; -pub use common::*; -pub use op::{ActorId, Op}; - -use radicle_cob as cob; +pub use radicle_cob::{create, get, list, remove, update}; diff --git a/radicle/src/cob/common.rs b/radicle/src/cob/common.rs index bf35c2c1..95e5bb6d 100644 --- a/radicle/src/cob/common.rs +++ b/radicle/src/cob/common.rs @@ -1,15 +1,59 @@ use std::fmt; use std::fmt::Display; +use std::ops::Deref; use std::str::FromStr; use localtime::LocalTime; use serde::{Deserialize, Serialize}; use crate::git_ext::Oid; -use crate::prelude::*; +use crate::prelude::{Did, PublicKey}; /// Timestamp used for COB operations. -pub type Timestamp = LocalTime; +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] +#[serde(transparent)] +pub struct Timestamp(LocalTime); + +impl Timestamp { + /// Construct a `Timestamp` corresponding to the current time. + /// + /// # Note + /// + /// If this is used in debug mode, `RAD_COMMIT_TIME` will be used + /// to construct the timestamp. + pub fn now() -> Self { + if cfg!(debug_assertions) { + if let Ok(s) = std::env::var("RAD_COMMIT_TIME") { + // SAFETY: Only used in test code. + #[allow(clippy::unwrap_used)] + let secs = s.trim().parse::().unwrap(); + Self::from_secs(secs) + } else { + Self(LocalTime::now()) + } + } else { + Self(LocalTime::now()) + } + } + + pub fn from_secs(secs: u64) -> Self { + Self(LocalTime::from_secs(secs)) + } +} + +impl From for Timestamp { + fn from(time: LocalTime) -> Self { + Self(time) + } +} + +impl Deref for Timestamp { + type Target = LocalTime; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} /// Author. #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]