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
- 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());
}- 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());
}- 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());- 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>
impl Repository<Local>
Sourcepub fn new<P>(path: P) -> Result<Self, Error>
pub fn new<P>(path: P) -> Result<Self, Error>
Instatiate a new Repository from a path on the local file system
Sourcepub fn raw(&self) -> &Repository
pub fn raw(&self) -> &Repository
Read access into the underlying git2 object
Sourcepub fn traverse_commits(
&self,
) -> Result<impl Iterator<Item = Result<Commit<'_>, Error>>, Error>
pub fn traverse_commits( &self, ) -> Result<impl Iterator<Item = Result<Commit<'_>, Error>>, Error>
Traverse the repositories commit graph from HEAD
Source§impl Repository<Remote>
impl Repository<Remote>
Sourcepub fn new<P>(url: &str, dest: Option<P>) -> Result<Repository<Local>, Error>
pub fn new<P>(url: &str, dest: Option<P>) -> Result<Repository<Local>, Error>
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.
Sourcepub fn from_https<P>(
url: &str,
dest: Option<P>,
) -> Result<Repository<Local>, Error>
pub fn from_https<P>( url: &str, dest: Option<P>, ) -> Result<Repository<Local>, Error>
Clone the given repository via the http or https protocol into the given destination