Struct radicle_surf::Repository
source · pub struct Repository { /* private fields */ }
Expand description
Represents the state associated with a Git repository.
Many other types in this crate are derived from methods in this struct.
Implementations§
source§impl Repository
impl Repository
sourcepub fn discover(repo_uri: impl AsRef<Path>) -> Result<Self, Error>
pub fn discover(repo_uri: impl AsRef<Path>) -> Result<Self, Error>
Attempt to open a git repository at or above repo_uri
in the file
system.
Examples found in repository?
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
fn main() {
let repo_path = match env::args().nth(1) {
Some(path) => path,
None => {
print_usage();
return;
}
};
let repo = Repository::discover(repo_path).unwrap();
let now = Instant::now();
let head = repo.head().unwrap();
let root = repo.root_dir(head).unwrap();
print_directory(&root, &repo, 0);
let elapsed_millis = now.elapsed().as_millis();
println!("browse with print: {elapsed_millis} ms");
}
sourcepub fn which_namespace(&self) -> Result<Option<Namespace>, Error>
pub fn which_namespace(&self) -> Result<Option<Namespace>, Error>
What is the current namespace we’re browsing in.
sourcepub fn switch_namespace(&self, namespace: &RefString) -> Result<(), Error>
pub fn switch_namespace(&self, namespace: &RefString) -> Result<(), Error>
Switch to a namespace
pub fn with_namespace<T, F>( &self, namespace: &RefString, f: F, ) -> Result<T, Error>
sourcepub fn branches<G>(&self, pattern: G) -> Result<Branches<'_>, Error>
pub fn branches<G>(&self, pattern: G) -> Result<Branches<'_>, Error>
Returns an iterator of branches that match pattern
.
sourcepub fn branch_names<G>(&self, filter: G) -> Result<BranchNames<'_>, Error>
pub fn branch_names<G>(&self, filter: G) -> Result<BranchNames<'_>, Error>
Lists branch names with filter
.
Returns an iterator of tags that match pattern
.
sourcepub fn tag_names(&self, filter: &Glob<Tag>) -> Result<TagNames<'_>, Error>
pub fn tag_names(&self, filter: &Glob<Tag>) -> Result<TagNames<'_>, Error>
Lists tag names in the local RefScope.
pub fn categories( &self, pattern: &Glob<Qualified<'_>>, ) -> Result<Categories<'_>, Error>
sourcepub fn namespaces(&self, pattern: &Glob<Namespace>) -> Result<Namespaces, Error>
pub fn namespaces(&self, pattern: &Glob<Namespace>) -> Result<Namespaces, Error>
Returns an iterator of namespaces that match pattern
.
sourcepub fn diff(
&self,
from: impl Revision,
to: impl Revision,
) -> Result<Diff, Error>
pub fn diff( &self, from: impl Revision, to: impl Revision, ) -> Result<Diff, Error>
Get the Diff
between two commits.
Examples found in repository?
25 26 27 28 29 30 31 32 33 34 35 36 37
fn main() {
let options = get_options_or_exit();
let repo = init_repository_or_exit(&options.path_to_repo);
let head_oid = match options.head_revision {
HeadRevision::Head => repo.head().unwrap(),
HeadRevision::Commit(id) => Oid::from_str(&id).unwrap(),
};
let base_oid = Oid::from_str(&options.base_revision).unwrap();
let now = Instant::now();
let elapsed_nanos = now.elapsed().as_nanos();
let diff = repo.diff(base_oid, head_oid).unwrap();
print_diff_summary(&diff, elapsed_nanos);
}
sourcepub fn diff_commit(&self, commit: impl ToCommit) -> Result<Diff, Error>
pub fn diff_commit(&self, commit: impl ToCommit) -> Result<Diff, Error>
Get the Diff
of a commit
.
If the commit
has a parent, then it the diff will be a
comparison between itself and that parent. Otherwise, the left
hand side of the diff will pass nothing.
sourcepub fn diff_file<P: AsRef<Path>, R: Revision>(
&self,
path: &P,
from: R,
to: R,
) -> Result<FileDiff, Error>
pub fn diff_file<P: AsRef<Path>, R: Revision>( &self, path: &P, from: R, to: R, ) -> Result<FileDiff, Error>
sourcepub fn root_dir<C: ToCommit>(&self, commit: C) -> Result<Directory, Error>
pub fn root_dir<C: ToCommit>(&self, commit: C) -> Result<Directory, Error>
Returns a top level Directory
without nested sub-directories.
To visit inside any nested sub-directories, call directory.get(&repo)
on the sub-directory.
Examples found in repository?
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
fn main() {
let repo_path = match env::args().nth(1) {
Some(path) => path,
None => {
print_usage();
return;
}
};
let repo = Repository::discover(repo_path).unwrap();
let now = Instant::now();
let head = repo.head().unwrap();
let root = repo.root_dir(head).unwrap();
print_directory(&root, &repo, 0);
let elapsed_millis = now.elapsed().as_millis();
println!("browse with print: {elapsed_millis} ms");
}
sourcepub fn directory<C: ToCommit, P: AsRef<Path>>(
&self,
commit: C,
path: &P,
) -> Result<Directory, Error>
pub fn directory<C: ToCommit, P: AsRef<Path>>( &self, commit: C, path: &P, ) -> Result<Directory, Error>
Returns a Directory
for path
in commit
.
sourcepub fn file<C: ToCommit, P: AsRef<Path>>(
&self,
commit: C,
path: &P,
) -> Result<File, Error>
pub fn file<C: ToCommit, P: AsRef<Path>>( &self, commit: C, path: &P, ) -> Result<File, Error>
Returns a File
for path
in commit
.
sourcepub fn tree<C: ToCommit, P: AsRef<Path>>(
&self,
commit: C,
path: &P,
) -> Result<Tree, Error>
pub fn tree<C: ToCommit, P: AsRef<Path>>( &self, commit: C, path: &P, ) -> Result<Tree, Error>
Returns a Tree
for path
in commit
.
sourcepub fn blob<'a, C: ToCommit, P: AsRef<Path>>(
&'a self,
commit: C,
path: &P,
) -> Result<Blob<BlobRef<'a>>, Error>
pub fn blob<'a, C: ToCommit, P: AsRef<Path>>( &'a self, commit: C, path: &P, ) -> Result<Blob<BlobRef<'a>>, Error>
Returns a Blob
for path
in commit
.
pub fn blob_ref(&self, oid: Oid) -> Result<BlobRef<'_>, Error>
sourcepub fn last_commit<P, C>(
&self,
path: &P,
rev: C,
) -> Result<Option<Commit>, Error>
pub fn last_commit<P, C>( &self, path: &P, rev: C, ) -> Result<Option<Commit>, Error>
Returns the last commit, if exists, for a path
in the history of
rev
.
sourcepub fn commit<R: Revision>(&self, rev: R) -> Result<Commit, Error>
pub fn commit<R: Revision>(&self, rev: R) -> Result<Commit, Error>
Returns a commit for rev
, if it exists.
sourcepub fn stats(&self) -> Result<Stats, Error>
pub fn stats(&self) -> Result<Stats, Error>
Gets the Stats
of this repository starting from the
HEAD
(see Repository::head
) of the repository.
sourcepub fn stats_from<R>(&self, rev: &R) -> Result<Stats, Error>where
R: Revision,
pub fn stats_from<R>(&self, rev: &R) -> Result<Stats, Error>where
R: Revision,
Gets the Stats
of this repository starting from the given
rev
.
sourcepub fn get_commit_file<P, R>(
&self,
rev: &R,
path: &P,
) -> Result<FileContent<'_>, Error>
pub fn get_commit_file<P, R>( &self, rev: &R, path: &P, ) -> Result<FileContent<'_>, Error>
Retrieves the file with path
in this commit.
sourcepub fn head(&self) -> Result<Oid, Error>
pub fn head(&self) -> Result<Oid, Error>
Returns the Oid
of the current HEAD
.
Examples found in repository?
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
fn main() {
let repo_path = match env::args().nth(1) {
Some(path) => path,
None => {
print_usage();
return;
}
};
let repo = Repository::discover(repo_path).unwrap();
let now = Instant::now();
let head = repo.head().unwrap();
let root = repo.root_dir(head).unwrap();
print_directory(&root, &repo, 0);
let elapsed_millis = now.elapsed().as_millis();
println!("browse with print: {elapsed_millis} ms");
}
More examples
25 26 27 28 29 30 31 32 33 34 35 36 37
fn main() {
let options = get_options_or_exit();
let repo = init_repository_or_exit(&options.path_to_repo);
let head_oid = match options.head_revision {
HeadRevision::Head => repo.head().unwrap(),
HeadRevision::Commit(id) => Oid::from_str(&id).unwrap(),
};
let base_oid = Oid::from_str(&options.base_revision).unwrap();
let now = Instant::now();
let elapsed_nanos = now.elapsed().as_nanos();
let diff = repo.diff(base_oid, head_oid).unwrap();
print_diff_summary(&diff, elapsed_nanos);
}
sourcepub fn extract_signature(
&self,
commit: impl ToCommit,
field: Option<&str>,
) -> Result<Option<Signature>, Error>
pub fn extract_signature( &self, commit: impl ToCommit, field: Option<&str>, ) -> Result<Option<Signature>, Error>
Extract the signature from a commit
§Arguments
field
- the name of the header field containing the signature block;
pass None
to extract the default ‘gpgsig’