Struct radicle_surf::vcs::Browser[][src]

pub struct Browser<Repo, A, Error> { /* fields omitted */ }

A Browser is a way of rendering a History into a Directory snapshot, and the current History it is viewing.

Implementations

impl<'a> Browser<RepositoryRef<'a>, Commit, Error>[src]

pub fn new(
    repository: impl Into<RepositoryRef<'a>>,
    rev: impl Into<Rev>
) -> Result<Self, Error>
[src]

Create a new browser to interact with.

The revspec provided will be used to kick off the History for this Browser.

Errors

Examples

use radicle_surf::vcs::git::{Browser, Branch, Repository};

let repo = Repository::new("./data/git-platinum")?;
let browser = Browser::new(&repo, Branch::local("master"))?;

pub fn new_with_namespace(
    repository: impl Into<RepositoryRef<'a>>,
    namespace: &Namespace,
    rev: impl Into<Rev>
) -> Result<Self, Error>
[src]

Create a new Browser that starts in a given namespace.

Errors

Examples

use radicle_surf::vcs::git::{Browser, Repository, Branch, BranchSelector, BranchName, Namespace};
use std::convert::TryFrom;

let repo = Repository::new("./data/git-platinum")?;
let browser = Browser::new_with_namespace(
    &repo,
    &Namespace::try_from("golden")?,
    Branch::local("master")
)?;

let mut branches = browser.list_branches(BranchSelector::Local)?;
branches.sort();

assert_eq!(
    branches,
    vec![
        Branch::local("banana"),
        Branch::local("master"),
    ]
);

pub fn switch_namespace(
    self,
    namespace: &Namespace,
    rev: impl Into<Ref>
) -> Result<Self, Error>
[src]

Switch the namespace you are browsing in. This will consume the previous Browser and give you back a new Browser for that particular namespace. The revision provided will kick-off the history for this Browser.

pub fn which_namespace(&self) -> Result<Option<Namespace>, Error>[src]

What is the current namespace we’re browsing in.

pub fn head(&mut self) -> Result<(), Error>[src]

Set the current Browser history to the HEAD commit of the underlying repository.

Errors

Examples

use radicle_surf::vcs::git::{Browser, Repository, Branch};

let repo = Repository::new("./data/git-platinum")?;
let mut browser = Browser::new(&repo, Branch::local("master"))?;

// ensure we're at HEAD
browser.head();

let directory = browser.get_directory();

// We are able to render the directory
assert!(directory.is_ok());

pub fn branch(&mut self, branch: Branch) -> Result<(), Error>[src]

Set the current Browser’s History to the given BranchName provided.

Errors

Examples

use radicle_surf::vcs::git::{Branch, Browser, Repository};

let repo = Repository::new("./data/git-platinum")?;
let mut browser = Browser::new(&repo, Branch::local("master"))?;

// ensure we're on 'master'
browser.branch(Branch::local("master"));

let directory = browser.get_directory();

// We are able to render the directory
assert!(directory.is_ok());
use radicle_surf::vcs::git::{Branch, Browser, Repository};
use radicle_surf::file_system::{Label, Path, SystemType};
use radicle_surf::file_system::unsound;

let repo = Repository::new("./data/git-platinum")?;
let mut browser = Browser::new(&repo, Branch::local("master"))?;
browser.branch(Branch::remote("dev", "origin"))?;

let directory = browser.get_directory()?;
let mut directory_contents = directory.list_directory();
directory_contents.sort();

assert!(directory_contents.contains(
    &SystemType::file(unsound::label::new("here-we-are-on-a-dev-branch.lol"))
));

pub fn tag(&mut self, tag_name: TagName) -> Result<(), Error>[src]

Set the current Browser’s History to the TagName provided.

Errors

Examples

use nonempty::NonEmpty;
use radicle_surf::vcs::History;
use radicle_surf::vcs::git::{TagName, Branch, Browser, Oid, Repository};

let repo = Repository::new("./data/git-platinum")?;
let mut browser = Browser::new(&repo, Branch::local("master"))?;

// Switch to "v0.3.0"
browser.tag(TagName::new("v0.3.0"))?;

