From patchwork Fri Nov 1 04:38:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb White X-Patchwork-Id: 13858689 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 8C4C1146D45 for ; Fri, 1 Nov 2024 04:38:43 +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=1730435925; cv=none; b=G+xLWhaEryftz0l5LM0wxVd1XZUwl/HDyjLgadJ8EBt68SgQwaGIYtkmPU4l7a6h/EufDv5JxOeh/o3t34fUj/Kuw3NoyhLATh5brPnwUx1W1ye+axa4K7IoawApLb3ryGvjMs5jE2Bsc8FEhU+pySAYx4eAHOf7l2w8Z/OdaN0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730435925; c=relaxed/simple; bh=/Se9OEAa8Z5ULWhKCgQOxmzssQTQloBNxRN/a/DiHvE=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=A7NUo8i3mmlpPymKZcJj0q5+uhnfG9dGKH9220LqRcMYMYMIC/5HUE6FsOORgoGivubIoTptex2hZ/i5uLOuxDUhsC5J2j4dy7nERVnMvfNXFeaSIrXn7AK/BY/b+zuRV4Qj2YfK5oBsBi9VR9qaLIwODJH9v2kSHrZ9UFZJGvM= 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=KVBti3M9; 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="KVBti3M9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1730435916; x=1730695116; 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=KVBti3M9tQTZ++29xi5Em30EHz16jLjHMMdyBntR4uq2SmPk0sXd4/Ga8j+XrkrbW YnKi9nlvaw+ySckQ7Lc2gs4nC5aCpKaizNbU9DjOqhLzW8TYYbEEqdXNbqBkJYsNoh oBBwpwKvysFPIuQxjobFZyR6hqLiE0/0SwlZOmeXHLvKnPmj8Ui0XGIZe+p01m5o3h mJj1m7N0IvZcfPGC4KvN0fZP12vx8sSnxCk/Znk8k8pGevuoZ+uREBlptFymtrPaER +fFImoHA4POwhP2A+gvGAHphWGFP3fTfEo2C0v041W7dHlVKCgOZfixmAzFmHdUajW RrlyqtJLxDuTA== Date: Fri, 01 Nov 2024 04:38:32 +0000 To: git@vger.kernel.org From: Caleb White Cc: Taylor Blau , Phillip Wood , Junio C Hamano , Eric Sunshine , Caleb White Subject: [PATCH v4 3/8] worktree: refactor infer_backlink return Message-ID: <20241031-wt_relative_options-v4-3-07a3dc0f02a3@pm.me> In-Reply-To: <20241031-wt_relative_options-v4-0-07a3dc0f02a3@pm.me> References: <20241031-wt_relative_options-v4-0-07a3dc0f02a3@pm.me> Feedback-ID: 31210263:user:proton X-Pm-Message-ID: 5db6c801399f7fdf4af234d942ea99845ec99f65 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- worktree.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/worktree.c b/worktree.c index 77ff484d3ec48c547ee4e3d958dfa28a52c1eaa7..9346d51c438cbd029e9e57591edd8c9f30cc7638 100644 --- a/worktree.c +++ b/worktree.c @@ -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,12 +725,15 @@ static int is_main_worktree_path(const char *path) * won't know which /worktrees//gitdir to repair. However, we may * 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) { struct strbuf actual = STRBUF_INIT; const char *id; + strbuf_reset(inferred); if (strbuf_read_file(&actual, gitfile, 0) < 0) goto error; if (!starts_with(actual.buf, "gitdir:")) @@ -741,18 +744,16 @@ static int infer_backlink(const char *gitfile, struct strbuf *inferred) id++; /* advance past '/' to point at */ if (!*id) goto error; - strbuf_reset(inferred); strbuf_git_common_path(inferred, the_repository, "worktrees/%s", id); if (!is_directory(inferred->buf)) goto error; strbuf_release(&actual); - return 1; - + return inferred->len; error: strbuf_release(&actual); strbuf_reset(inferred); /* clear invalid path */ - return 0; + return -1; } /*