Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clippy fixes #1392

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions git-branchless-init/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ tracing = { workspace = true }

[dev-dependencies]
assert_cmd = { workspace = true }

[features]
man-pages = []
8 changes: 4 additions & 4 deletions git-branchless-init/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,11 @@ fn uninstall_hooks(effects: &Effects, git_run_info: &GitRunInfo, repo: &Repo) ->
/// tries to look up with `man` when you run e.g. `git smartlog --help`:
///
/// - `branchless smartlog`: invokes `man git-branchless`, which means that the
/// subcommand is not included in the `man` invocation, so it can only show
/// generic help.
/// subcommand is not included in the `man` invocation, so it can only show
/// generic help.
/// - `branchless-smartlog`: invokes `man git-branchless-smartlog, so the
/// subcommand is included in the `man` invocation, so it can show more specific
/// help.
/// subcommand is included in the `man` invocation, so it can show more specific
/// help.
fn should_use_wrapped_command_alias() -> bool {
cfg!(feature = "man-pages")
}
Expand Down
Binary file added git-branchless-lib/.Cargo.toml.swp
Binary file not shown.
9 changes: 5 additions & 4 deletions git-branchless-lib/src/core/dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,10 +728,11 @@ impl std::fmt::Debug for Dag {
}
}

/// Sort the given set of commits topologically. In the case of two commits
/// being unorderable, sort them using a deterministic tie-breaking function.
/// Commits which have been garbage collected and are no longer available in the
/// repository are omitted.
/// Sort the given set of commits topologically.
///
/// In the case of two commits being unorderable, sort them using a
/// deterministic tie-breaking function. Commits which have been garbage
/// collected and are no longer available in the repository are omitted.
///
/// FIXME: this function does not use a total ordering for the sort, which could
/// mean that it produces incorrect results. Suppose that we have a graph with
Expand Down
4 changes: 2 additions & 2 deletions git-branchless-lib/src/core/eventlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,8 +1105,8 @@ impl EventReplayer {
///
/// Args:
/// * `num_events`: The number of events to advance by. Can be positive,
/// zero, or negative. If out of bounds, the cursor is set to the first or
/// last valid position, as appropriate.
/// zero, or negative. If out of bounds, the cursor is set to the first or
/// last valid position, as appropriate.
pub fn advance_cursor(&self, cursor: EventCursor, num_events: isize) -> EventCursor {
self.make_cursor(cursor.event_id + num_events)
}
Expand Down
2 changes: 1 addition & 1 deletion git-branchless-lib/src/core/rewrite/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ mod in_memory {
///
/// - This is only `None` if `HEAD` was unborn.
/// - This doesn't capture if `HEAD` was pointing to a branch. The
/// caller will need to figure that out.
/// caller will need to figure that out.
new_head_oid: Option<NonZeroOid>,
},
MergeFailed(FailedMergeInfo),
Expand Down
2 changes: 2 additions & 0 deletions git-branchless-lib/src/core/rewrite/rewrite_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ fn load_updated_head_oid(repo: &Repo) -> eyre::Result<Option<NonZeroOid>> {
}
}

/// Register extra cleanup actions for rebase.
///
/// For rebases, register that extra cleanup actions should be taken when the
/// rebase finishes and calls the post-rewrite hook. We don't want to change the
/// behavior of `git rebase` itself, except when called via `git-branchless`, so
Expand Down
8 changes: 5 additions & 3 deletions git-branchless-lib/src/git/oid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ pub(super) fn make_non_zero_oid(oid: git2::Oid) -> NonZeroOid {
NonZeroOid { inner: oid }
}

/// Represents an OID which may be zero or non-zero. This exists because Git
/// often represents the absence of an object using the zero OID. We want to
/// statically check for those cases by using a more descriptive type.
/// OID which may be zero or non-zero.
///
/// This exists because Git often represents the absence of an object using the
/// zero OID. We want to statically check for those cases by using a more
/// descriptive type.
///
/// This type is isomorphic to `Option<NonZeroOid>`. It should be used primarily
/// when converting to and from string representations of OID values.
Expand Down
9 changes: 5 additions & 4 deletions git-branchless-lib/src/git/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@ impl<'repo> Reference<'repo> {
}
}

