]> git.ipfire.org Git - thirdparty/git.git/commitdiff
worktree: refactor infer_backlink return
authorCaleb White <cdwhite3@pm.me>
Fri, 29 Nov 2024 22:22:41 +0000 (22:22 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 2 Dec 2024 00:36:16 +0000 (09:36 +0900)
The previous round[1] was merged a bit early before reviewer feedback
could be applied. This correctly indents a code block and updates the
`infer_backlink` function to return `-1` on failure and strbuf.len on
success.

[1]: https://lore.kernel.org/git/20241007-wt_relative_paths-v3-0-622cf18c45eb@pm.me

Signed-off-by: Caleb White <cdwhite3@pm.me>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
worktree.c

index 77ff484d3ec48c547ee4e3d958dfa28a52c1eaa7..afde5394c8760c328f12aa321be3ac5c199cc0f1 100644 (file)
@@ -111,9 +111,9 @@ struct worktree *get_linked_worktree(const char *id,
        strbuf_strip_suffix(&worktree_path, "/.git");
 
        if (!is_absolute_path(worktree_path.buf)) {
-           strbuf_strip_suffix(&path, "gitdir");
-           strbuf_addbuf(&path, &worktree_path);
-           strbuf_realpath_forgiving(&worktree_path, path.buf, 0);
+               strbuf_strip_suffix(&path, "gitdir");
+               strbuf_addbuf(&path, &worktree_path);
+               strbuf_realpath_forgiving(&worktree_path, path.buf, 0);
        }
 
        CALLOC_ARRAY(worktree, 1);
@@ -725,8 +725,10 @@ static int is_main_worktree_path(const char *path)
  * won't know which <repo>/worktrees/<id>/gitdir to repair. However, we may
  * be able to infer the gitdir by manually reading /path/to/worktree/.git,
  * extracting the <id>, and checking if <repo>/worktrees/<id> exists.
+ *
+ * Returns -1 on failure and strbuf.len on success.
  */
-static int infer_backlink(const char *gitfile, struct strbuf *inferred)
+static ssize_t infer_backlink(const char *gitfile, struct strbuf *inferred)
 {
        struct strbuf actual = STRBUF_INIT;
        const char *id;
@@ -747,12 +749,11 @@ static int infer_backlink(const char *gitfile, struct strbuf *inferred)
                goto error;
 
        strbuf_release(&actual);
-       return 1;
-
+       return inferred->len;
 error:
        strbuf_release(&actual);
        strbuf_reset(inferred); /* clear invalid path */
-       return 0;
+       return -1;
 }
 
 /*