Commit Graph
293 Commits
Author SHA1 Message Date
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
Fintan Halpenny 93c13505bb Merge remote-tracking branch 'origin/surf/iter-names'
* origin/surf/iter-names:
  radicle-surf: use specialised iterators for names

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-18 11:33:30 +00:00
Fintan Halpenny d17cb3a8d3 radicle-surf: use specialised iterators for names
The `tag_names` and `branch_names` functions use the `Tags` and
`Branches` functions which require to go through their `TryFrom`
instances. This can be expensive, in the case of `Tags` especially.

Add `TagNames` and `BranchNames` iterators that only return the names
of the tags and branches, respectively.

This requires to change the definition of Revisions, where the
NonEmpty branch list is now foregone and there references are
collected in a BTreeSet to ensure ordering.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-18 11:21:06 +00:00
Fintan Halpenny 08c311b640 Merge remote-tracking branch 'origin/surf/git-ref-namespaces'
* origin/surf/git-ref-namespaces:
  radicle-surf: add short_name methods
  radicle-surf: Namespace using RefString
  git-ref-format: add well-known refspec components
  git-ref-format: fix typo in documentation
  git-ref-format: DoubleEndedIterator for Components
  git-ref-format: add QualifiedPattern and NamespacedPattern

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-18 11:20:30 +00:00
Fintan Halpenny 9f1302649c radicle-surf: add short_name methods
Add `short_name` methods to `Branch`, `Local`, `Remote`, and `Tag` to
get the short version of the reference name.

Also adds a `remote` method to `Remote`.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-18 11:20:08 +00:00
Fintan Halpenny 1ac99ac456 radicle-surf: Namespace using RefString
A `Namespace` is a '/' separated list of components, where each
component represents another level of the namespaces hierarchy. Notice
that a `RefString` is also a '/' separated list of components, thus it
could be reused to define a `Namespace`.

This change uses this observation and reworks `Namespace` to be backed
by a `RefString`.

This naturally leads to defining its helper functions to return
`Namespaced` and `NamespacedPattern` reference names. They are
reworked to take a `Qualified` for regular reference names and
`QualifiedPattern` for refspec names, respectively.

This leads to changing the backing vector of `Glob` to use
`QualifiedPattern` instead of `PatternString`.

While changing `Glob`, it was also noticed that the PhantomData was
not used correctly -- all `impl`s used a generic parameter. This was
changed to use the `Namespace`, `Tag`, and `Branch` types directly,
providing the type-safety that would be expected.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-18 11:13:37 +00:00
Fintan Halpenny 2b5a34a703 git-ref-format: add well-known refspec components
Add constants for well-known refspec component names.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-18 10:49:22 +00:00
Fintan Halpenny a4fc3db933 git-ref-format: fix typo in documentation
Fixes small typo in documentation of `and` function.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-18 10:49:22 +00:00
Fintan Halpenny cf1594cf43 git-ref-format: DoubleEndedIterator for Components
Add DoubleEndedIterator implementations for the two Components
iterators.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-18 10:49:22 +00:00
Fintan Halpenny 6479ba091f git-ref-format: add QualifiedPattern and NamespacedPattern
There was no mechanism for building refspec patterns that included
namespaces.

To get around this limitation, QualifiedPattern and NamespacedPattern
are added to the refspec module.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-18 10:49:22 +00:00
Fintan Halpenny b98c9aac03 Merge remote-tracking branch 'origin/surf/rework-errors'
* origin/surf/rework-errors:
  radicle-surf: reorganise errors

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-18 10:47:49 +00:00
Fintan Halpenny 42093a2fe1 radicle-surf: reorganise errors
The current `error::Error` type aggregated a lot of different error
scenarios that were not for the actual repo actions, instead they
would be for the domains that the repo actions would return.

This is a reorganisation of those by localising error variants in
their modules:
* namespace::Error
* commit::Error
* glob::Error
* adding `type Error` to ToCommit
* adding `type Error` to Revision

The main Error type now consists of these other Error types and lives
in the `repo` module. It is re-exported at the top-level since
RepositoryRef is the main interaction with the library.

During this refactor, some reorganisation of functions was done as
well:
* Move `get_file` from `Commit` to `RepositoryRef` as
`get_commit_file`.
* Have a blanket implementation of `ToCommit` for any `Revision`,
instead of repeating the implementations.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-18 10:39:15 +00:00
Fintan Halpenny 0d1bfb89a2 Merge remote-tracking branch 'origin/surf/git-ref-format'
* origin/surf/git-ref-format:
  radicle-surf: rework to use git-ref-format
  radicle-surf: move vcs::git to git
  radicle-surf: remove RefScope
  radicle-surf: remove deny pragma

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-18 10:29:45 +00:00
Fintan Halpenny 9b5ea4352f radicle-surf: rework to use git-ref-format
The aim of this commit is to better represent the reference names
using git-ref-format.

