Commit Graph
137 Commits
Author SHA1 Message Date
Han Xu 4e373fb8de remove source/ layer and file_system/ layer.
- Merge `person.rs` into `object/commit.rs`.
- Move `source/commit.rs` into `object/`.
- Merge `file_system/directory.rs` into `file_system.rs`.
- Rename `file_system.rs` to `fs.rs`.

Signed-off-by: Han Xu <keepsimple@gmail.com>
2022-12-21 13:32:19 -08:00
Fintan Halpenny 824e0d5d9b Merge remote-tracking branch 'origin/surf/revision-stats'
* origin/surf/revision-stats:
  surf: stats for a given revision

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-12-22 14:12:47 +00:00
Fintan Halpenny 5d7b1e4c01 surf: stats for a given revision
The `stats` method always provided the stats at the `head` of the
repository.

Introduce the `stats_from` method which takes a revision to start
from. `stats` can be defined using `stats_from` and `head`.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-12-22 12:07:58 +00:00
Fintan Halpenny c2cc44bcc4 Merge remote-tracking branch 'origin/commit/time-accessors'
* origin/commit/time-accessors:
  git-commit: add Time accessors

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-12-22 10:50:18 +00:00
Fintan Halpenny 9f13cd8d07 Merge remote-tracking branch 'han/dogfood'
* han/dogfood:
  refactored Directory, File, Tree and Blob.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-12-22 10:49:38 +00:00
Han Xu 922206e08e refactored Directory, File, Tree and Blob.
Signed-off-by: Han Xu <keepsimple@gmail.com>
2022-12-21 03:15:28 -08:00
Fintan Halpenny a65ff27e22 git-commit: add Time accessors
Previously, there was no way to access the seconds and offset fields
of the Time type.

Add methods for accessing the fields.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-12-19 15:54:52 +00:00
Fintan Halpenny 79a9472136 Merge remote-tracking branch 'origin/fix/serialize-tree'
* origin/fix/serialize-tree:
  radicle-surf: serialize type for any kind of line
  surf: testing an added file
  surf: test serialization of tree
  surf: fix directory construction
  surf: fix path serialization for tree and blob

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-12-19 11:28:13 +00:00
Fintan Halpenny f4d2e38620 radicle-surf: serialize type for any kind of line
To help frontends with figuring out what kind of line is being talked
about for added and deleted files, the serialization of `Addition` and
`Deletion` always include a type. This mirrors the serialization of
the `Modification` type, which is tagged because it's an enum.

The serialization is hand-rolled since it is desirable to make sure
that added files and deleted files are only ever composed of lines
that are not modified.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-12-18 15:04:15 +00:00
Fintan Halpenny 21c0e68ab5 surf: testing an added file
Test the serialization of an added file in a Diff.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-12-16 11:37:59 +00:00
Fintan Halpenny 0d5b6c4c30 surf: test serialization of tree
Confirm that the serialization of `source::Tree` has the expected
output.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-12-16 11:37:59 +00:00
Fintan Halpenny 95c31f2a8e surf: fix directory construction
If a git Tree is a subtree then it no longer contains the path
information while traversing it. The traversal will only carry the
path with it if it does not skip directories, which in the case of
`entries`, it does.

To remedy this, the `path` method is used to pass the information to
`from_entry` instead.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-12-16 11:37:58 +00:00
Fintan Halpenny d957f0b1c2 surf: fix path serialization for tree and blob
The http-api code expects the 'path' serialized field to be the full
path for trees, tree entries, and blobs, i.e. the path where it is
located concatenated with the name of the entry.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-12-16 11:37:58 +00:00
Fintan Halpenny 9df4291616 Merge remote-tracking branch 'origin/nix/rust-1.66'
* origin/nix/rust-1.66:
  surf: missed expect from refactoring diff
  nix: update to rust-1.66

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-12-16 11:37:10 +00:00
Fintan Halpenny 01e2305a41 surf: missed expect from refactoring diff
A placeholder `.expect("TODO")` was left in the diff code while
refactoring.

