Commit Graph

744 Commits

Author SHA1 Message Date
Fintan Halpenny 8fd044833e
radicle: use `git push` to avoid `libgit2` push
In issue #[2836] of `libgit2`, the speed of `libgit2`'s `file://` protocol for
git operations is found to be very slow. This is further corrobarated by `rad
init` taking 13 hours to initialise the hardenedbsd [ports] repository.

There are two areas where the `heartwood` project uses `libgit2` to push using
the file protocol. The first is when via the `trasnport::local` smart transport
registration and the second is the final push to storage in the `git-remote-rad`
binary.

When both these `push` operations are changed to use the `git` binary instead,
the [ports] repository can be initialised in less than 10 minutes (nearly 100x
speed up).

This change is clearly required if `heartwood` wishes to support larger
repositories.

[2836]: https://github.com/libgit2/libgit2/issues/2836
[ports]: https://git.hardenedbsd.org/hardenedbsd/ports
2025-04-17 15:12:12 +02:00
Fintan Halpenny 96637aca7e
chore: update rust-toolchain
Update the rust toolchain version to 1.85.

Note that this is not the latest, however, it is the latest available in nixpgs,
so this version is good enough for now.
2025-04-17 10:39:34 +02:00
Fintan Halpenny 9ef9c5d59a radicle: add Op::load method
Adds an `Op::load` helper method for loading an `Entry`, given its `Oid` and the
`store` it is stored in.

This can be useful for downstream consumers to inspect operations on COBs given
a single `Oid`, without having to load the entire object and/or graph.

It can also be useful when looking at implementing COB stream primitives.
2025-04-11 12:52:09 +02:00
Fintan Halpenny c847a16e14 radicle: return iterator types for db policies
Instead of collecting the results and returning the collection as an
iterator, introduce `FollowPolicies` and `SeedPolicies` types, which
implement `Iterator`.

Note that a call in `service` changed due to the lifetime borrow. It
simply `collect`s into a `Vec` for the time being.
2025-04-11 12:35:55 +02:00
Fintan Halpenny 7de82b5025 radicle: use `Alias` in `follow`
Ensure that the validated `Alias` type is used for inserting into the
policy database.
2025-04-11 12:35:55 +02:00
Fintan Halpenny 6940ac42be radicle: reverse lookup for AliasStore
Provide functionality to lookup the `NodeId`s associated with a given
`Alias`.

The use for this functionality is to allow callers to use aliases as
shorthands for `NodeId`s, but still refer to the exact identifier.

The implementation allows for searching using the `LIKE '%<pattern>%'`
queries in sqlite, so searches do not have to be exact matches.
2025-04-11 12:18:35 +02:00
Fintan Halpenny dd5f739630 radicle: generic Transaction::initial
The use of `Transaction` outside of the `radicle` crate requires that a newtype is used, if the upstream code wants to write methods, such as:

```
pub struct Transaction<R>(store::Transaction<MyCob, R>);

impl Transaction<R> {
  pub fn add_foo(&mut self, foo: Foo) -> Result<(), store::Error> { /* code */ }
  pub fn add_bar(&mut self, bar: Bar) -> Result<(), store::Error> { /* code */ }}
```

This works up until the point that it tries to re-use the
`Transaction::initial` method.

