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 <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny
2022-12-16 11:37:58 +00:00
parent 9df4291616
commit d957f0b1c2
3 changed files with 6 additions and 5 deletions
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -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()
}
}
+4 -3
View File
@@ -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<commit::Header>,
@@ -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::<commit::Header>)?;
state.serialize_field(
"kind",
match self.entry {
directory::Entry::File(_) => "blob",
directory::Entry::Directory(_) => "directory",
directory::Entry::Directory(_) => "tree",
},
)?;
state.end()