Skip to content

Commit 6194ebe

Browse files
committed
imrpove git2 mapping by using aliases.
Thanks so much, @epage, it's a game-changer.
1 parent 12699d7 commit 6194ebe

File tree

8 files changed

+22
-11
lines changed

8 files changed

+22
-11
lines changed

gix/src/lib.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,12 @@
5656
//!
5757
//! ### `libgit2` API to `gix`
5858
//!
59-
//! This section is a 'striving to be complete' mapping from `libgit2` APIs to the respective methods in `gix`.
59+
//! This doc-aliases are used to help finding methods under a possibly changed name. Just search in the docs.
60+
//! Entering `git2` into the search field will also surface all methods with such annotations.
6061
//!
61-
//! * [`git2::Repository::open()`](https://docs.rs/git2/*/git2/struct.Repository.html#method.open) ➡ [`open()`]
62-
//! * [`git2::Repository::open_bare()`](https://docs.rs/git2/*/git2/struct.Repository.html#method.open_bare) ➡ ❌
63-
//! * [`git2::Repository::open_from_env()`](https://docs.rs/git2/*/git2/struct.Repository.html#method.open_from_env) ➡ [`ThreadSafeRepository::open_with_environment_overrides()`]
64-
//! * [`git2::Repository::open_ext()`](https://docs.rs/git2/*/git2/struct.Repository.html#method.open_ext) ➡ [`open_opts()`]
65-
//! * [`git2::Repository::revparse()`](https://docs.rs/git2/*/git2/struct.Repository.html#method.revparse) ➡ [`Repository::rev_parse()`]
66-
//! * [`git2::Repository::revparse_single()`](https://docs.rs/git2/*/git2/struct.Repository.html#method.revparse_single) ➡ [`Repository::rev_parse_single()`]
67-
//! * [`git2::Repository::revwalk()`](https://docs.rs/git2/*/git2/struct.Repository.html#method.revwalk) ➡ [`Repository::rev_walk()`]
62+
//! What follows is a list of methods you might be missing, along with workarounds if available.
63+
//! * [`git2::Repository::open_bare()`](https://docs.rs/git2/*/git2/struct.Repository.html#method.open_bare) ➡ ❌ - use [`open()`] and discard it is not bare.
6864
//! * [`git2::build::CheckoutBuilder::disable_filters()](https://docs.rs/git2/*/git2/build/struct.CheckoutBuilder.html#method.disable_filters) ➡ ❌ *(filters are always applied during checkouts)*
69-
//! * [`git2::Odb::read_header()`](https://docs.rs/git2/*/git2/struct.Odb.html#method.read_header) ➡ [`Repository::find_header()`]
70-
//! * [`git2::Repository::submodules()`](https://docs.rs/git2/*/git2/struct.Repository.html#method.submodules) ➡ [`Repository::submodules()`]
71-
//! * [`git2::Repository::submodules()`](https://docs.rs/git2/*/git2/struct.Repository.html#method.submodules) ➡ [`Repository::submodules()`]
7265
//! * [`git2::Repository::submodule_status()`](https://docs.rs/git2/*/git2/struct.Repository.html#method.submodule_status) ➡ [`Submodule::state()`] - status provides more information and conveniences though, and an actual worktree status isn't performed.
7366
//!
7467
//! ## Feature Flags
@@ -234,12 +227,14 @@ fn open_opts_with_git_binary_config() -> open::Options {
234227

235228
/// See [`ThreadSafeRepository::open()`], but returns a [`Repository`] instead.
236229
#[allow(clippy::result_large_err)]
230+
#[doc(alias = "git2")]
237231
pub fn open(directory: impl Into<std::path::PathBuf>) -> Result<Repository, open::Error> {
238232
ThreadSafeRepository::open(directory).map(Into::into)
239233
}
240234

241235
/// See [`ThreadSafeRepository::open_opts()`], but returns a [`Repository`] instead.
242236
#[allow(clippy::result_large_err)]
237+
#[doc(alias = "open_ext", alias = "git2")]
243238
pub fn open_opts(directory: impl Into<std::path::PathBuf>, options: open::Options) -> Result<Repository, open::Error> {
244239
ThreadSafeRepository::open_opts(directory, options).map(Into::into)
245240
}

gix/src/open/repository.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ impl ThreadSafeRepository {
108108
// TODO: The following vars should end up as overrides of the respective configuration values (see git-config).
109109
// GIT_PROXY_SSL_CERT, GIT_PROXY_SSL_KEY, GIT_PROXY_SSL_CERT_PASSWORD_PROTECTED.
110110
// GIT_PROXY_SSL_CAINFO, GIT_SSL_CIPHER_LIST, GIT_HTTP_MAX_REQUESTS, GIT_CURL_FTP_NO_EPSV,
111+
#[doc(alias = "open_from_env", alias = "git2")]
111112
pub fn open_with_environment_overrides(
112113
fallback_directory: impl Into<PathBuf>,
113114
trust_map: gix_sec::trust::Mapping<Options>,

gix/src/pathspec.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ impl<'repo> Pathspec<'repo> {
8484
/// Return the first [`Match`](search::Match) of `relative_path`, or `None`.
8585
/// Note that the match might [be excluded](search::Match::is_excluded()).
8686
/// `is_dir` is true if `relative_path` is a directory.
87+
#[doc(
88+
alias = "match_diff",
89+
alias = "match_tree",
90+
alias = "match_index",
91+
alias = "match_workdir",
92+
alias = "matches_path",
93+
alias = "git2"
94+
)]
8795
pub fn pattern_matching_relative_path<'a>(
8896
&mut self,
8997
relative_path: impl Into<&'a BStr>,

gix/src/repository/object.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl crate::Repository {
3939
/// Obtain information about an object without fully decoding it, or fail if the object doesn't exist.
4040
///
4141
/// Note that despite being cheaper than [`Self::find_object()`], there is still some effort traversing delta-chains.
42+
#[doc(alias = "read_header", alias = "git2")]
4243
pub fn find_header(&self, id: impl Into<ObjectId>) -> Result<gix_odb::find::Header, object::find::existing::Error> {
4344
let id = id.into();
4445
if id == gix_hash::ObjectId::empty_tree(self.object_hash()) {

gix/src/repository/pathspec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ impl Repository {
1111
///
1212
/// It will be initialized exactly how it would, and attribute matching will be conducted by reading the worktree first if available.
1313
/// If that is not desirable, consider calling [`Pathspec::new()`] directly.
14+
#[doc(alias = "Pathspec", alias = "git2")]
1415
pub fn pathspec(
1516
&self,
1617
patterns: impl IntoIterator<Item = impl AsRef<BStr>>,

gix/src/repository/revision.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ impl crate::Repository {
88
///
99
/// - `@` actually stands for `HEAD`, whereas `git` resolves it to the object pointed to by `HEAD` without making the
1010
/// `HEAD` ref available for lookups.
11+
#[doc(alias = "revparse", alias = "git2")]
1112
pub fn rev_parse<'a>(&self, spec: impl Into<&'a BStr>) -> Result<revision::Spec<'_>, revision::spec::parse::Error> {
1213
revision::Spec::from_bstr(
1314
spec,
@@ -20,6 +21,7 @@ impl crate::Repository {
2021
}
2122

2223
/// Parse a revision specification and return single object id as represented by this instance.
24+
#[doc(alias = "revparse_single", alias = "git2")]
2325
pub fn rev_parse_single<'repo, 'a>(
2426
&'repo self,
2527
spec: impl Into<&'a BStr>,
@@ -33,6 +35,7 @@ impl crate::Repository {
3335
/// Create the baseline for a revision walk by initializing it with the `tips` to start iterating on.
3436
///
3537
/// It can be configured further before starting the actual walk.
38+
#[doc(alias = "revwalk", alias = "git2")]
3639
pub fn rev_walk(
3740
&self,
3841
tips: impl IntoIterator<Item = impl Into<gix_hash::ObjectId>>,

gix/src/repository/submodule.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ impl Repository {
7373
}
7474

7575
/// Return the list of available submodules, or `None` if there is no submodule configuration.
76+
#[doc(alias = "git2")]
7677
pub fn submodules(&self) -> Result<Option<impl Iterator<Item = crate::Submodule<'_>>>, submodule::modules::Error> {
7778
let modules = match self.modules()? {
7879
None => return Ok(None),

gix/src/submodule/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ impl<'repo> Submodule<'repo> {
226226
}
227227

228228
/// Query various parts of the submodule and assemble it into state information.
229+
#[doc(alias = "status", alias = "git2")]
229230
pub fn state(&self) -> Result<State, config::path::Error> {
230231
let maybe_old_path = self.git_dir_try_old_form()?;
231232
let git_dir = self.git_dir();

0 commit comments

Comments
 (0)