]> git.ipfire.org Git - thirdparty/git.git/commitdiff
worktree: use skip_prefix to parse target
authorMartin Ågren <martin.agren@gmail.com>
Sun, 27 Sep 2020 13:15:47 +0000 (15:15 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sun, 27 Sep 2020 21:21:47 +0000 (14:21 -0700)
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>
worktree.c

index 6a236d2e7251873f3f26023f0bd4407e684cbd31..0b1252569775556337a29ccc579caec2ad942c43 100644 (file)
@@ -352,11 +352,11 @@ int is_worktree_being_rebased(const struct worktree *wt,
 
        memset(&state, 0, sizeof(state));
        found_rebase = wt_status_check_rebase(wt, &state) &&
-               ((state.rebase_in_progress ||
-                 state.rebase_interactive_in_progress) &&
-                state.branch &&
-                starts_with(target, "refs/heads/") &&
-                !strcmp(state.branch, target + strlen("refs/heads/")));
+                      (state.rebase_in_progress ||
+                       state.rebase_interactive_in_progress) &&
+                      state.branch &&
+                      skip_prefix(target, "refs/heads/", &target) &&
+                      !strcmp(state.branch, target);
        wt_status_state_free_buffers(&state);
        return found_rebase;
 }
@@ -370,8 +370,8 @@ int is_worktree_being_bisected(const struct worktree *wt,
        memset(&state, 0, sizeof(state));
        found_bisect = wt_status_check_bisect(wt, &state) &&
                       state.branch &&
-                      starts_with(target, "refs/heads/") &&
-                      !strcmp(state.branch, target + strlen("refs/heads/"));
+                      skip_prefix(target, "refs/heads/", &target) &&
+                      !strcmp(state.branch, target);
        wt_status_state_free_buffers(&state);
        return found_bisect;
 }