The `Odb::reader` method states:
Note that most backends do not support streaming reads because
they store their objects as compressed/delta’ed blobs. If the
backend does not support streaming reads, use the read method
instead.
This can lead to objects not being found when verifying for
commits. Instead use `read_header` to determine the `ObjectType` of
the `Oid`.
Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
During the reorganisation of the codebase, the constructors for Token
were removed.
Add back a constructor via the `TryFrom<&'a str>` trait.
Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
In an attempt to publish radicle-surf, it could not compile due to
git-ref-format supposedly missing.
This is an attempt to publish the git-ref-format family and
radicle-git-ext again in order to try publish radicle-surf.
Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
Adds several methods to Line:
* as_bytes -- gets the underlying bytes
* from_utf8 -- convert the Line to a String
* from_utf8_lossy -- convert Line to Cow<str>
Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
Updates all crates to the latest git2 version, 0.17.0.
Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
Move git-commit, git-trailers, and link-git to an archived directory
to hide them away -- showing the intent that radicle-git-ext will be
the main crate for git functionality.
Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
Update radicle-git-ext to version 0.3.0 for publishing to crates.io.
Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
The `Oid`s passed into `Commit::new` for parents and tree are never
verified to be commits or a tree, respectively.
Upon `write` of the commit, read the object using the ODB to determine
its type. If its the incorrect object then function fails without
writing to the ODB.
Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
A vulnerability in a transitive dependency, remove_dir_all, used by
tempfile was found[0].
Update tempfile to 3.4, which does not depend on remove_dir_all.
[0]: https://rustsec.org/advisories/RUSTSEC-2023-0018
Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
The git-trailers crate depends on parsing logic using nom. This is a
heavy dependency for something that can be done using git2.
Remove the dependency of git-trailers in git-commit and localise the
trailer types -- using git2 to parse the trailers out of the git
commit message.
Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
* han/rm-blob-content:
change BlobContent to BlobRef that borrows its content from git2::Blob
Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
Rust 1.67 was announced[0].
Update the nix sources to be on par with the latest rustc version.
This required fixes to clippy warnings for using variable
interpolation for format strings.
There was also an advisory error related to libgit2-sys[1], which is
transitively depended on via git2. The fix is included in the 0.16.1
version of git2.
[0]: https://blog.rust-lang.org/2023/01/26/Rust-1.67.0.html
[1]: https://rustsec.org/advisories/RUSTSEC-2023-0003
Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
There is an advisory error[0] relating to tokio which is transitively
brought in via deadpool.
Since git-storage is not currently used and heartwood is avoiding any
async runtimes, the pool module is removed.
[0]: https://rustsec.org/advisories/RUSTSEC-2023-0001.html
Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
The Error type is no longer used thanks to the clean up of the Tree
and Blob constructions now being exposed through Repository.
Remove the Error type and clean up the imports as a result.
Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
Comparing tree entries would only take into account their names. While
this is useful, it is also useful to compare by their entry kind
first, where trees take precedence over blobs.
A test is added to ensure the ordering is respected. While testing, it
was noticed that the entries aren't sorted when be passed in. When a
`Tree` is constructed it will now sort the entries first, ensure they
are given back in sorted order.
Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
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
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
* 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>
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Add constants for well-known refspec component names.
Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
Add DoubleEndedIterator implementations for the two Components
iterators.
Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
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
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