Commit Graph
110 Commits
Author SHA1 Message Date
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
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