/// Determine what kind of branch a reference is, given its name. The returned
/// `suffix` value is converted to a `String` to be rendered to the screen, so
/// it may have lost some information if the reference name had unusual
/// characters.
/// Determine what kind of branch a reference is, given its name.
///
/// The returned `suffix` value is converted to a `String` to be rendered to
/// the screen, so it may have lost some information if the reference name had
/// unusual characters.
///
/// FIXME: This abstraction seems uncomfortable and clunky to use; consider
/// revising.
Expand Down
16 changes: 8 additions & 8 deletions git-branchless-lib/src/git/repo.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Operations on the Git repository. This module exists for a few reasons:
//!
//! - To ensure that every call to a Git operation has an associated `wrap_err`
//! for use with `Try`.
//! for use with `Try`.
//! - To improve the interface in some cases. In particular, some operations in
//! `git2` return an `Error` with code `ENOTFOUND`, but we should really return
//! an `Option` in those cases.
//! `git2` return an `Error` with code `ENOTFOUND`, but we should really return
//! an `Option` in those cases.
//! - To make it possible to audit all the Git operations carried out in the
//! codebase.
//! codebase.
//! - To collect some different helper Git functions.

use std::borrow::Borrow;
Expand Down Expand Up @@ -320,11 +320,11 @@ pub fn message_prettify(message: &str, comment_char: Option<char>) -> Result<Str
/// There are a couple of interesting edge cases to worry about:
///
/// - `HEAD` is detached. This means that it's pointing directly to a commit and
/// is not a symbolic reference for the time being. This is uncommon in normal
/// Git usage, but very common in `git-branchless` usage.
/// is not a symbolic reference for the time being. This is uncommon in normal
/// Git usage, but very common in `git-branchless` usage.
/// - `HEAD` is unborn. This means that it doesn't even exist yet. This happens
/// when a repository has been freshly initialized, but no commits have been
/// made, for example.
/// when a repository has been freshly initialized, but no commits have been
/// made, for example.
#[derive(Debug, PartialEq, Eq)]
pub struct ResolvedReferenceInfo {
/// The OID of the commit that `HEAD` points to. If `HEAD` is unborn, then
Expand Down
10 changes: 5 additions & 5 deletions git-branchless-lib/src/git/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
//! There are two main reasons to implement working copy snapshots:
//!
//! 1. To support enhanced undo features. For example, you should be able to
//! jump back into merge conflict resolution which was happening at some past
//! time.
//! jump back into merge conflict resolution which was happening at some
//! past time.
//! 2. To unify the implementations of operations across commits and the
//! working copy. For example, a `git split` command which splits one commit
//! into multiple could also be used to split the working copy into multiple
//! commits.
//! working copy. For example, a `git split` command which splits one commit
//! into multiple could also be used to split the working copy into multiple
//! commits.

use itertools::Itertools;
use std::collections::HashMap;
Expand Down
28 changes: 17 additions & 11 deletions git-branchless-lib/src/git/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@ use super::{Commit, NonZeroOid, Repo, RepoError};
pub const TEST_SUCCESS_EXIT_CODE: i32 = 0;

/// The exit status to use when a test command intends to skip the provided commit.
///
/// This exit code is used officially by several source control systems:
///
/// - Git: "Note that the script (my_script in the above example) should exit
/// with code 0 if the current source code is good/old, and exit with a code
/// between 1 and 127 (inclusive), except 125, if the current source code is
/// bad/new."
/// with code 0 if the current source code is good/old, and exit with a code
/// between 1 and 127 (inclusive), except 125, if the current source code is
/// bad/new."
/// - Mercurial: "The exit status of the command will be used to mark revisions
/// as good or bad: status 0 means good, 125 means to skip the revision, 127
/// (command not found) will abort the bisection, and any other non-zero exit
/// status means the revision is bad."
/// as good or bad: status 0 means good, 125 means to skip the revision, 127
/// (command not found) will abort the bisection, and any other non-zero exit
/// status means the revision is bad."
///
/// And it's become the de-facto standard for custom bisection scripts for other
/// source control systems as well.
pub const TEST_INDETERMINATE_EXIT_CODE: i32 = 125;

/// The exit status used to abort a process.
///
/// Similarly to `INDETERMINATE_EXIT_CODE`, this exit code is used officially by
/// `git-bisect` and others to abort the process. It's also typically raised by
/// the shell when the command is not found, so it's technically ambiguous
Expand All @@ -43,9 +46,10 @@ pub fn make_test_command_slug(command: String) -> String {
command.replace(['/', ' ', '\n'], "__")
}

/// A version of `NonZeroOid` that can be serialized and deserialized. This
/// exists in case we want to move this type (back) into a separate module which
/// has a `serde` dependency in the interest of improving build times.
/// A version of `NonZeroOid` that can be serialized and deserialized.
///
/// This exists in case we want to move this type (back) into a separate module
/// which has a `serde` dependency in the interest of improving build times.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SerializedNonZeroOid(pub NonZeroOid);

Expand Down Expand Up @@ -109,8 +113,10 @@ fn get_test_dir(repo: &Repo) -> Result<PathBuf, RepoError> {
}

/// Get the directory where the result of tests for a particular commit are
/// stored. Tests are keyed by tree OID, not commit OID, so that they can be
/// cached based on the contents of the commit, rather than its specific commit
/// stored.
///
/// Tests are keyed by tree OID, not commit OID, so that they can be cached
/// based on the contents of the commit, rather than its specific commit
/// hash. This means that we can cache the results of tests for commits that
/// have been amended or rebased.
pub fn get_test_tree_dir(repo: &Repo, commit: &Commit) -> Result<PathBuf, RepoError> {
Expand Down
2 changes: 2 additions & 0 deletions git-branchless-lib/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ impl TryFrom<ExitStatus> for ExitCode {
}
}

/// Encapsulate both an `eyre::Result<T>` and a possible subcommand exit code.
///
/// Helper type alias for the common case that we want to run a computation and
/// return `eyre::Result<T>`, but it's also possible that we run a subcommand
/// which returns an exit code that we want to propagate. See also `try_exit_code`.
Expand Down
7 changes: 4 additions & 3 deletions git-branchless-opts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,9 +989,10 @@ fn generate_man_page(man1_dir: &Path, name: &str, command: &ClapCommand) -> std:
Ok(())
}