The first places to change were the Branch and Tag types. For Branch,
the previous types were simply wrappers around the names. They stay
this way, using RefString instead. For Tag, the `name` field is
replaced with RefString.
Note: The parsing logic becomes easier here by utilising the
Namespaced and Qualified types.

The consequences of these changes meant that areas that used
BranchName or TagName are changed to use RefString.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-18 10:18:11 +00:00
Fintan Halpenny c6c8fe3164 radicle-surf: move vcs::git to git
Other VCS systems are no longer expected to be supported.

Remove the git hierarchy up to the top-level and remove the vcs
hierarchy.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-18 10:09:43 +00:00
Fintan Halpenny 1649ff3e71 radicle-surf: remove RefScope
RefScope is no longer used, so it's removed.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-18 10:07:21 +00:00
Fintan Halpenny 42a8855dcd radicle-surf: remove deny pragma
This pragma gets in the way more than it solves anything.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-18 10:07:21 +00:00
Fintan Halpenny 46257a8b14 Merge remote-tracking branch 'han/design-update'
* han/design-update:
  redesign Directory and File to be lightweight and lazy.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-18 09:49:21 +00:00
Fintan Halpenny 84d598b4db Merge remote-tracking branch 'origin/qualified-ref-import'
* origin/qualified-ref-import:
  git-ref-format: Component::from_refstr
  git-ref-format: import Qualified within macro

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-16 17:58:07 +00:00
Fintan Halpenny d6c7bb29ab git-ref-format: Component::from_refstr
Improve Component::from_refstring by redefining it as
Component::from_refstr. This allows the use of `RefStr` or `RefString`
instead of just RefString.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-16 13:47:22 +00:00
Fintan Halpenny 629191f55a git-ref-format: import Qualified within macro
If the `qualified` macro was used, the compiler would complain that it
required an import of `Qualified`.

Fixed by importing Qualified within the unsafe block of the definition
of `qualified`.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-16 13:40:48 +00:00
Han Xu dcefffaa3b redesign Directory and File to be lightweight and lazy.
- Added Oid into Directory and File.
- Moved file content and directory content out into their own.
- Lazily load directory content on-demand.
- Take advantage of git2::tree to retrieve an entry on-demand.

Also added a new example for browsing.

Signed-off-by: Han Xu <keepsimple@gmail.com>
2022-11-15 20:17:11 -08:00
Fintan Halpenny d7fb4ab984 Merge remote-tracking branch 'han/repo-open'
* han/repo-open:
  search parent directories in Repository

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-15 17:00:36 +00:00
Han Xu 520c97f03b search parent directories in Repository
- Replace the existing Repository::new() with ::open()
- Add Repository::discover() to support searching parent directories.

Signed-off-by: Han Xu <keepsimple@gmail.com>
2022-11-13 21:17:00 -08:00
Fintan Halpenny 55668e6e0f Merge remote-tracking branch 'han/ref-format'
* han/ref-format:
  Remove Ref, RefGlob and Rev, add Glob that uses git-ref-format.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-09 11:20:57 +00:00
Han Xu 35b9598a29 Remove Ref, RefGlob and Rev, add Glob that uses git-ref-format.
- Refactored branches(), tags(), namespaces().
- Added filtering for revision_branches().

Signed-off-by: Han Xu <keepsimple@gmail.com>
2022-11-07 14:33:16 -08:00
Fintan Halpenny b2d2bd172e Merge remote-tracking branch 'origin/fix/git-commit-trailer'
* origin/fix/git-commit-trailer:
  git-commit: fix for trailer handling

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-04 14:52:01 +00:00
Fintan Halpenny ae4e7bce59 git-commit: fix for trailer handling
If a Commit was constructed with trailers, they would not be added to
the buffer for committing.

Fix this by parsing the message by inspecting each line for a
potential trailer, if there is one then store it for later, otherwise
keep it as part of the message. This means that a message stays intact
even if a trailer that is expected to parse did not.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-04 14:45:10 +00:00
Fintan Halpenny fefe20343f git-commit: add a description field to Cargo.toml
Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-04 12:53:53 +00:00
Fintan Halpenny 1216dd0b42 Merge remote-tracking branch 'origin/git-commit'
* origin/git-commit:
  git-commit: add trailers to Commit
  git-commit: introduce git-commit crate

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-04 12:49:43 +00:00
Fintan Halpenny 9dec69a29a git-commit: add trailers to Commit
Add git trailers to the data of the Commit.