let expected_history = History(NonEmpty::from((
    Oid::from_str("19bec071db6474af89c866a1bd0e4b1ff76e2b97")?,
    vec![
        Oid::from_str("f3a089488f4cfd1a240a9c01b3fcc4c34a4e97b2")?,
        Oid::from_str("2429f097664f9af0c5b7b389ab998b2199ffa977")?,
        Oid::from_str("d3464e33d75c75c99bfb90fa2e9d16efc0b7d0e3")?,
    ]
)));

let history_ids = browser.get().map(|commit| commit.id);

// We are able to render the directory
assert_eq!(history_ids, expected_history);

pub fn commit(&mut self, oid: Oid) -> Result<(), Error>[src]

Set the current Browser’s History to the Oid (SHA digest) provided.

Errors

Examples

use radicle_surf::file_system::{Label, SystemType};
use radicle_surf::file_system::unsound;
use radicle_surf::vcs::git::{Branch, Browser, Oid, Repository};
use std::str::FromStr;

let repo = Repository::new("./data/git-platinum")?;
let mut browser = Browser::new(&repo, Branch::local("master"))?;

// Set to the initial commit
let commit = Oid::from_str("e24124b7538658220b5aaf3b6ef53758f0a106dc")?;

browser.commit(commit)?;

let directory = browser.get_directory()?;
let mut directory_contents = directory.list_directory();

assert_eq!(
    directory_contents,
    vec![
        SystemType::file(unsound::label::new("README.md")),
        SystemType::directory(unsound::label::new("bin")),
        SystemType::directory(unsound::label::new("src")),
        SystemType::directory(unsound::label::new("this")),
    ]
);

pub fn rev(&mut self, rev: impl Into<Rev>) -> Result<(), Error>[src]

Set a Browser’s History based on a revspec.

Errors

Examples

use radicle_surf::file_system::{Label, SystemType};
use radicle_surf::file_system::unsound;
use radicle_surf::vcs::git::{Browser, Branch, Oid, Repository};
use std::str::FromStr;

let repo = Repository::new("./data/git-platinum")?;
let mut browser = Browser::new(&repo, Branch::local("master"))?;

browser.rev(Branch::remote("dev", "origin"))?;

let directory = browser.get_directory()?;
let mut directory_contents = directory.list_directory();
directory_contents.sort();

assert!(directory_contents.contains(
    &SystemType::file(unsound::label::new("here-we-are-on-a-dev-branch.lol"))
));

pub fn oid(&self, oid: &str) -> Result<Oid, Error>[src]

Parse an Oid from the given string. This is useful if we have a shorthand version of the Oid, as opposed to the full one.

Examples

use radicle_surf::vcs::git::{Branch, Browser, Oid, Repository};
use std::str::FromStr;

let repo = Repository::new("./data/git-platinum")?;
let mut browser = Browser::new(&repo, Branch::local("master"))?;

// Set to the initial commit
let commit = Oid::from_str("e24124b7538658220b5aaf3b6ef53758f0a106dc")?;

assert_eq!(
    commit,
    browser.oid("e24124b")?,
);

pub fn diff(&self, from: Oid, to: Oid) -> Result<Diff, Error>[src]

Get the Diff between two commits.

pub fn initial_diff(&self, oid: Oid) -> Result<Diff, Error>[src]

Get the Diff of a commit with no parents.

pub fn list_branches(
    &self,
    filter: BranchSelector
) -> Result<Vec<Branch>, Error>
[src]

List the names of the branches that are contained in the underlying Repository.

Errors

Examples

use radicle_surf::vcs::git::{Branch, BranchSelector, BranchName, Browser, Namespace, Repository};
use std::convert::TryFrom;

let repo = Repository::new("./data/git-platinum")?;
let mut browser = Browser::new(&repo, Branch::local("master"))?;

let branches = browser.list_branches(BranchSelector::All)?;

// 'master' exists in the list of branches
assert!(branches.contains(&Branch::local("master")));

// Filter the branches by `Remote` 'origin'.
let mut branches = browser.list_branches(BranchSelector::Remote {
    name: Some("origin".to_string())
})?;
branches.sort();

assert_eq!(branches, vec![
    Branch::remote("HEAD", "origin"),
    Branch::remote("dev", "origin"),
    Branch::remote("master", "origin"),
]);

