From d957f0b1c27bd881e552e270f54cddf7eff8b44d Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Wed, 14 Dec 2022 10:35:57 +0000 Subject: [PATCH] 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 X-Clacks-Overhead: GNU Terry Pratchett --- radicle-surf/src/source/commit.rs | 2 +- radicle-surf/src/source/object/blob.rs | 2 +- radicle-surf/src/source/object/tree.rs | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/radicle-surf/src/source/commit.rs b/radicle-surf/src/source/commit.rs index 927718a..048a70b 100644 --- a/radicle-surf/src/source/commit.rs +++ b/radicle-surf/src/source/commit.rs @@ -47,7 +47,7 @@ pub struct Commit { } /// Representation of a code commit. -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct Header { /// Identifier of the commit in the form of a sha1 hash. Often referred to /// as oid or object id. diff --git a/radicle-surf/src/source/object/blob.rs b/radicle-surf/src/source/object/blob.rs index c3f95ad..281ef93 100644 --- a/radicle-surf/src/source/object/blob.rs +++ b/radicle-surf/src/source/object/blob.rs @@ -103,7 +103,7 @@ impl Serialize for Blob { state.serialize_field("content", &self.content)?; state.serialize_field("lastCommit", &self.commit)?; state.serialize_field("name", &self.file.name())?; - state.serialize_field("path", &self.file.location())?; + state.serialize_field("path", &self.file.path())?; state.end() } } diff --git a/radicle-surf/src/source/object/tree.rs b/radicle-surf/src/source/object/tree.rs index ef70379..40e5a4b 100644 --- a/radicle-surf/src/source/object/tree.rs +++ b/radicle-surf/src/source/object/tree.rs @@ -33,6 +33,7 @@ use crate::{ }; /// Result of a directory listing, carries other trees and blobs. +#[derive(Clone, Debug)] pub struct Tree { pub directory: Directory, pub commit: Option, @@ -95,7 +96,7 @@ impl Serialize for Tree { state.serialize_field("entries", &self.entries)?; state.serialize_field("lastCommit", &self.commit)?; state.serialize_field("name", &self.directory.name())?; - state.serialize_field("path", &self.directory.location())?; + state.serialize_field("path", &self.directory.path())?; state.end() } } @@ -126,14 +127,14 @@ impl Serialize for TreeEntry { { const FIELDS: usize = 4; let mut state = serializer.serialize_struct("TreeEntry", FIELDS)?; - state.serialize_field("path", &self.entry.location())?; + state.serialize_field("path", &self.entry.path())?; state.serialize_field("name", &self.entry.name())?; state.serialize_field("lastCommit", &None::)?; state.serialize_field( "kind", match self.entry { directory::Entry::File(_) => "blob", - directory::Entry::Directory(_) => "directory", + directory::Entry::Directory(_) => "tree", }, )?; state.end()