Skip to content

Commit f4c96f3

Browse files
committed
more AI review suggestions
1 parent 36510eb commit f4c96f3

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

cpp-linter/src/git.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,17 @@ fn get_sha<'d, T: Display>(
4040
match depth {
4141
Some(base) => {
4242
let base = base.to_string();
43-
if base.chars().all(|c| c.is_ascii_digit()) {
44-
repo.revparse_single(format!("HEAD~{}", base).as_str())
45-
} else {
46-
repo.revparse_single(base.as_str())
43+
// First treat base as an explicit refs/SHAs. If that fails, then
44+
// fall back to `HEAD~<base>` if `base` is purely numeric.
45+
match repo.revparse_single(base.as_str()) {
46+
Ok(obj) => Ok(obj),
47+
Err(err) => {
48+
if base.chars().all(|c| c.is_ascii_digit()) {
49+
repo.revparse_single(format!("HEAD~{}", base).as_str())
50+
} else {
51+
Err(err)
52+
}
53+
}
4754
}
4855
}
4956
None => repo.revparse_single("HEAD"),
@@ -61,12 +68,12 @@ fn get_sha<'d, T: Display>(
6168
/// The `diff_base` is a commit or ref to use as the base of the diff.
6269
/// Use `ignore_index` to exclude any staged changes in the local index.
6370
///
64-
/// | Parameter Value | Git index state | Scope of diff |
65-
/// |-----------------|-----------------|----------------|
66-
/// | `None` (the default) | No staged changes | `HEAD~1..HEAD` |
67-
/// | `None` (the default) | Has staged changes | `HEAD..index` |
68-
/// | `int` (eg `2`) or `str` (eg `HEAD~2`) | No staged changes | `HEAD~2..HEAD` |
69-
/// | `int` (eg `2`) or `str` (eg `HEAD~2`) | Has staged changes | `HEAD~2..index` |
71+
/// | `diff_base` value | Git index state | Scope of diff |
72+
/// |-------------------|-----------------|---------------|
73+
/// | `None` | No staged changes | `HEAD~1..HEAD` |
74+
/// | `None` | Has staged changes | `HEAD..index` |
75+
/// | `Some(2)` or `Some("HEAD~2")` | No staged changes | `HEAD~2..HEAD` |
76+
/// | `Some(2)` or `Some("HEAD~2")` | Has staged changes | `HEAD~2..index` |
7077
pub fn get_diff<'d, T: Display>(
7178
repo: &'d Repository,
7279
diff_base: &Option<T>,
@@ -151,7 +158,7 @@ fn parse_patch(patch: &Patch) -> (Vec<u32>, Vec<RangeInclusive<u32>>) {
151158

152159
/// Parses a given [`git2::Diff`] and returns a list of [`FileObj`]s.
153160
///
154-
/// The `lines_changed_only`, parameter is used to expedite the process and only
161+
/// The `lines_changed_only` parameter is used to expedite the process and only
155162
/// focus on files that have relevant changes. The `file_filter` parameter applies
156163
/// a filter to only include source files (or ignored files) based on the
157164
/// extensions and ignore patterns specified.

0 commit comments

Comments
 (0)