// Filter the branches by all `Remote`s.
let mut branches = browser.list_branches(BranchSelector::Remote {
    name: None
})?;
branches.sort();

assert_eq!(branches, vec![
    Branch::remote("HEAD", "origin"),
    Branch::remote("dev", "origin"),
    Branch::remote("master", "origin"),
    Branch::remote("pineapple", "banana"),
]);

// We can also switch namespaces and list the branches in that namespace.
let golden = browser.switch_namespace(&Namespace::try_from("golden")?, Branch::local("master"))?;

let mut branches = golden.list_branches(BranchSelector::Local)?;
branches.sort();

assert_eq!(branches, vec![
    Branch::local("banana"),
    Branch::local("master"),
]);

pub fn list_tags(&self) -> Result<Vec<Tag>, Error>[src]

List the names of the tags that are contained in the underlying Repository.

Errors

Examples

use radicle_surf::vcs::git::{Branch, Browser, Namespace, Oid, Repository, Tag, TagName};
use std::convert::TryFrom;

let repo = Repository::new("./data/git-platinum")?;
let mut browser = Browser::new(&repo, Branch::local("master"))?;

let tags = browser.list_tags()?;

assert_eq!(
    tags,
    vec![
        Tag::Light {
            id: Oid::from_str("d3464e33d75c75c99bfb90fa2e9d16efc0b7d0e3")?,
            name: TagName::new("v0.1.0"),
        },
        Tag::Light {
            id: Oid::from_str("2429f097664f9af0c5b7b389ab998b2199ffa977")?,
            name: TagName::new("v0.2.0")
        },
        Tag::Light {
            id: Oid::from_str("19bec071db6474af89c866a1bd0e4b1ff76e2b97")?,
            name: TagName::new("v0.3.0")
        },
        Tag::Light {
            id: Oid::from_str("91b69e00cd8e5a07e20942e9e4457d83ce7a3ff1")?,
            name: TagName::new("v0.4.0")
        },
        Tag::Light {
            id: Oid::from_str("80ded66281a4de2889cc07293a8f10947c6d57fe")?,
            name: TagName::new("v0.5.0")
        },
    ]
);

// We can also switch namespaces and list the branches in that namespace.
let golden = browser.switch_namespace(&Namespace::try_from("golden")?, Branch::local("master"))?;

let branches = golden.list_tags()?;
assert_eq!(branches, vec![
    Tag::Light {
        id: Oid::from_str("d3464e33d75c75c99bfb90fa2e9d16efc0b7d0e3")?,
        name: TagName::new("v0.1.0"),
    },
    Tag::Light {
        id: Oid::from_str("2429f097664f9af0c5b7b389ab998b2199ffa977")?,
        name: TagName::new("v0.2.0")
    },
]);

pub fn list_namespaces(&self) -> Result<Vec<Namespace>, Error>[src]

List the namespaces within a Browser, filtering out ones that do not parse correctly.

Errors

Examples

use radicle_surf::vcs::git::{Branch, BranchType, BranchName, Browser, Namespace, Repository};
use std::convert::TryFrom;

let repo = Repository::new("./data/git-platinum")?;
let mut browser = Browser::new(&repo, Branch::local("master"))?;

let mut namespaces = browser.list_namespaces()?;
namespaces.sort();

assert_eq!(namespaces, vec![
    Namespace::try_from("golden")?,
    Namespace::try_from("golden/silver")?,
    Namespace::try_from("me")?,
]);

pub fn last_commit(&self, path: Path) -> Result<Option<Commit>, Error>[src]

Given a crate::file_system::Path to a file, return the last Commit that touched that file or directory.

Errors

Examples

use radicle_surf::vcs::git::{Branch, Browser, Oid, Repository};
use radicle_surf::file_system::{Label, Path, SystemType};
use radicle_surf::file_system::unsound;
use std::str::FromStr;

let repo = Repository::new("./data/git-platinum")?;
let mut browser = Browser::new(&repo, Branch::local("master"))?;

// Clamp the Browser to a particular commit
let commit = Oid::from_str("d6880352fc7fda8f521ae9b7357668b17bb5bad5")?;
browser.commit(commit)?;

