Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

Commit

Permalink
feat: switch to new surf revparser (#152)
Browse files Browse the repository at this point in the history
This avoids brittle chaining and is closer to the underlying git2
mechanisms.

Closes #139

* Please @FintanH
  • Loading branch information
xla authored and rudolfs committed Mar 4, 2020
1 parent 196ab71 commit 44606dd
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 88 deletions.
46 changes: 32 additions & 14 deletions proxy/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@ warp = "0.1"

[dependencies.librad]
git = "https://github.com/radicle-dev/radicle-link.git"
rev = "0034bd0fca27596b6fd2982ec875daa426ded120"
rev = "4cedafaeb46deee4ec11d0e4b779a1a0d124d599"

[dependencies.radicle-registry-client]
git = "https://github.com/radicle-dev/radicle-registry.git"
rev = "8689536f7e30d5e4839141658d2357e2cc550755"

[dependencies.radicle-surf]
version = "0.2"

[dev-dependencies]
indexmap = "1.3"
pretty_assertions = "0.6"
50 changes: 17 additions & 33 deletions proxy/src/coco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use librad::meta::{self, common::Url};
use librad::paths::Paths;
use librad::peer;
use librad::project;
use radicle_surf as surf;
use radicle_surf::git::git2;
use librad::surf;
use librad::surf::git::git2;

use crate::error;

Expand Down Expand Up @@ -158,21 +158,14 @@ pub fn blob(paths: &Paths, id: &str, revision: &str, path: &str) -> Result<Blob,
};

// Best effort to guess the revision.
if browser
.branch(surf::git::BranchName::new(revision))
.or(browser.commit(surf::git::Sha1::new(revision)))
.or(browser.tag(surf::git::TagName::new(revision)))
.is_err()
{
return Err(error::Error::Git(surf::git::error::Error::NotBranch));
};
browser.revspec(revision)?;

let root = browser.get_directory()?;

let mut p = surf::file_system::Path::from_str(path)?;

let file = root.find_file(&p).ok_or_else(|| {
radicle_surf::file_system::error::Error::Path(radicle_surf::file_system::error::Path::Empty)
surf::file_system::error::Error::Path(surf::file_system::error::Path::Empty)
})?;

