Skip to content

Commit 5976310

Browse files
calebdwgitster
authored andcommitted
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/[email protected] Signed-off-by: Caleb White <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1860ba1 commit 5976310

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

worktree.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ struct worktree *get_linked_worktree(const char *id,
111111
strbuf_strip_suffix(&worktree_path, "/.git");
112112

113113
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);
117117
}
118118

119119
CALLOC_ARRAY(worktree, 1);
@@ -725,8 +725,10 @@ static int is_main_worktree_path(const char *path)
725725
* won't know which <repo>/worktrees/<id>/gitdir to repair. However, we may
726726
* be able to infer the gitdir by manually reading /path/to/worktree/.git,
727727
* extracting the <id>, and checking if <repo>/worktrees/<id> exists.
728+
*
729+
* Returns -1 on failure and strbuf.len on success.
728730
*/
729-
static int infer_backlink(const char *gitfile, struct strbuf *inferred)
731+
static ssize_t infer_backlink(const char *gitfile, struct strbuf *inferred)
730732
{
731733
struct strbuf actual = STRBUF_INIT;
732734
const char *id;
@@ -747,12 +749,11 @@ static int infer_backlink(const char *gitfile, struct strbuf *inferred)
747749
goto error;
748750

749751
strbuf_release(&actual);
750-
return 1;
751-
752+
return inferred->len;
752753
error:
753754
strbuf_release(&actual);
754755
strbuf_reset(inferred); /* clear invalid path */
755-
return 0;
756+
return -1;
756757
}
757758

758759
/*

0 commit comments

Comments
 (0)