let head_commit = browser.get().first().clone();
let expected_commit = Oid::from_str("d3464e33d75c75c99bfb90fa2e9d16efc0b7d0e3")?;

let readme_last_commit = browser
    .last_commit(Path::with_root(&[unsound::label::new("README.md")]))?
    .map(|commit| commit.id);

assert_eq!(readme_last_commit, Some(expected_commit));

let expected_commit = Oid::from_str("e24124b7538658220b5aaf3b6ef53758f0a106dc")?;

let memory_last_commit = browser
    .last_commit(Path::with_root(&[unsound::label::new("src"), unsound::label::new("memory.rs")]))?
    .map(|commit| commit.id);

assert_eq!(memory_last_commit, Some(expected_commit));

pub fn file_history(&self, path: Path) -> Result<Vec<Commit>, Error>[src]

Get the commit history for a file or directory.

Examples

use nonempty::NonEmpty;
use radicle_surf::vcs::git::{Branch, Browser, Oid, Repository};
use radicle_surf::file_system::{Label, Path, SystemType};
use radicle_surf::file_system::unsound;
use std::str::FromStr;

let repo = Repository::new("./data/git-platinum")?;
let mut browser = Browser::new(&repo, Branch::local("master"))?;

// Clamp the Browser to a particular commit
let commit = Oid::from_str("223aaf87d6ea62eef0014857640fd7c8dd0f80b5")?;
browser.commit(commit)?;

let root_commits: Vec<Oid> = browser
    .file_history(unsound::path::new("~"))?
    .into_iter()
    .map(|commit| commit.id)
    .collect();

assert_eq!(root_commits,
    vec![
        Oid::from_str("223aaf87d6ea62eef0014857640fd7c8dd0f80b5")?,
        Oid::from_str("80bacafba303bf0cdf6142921f430ff265f25095")?,
        Oid::from_str("a57846bbc8ced6587bf8329fc4bce970eb7b757e")?,
        Oid::from_str("3873745c8f6ffb45c990eb23b491d4b4b6182f95")?,
        Oid::from_str("80ded66281a4de2889cc07293a8f10947c6d57fe")?,
        Oid::from_str("91b69e00cd8e5a07e20942e9e4457d83ce7a3ff1")?,
        Oid::from_str("1820cb07c1a890016ca5578aa652fd4d4c38967e")?,
        Oid::from_str("1e0206da8571ca71c51c91154e2fee376e09b4e7")?,
        Oid::from_str("e24124b7538658220b5aaf3b6ef53758f0a106dc")?,
        Oid::from_str("19bec071db6474af89c866a1bd0e4b1ff76e2b97")?,
        Oid::from_str("f3a089488f4cfd1a240a9c01b3fcc4c34a4e97b2")?,
        Oid::from_str("2429f097664f9af0c5b7b389ab998b2199ffa977")?,
        Oid::from_str("d3464e33d75c75c99bfb90fa2e9d16efc0b7d0e3")?,
    ]
);

let eval_commits: Vec<Oid> = browser
    .file_history(unsound::path::new("~/src/Eval.hs"))?
    .into_iter()
    .map(|commit| commit.id)
    .collect();

assert_eq!(eval_commits,
    vec![
        Oid::from_str("3873745c8f6ffb45c990eb23b491d4b4b6182f95")?,
        Oid::from_str("e24124b7538658220b5aaf3b6ef53758f0a106dc")?,
    ]
);

pub fn extract_signature(
    &self,
    commit: &Commit,
    field: Option<&str>
) -> Result<Option<Signature>, Error>
[src]

Extract the signature for a commit

Arguments

  • commit - The commit to extract the signature for
  • field - the name of the header field containing the signature block; pass None to extract the default ‘gpgsig’

Examples

use radicle_surf::vcs::git::{Branch, Browser, Repository, Oid, error};

let repo = Repository::new("./data/git-platinum")?;
let mut browser = Browser::new(&repo, Branch::local("master"))?;

let commit_with_signature_oid = Oid::from_str(
    "e24124b7538658220b5aaf3b6ef53758f0a106dc"
)?;

browser.commit(commit_with_signature_oid)?;
let history = browser.get();
let commit_with_signature = history.first();
let signature = browser.extract_signature(commit_with_signature, None)?;