/// Carry out some rewrites on the command-line arguments for uniformity. For
/// example, `git-branchless-smartlog` becomes `git-branchless smartlog`, and
/// the `.exe` suffix is removed on Windows. These are necessary for later
/// Carry out some rewrites on the command-line arguments for uniformity.
///
/// For example, `git-branchless-smartlog` becomes `git-branchless smartlog`,
/// and the `.exe` suffix is removed on Windows. These are necessary for later
/// command-line argument parsing.
pub fn rewrite_args(args: Vec<OsString>) -> Vec<OsString> {
let first_arg = match args.first() {
Expand Down
Binary file added git-branchless-submit/src/.github.rs.swp
Binary file not shown.
2 changes: 1 addition & 1 deletion git-branchless-submit/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub fn github_push_remote(repo: &Repo) -> eyre::Result<Option<String>> {
// Possible values seem to be `base` and `other`. See:
// https://github.com/search?q=repo%3Acli%2Fcli%20gh-resolved&type=code
let gh_resolved: Option<String> =
config.get(&format!("remote.{remote_name}.gh-resolved"))?;
config.get(format!("remote.{remote_name}.gh-resolved"))?;
if gh_resolved.as_deref() == Some("base") {
return Ok(Some(remote_name));
}
Expand Down
3 changes: 3 additions & 0 deletions git-branchless/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ tracing-subscriber = { workspace = true }
[dev-dependencies]
insta = { workspace = true }

[features]
man-pages = []

[package.metadata.release]
pre-release-replacements = [
{ file = "../CHANGELOG.md", search = "Unreleased", replace = "{{version}}", min = 1 },
Expand Down
2 changes: 1 addition & 1 deletion git-branchless/tests/test_undo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ fn test_undo_no_confirm() -> eyre::Result<()> {
fn test_undo_unseen_commit() -> eyre::Result<()> {
// Disabled since we no longer support `origin/master` as a main branch, but this test might be
// useful in the future.
if cfg!(none) {
if false {
let git = make_git()?;
if !git.supports_reference_transactions()? {
return Ok(());
Expand Down
6 changes: 4 additions & 2 deletions scm-bisect/src/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use tracing::instrument;

use crate::search;

/// Directed acyclic graph commonly used in source control.
///
/// Implementation of `Graph` that represents the common case of a directed
/// acyclic graph in source control. You can implement this trait instead of
/// `Graph` (as there is a blanket implementation for `Graph`) and also make use
Expand Down Expand Up @@ -165,8 +167,8 @@ pub enum BasicStrategyKind {
/// approach. In order to solve the following problem:
///
/// > sometimes the best bisection points all happened to be in an area
/// where all the commits are untestable. And in this case the user was
/// asked to test many untestable commits, which could be very inefficient.
/// > where all the commits are untestable. And in this case the user was
/// > asked to test many untestable commits, which could be very inefficient.
///
/// We instead consider the hypothetical case that the node is a success,
/// and yield further nodes as if it were a success, and then interleave
Expand Down
2 changes: 1 addition & 1 deletion scm-bisect/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub trait Graph: Debug {
/// - `X == Y`
/// - `X` is an immediate parent of `Y`.
/// - `X` is an ancestor of an immediate parent of `Y` (defined
/// recursively).
/// recursively).
fn is_ancestor(
&self,
ancestor: Self::Node,
Expand Down
Loading