worktree: refactor infer_backlink return

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>

Caleb White committed Nov 29, 2024 at 22:22 UTC 5976310916458868b5cbd9d8c7cc7de5af418230
1 file changed +8 -7
worktree.c
+8 -7
@@ -111,9 +111,9 @@ struct worktree *get_linked_worktree(const char *id,
111 strbuf_strip_suffix(&worktree_path, "/.git");
112
113 if (!is_absolute_path(worktree_path.buf)) {
114 - strbuf_strip_suffix(&path, "gitdir");
115 - strbuf_addbuf(&path, &worktree_path);
116 - strbuf_realpath_forgiving(&worktree_path, path.buf, 0);
114 + strbuf_strip_suffix(&path, "gitdir");
115 + strbuf_addbuf(&path, &worktree_path);
116 + strbuf_realpath_forgiving(&worktree_path, path.buf, 0);
117 }
118
119 CALLOC_ARRAY(worktree, 1);
@@ -725,8 +725,10 @@ static int is_main_worktree_path(const char *path)
725 * won't know which <repo>/worktrees/<id>/gitdir to repair. However, we may
726 * be able to infer the gitdir by manually reading /path/to/worktree/.git,
727 * extracting the <id>, and checking if <repo>/worktrees/<id> exists.
728 + *
729 + * Returns -1 on failure and strbuf.len on success.
730 */
729 -static int infer_backlink(const char *gitfile, struct strbuf *inferred)
731 +static ssize_t infer_backlink(const char *gitfile, struct strbuf *inferred)
732 {
733 struct strbuf actual = STRBUF_INIT;
734 const char *id;
@@ -747,12 +749,11 @@ static int infer_backlink(const char *gitfile, struct strbuf *inferred)
749 goto error;
750
751 strbuf_release(&actual);
750 - return 1;
751 -
752 + return inferred->len;
753 error:
754 strbuf_release(&actual);
755 strbuf_reset(inferred); /* clear invalid path */
755 - return 0;
756 + return -1;
757 }
758
759 /*