mirror of
https://seed.radicle.dev/rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt.git
synced 2026-11-28 21:50:27 +08:00
radicle-surf: an updated design
- A new design document. - Uses examples/diff.rs to test out some ideas. - Removes the type Browser. - Removes the type Snapshot.
This commit is contained in:
@@ -32,9 +32,10 @@ use serde::{
|
||||
use crate::{
|
||||
commit,
|
||||
file_system,
|
||||
git::RepositoryRef,
|
||||
object::{Error, Info, ObjectType},
|
||||
revision::Revision,
|
||||
vcs::git::{Browser, Rev},
|
||||
vcs::git::Rev,
|
||||
};
|
||||
|
||||
#[cfg(feature = "syntax")]
|
||||
@@ -118,18 +119,18 @@ impl Serialize for BlobContent {
|
||||
/// Will return [`Error`] if the project doesn't exist or a surf interaction
|
||||
/// fails.
|
||||
pub fn blob<P>(
|
||||
browser: &mut Browser,
|
||||
repo: &RepositoryRef,
|
||||
maybe_revision: Option<Revision<P>>,
|
||||
path: &str,
|
||||
) -> Result<Blob, Error>
|
||||
where
|
||||
P: ToString,
|
||||
{
|
||||
make_blob(browser, maybe_revision, path, content)
|
||||
make_blob(repo, maybe_revision, path, content)
|
||||
}
|
||||
|
||||
fn make_blob<P, C>(
|
||||
browser: &mut Browser,
|
||||
repo: &RepositoryRef,
|
||||
maybe_revision: Option<Revision<P>>,
|
||||
path: &str,
|
||||
content: C,
|
||||
@@ -139,11 +140,9 @@ where
|
||||
C: FnOnce(&[u8]) -> BlobContent,
|
||||
{
|
||||
let maybe_revision = maybe_revision.map(Rev::try_from).transpose()?;
|
||||
if let Some(revision) = maybe_revision {
|
||||
browser.rev(revision)?;
|
||||
}
|
||||
let revision = maybe_revision.unwrap();
|
||||
|
||||
let root = browser.get_directory()?;
|
||||
let root = repo.snapshot(&revision)?;
|
||||
let p = file_system::Path::from_str(path)?;
|
||||
|
||||
let file = root
|
||||
@@ -153,8 +152,8 @@ where
|
||||
let mut commit_path = file_system::Path::root();
|
||||
commit_path.append(p.clone());
|
||||
|
||||
let last_commit = browser
|
||||
.last_commit(commit_path)?
|
||||
let last_commit = repo
|
||||
.last_commit(commit_path, &revision)?
|
||||
.map(|c| commit::Header::from(&c));
|
||||
let (_rest, last) = p.split_last();
|
||||
|
||||
|
||||
@@ -29,9 +29,13 @@ use serde::{
|
||||
use crate::{
|
||||
commit,
|
||||
file_system,
|
||||
git::RepositoryRef,
|
||||
object::{Error, Info, ObjectType},
|
||||
revision::Revision,
|
||||
vcs::git::{Browser, Rev},
|
||||
vcs::{
|
||||
git::{Branch, Rev},
|
||||
Vcs,
|
||||
},
|
||||
};
|
||||
|
||||
/// Result of a directory listing, carries other trees and blobs.
|
||||
@@ -86,7 +90,7 @@ impl Serialize for TreeEntry {
|
||||
///
|
||||
/// Will return [`Error`] if any of the surf interactions fail.
|
||||
pub fn tree<P>(
|
||||
browser: &mut Browser<'_>,
|
||||
repo: &RepositoryRef,
|
||||
maybe_revision: Option<Revision<P>>,
|
||||
maybe_prefix: Option<String>,
|
||||
) -> Result<Tree, Error>
|
||||
@@ -96,9 +100,10 @@ where
|
||||
let maybe_revision = maybe_revision.map(Rev::try_from).transpose()?;
|
||||
let prefix = maybe_prefix.unwrap_or_default();
|
||||
|
||||
if let Some(revision) = maybe_revision {
|
||||
browser.rev(revision)?;
|
||||
}
|
||||
let rev = match maybe_revision {
|
||||
Some(r) => r,
|
||||
None => Branch::local("main").into(),
|
||||
};
|
||||
|
||||
let path = if prefix == "/" || prefix.is_empty() {
|
||||
file_system::Path::root()
|
||||
@@ -106,7 +111,7 @@ where
|
||||
file_system::Path::from_str(&prefix)?
|
||||
};
|
||||
|
||||
let root_dir = browser.get_directory()?;
|
||||
let root_dir = repo.snapshot(&rev)?;
|
||||
let prefix_dir = if path.is_root() {
|
||||
root_dir
|
||||
} else {
|
||||
@@ -155,7 +160,7 @@ where
|
||||
entries.sort_by(|a, b| a.info.object_type.cmp(&b.info.object_type));
|
||||
|
||||
let last_commit = if path.is_root() {
|
||||
Some(commit::Header::from(browser.get().first()))
|
||||
Some(commit::Header::from(repo.get_history(rev).unwrap().first()))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user