worktree: use skip_prefix to parse target
Instead of checking for "refs/heads/" using `starts_with()`, then skipping past "refs/heads/" using `strlen()`, just use `skip_prefix()`. In `is_worktree_being_rebased()`, we can adjust the indentation while we're here and lose a pair of parentheses which isn't needed and which might even make the reader wonder what they're missing and why that grouping is there. Signed-off-by: Martin Ågren <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Martin Ågren committed
Sep 27, 2020 at 15:15 UTC
a46d1f732192a8621ead7ea5c4a3ca391ad881cb
1 file changed
+7
-7
worktree.c
+7
-7
@@ -352,11 +352,11 @@ int is_worktree_being_rebased(const struct worktree *wt,
352
353
memset(&state, 0, sizeof(state));
354
found_rebase = wt_status_check_rebase(wt, &state) &&
355
- ((state.rebase_in_progress ||
356
- state.rebase_interactive_in_progress) &&
357
- state.branch &&
358
- starts_with(target, "refs/heads/") &&
359
- !strcmp(state.branch, target + strlen("refs/heads/")));
355
+ (state.rebase_in_progress ||
356
+ state.rebase_interactive_in_progress) &&
357
+ state.branch &&
358
+ skip_prefix(target, "refs/heads/", &target) &&
359
+ !strcmp(state.branch, target);
360
wt_status_state_free_buffers(&state);
361
return found_rebase;
362
}
@@ -370,8 +370,8 @@ int is_worktree_being_bisected(const struct worktree *wt,
370
memset(&state, 0, sizeof(state));
371
found_bisect = wt_status_check_bisect(wt, &state) &&
372
state.branch &&
373
- starts_with(target, "refs/heads/") &&
374
- !strcmp(state.branch, target + strlen("refs/heads/"));
373
+ skip_prefix(target, "refs/heads/", &target) &&
374
+ !strcmp(state.branch, target);
375
wt_status_state_free_buffers(&state);
376
return found_bisect;
377
}