To make this possible, the method needs to know that it can be
converted to the upstream `Transaction` and back to `radicle`
`Transaction`.
2025-04-10 15:37:08 +02:00
Fintan Halpenny c2863c08ab radicle: extend emoji support
Extend the ranges of emojis that are supported, listed
[below](#new-emojis-supported).

To ensure that single `char` emojis are supported, the `emojis` crate
is added as a dev dependency, using it to check that a `Reaction` can
be constructed for the two groups `SmileysAndEmotion` and
`PeopleAndBody`.

### New Emojis Supported

'🩵' 0x1FA75
'🩶' 0x1FA76
'🩷' 0x1FA77
'🫀' 0x1FAC0
'🫁' 0x1FAC1
'🫂' 0x1FAC2
'🫃' 0x1FAC3
'🫄' 0x1FAC4
'🫅' 0x1FAC5
'🫆' 0x1FAC6
'🫠' 0x1FAE0
'🫡' 0x1FAE1
'🫢' 0x1FAE2
'🫣' 0x1FAE3
'🫤' 0x1FAE4
'🫥' 0x1FAE5
'🫦' 0x1FAE6
'🫨' 0x1FAE8
'🫩' 0x1FAE9
'🫰' 0x1FAF0
'🫱' 0x1FAF1
'🫲' 0x1FAF2
'🫳' 0x1FAF3
'🫴' 0x1FAF4
'🫵' 0x1FAF5
'🫶' 0x1FAF6
'🫷' 0x1FAF7
'🫸' 0x1FAF8
2025-04-10 15:18:31 +02:00
Fintan Halpenny 62d000f7cb radicle: fix `parse_ref_*` documentation
The `parse_ref` and `parse_ref_namespaced` documentation used 4 space
indentation for the reference names. Unfortunately, `cargo test` attempts to
interpret this as code.

Use triple-backtick code fencing, with `text` and `no_run`, instead.
2025-01-16 11:08:35 +00:00
Sebastian Martinez 985987468d
radicle: add `list_by_status` method to `cob::issue::Issues`
Provides the same `list_by_status` and `<status>` methods that
`cob::patch::Patches` has to `Issues`
2025-01-14 13:36:14 +01:00
Sebastian Martinez 7c902b6905
radicle: Add `resolves` and `labels` method to `cob::patch::Revision`
To be able to query the `BTreeSet` that shows which comments are
resolved by a specific revision and the `Iterator` of `Label` we require
some methods to obtain them.
2025-01-14 13:34:38 +01:00
Fintan Halpenny 6598243465
radicle: document `parse_ref` and `parse_ref_namespaced`
Provide better documentation for the two methods.

Solves the issue:
```
rad issue show 4603f55d97a0776f37bae2f9d2ba7d455d8a4c83
```

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2025-01-14 13:34:13 +01:00
Leah Neukirchen 41c33901ff
radicle: use rlim_t when working with limits
rlimit values have different types on Linux and FreeBSD, as well as
64-bit and 32-bit platforms, so stick to the type rlim_t provided by the
libc crate.
2025-01-14 13:29:03 +01:00
Lars Wirzenius 4c82bb4c4e
radicle: add some documentation for node::events::Event
Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-01-14 13:24:11 +01:00
Lars Wirzenius 2929146c49
radicle: clarify RefsAt description
Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-01-14 13:22:51 +01:00
cloudhead fd892d006f
Update `radicle` to 0.14 2024-11-29 15:25:09 +01:00
cloudhead 3ad84420bd
cli: Implement `rad cob migrate`
Adds the new `migrate` sub-command to migrate the COB database.
Checks for version when opening the COBs database and suggests the
command on out of date version.

Also adds the 2nd migration to the COBs cache, which updates the patch
JSON schema.
2024-11-22 21:27:45 +01:00
cloudhead 2d13591ec2
radicle: Fix flaky test `counts_by_repo` 2024-11-21 16:05:01 +01:00
Sebastian Martinez a7e96131ce
radicle: add notification count grouped by repo
While the total notification count and the notification count by repo
are needed, for most UIs users will want to see the total notification
count grouped by repo.

This new method will provide this without the need of checking all
possible repos to see if they have notifications.
2024-11-21 12:04:32 +01:00
Fintan Halpenny 259adf7dc2
cob: mutable stable time for testing
The `radicle-cob` crate provides a feature flag, `stable-commit-ids` to allow
for `Oid`s to remain stable for testing by always using the same author and
timestamp when creating commits.

This can be an issue when it interplays with COB related tests that are relying
on the ordering for the DAG walk. If the `Oid` values change and get re-ordered
then the test will fail. The DAG for COBs are now ordered via the `Oid` and
`Timestamp`.

In this change, a global timestamp is introduced that is initialised
per thread. The value is read, via `read_timestamp`, and can be
advanced using `with_advanced_timestamp` – while performing an action
that creates a new commit.
2024-11-18 16:11:44 +01:00
Fintan Halpenny 91914d9345
radicle: improve quorum copy
The `no quorum found` error can be opaque and lead to a lot of confusion. It is
better to give more information for this error so that it leads to easier
debugging, since it can be quite a common warning/error.

Instead of a single error, there are two cases provided: `NoCandidates` and
`Diverging`, to capture the two different variants of errors that can occur.

`Display` implementations are provided for both to provide more information.
2024-11-18 12:32:44 +01:00
cloudhead 6c8ee4330e
radicle: Implement migration callback mechanism
Add the ability to have native migrations and progress callback
functions in migration code for the COB cache.
2024-11-14 17:21:33 +01:00
Fintan Halpenny 088339850b
radicle: introduce identity document version
This change introduces versioning to the identity document format.

The `Version` type is introduced to capture this. Importantly, it is very
restricted in its construction and API. `Version::new` provides a smart
constructor to ensure that it is only ever constructed within the expected
bounds of `0 < v <= IDENTITY_VERSION`, where `IDENTITY_VERSION` is the constant
for the current version.

Note that serializing of the `Doc::version` is skipped to preserve the `Oid`
outputs of all the tests – which means that the first `version` is always
implicit and is not really expected to exist in the serialized forms of the
identity document.
2024-11-14 12:09:28 +01:00
Lars Wirzenius df44cee9ef
cob: Add an experimental "job" COB
This is meant to record in Radicle that automated "jobs" have been run
on a repository. The job might be, for example, a CI run that builds
the software and runs its tests. The recording is done in a "job COB",
which can be in three states:

* fresh -- when the job has been triggered, but has not yet started running
* running -- when it's running
* finished -- when it's finished running

The finished state also records whether the job was successful or if
it failed.

A job COB records the git commit that it runs on, and the "run ID" of
the job. The run ID represents an external identifier, such as one
assigned by a remote CI system. The COB can optionally store a URL
related to the job, such as to the build log from CI.

Add the "rad job" subcommand to create and manage job COBs. For
production use, the COBs should be created and updated using
`heartwood` as a library instead of running "rad job", if at all
possible. However, "rad job list" lists the jobs that have been run on
the repository.

The COB type name is xyz.radicle.beta.job, until we've gained
experience with the COB and its implementation and are ready to
declare it stable.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2024-11-06 17:26:00 +01:00
cloudhead f6aa46a283
cli: Try to connect to seeds specified as options
When fetching with a `--seed` specified on the CLI, try to connect to it
if not already connected.
2024-11-05 12:18:12 +01:00
cloudhead 11a6ec5dc6
cob: Add logging to COB evaluation
To use it, run for eg. the following command:

    $ RUST_LOG=debug rad patch cache
2024-11-05 12:14:26 +01:00
cloudhead 0bb0fe8f25
cob: Fix compatibility with certain old patches
We were rejecting patches that were once valid, due to a rule that was
added some time ago. Move that rule one level up, in the write path,
instead of in the read path.
2024-11-04 14:34:30 +01:00
cloudhead 09f796234d
radicle: Compute root OID for older remotes
For older clients, `refs/rad/root` won't be set. In that case, compute
it locally based on `refs/rad/id`.
2024-10-31 17:34:03 +01:00
Johannes Kuehlewindt 0c9a7419dc
cli: Add config modification sub-commands
Adds `set`, `add`, `remove`, `delete` to `rad config`.

Note that the changes will affect the configuration file, but not the
running instances. For changes to be reflected in the running instances
the node would need to be restarted.
2024-10-23 17:19:27 +02:00
Fintan Halpenny de1958fab0 radicle: refactor doc
The aim of this change is to make the `Doc` type more safe to use by approaching
the design via [Parse don't validate][[0]] approach.

The problem with the previous approach was that all field were `pub` and thus a
`Doc<Verified>` could easily be mutated and serialized. Granted, the code that
used the serialization would tend to verify the `Doc` first, however, this
approach *ensures* that only a verified `Doc` can be serialized. It also meant
that trying to add new data that would follow the parse approach would require
more generic parameters on top of the existing `PhantomData` parameter, i.e. we
need to do something like: `Doc<RawField, V> -> Doc<ValidField, V>`.

The new approach splits the type into two separate types: `RawDoc` and `Doc`.
The former is allowed to be mutated at will, and uses types that are less
strict. The latter is the valid type that can only be constructed by validating
a `RawDoc` (or the `initial` constructor). The `Doc` type's fields can then only
be accessed by read-only methods.

Solves the problems above by only allowing mutations to `RawDoc`, as well as,
new fields being added to `RawDoc` which are then validated via
`RawDoc::verified`.

[0]: https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/
2024-10-22 14:58:12 +01:00
cloudhead f83c116742
radicle: Fix clippy warnings around `unwrap`
The policy should be that we don't use unwraps outside of test code,
unless we have a good reason to.
2024-10-21 16:42:06 +02:00
cloudhead 989edacd56
Include new `rad/root` in signed refs
We ensure that a `rad/root` ref is included in the signed refs file
under `rad/sigrefs` for all remotes. This prevents a certain kind of
"grafting" attack where signed refs can be copied between repositories,
by having the peer sign over the identity root together with the data refs.

When verifying signed refs, we ensure that the ref is present and points
to an identity branch root that matches the repository identity containing
the signed refs.

Alternatives: lots of alternatives were considered, but this one doesn't
introduce any changes to the signing. The `rad/id/root` name was
considered but is invalid due to `rad/id`.
2024-10-21 16:32:49 +02:00
cloudhead 24066c2600
radicle: Test the signed refs grafting attack 2024-10-21 16:32:49 +02:00
Fintan Halpenny 46c2637f77
radicle: add tags fetch refspec
Add a fetch refspec to fetch tags from a Radicle remote. The
`--no-tag` option is also included. This is to ensure that it is easy
to collaborate by having tags placed in the remote namespace of
another peer. However, if the namespace is the default `rad` remote,
then tags are expected to be allowed -- this is to pave way for the
feature of canonical tags.

In the tests, the `--tags` option is removed -- and is generally
recommended that it is not used. This is to ensure that it does not
override the `--no-tag` option.
2024-10-21 14:30:37 +02:00
cloudhead 855327d303
cob: Change APIs to take URIs for embeds
To facilitate edit actions, take URIs instead of the actual blobs. This
means API callers don't have to load all the blobs just for them to be
re-hashed when an edit action is submitted.

There are some peculiarities when dealing with the `Identity` COB since
the embed is the identity document itself. We handle that special case.
2024-10-14 12:51:36 +02:00
cloudhead 3acdb17b86
cob: Fix patch review editing
Due to the way review editing was implemented, we were losing comments
on previous review edits.

Here, we add a new `review.edit` action that is specifically for
editing, and make the existing `review` action fail silently (for
backwards compatibility) in case it is used when there is already a
review.

We also simplify the review data structure by only keeping track of one
review per author per revision, instead of all edits. Later, if needed,
it will be possible to keep track of all review edits.
2024-10-04 17:44:45 +02:00
Alexis Sellier 729a6e057e
cobs: Fix COB drafts to work correctly 2024-10-01 15:59:23 +02:00
Fintan Halpenny e130b4dc06
radicle: custom upstream remote for patches
When creating a new upstream for the patch workflow, the remote name is always
assumed to be `rad`.

It's possible for users to use another remote name but still use a `rad://` URL
for pushing. To allow for this, the function that creates the upstream entry now
takes a remote name. In the remote helper, `rad patch checkout`, and `rad patch
set` the remote can be optionally specified and fall back to the `rad` remote
name as a default.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2024-09-12 17:59:57 +02:00
Lorenz Leutgeb 1d57778f6b
profile: Treat empty passphrase as no passphrase 2024-09-11 13:34:41 +02:00
cloudhead 4e112aaeaa
Update `radicle` crate to 0.13.0 2024-08-28 13:01:35 +02:00
cloudhead 757483f351
radicle: Fix patch COB `review` action
When two `review` actions were posted by the same author, for the same
revision, an error was returned, cancelling evaluation for that author.
This caused certain patches to for eg. lose their merge status.

To remedy this, we *allow* multiple `review` actions per revision, but
simply take the last one as the "current" review. Since this makes the
`review.edit` action redundant, we remove that action completely. This
is safe, as none of the tools created review edits.
2024-08-21 17:37:58 +02:00
Sebastian Martinez cae66b6168
Update `radicle-git-ext` to 0.8.0 2024-08-20 16:35:04 +02:00
Sebastian Martinez f71da0ee95
Update `git2` to 0.19.0 2024-08-20 16:35:04 +02:00
cloudhead 1d1b9c3d49
radicle: Don't use transactions in cache
The `transaction` method was being used for single queries. This
was unnecessary.
2024-08-09 10:54:04 +02:00
cloudhead 9db69a40a6
radicle: Remove cache entries before caching
In case of a bug or failed cache update, there may be objects in the
cache that are no longer in storage.

When doing a full re-cache, remove all existing entries from the repo
first.
2024-08-09 10:48:46 +02:00
cloudhead bfc949d094
cli: Log errors when COBs can't load 2024-08-09 10:47:54 +02:00
cloudhead 16560950ec
radicle: Fix log when delegate is not found 2024-08-06 16:36:27 +02:00
cloudhead c6a8a00055
Update `rust-toolchain` to 1.80
Fix new clippy warnings.
2024-08-06 14:37:21 +02:00
cloudhead 0e08452323
node: Ensure we don't prune our own routes
Filter out routing entries of our own node when prunning.
2024-08-06 14:17:12 +02:00
Fintan Halpenny 52554af4f1
cli: add `rad unblock` command
Add the `rad unblock` command for reversing the effect of blocking an NID or RID.

In both cases, the entry is removed from the DB, if the policy was set to block
-- otherwise it is a no-op.
2024-08-06 14:12:44 +02:00