// We have a signature
assert!(signature.is_some());

let commit_without_signature_oid = Oid::from_str(
    "80bacafba303bf0cdf6142921f430ff265f25095"
)?;

browser.commit(commit_without_signature_oid)?;
let history = browser.get();
let commit_without_signature = history.first();
let signature = browser.extract_signature(commit_without_signature, None)?;

// There is no signature
assert!(signature.is_none());

pub fn revision_branches(
    &self,
    rev: impl Into<Rev>
) -> Result<Vec<Branch>, Error>
[src]

List the Branches, which contain the provided Commit.

Errors

Examples

use radicle_surf::vcs::git::{Browser, Repository, Branch, BranchName, Namespace, Oid};
use std::convert::TryFrom;

let repo = Repository::new("./data/git-platinum")?;
let browser = Browser::new(&repo, Branch::local("master"))?;


let branches = browser.revision_branches(Oid::from_str("27acd68c7504755aa11023300890bb85bbd69d45")?)?;
assert_eq!(
    branches,
    vec![
        Branch::local("dev"),
        Branch::remote("dev", "origin"),
    ]
);

// TODO(finto): I worry that this test will fail as other branches get added
let mut branches = browser.revision_branches(Oid::from_str("1820cb07c1a890016ca5578aa652fd4d4c38967e")?)?;
branches.sort();
assert_eq!(
    branches,
    vec![
        Branch::remote("HEAD", "origin"),
        Branch::local("dev"),
        Branch::remote("dev", "origin"),
        Branch::local("master"),
        Branch::remote("master", "origin"),
        Branch::remote("pineapple", "banana"),
    ]
);

let golden_browser = browser.switch_namespace(&Namespace::try_from("golden")?,
Branch::local("master"))?;

let branches = golden_browser.revision_branches(Oid::from_str("27acd68c7504755aa11023300890bb85bbd69d45")?)?;
assert_eq!(
    branches,
    vec![
        Branch::local("banana"),
        Branch::remote("fakie/bigspin", "kickflip"),
        Branch::remote("heelflip", "kickflip"),
    ]
);

pub fn get_stats(&self) -> Result<Stats, Error>[src]

Get the Stats of the underlying Repository.

Errors

Examples

use radicle_surf::vcs::git::{Branch, Browser, Repository};

let repo = Repository::new("./data/git-platinum")?;
let mut browser = Browser::new(&repo, Branch::local("master"))?;

let stats = browser.get_stats()?;

assert_eq!(stats.branches, 2);

assert_eq!(stats.commits, 15);

assert_eq!(stats.contributors, 4);

impl<Repo, A, Error> Browser<Repo, A, Error>[src]

pub fn get(&self) -> History<A> where
    A: Clone
[src]

Get the current History the Browser is viewing.

pub fn set(&mut self, history: History<A>)[src]

Set the History the Browser should view.

pub fn get_directory(&self) -> Result<Directory, Error>[src]

Render the Directory for this Browser.

pub fn modify<F>(&mut self, f: F) where
    F: Fn(&History<A>) -> History<A>, 
[src]

Modify the History in this Browser.

pub fn view_at<F>(&mut self, default_history: History<A>, f: F) where
    A: Clone,
    F: Fn(&History<A>) -> Option<History<A>>, 
[src]

Change the Browser’s view of History by modifying it, or using the default History provided if the operation fails.

Trait Implementations

impl<Repo, A, Error> VCS<A, Error> for Browser<Repo, A, Error> where
    Repo: VCS<A, Error>, 
[src]

type HistoryId = Repo::HistoryId

The way to identify a History.

type ArtefactId = Repo::ArtefactId

The way to identify an artefact.

Auto Trait Implementations

impl<Repo, A, Error> !RefUnwindSafe for Browser<Repo, A, Error>

impl<Repo, A, Error> !Send for Browser<Repo, A, Error>

impl<Repo, A, Error> !Sync for Browser<Repo, A, Error>

impl<Repo, A, Error> Unpin for Browser<Repo, A, Error> where
    A: Unpin,
    Repo: Unpin

impl<Repo, A, Error> !UnwindSafe for Browser<Repo, A, Error>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T where
    T: ?Sized

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Tap for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> TryConv for T

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.