summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2025-06-23 09:05:10 +0200
committerJoel Klinghed <the_jk@spawned.biz>2025-06-23 09:05:10 +0200
commit0784fd95bcca54c01285097eddea01020203e0a4 (patch)
tree54f2cc8385a10759a0e0ddd4905c65e23df1e5a5
parentf9b7c2a14c939d0bb7d1ac2fcca3116e38e37f74 (diff)
clippy: Use strip_prefix instead of start_prefix + manual slicing
-rw-r--r--server/common/src/git.rs6
-rw-r--r--server/src/git_root.rs8
2 files changed, 7 insertions, 7 deletions
diff --git a/server/common/src/git.rs b/server/common/src/git.rs
index 37995b3..07c7e32 100644
--- a/server/common/src/git.rs
+++ b/server/common/src/git.rs
@@ -160,9 +160,9 @@ fn parse_tree_entries(output: String) -> Vec<TreeEntry> {
fn branch_eq(a: impl AsRef<str>, b: impl AsRef<str>) -> bool {
let a = a.as_ref();
let b = b.as_ref();
- if a.starts_with("refs/heads/") {
- if b.starts_with("refs/heads/") {
- return a[11..] == b[11..];
+ if let Some(stripped_a) = a.strip_prefix("refs/heads/") {
+ if let Some(stripped_b) = b.strip_prefix("refs/heads/") {
+ return stripped_a == stripped_b;
}
return a == format!("refs/heads/{b}");
} else {
diff --git a/server/src/git_root.rs b/server/src/git_root.rs
index ec741c4..f915095 100644
--- a/server/src/git_root.rs
+++ b/server/src/git_root.rs
@@ -252,10 +252,10 @@ async fn git_process_prehook(
let translation_review_id;
- if branch.starts_with("t/") {
+ if let Some(stripped_branch) = branch.strip_prefix("t/") {
// Translation review
- translation_review_id = branch[2..].parse::<u64>().ok();
+ translation_review_id = stripped_branch.parse::<u64>().ok();
if translation_review_id.is_none() {
error!("{branch}: Invalid translation review branch");
errors.push(format!("{branch}: Invalid translation review branch"));
@@ -428,9 +428,9 @@ async fn git_process_posthook(
let branch = row.reference.strip_prefix("refs/heads/").unwrap();
- if branch.starts_with("t/") {
+ if let Some(stripped_branch) = branch.strip_prefix("t/") {
// pre-hook already checked format
- let id = branch[2..].parse::<u64>().unwrap();
+ let id = stripped_branch.parse::<u64>().unwrap();
match sqlx::query!(
"UPDATE translation_reviews SET head=? WHERE project=? AND id=?",