Change the `expect` to `?` and use the correct `type Error`.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-12-16 11:00:16 +00:00
Fintan Halpenny 8d451e3d9d nix: update to rust-1.66
Rust 1.66.0 was announced[0].

The code fixes were all for the clippy warning regarding needless
borrows.

The doc tool now parses for HTML, so any <placeholder> now needs to
be wrapped in backticks, i.e. `<placeholder>`.

[0]: https://blog.rust-lang.org/2022/12/15/Rust-1.66.0.html

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-12-16 10:54:55 +00:00
Fintan Halpenny 39ce2f9349 Merge remote-tracking branch 'origin/fix/ref-serde'
* origin/fix/ref-serde:
  git-ref-format: fix to deserialization
  test: add roundtrip::json_value

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-12-08 16:04:36 +00:00
Fintan Halpenny db7f2d40e3 git-ref-format: fix to deserialization
When deserializing through `serde_json::from_value` the following
error would occur:

  panicked at 'called Result::unwrap() on an Err value: Error("invalid
  type: string "master", expected a borrowed string", line: 0, column:
  0)'

To fix this it is necessary for the Deserialize implementations to
deserialize into an owned String and convert from there.

While attempting to test this the `Qualified` and `Namespaced`
implementations were not able to be used:

  error: implementation of `serde::de::Deserialize` is not general enough
  --> git-ref-format/t/src/properties/name.rs:86:9
   |
86 |         roundtrip::json_value(qualified);
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `serde::de::Deserialize` is not general enough
   |
   = note: `Qualified<'_>` must implement `serde::de::Deserialize<'0>`, for any lifetime `'0`...
   = note: ...but `Qualified<'_>` actually implements
   `serde::de::Deserialize<'1>`, for some specific lifetime `'1`

The Deserialize for both of those types now return owned data by
returning a 'static lifetime instead.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-12-08 15:20:11 +00:00
Fintan Halpenny 9d137e5e7d test: add roundtrip::json_value
Adds a roundtrip helper for going to/from a json value. This can have
slightly different semantics in comparison to/from a json string.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-12-08 15:17:19 +00:00
Fintan Halpenny 1316a13dfc Merge remote-tracking branch 'han/fix-traits'
* han/fix-traits:
  refactoring Revision and ToCommit traits

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-12-06 14:03:16 +00:00
Han Xu a16a627151 refactoring Revision and ToCommit traits
- Added a generic impl for &Revision
- Updated ToCommit for easier usage.

Signed-off-by: Han Xu <keepsimple@gmail.com>
2022-12-05 21:07:56 -08:00
Fintan Halpenny 761e14e7cc Merge remote-tracking branch 'han/doc-comments'
* han/doc-comments:
  Updated docs, include tests in file_system.rs and fix bugs found.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-12-05 10:55:21 +00:00
Han Xu 6100b12006 Updated docs, include tests in file_system.rs and fix bugs found.
Signed-off-by: Han Xu <keepsimple@gmail.com>
2022-12-04 19:46:52 -08:00
Fintan Halpenny 858f13f871 Merge remote-tracking branch 'origin/surf/repo'
* origin/surf/repo:
  radicle-surf: refactor repo

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-30 14:22:52 +00:00
Fintan Halpenny 29f2ca337d Merge remote-tracking branch 'origin/surf/diff'
* origin/surf/diff:
  radicle-surf: refactor diff

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-30 14:22:41 +00:00
Fintan Halpenny dab5105eba Merge remote-tracking branch 'origin/surf/source'
* origin/surf/source:
  radicle-surf: remove view
  radicle-surf: remove syntax highlighting
  radicle-surf: rename serialize to serde
  radicle-surf: refactor source objects
  radicle-surf: source module

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-30 14:22:28 +00:00
Fintan Halpenny c06ce205f8 radicle-surf: refactor repo
To have a clear separation of which are public functions and which are
private functions, two `impl Repository` blocks are created.

This lead to some refactoring of names and inclusion of helper
functions, removing the need for the `git2_repo` function.

