mirror of
https://seed.radicle.dev/rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt.git
synced 2026-10-18 19:10:31 +08:00
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
This commit is contained in:
@@ -20,7 +20,6 @@ test = false
|
||||
doctest = false
|
||||
|
||||
[features]
|
||||
serialize = ["serde"]
|
||||
syntax = ["syntect", "lazy_static"]
|
||||
# NOTE: testing `test_submodule_failure` on GH actions
|
||||
# is painful since it uses this specific repo and expects
|
||||
@@ -32,7 +31,6 @@ gh-actions = []
|
||||
base64 = "0.13"
|
||||
log = "0.4"
|
||||
nonempty = "0.5"
|
||||
serde = { features = ["serde_derive"], optional = true, version = "1" }
|
||||
thiserror = "1.0"
|
||||
|
||||
[dependencies.git2]
|
||||
@@ -58,6 +56,11 @@ features = ["serde"]
|
||||
version = "0.1.0"
|
||||
path = "../radicle-std-ext"
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1"
|
||||
features = ["serde_derive"]
|
||||
optional = true
|
||||
|
||||
[dependencies.syntect]
|
||||
version = "5"
|
||||
optional = true
|
||||
|
||||
+18
-46
@@ -19,16 +19,12 @@
|
||||
|
||||
use std::{convert::TryFrom, path::PathBuf, slice};
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{ser, Serialize, Serializer};
|
||||
|
||||
pub mod git;
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
derive(Serialize),
|
||||
serde(rename_all = "camelCase")
|
||||
)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "camelCase"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Diff {
|
||||
pub created: Vec<CreateFile>,
|
||||
@@ -44,47 +40,35 @@ impl Default for Diff {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serialize", derive(Serialize))]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct CreateFile {
|
||||
pub path: PathBuf,
|
||||
pub diff: FileDiff,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serialize", derive(Serialize))]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct DeleteFile {
|
||||
pub path: PathBuf,
|
||||
pub diff: FileDiff,
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
derive(Serialize),
|
||||
serde(rename_all = "camelCase")
|
||||
)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "camelCase"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct MoveFile {
|
||||
pub old_path: PathBuf,
|
||||
pub new_path: PathBuf,
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
derive(Serialize),
|
||||
serde(rename_all = "camelCase")
|
||||
)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "camelCase"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct CopyFile {
|
||||
pub old_path: PathBuf,
|
||||
pub new_path: PathBuf,
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
derive(Serialize),
|
||||
serde(rename_all = "camelCase")
|
||||
)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "camelCase"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum EofNewLine {
|
||||
OldMissing,
|
||||
@@ -92,11 +76,7 @@ pub enum EofNewLine {
|
||||
BothMissing,
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
derive(Serialize),
|
||||
serde(rename_all = "camelCase")
|
||||
)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "camelCase"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct ModifiedFile {
|
||||
pub path: PathBuf,
|
||||
@@ -106,25 +86,21 @@ pub struct ModifiedFile {
|
||||
|
||||
/// A set of changes belonging to one file.
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
feature = "serde",
|
||||
derive(Serialize),
|
||||
serde(tag = "type", rename_all = "camelCase")
|
||||
)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum FileDiff {
|
||||
Binary,
|
||||
#[cfg_attr(feature = "serialize", serde(rename_all = "camelCase"))]
|
||||
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
|
||||
Plain {
|
||||
hunks: Hunks,
|
||||
},
|
||||
}
|
||||
|
||||
/// Statistics describing a particular [`Diff`].
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
derive(Serialize),
|
||||
serde(rename_all = "camelCase")
|
||||
)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "camelCase"))]
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct Stats {
|
||||
/// Get the total number of files changed in a diff.
|
||||
@@ -136,11 +112,7 @@ pub struct Stats {
|
||||
}
|
||||
|
||||
/// A set of line changes.
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
derive(Serialize),
|
||||
serde(rename_all = "camelCase")
|
||||
)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "camelCase"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Hunk {
|
||||
pub header: Line,
|
||||
@@ -148,7 +120,7 @@ pub struct Hunk {
|
||||
}
|
||||
|
||||
/// A set of [`Hunk`]s.
|
||||
#[cfg_attr(feature = "serialize", derive(Serialize))]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
pub struct Hunks(pub Vec<Hunk>);
|
||||
|
||||
@@ -215,7 +187,7 @@ impl From<String> for Line {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
#[cfg(feature = "serde")]
|
||||
impl Serialize for Line {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -230,22 +202,22 @@ impl Serialize for Line {
|
||||
/// Single line delta. Two of these are need to represented a modified line: one
|
||||
/// addition and one deletion. Context is also represented with this type.
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
feature = "serde",
|
||||
derive(Serialize),
|
||||
serde(tag = "type", rename_all = "camelCase")
|
||||
)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum LineDiff {
|
||||
/// Line added.
|
||||
#[cfg_attr(feature = "serialize", serde(rename_all = "camelCase"))]
|
||||
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
|
||||
Addition { line: Line, line_num: u32 },
|
||||
|
||||
/// Line deleted.
|
||||
#[cfg_attr(feature = "serialize", serde(rename_all = "camelCase"))]
|
||||
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
|
||||
Deletion { line: Line, line_num: u32 },
|
||||
|
||||
/// Line context.
|
||||
#[cfg_attr(feature = "serialize", serde(rename_all = "camelCase"))]
|
||||
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
|
||||
Context {
|
||||
line: Line,
|
||||
line_num_old: u32,
|
||||
|
||||
@@ -20,7 +20,7 @@ use std::{convert::TryFrom, str};
|
||||
use git_ext::Oid;
|
||||
use thiserror::Error;
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
@@ -34,7 +34,7 @@ pub enum Error {
|
||||
}
|
||||
|
||||
/// `Author` is the static information of a [`git2::Signature`].
|
||||
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))]
|
||||
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct Author {
|
||||
/// Name of the author.
|
||||
@@ -43,7 +43,7 @@ pub struct Author {
|
||||
pub email: String,
|
||||
/// Time the action was taken, e.g. time of commit.
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
feature = "serde",
|
||||
serde(
|
||||
serialize_with = "serialize_time",
|
||||
deserialize_with = "deserialize_time"
|
||||
@@ -52,7 +52,7 @@ pub struct Author {
|
||||
pub time: git2::Time,
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
#[cfg(feature = "serde")]
|
||||
fn deserialize_time<'de, D>(deserializer: D) -> Result<git2::Time, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
@@ -61,7 +61,7 @@ where
|
||||
Ok(git2::Time::new(seconds, 0))
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
#[cfg(feature = "serde")]
|
||||
fn serialize_time<S>(t: &git2::Time, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
@@ -100,7 +100,7 @@ impl<'repo> TryFrom<git2::Signature<'repo>> for Author {
|
||||
/// `Commit` is the static information of a [`git2::Commit`]. To get back the
|
||||
/// original `Commit` in the repository we can use the [`Oid`] to retrieve
|
||||
/// it.
|
||||
#[cfg_attr(feature = "serialize", derive(Deserialize))]
|
||||
#[cfg_attr(feature = "serde", derive(Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct Commit {
|
||||
/// Object Id
|
||||
@@ -129,7 +129,7 @@ impl Commit {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
#[cfg(feature = "serde")]
|
||||
impl Serialize for Commit {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
|
||||
@@ -17,15 +17,11 @@
|
||||
|
||||
pub use radicle_git_ext::Oid;
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::Serialize;
|
||||
|
||||
/// Stats for a repository
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
derive(Serialize),
|
||||
serde(rename_all = "camelCase")
|
||||
)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "camelCase"))]
|
||||
pub struct Stats {
|
||||
/// Number of commits
|
||||
pub commits: usize,
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use git_ref_format::RefString;
|
||||
#[cfg(feature = "serialize")]
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{
|
||||
ser::{SerializeStruct as _, Serializer},
|
||||
Serialize,
|
||||
@@ -35,7 +35,7 @@ use crate::{
|
||||
use radicle_git_ext::Oid;
|
||||
|
||||
/// Commit statistics.
|
||||
#[cfg_attr(feature = "serialize", derive(Serialize))]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[derive(Clone)]
|
||||
pub struct Stats {
|
||||
/// Additions.
|
||||
@@ -45,7 +45,7 @@ pub struct Stats {
|
||||
}
|
||||
|
||||
/// Representation of a changeset between two revs.
|
||||
#[cfg_attr(feature = "serialize", derive(Serialize))]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
#[derive(Clone)]
|
||||
pub struct Commit {
|
||||
/// The commit header.
|
||||
@@ -114,7 +114,7 @@ impl From<git::Commit> for Header {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
#[cfg(feature = "serde")]
|
||||
impl Serialize for Header {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -132,7 +132,7 @@ impl Serialize for Header {
|
||||
}
|
||||
|
||||
/// A selection of commit headers and their statistics.
|
||||
#[cfg_attr(feature = "serialize", derive(Serialize))]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize))]
|
||||
pub struct Commits {
|
||||
/// The commit headers
|
||||
pub headers: Vec<Header>,
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
use std::{path::Path, str};
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{
|
||||
ser::{SerializeStruct as _, Serializer},
|
||||
Serialize,
|
||||
@@ -97,7 +97,7 @@ impl Blob {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
#[cfg(feature = "serde")]
|
||||
impl Serialize for Blob {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -130,7 +130,7 @@ pub enum BlobContent {
|
||||
Binary(Vec<u8>),
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
#[cfg(feature = "serde")]
|
||||
impl Serialize for BlobContent {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{
|
||||
ser::{SerializeStruct as _, Serializer},
|
||||
Serialize,
|
||||
@@ -118,7 +118,7 @@ impl From<TreeEntry> for directory::Entry {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
#[cfg(feature = "serde")]
|
||||
impl Serialize for TreeEntry {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
|
||||
@@ -17,12 +17,9 @@
|
||||
|
||||
//! Represents a person in a repo.
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
use serde::Serialize;
|
||||
|
||||
/// Representation of a person (e.g. committer, author, signer) from a
|
||||
/// repository. Usually extracted from a signature.
|
||||
#[cfg_attr(feature = "serialize", derive(Serialize))]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Person {
|
||||
/// Name part of the commit signature.
|
||||
|
||||
@@ -10,7 +10,6 @@ publish = false
|
||||
test = true
|
||||
|
||||
[features]
|
||||
serialize = []
|
||||
test = []
|
||||
|
||||
[dev-dependencies]
|
||||
@@ -37,7 +36,7 @@ path = "../../radicle-git-ext"
|
||||
|
||||
[dev-dependencies.radicle-surf]
|
||||
path = ".."
|
||||
features = ["serialize"]
|
||||
features = ["serde", "syntax"]
|
||||
|
||||
[dev-dependencies.test-helpers]
|
||||
path = "../../test/test-helpers"
|
||||
|
||||
@@ -5,12 +5,10 @@
|
||||
|
||||
const GIT_PLATINUM: &str = "../data/git-platinum";
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
#[cfg(test)]
|
||||
mod branch;
|
||||
#[cfg(test)]
|
||||
mod code_browsing;
|
||||
#[cfg(feature = "serialize")]
|
||||
#[cfg(test)]
|
||||
mod commit;
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -5,7 +5,6 @@ use radicle_git_ext::Oid;
|
||||
use radicle_surf::git::{Author, Commit};
|
||||
use test_helpers::roundtrip;
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
proptest! {
|
||||
#[test]
|
||||
fn prop_test_commits(commit in commits_strategy()) {
|
||||
|
||||
@@ -122,7 +122,6 @@ fn test_branch_diff() -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
#[test]
|
||||
fn test_diff_serde() {
|
||||
use radicle_surf::diff::{Hunks, MoveFile};
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ features = ["test"]
|
||||
|
||||
[dev-dependencies.radicle-surf-test]
|
||||
path = "../radicle-surf/t"
|
||||
features = ["serialize", "test"]
|
||||
features = ["test"]
|
||||
|
||||
[dev-dependencies.git-storage-test]
|
||||
path = "../git-storage/t"
|
||||
|
||||
Reference in New Issue
Block a user