let mut commit_path = surf::file_system::Path::root();
Expand All @@ -188,7 +181,7 @@ pub fn blob(paths: &Paths, id: &str, revision: &str, path: &str) -> Result<Blob,
Ok(Blob {
content,
info: Info {
name: last.label,
name: last.to_string(),
object_type: ObjectType::Blob,
last_commit,
},
Expand All @@ -211,7 +204,7 @@ pub fn branches(paths: &Paths, id: &str) -> Result<Vec<Branch>, error::Error> {
.list_branches(None)
.expect("Getting branches failed")
.into_iter()
.map(|b| Branch(b.name.name()))
.map(|b| Branch(b.name.name().to_string()))
.collect::<Vec<Branch>>();

branches.sort();
Expand All @@ -230,7 +223,7 @@ pub fn local_branches(repo_path: &str) -> Result<Vec<Branch>, error::Error> {
let mut branches = browser
.list_branches(None)?
.into_iter()
.map(|b| Branch(b.name.name()))
.map(|b| Branch(b.name.name().to_string()))
.collect::<Vec<Branch>>();

branches.sort();
Expand All @@ -250,10 +243,10 @@ pub fn commit(paths: &Paths, id: &str, sha1: &str) -> Result<Commit, error::Erro
project::Project::Git(git_project) => git_project.browser()?,
};

browser.commit(radicle_surf::git::Sha1::new(sha1))?;
browser.commit(surf::git::Oid::from_str(sha1)?)?;

let history = browser.get_history();
let commit = history.0.first();
let history = browser.get();
let commit = history.first();

Ok(Commit::from(commit))
}
Expand All @@ -274,7 +267,7 @@ pub fn tags(paths: &Paths, id: &str) -> Result<Vec<Tag>, error::Error> {

let mut tags: Vec<Tag> = tag_names
.into_iter()
.map(|tag_name| Tag(tag_name.name()))
.map(|tag_name| Tag(tag_name.name().to_string()))
.collect();

tags.sort();
Expand All @@ -295,14 +288,7 @@ pub fn tree(paths: &Paths, id: &str, revision: &str, prefix: &str) -> Result<Tre
project::Project::Git(git_project) => git_project.browser()?,
};

if browser
.branch(surf::git::BranchName::new(revision))
.or(browser.commit(surf::git::Sha1::new(revision)))
.or(browser.tag(surf::git::TagName::new(revision)))
.is_err()
{
return Err(error::Error::Git(surf::git::error::Error::NotBranch));
};
browser.revspec(revision)?;

let mut path = if prefix == "/" || prefix == "" {
surf::file_system::Path::root()
Expand All @@ -315,9 +301,7 @@ pub fn tree(paths: &Paths, id: &str, revision: &str, prefix: &str) -> Result<Tre
root_dir
} else {
root_dir.find_directory(&path).ok_or_else(|| {
radicle_surf::file_system::error::Error::Path(
radicle_surf::file_system::error::Path::Empty,
)
surf::file_system::error::Error::Path(surf::file_system::error::Path::Empty)
})?
};
let mut prefix_contents = prefix_dir.list_directory();
Expand All @@ -329,8 +313,8 @@ pub fn tree(paths: &Paths, id: &str, revision: &str, prefix: &str) -> Result<Tre
let mut entry_path = if path.is_root() {
let label_path =
nonempty::NonEmpty::from_slice(&[label.clone()]).ok_or_else(|| {
radicle_surf::file_system::error::Error::Label(
radicle_surf::file_system::error::Label::Empty,
surf::file_system::error::Error::Label(
surf::file_system::error::Label::Empty,
)
})?;
surf::file_system::Path(label_path)
Expand Down Expand Up @@ -368,7 +352,7 @@ pub fn tree(paths: &Paths, id: &str, revision: &str, prefix: &str) -> Result<Tre
entries.sort_by(|a, b| a.info.object_type.cmp(&b.info.object_type));

let last_commit = if path.is_root() {
Some(Commit::from(browser.get_history().0.first()))
Some(Commit::from(browser.get().first()))
} else {
let mut commit_path = surf::file_system::Path::root();
commit_path.append(&mut path);
Expand All @@ -379,7 +363,7 @@ pub fn tree(paths: &Paths, id: &str, revision: &str, prefix: &str) -> Result<Tre
"".into()
} else {
let (_first, last) = path.split_last();
last.label
last.to_string()
};
let info = Info {
name,
Expand Down
10 changes: 5 additions & 5 deletions proxy/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Domain errors returned by the API.
use librad::meta::common::url;
use librad::surf;
use librad::surf::git::git2;
use radicle_registry_client::{DispatchError, Error as ProtocolError};
use radicle_surf as surf;
use radicle_surf::git::git2;
use std::time::SystemTimeError;

/// Project problems.
Expand All @@ -19,7 +19,7 @@ pub enum ProjectValidation {
#[derive(Debug)]
pub enum Error {
/// FileSystem errors from interacting with code in repository.
FS(radicle_surf::file_system::error::Error),
FS(surf::file_system::error::Error),
/// Originated from `radicle_surf`.
Git(surf::git::error::Error),
/// Originated from `radicle_surf::git::git2`.
Expand All @@ -46,8 +46,8 @@ pub enum Error {
Time(SystemTimeError),
}

impl From<radicle_surf::file_system::error::Error> for Error {
fn from(fs_error: radicle_surf::file_system::error::Error) -> Self {
impl From<surf::file_system::error::Error> for Error {
fn from(fs_error: surf::file_system::error::Error) -> Self {
Self::FS(fs_error)
}
}
Expand Down
Loading

0 comments on commit 44606dd

Please sign in to comment.