The `get_commit_stats` function seemed off, since the `Stats` in this
case are to do with the repository. Thus, it does not take a commit
anymore and instead uses the `head` commit to calculate the
repository's `Stats`.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-30 13:23:38 +00:00
Fintan Halpenny c316ce8d70 radicle-surf: refactor diff
This is an overhaul of the diff module. The major changes are as
follows.

It shouldn't be possible for an added or deleted file to have any
other kind line changes other than additions or deletions. So there
are now 3 different kinds of changes, Addition, Deletion, or
Modification.

Hunk and Hunks now take a generic type parameter to allow for the
three types of changes. As a consequence a FileDiff does the same.

For the actual file representations, they fill in their parameters as
Addition, Deletion, or Modification.

During this refactor some renaming was also made:
* CreateFile -> Added -- as well as the created field being renamed
to added.
* DeleteFile -> Deleted
* MoveFile -> Moved
* CopyFile -> Copied
* ModifiedFile -> Modified

The Stats are also now carried in the Diff instead of being
calculated. They can be retrieved from the `git2::Diff`.

The final change was to remove the `source::Commit::stats` field in
favour of accessing the `Diff::stats` instead.

The above changes mean that the serialization of `Diff` and `Commit`
are not backwards compatible.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-30 13:23:09 +00:00
Fintan Halpenny c0545f4fac radicle-surf: remove view
The View type is specific to Heartwood and was preemptively defined
when in fact it will not be used. YAGNI.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-30 13:22:44 +00:00
Fintan Halpenny 59d2508392 radicle-surf: remove syntax highlighting
Remove the syntax feature flag and any of the syntax highlighting
logic. This is not required any more from the clients implementation
and so we minimise this codebase in favour of any downstream dependent
to define how they highlight the blob's content.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-30 13:22:44 +00:00
Fintan Halpenny 3284149bd6 radicle-surf: rename serialize to serde
Instead of creating a named feature flag, opt for using the `serde`
package name as the feature flag name. This makes it more clear that
the feature is only enabling serde serialization and nothing else.

This patch also cleans up the testing flags by removing the serialize
flag for testing, as this should just always be tested, and also adds
the syntax flag for future testing.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-30 13:22:44 +00:00
Fintan Halpenny b4d3bf69cf radicle-surf: refactor source objects
Refactor the source data types to reuse existing logic and update to
the latest protocol.

The `Blob` and `Tree` data types are updated to be backed by `File`
and `Directory` respectively. This allows the construction of them to
be much simpler and reuse any existing logic on those types. This also
lead to the removal of `ObjectType` and `Info`.

The `Revision` type was removed in favour of using the `Revision`
trait.

The `Revisions` type was renamed to `View`, while also renaming the
`revision` module to `view`. A `View` is a simple encoding of what a
peer's "view" would look like, i.e. what references do they have. This
also required the introduction of getting free-form categories in the
reference db, i.e. `refs/<category>`, and so a `Categories` iterator
was also introduced.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-30 13:22:44 +00:00
Fintan Halpenny 02321aba7c radicle-surf: source module
This is a straightforward move of all the code source browsing modules
into a module called `source`.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-30 13:22:43 +00:00
Fintan Halpenny 5b6b447a96 Merge remote-tracking branch 'origin/surf/infallible-glob'
* origin/surf/infallible-glob:
  radicle-link: refactor glob

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-30 12:53:09 +00:00
Fintan Halpenny 80e1ce3059 Merge remote-tracking branch 'origin/fix/git-commit'
* origin/fix/git-commit:
  git-commit: fix to lack of newline separation

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-30 12:52:09 +00:00
Fintan Halpenny 295b0d25e5 git-commit: fix to lack of newline separation
There was an issue where the trailers were not properly separated from
the commit message itself. In fact, a new line is not added if there
are not trailers either.

Add a fix to add a newline after the commit message. Also adding test
cases to test 0, 1, or 2 trailers in a git commit.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-28 10:07:08 +00:00
Fintan Halpenny d7b5186d8c radicle-link: refactor glob
This patch changes the glob module in a couple of ways, outlined
below.

