Skip to main content

Repository

Struct Repository 

Source
pub struct Repository<Location = Local> { /* private fields */ }
Expand description

A Git Repository which can be mined.

Two marker variations Local and Remote. Local is the variant which exists on the local filesystem and can therefore be mined. Remote, is of course not on the local filesystem and is represented via its remote url. A remote Repository upon instantiation will be cloned and returned as a Local variant such that it can be mined.

§Examples

  1. Traversing a local repository from HEAD
use stratum::{Repository, Local};

let p = PathBuf::from_str("~/repository/").unwrap();
let repo = Repository::<Local>::new(p).unwrap();

for commit in repo.traverse_commits().unwrap() {
    let commit = commit.unwrap();
    println!("Commit {} was authored by {:?}", commit.hash(), commit.author().name());
}
  1. Traversing a remote repository from HEAD
use stratum::{Repository, Remote};

let repo = Repository::<Remote>::new::<PathBuf>(
        "https://server.example/owner/repo.git",
        None
    ).unwrap();
for commit in repo.traverse_commits().unwrap() {
    let commit = commit.unwrap();
    println!("Commit {} was authored by {:?}", commit.hash(), commit.author().name());
}
  1. Extracting HEAD from a local repository
use stratum::{Repository, Local};

let p = PathBuf::from_str("~/repository/").unwrap();
let repo = Repository::<Local>::new(p).unwrap();

println!("HEAD was authored by {:?}", repo.head().unwrap().author().name());
  1. Using the helper functions
use stratum::open_repository;

let p = PathBuf::from_str("~/repository/").unwrap();
// use clone_repository for the remote helper fucntion
let repo = open_repository(p);

println!("HEAD was authored by {:?}", repo.unwrap().head().unwrap().author().name());

Implementations§

Source§

impl Repository<Local>

Source

pub fn new<P>(path: P) -> Result<Self, Error>
where P: AsRef<Path>,

Instatiate a new Repository from a path on the local file system

Source

pub fn raw(&self) -> &Repository

Read access into the underlying git2 object

Source

pub fn traverse_commits( &self, ) -> Result<impl Iterator<Item = Result<Commit<'_>, Error>>, Error>

Traverse the repositories commit graph from HEAD

Source

pub fn traverse_from( &self, oid: &str, ) -> Result<impl Iterator<Item = Result<Commit<'_>, Error>>, Error>

Traverse the repositories commit graph from a specified commit hash

Source

pub fn head(&self) -> Result<Commit<'_>, Error>

Return head as a stratum commit

Source

pub fn single(&self, oid: &str) -> Result<Commit<'_>, Error>

Return a single commit object based on a given oid/hash

Source§

impl Repository<Remote>

Source

pub fn new<P>(url: &str, dest: Option<P>) -> Result<Repository<Local>, Error>
where P: AsRef<Path>,

Instatiate a new Repository from a remote URL, returning the Local variant after cloning the repository into dest.

Type of clone to perform will be automatically resolved based on the URL.

Source

pub fn from_https<P>( url: &str, dest: Option<P>, ) -> Result<Repository<Local>, Error>
where P: AsRef<Path>,

Clone the given repository via the http or https protocol into the given destination

Source

pub fn from_ssh<P>( _url: &str, _dest: Option<P>, ) -> Result<Repository<Local>, Error>
where P: AsRef<Path>,

Auto Trait Implementations§

§

impl<Location> Freeze for Repository<Location>

§

impl<Location> RefUnwindSafe for Repository<Location>
where Location: RefUnwindSafe,

§

impl<Location> Send for Repository<Location>
where Location: Send,

§

impl<Location = Local> !Sync for Repository<Location>

§

impl<Location> Unpin for Repository<Location>
where Location: Unpin,

§

impl<Location> UnsafeUnpin for Repository<Location>

§

impl<Location> UnwindSafe for Repository<Location>
where Location: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.