For convenience, git2 is used to extract the git trailers and they are
then converted to `OwnedTrailer`.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-04 12:33:17 +00:00
Fintan Halpenny 8745e46745 git-commit: introduce git-commit crate
Porting the commit code that is found in heartwood[0]. It represents a
parsed git commit object -- sans the id for the commit itself.

[0]: https://github.com/radicle-dev/heartwood/blob/16b22d9178fa6a1aaf2ecb01ec97e067399c5286/radicle/src/git.rs#L392-L575

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-04 12:33:17 +00:00
Fintan Halpenny 7fd402891f Merge remote-tracking branch 'origin/remove-multihash'
* origin/remove-multihash:
  radicle-git-ext: remove multihash and minicbor

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-04 12:32:44 +00:00
Fintan Halpenny 0728ee1f66 radicle-git-ext: remove multihash and minicbor
Multihash was deemed as not needed for compatibility since it is
possible to detect a change from SHA1 to SHA256 based on their encoded
lengths. The YAGNI principle is executed and multihash (and minicbor
while we're here) are removed.

This also had an effect on `Urn` which relied heavily on encoding the
value using multihash. The `urn` and `namespace` modules were removed
from radicle-git-types, since they were likely not going to be used
anyway.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-04 12:25:02 +00:00
Fintan Halpenny bf33be9220 Merge remote-tracking branch 'origin/nix/rust-1.65'
* origin/nix/rust-1.65:
  nix: update to rust-1.65

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-04 12:14:38 +00:00
Fintan Halpenny d349b18156 nix: update to rust-1.65
Update to rust-1.65[0].

All hail our new GATs overlord!

[0]: https://blog.rust-lang.org/2022/11/03/Rust-1.65.0.html

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-04 11:13:57 +00:00
Fintan Halpenny 7a82c404c4 Merge remote-tracking branch 'han/new-design-4'
* han/new-design-4:
  radicle-surf: refactor design: part 4

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-01 08:40:46 +00:00
Han Xu 97c930cd66 radicle-surf: refactor design: part 4
- Update design doc.
- Refactor History API.
- Use FromRevision and IntoCommit traits.
- Add more test cases.

Signed-off-by: Han Xu <keepsimple@gmail.com>
2022-10-31 22:58:20 -07:00
Fintan Halpenny e913628f0d Merge remote-tracking branch 'origin/trailer-improvements'
* origin/trailer-improvements:
  git-trailers: prepare git-trailers for publishing
  git-trailers: improve usage of OwnedTrailer

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-10-27 12:45:35 +01:00
Fintan Halpenny c6fe71d2e5 git-trailers: prepare git-trailers for publishing
Prepares git-trailers for publishing to crates.io by adding metadata
to the Cargo.toml.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-10-27 12:33:05 +01:00
Fintan Halpenny ddbdbea932 git-trailers: improve usage of OwnedTrailer
OwnedTrailer was lacking a Debug impl and access to its values.

Add a Debug derivation for OwnedTrailer and OwnedToken. Make token and
values public. Add Deref implementation for OwnedToken.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-10-27 11:46:59 +01:00
Fintan Halpenny ea0afc4993 Merge remote-tracking branch 'origin/storage-tests'
* origin/storage-tests:
  git-storage: add ODB tests

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-10-24 10:04:48 +01:00
Jorge Iglesias Garcia f6b72dce85 git-storage: add ODB tests
We add tests for ODB functionality, as well as a new `TreeBuilder`
Struct to make building git trees easier (see below).

The `git2::TreeBuilder` can be a pain to use since it has a lifetime
that is tied to the `git2::Repository`. This was causing issues when
trying to write generators for property tests.

Instead, define a custom TreeBuilder which is a defunctionalised list
operations that represent the `insert` and `remove` methods on
`git2::TreeBuilder`.

The implementation of writing a tree then becomes converting the
custom `TreeBuilder` into a `git2::TreeBuilder`.

Signed-off-by: Jorge Iglesias Garcia <me@jorgeig.com>
2022-10-24 16:52:56 +08:00
Fintan Halpenny 7fe6993624 Merge remote-tracking branch 'han/new-design-3'
* han/new-design-3:
  radicle-surf: refactor the design: part 3

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-10-19 10:32:30 +01:00
Han Xu a4bc76f2ea radicle-surf: refactor the design: part 3
- Detect renames in Diff by default.
- Remove Vcs trait.
- Move `history()` to be a regular method of RepositoryRef.
- Update design doc.

Signed-off-by: Han Xu <keepsimple@gmail.com>
2022-10-18 22:31:38 -07:00