The first change is the use of PatternString in the constructor
functions. This removes the fallibility of the constructors. This
meant that the tests changed to use the `pattern!` macro instead.

The second change is splitting out the `Glob<Branch>` methods into
`Glob<Local>` and `Glob<Remote>`. This means that the local and remote
globs can be constructed separately, and are then combined via the
`branches` and `and` methods.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-24 12:38:28 +00:00
Fintan Halpenny 0d32904d27 Merge remote-tracking branch 'origin/surf/remove-manual-diff'
* origin/surf/remove-manual-diff:
  radicle-surf: remove diff function

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-24 12:32:57 +00:00
Fintan Halpenny 2061f7777a Merge remote-tracking branch 'origin/surf/organise-tests'
* origin/surf/organise-tests:
  radicle-surf: organise tests

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-24 12:29:49 +00:00
Fintan Halpenny 0ad95dbdfe Merge remote-tracking branch 'origin/std-path'
* origin/std-path:
  radicle-surf: remove file_system::path

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-24 12:29:15 +00:00
Fintan Halpenny b173483fa9 radicle-surf: remove diff function
Remove the `Diff::diff` as it is unused.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-24 12:28:19 +00:00
Fintan Halpenny a4ec9e07e1 radicle-surf: organise tests
Reorganise the tests into module files, rather than all being in a
single file. No tests were changed in this patch.

The `serialize` flag was also not enabled in `test/Cargo.toml`. This
is enabled to ensure those tests are run moving forward.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-24 12:25:31 +00:00
Fintan Halpenny d657572dfd radicle-surf: remove file_system::path
The file_system types, Label & Path, are overengineered. It's more
natural to use the Path and PathBuf types provided by the std library.

This replaces any mention of Label with String and any use of the old
Path with either std::path::Path or std::path::PathBuf, depending on
what kind of ownwership is needed.

Anywhere a "root" directory is needed `PathBuf::new()` is used,
i.e. an empty `PathBuf`. Otherwise `Path::new` can used to pass
directory, or in fact a &str can also be used since it implements
AsRef<Path>.

The `File` and `Directory` types also contain there relative paths,
which can be retrieved while traversing the Tree.

Note the special file name `"special/faux\\path"` requires the use of an
escaping string construction, i.e. `r"special/faux\\path"`.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-24 12:08:44 +00:00
Fintan Halpenny 887cdc8010 Merge remote-tracking branch 'origin/directory-generic'
* origin/directory-generic:
  radicle-surf: refactor directory

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-24 12:01:57 +00:00
Fintan Halpenny a549eccd08 radicle-surf: refactor directory
This patch applies some refactoring to the directory module. It
applies some renaming and adds some useful methods to the `File` and
`Directory` types.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-24 12:01:39 +00:00
Fintan Halpenny aad5f04aef Merge remote-tracking branch 'origin/cargo/clean-up'
* origin/cargo/clean-up:
  meta: clean up cargo dependencies

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-24 11:59:23 +00:00
Fintan Halpenny 9c80fb06a7 meta: clean up cargo dependencies
The aim of this patch is to solve some of the `cargo deny`
warnings. This required updating some dependencies. Some dependencies
of radicle-surf were not used, so they were outright removed.

The last_commit benchmark in radicle-surf is irrelevant as we use more
efficient methods for getting repository histories, so it has been
removed.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-24 11:26:32 +00:00
Han Xu c44348fc3c Remove RepositoryRef type and simply use &Repository.
Signed-off-by: Han Xu <keepsimple@gmail.com>
2022-11-24 11:23:42 +00:00
Fintan Halpenny d3115a2215 Merge remote-tracking branch 'origin/git-ref/remove-link-feature'
* origin/git-ref/remove-link-feature:
  git-ref-format: remove link-literals feature

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-21 09:29:04 +00:00
Fintan Halpenny d45d63b7ce git-ref-format: remove link-literals feature
Since this package is not intended for radicle-link anymore, the
feature flag and the literals are removed.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-18 15:45:08 +00:00