From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 510B67F460 for ; Thu, 31 Oct 2024 05:05:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730351150; cv=none; b=pNYlKNT0aR/XifpPzYCo7oSVGZrmck7RRDPFOub0c3V4F0DM1P9R1g3GvstgjfxSrBgixiqJHFuSduJlgrESBgsmyfa0PSnd7YKI8UJwAASVZnHej2mWs1nsVR0ccRFu2r7YFdO9+5fIQYC3XOQDqV4LlI7hWbrcjoU76HyDmvo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730351150; c=relaxed/simple; bh=/Se9OEAa8Z5ULWhKCgQOxmzssQTQloBNxRN/a/DiHvE=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VGSsp1lM7I1166QGUEOUK3U1eNFtc5KVYLeTOHwi679tJSud3c4gPjAIC3JXhXtG2UCLPqYmxb6/7zQ/VvwmdVcZtPZ2JA1In6cQUg5IUCOK0QAOQ8/bIX5fm82sFcE7n8KM/LoMMDI5Rn/WY0xIe8qhckiywNq0i6ErDa50EDY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me; spf=pass smtp.mailfrom=pm.me; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b=sMzY+LPL; arc=none smtp.client-ip=185.70.43.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pm.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b="sMzY+LPL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1730351146; x=1730610346; bh=I4JVVGWtkHbLhQbETsc5Fv8E4IGvq+MC12C3u0SKQBk=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=sMzY+LPLEo4jZ7NJntdDhT+nXBzm/N1KnOPew0oQurhrXYSAWHELDCN60KcO1Oa5E KD+i/M2evil2TtBjMdgyxcpOK1u2vvBbSAdr51uqut49DYZ6AS0yZ5B2kfEnsmGdgv JYt/UxAXdg+UWg2S/aZtPFjTOdiRmnufLjF027wS5sLrvI4/WUkc2UbgRIE7wN3PtL 2p/5aUkU2ewOB4UMkZOHfDzFvdqKIC0xaQvPRWP/ekh3wqUF8S4qBZlfqgI8p+2bUy 0b+pbu8sWAfQc4lDLa3disoVJPMbLN/RC3aUtCnVNTVYu6Gw1iBL2LaIH41e+cW9vY iGUeMzPzZw6KQ== Date: Thu, 31 Oct 2024 05:05:42 +0000 To: git@vger.kernel.org From: Caleb White Cc: Taylor Blau , Phillip Wood , Junio C Hamano , Eric Sunshine , Caleb White Subject: [PATCH v3 3/8] worktree: refactor infer_backlink return Message-ID: <20241031-wt_relative_options-v3-3-3e44ccdf64e6@pm.me> In-Reply-To: <20241031-wt_relative_options-v3-0-3e44ccdf64e6@pm.me> References: <20241031-wt_relative_options-v3-0-3e44ccdf64e6@pm.me> Feedback-ID: 31210263:user:proton X-Pm-Message-ID: 82849a08d8776b0f172a80f16f24be8b2f6d8aaa Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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-622cf18c45= eb@pm.me Signed-off-by: Caleb White --- worktree.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/worktree.c b/worktree.c index 77ff484d3ec48c547ee4e3d958dfa28a52c1eaa7..9346d51c438cbd029e9e57591ed= d8c9f30cc7638 100644 --- a/worktree.c +++ b/worktree.c @@ -111,9 +111,9 @@ struct worktree *get_linked_worktree(const char *id, =09strbuf_strip_suffix(&worktree_path, "/.git"); =20 =09if (!is_absolute_path(worktree_path.buf)) { -=09 strbuf_strip_suffix(&path, "gitdir"); -=09 strbuf_addbuf(&path, &worktree_path); -=09 strbuf_realpath_forgiving(&worktree_path, path.buf, 0); +=09=09strbuf_strip_suffix(&path, "gitdir"); +=09=09strbuf_addbuf(&path, &worktree_path); +=09=09strbuf_realpath_forgiving(&worktree_path, path.buf, 0); =09} =20 =09CALLOC_ARRAY(worktree, 1); @@ -725,12 +725,15 @@ static int is_main_worktree_path(const char *path) * won't know which /worktrees//gitdir to repair. However, we ma= y * be able to infer the gitdir by manually reading /path/to/worktree/.git, * extracting the , and checking if /worktrees/ 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= ) { =09struct strbuf actual =3D STRBUF_INIT; =09const char *id; =20 +=09strbuf_reset(inferred); =09if (strbuf_read_file(&actual, gitfile, 0) < 0) =09=09goto error; =09if (!starts_with(actual.buf, "gitdir:")) @@ -741,18 +744,16 @@ static int infer_backlink(const char *gitfile, struct= strbuf *inferred) =09id++; /* advance past '/' to point at */ =09if (!*id) =09=09goto error; -=09strbuf_reset(inferred); =09strbuf_git_common_path(inferred, the_repository, "worktrees/%s", id); =09if (!is_directory(inferred->buf)) =09=09goto error; =20 =09strbuf_release(&actual); -=09return 1; - +=09return inferred->len; error: =09strbuf_release(&actual); =09strbuf_reset(inferred); /* clear invalid path */ -=09return 0; +=09return -1; } =20 /* --=20 2.47.0