diff options
Diffstat (limited to 'server')
| -rw-r--r-- | server/common/src/git.rs | 6 | ||||
| -rw-r--r-- | server/src/git_root.rs | 8 |
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=?", |
