From patchwork Fri Jul 31 23:32:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sunshine X-Patchwork-Id: 11695633 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D7ED161F for ; Fri, 31 Jul 2020 23:33:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 329A520836 for ; Fri, 31 Jul 2020 23:33:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GanNvYsg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727103AbgGaXdV (ORCPT ); Fri, 31 Jul 2020 19:33:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726099AbgGaXdU (ORCPT ); Fri, 31 Jul 2020 19:33:20 -0400 Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41757C06174A for ; Fri, 31 Jul 2020 16:33:20 -0700 (PDT) Received: by mail-io1-xd44.google.com with SMTP id j8so20923970ioe.9 for ; Fri, 31 Jul 2020 16:33:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KCMrxd5dz72w5zTffG6R4Mu6cpLfVn+LNnf+gEq8jyU=; b=GanNvYsgN8SveB8C0dvTyvdJHgZUEe4VK8nZ6RzsP1loX9sKhWqCJlx4xV9WLUR0Fz JbidLYSGRTzdU/AF+Wt6QATiXXnm6qFifR29tPGsl4RbBe601fZdpO0j4dz0c2kHwRvZ c2rL/kl4ndlk8wgVPfXTWCleQBtfvZHHyIdfzilxyU/2mgv+mwhpu1r2JrcxgKT7fpgj BAcY8yU/zmTLbp+ZTofHKFVAuzfIt1eW4OGnLQ9w7dRCgPL5/Jiz6N9g+8luqNuZNNV1 0iUiZy/v5RuIKT9odE5VK8oWLn3qE3NumADlXvG0GApuYeu/DGgCDJMdyyLwDOANBfUh TFdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=KCMrxd5dz72w5zTffG6R4Mu6cpLfVn+LNnf+gEq8jyU=; b=tSWGcEoql4vtk4rJM2aGJiSnOgBQyatJjW+3DL4svmxVvcqzYCT1qqtFvJZqXsY+v4 URvgZSOpsxjItzm+fwGLCyBr5YExbDd5xGyNt46h43q+w1LlDlhPW8RBvWT1RCzMUPZR K0vM6SZo3o2OWyvKqE6utPpvOYyVpKH3bIhhRdPb1wQlhHfTAXbCbisX2aSs7FGyC8mG OI2sUzsdFFc0KZSOcGmGdBaeSM5UrXZQ/r9tChiBYAk4nWOFmxI2133+M7YPPl4NwO7I 1CIdV0u2HUhaeZE/EyIjsgg00xdJjullc07MT6+SnloO+XB5TBFsrdf5YyKl106HpuGw +MQA== X-Gm-Message-State: AOAM530sw/kgpug8L3Qwug5lotZqmCSe5EKtcQiBAO8puNMYSHZm28Ad JGBJLDUy/0MfJWwEQlvAMEZ1gWqXBPM= X-Google-Smtp-Source: ABdhPJycMqNEWh29M5Bqv/Wb+FS+fhX97p5wMQaCYRxL6p/5hzw8IBOyqeRhtiFjif0D+BPpzVJBow== X-Received: by 2002:a6b:b7ce:: with SMTP id h197mr5984008iof.60.1596238399243; Fri, 31 Jul 2020 16:33:19 -0700 (PDT) Received: from localhost.localdomain (user-12l2dpj.cable.mindspring.com. [69.81.55.51]) by smtp.gmail.com with ESMTPSA id t18sm3336758ild.46.2020.07.31.16.33.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jul 2020 16:33:18 -0700 (PDT) From: Eric Sunshine To: git@vger.kernel.org Cc: Junio C Hamano , Duy Nguyen , Michael Rappazzo , Eric Sunshine Subject: [PATCH 1/4] worktree: drop pointless strbuf_release() Date: Fri, 31 Jul 2020 19:32:11 -0400 Message-Id: <20200731233214.22131-2-sunshine@sunshineco.com> X-Mailer: git-send-email 2.28.0.203.gce1f2e0ef1 In-Reply-To: <20200731233214.22131-1-sunshine@sunshineco.com> References: <20200731233214.22131-1-sunshine@sunshineco.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The content of this strbuf is unconditionally detached several lines before the strbuf_release() and the strbuf is never touched again after that point. Signed-off-by: Eric Sunshine --- Notes: I'm on the fence about this change. On the one hand, I spent extra cycles studying the code to determine if the strbuf was used again after being detached. On the other hand, the strbuf_release() at the end of the function protects against a leak if someone ever inserts code which re-uses the strbuf. So, I wouldn't be bothered if this patch is dropped from the series. worktree.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/worktree.c b/worktree.c index cba2e54598..c0df5e2c79 100644 --- a/worktree.c +++ b/worktree.c @@ -66,8 +66,6 @@ static struct worktree *get_main_worktree(void) worktree->is_bare = (is_bare_repository_cfg == 1) || is_bare_repository(); add_head_info(worktree); - - strbuf_release(&worktree_path); return worktree; } From patchwork Fri Jul 31 23:32:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sunshine X-Patchwork-Id: 11695629 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 59AA3722 for ; Fri, 31 Jul 2020 23:33:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3FB5B20836 for ; Fri, 31 Jul 2020 23:33:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Anb9+/mh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727815AbgGaXdZ (ORCPT ); Fri, 31 Jul 2020 19:33:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727093AbgGaXdV (ORCPT ); Fri, 31 Jul 2020 19:33:21 -0400 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BCE7C06174A for ; Fri, 31 Jul 2020 16:33:21 -0700 (PDT) Received: by mail-io1-xd33.google.com with SMTP id g19so21210088ioh.8 for ; Fri, 31 Jul 2020 16:33:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0RArvJ2r+niN5CxeWy9DTE3YcMhO/ThVEAVUKztk4rA=; b=Anb9+/mh6WhjJhmxIUdQQHxaa4hlCkMKcv/+OjoLwoqj5EKbqwWo6hT5ViF5SwsWcY lSGmB4Jf2hmFGxSd0M0umhdnm3pTPRfx+Byq8mm01eqhiFhyP2xQW/gGnp03Tj5yEWGs PXV/jDp6IXv0EwlGCo7SF3d2B3XFqFE4xX0391gGWqgr6Vx3JDjeGVXBOfGihYTJ67Hr EwNkcXOSza3eohPG4tC3CUFcgl6hAhwNUvQ0XViomdeLPgZdUyCRcykvgNzkUlJBcPWc gnGlK/K9iKMbCNjTYHIN7YU9S3W0H/U/mfuJG5YfD7kGPbNmXFnkR6dg4J3X1FOkg215 +oWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=0RArvJ2r+niN5CxeWy9DTE3YcMhO/ThVEAVUKztk4rA=; b=XVR7NV4RvEA20YrRFNstgNgrjbvint3KTBu/pU2qDp3lGXHs15CaZnxjjzM65aVz98 sFK7qe8nvjgB7lVhjlOdNQq+F1Up9mnt6OzsJ4iw0WuQR8gzaooZ3WRn/LlLCxJOkMjh WzVoqceb5VWIpF7mKYifvHpb0+KdpfFeDDiOZZCiqkXmsw+MdpfOlZ4tVw8R/I/1Hj/V 7xGsdsWmyyusJ0II7gLG27gKgsB+00IHCol9Subzytdc4KlOh4geQtYHhYN918SNslGg iX+2aG6c2rlM+jjsYyhokLA3aHuZJiGDxvFcGXLJs8i9JoDapcb/dP8yvgeICizHe9dL C1LA== X-Gm-Message-State: AOAM533IeEdLvyrhWu7qJHUQePnchtAbOmzo9fDmB5b09n/96cCIHy5T B+pePf7GOHiPqK6fJGdrdGN8kKvSAvQ= X-Google-Smtp-Source: ABdhPJy9tZMFldiIDvIRLbPKBqpnBYYwl8AvK5agDfzAnO0Wkw6BOI7x0tXVRgxKG1IcMIA/rD1qXw== X-Received: by 2002:a5d:8d12:: with SMTP id p18mr5928407ioj.148.1596238400532; Fri, 31 Jul 2020 16:33:20 -0700 (PDT) Received: from localhost.localdomain (user-12l2dpj.cable.mindspring.com. [69.81.55.51]) by smtp.gmail.com with ESMTPSA id t18sm3336758ild.46.2020.07.31.16.33.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jul 2020 16:33:19 -0700 (PDT) From: Eric Sunshine To: git@vger.kernel.org Cc: Junio C Hamano , Duy Nguyen , Michael Rappazzo , Eric Sunshine Subject: [PATCH 2/4] worktree: drop unused code from get_linked_worktree() Date: Fri, 31 Jul 2020 19:32:12 -0400 Message-Id: <20200731233214.22131-3-sunshine@sunshineco.com> X-Mailer: git-send-email 2.28.0.203.gce1f2e0ef1 In-Reply-To: <20200731233214.22131-1-sunshine@sunshineco.com> References: <20200731233214.22131-1-sunshine@sunshineco.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This code has been unused since fa099d2322 (worktree.c: kill parse_ref() in favor of refs_resolve_ref_unsafe(), 2017-04-24), so drop it. Signed-off-by: Eric Sunshine --- Notes: This is a companion to 02bbbe9df9 (worktree: drop unused code from get_main_worktree(), 2020-02-23), which also cleaned up fallout from fa099d2322 (worktree.c: kill parse_ref() in favor of refs_resolve_ref_unsafe(), 2017-04-24). worktree.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/worktree.c b/worktree.c index c0df5e2c79..fa8366a3ca 100644 --- a/worktree.c +++ b/worktree.c @@ -90,9 +90,6 @@ static struct worktree *get_linked_worktree(const char *id) strbuf_strip_suffix(&worktree_path, "/."); } - strbuf_reset(&path); - strbuf_addf(&path, "%s/worktrees/%s/HEAD", get_git_common_dir(), id); - worktree = xcalloc(1, sizeof(*worktree)); worktree->path = strbuf_detach(&worktree_path, NULL); worktree->id = xstrdup(id); From patchwork Fri Jul 31 23:32:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sunshine X-Patchwork-Id: 11695627 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 33031722 for ; Fri, 31 Jul 2020 23:33:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B20D20838 for ; Fri, 31 Jul 2020 23:33:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mTfELATT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727803AbgGaXdX (ORCPT ); Fri, 31 Jul 2020 19:33:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726807AbgGaXdW (ORCPT ); Fri, 31 Jul 2020 19:33:22 -0400 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 961DCC06174A for ; Fri, 31 Jul 2020 16:33:22 -0700 (PDT) Received: by mail-io1-xd41.google.com with SMTP id e64so33264835iof.12 for ; Fri, 31 Jul 2020 16:33:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hQcugFfn5Wgx4+KU26yD2EPjdPvfnMbw8pSKoG73lIM=; b=mTfELATTywcOZAJ3VMOSV56ju8JWlYy+ue/ANCqXkk7zyI+xoK+IMgFp6pEyaDraOI hGQFOMpklCMTB/zbkghTOcPySi05QeRgjlNJUHEsMfUV+eteAWuuwQ9Zg7KTHjzhWBOs 4JtsxuI5VX7kW40cwxWaoGxjZo8i4xd9cMfpMz7gBAL3TFF8tK/wrfRUx8YBvXRVIwa6 VRNfeQUncOmdOq3h2S3+bhrn0u5fh/CjIwktQpgSblsSK3NUH8X7Ym/ak3XPS1nvDcOo 3cCg5ZL0Xf141byIPrAiOH4iiImIWIsmS53KYSixAZoIWtRN29d824DqDPtq0SoVpCjs oyqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=hQcugFfn5Wgx4+KU26yD2EPjdPvfnMbw8pSKoG73lIM=; b=DkofzPdgfoIcNsg0SejKFaj70pqn0i9sNVVC9UIWTXcXqw+lTQBorauyhvSZkpLftl LrU2GPClrRMXsiH1rq9Ir0Gb2M7PtAZNBf2+u3UuEOX+E+EEuvRQjygv5MLzbQwYEAtE BEVLjJXR8K+XdKePgCu4GO9595cB/OGp2N/KflX91AvrPI1hU8X4AB16GbCPv7KwhBX8 aumiWNSwfO65kfytwOd8dbK49olOm3VDuDtXXOEOSb1/rvApFmLDci+XAqSLThvAduFz yTr+Ystvp+RShCFSPdF7KzUmDs1O0GQE7URpBdJPtBG9VPGPVWaE6CJKQrOaulU59Dxg yH/g== X-Gm-Message-State: AOAM533gMiB3yFOj/a3otCh6eua5CJnLLtQdw9NGKkrbMKowaLoW9UQD lv5sgTvuGvynTEdw1fiq4U95aHdfaFA= X-Google-Smtp-Source: ABdhPJzCaqHhDVGfVEf6AhxUOWZ0i3UOC4UQMGz+Qd+NQ8r3EEVmAX30+0JAiouwpAY94hk08oqKnA== X-Received: by 2002:a6b:7610:: with SMTP id g16mr5957808iom.115.1596238401598; Fri, 31 Jul 2020 16:33:21 -0700 (PDT) Received: from localhost.localdomain (user-12l2dpj.cable.mindspring.com. [69.81.55.51]) by smtp.gmail.com with ESMTPSA id t18sm3336758ild.46.2020.07.31.16.33.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jul 2020 16:33:21 -0700 (PDT) From: Eric Sunshine To: git@vger.kernel.org Cc: Junio C Hamano , Duy Nguyen , Michael Rappazzo , Eric Sunshine Subject: [PATCH 3/4] worktree: drop bogus and unnecessary path munging Date: Fri, 31 Jul 2020 19:32:13 -0400 Message-Id: <20200731233214.22131-4-sunshine@sunshineco.com> X-Mailer: git-send-email 2.28.0.203.gce1f2e0ef1 In-Reply-To: <20200731233214.22131-1-sunshine@sunshineco.com> References: <20200731233214.22131-1-sunshine@sunshineco.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The content of .git/worktrees//gitdir must be a path of the form "/path/to/worktree/.git". Any other content would be indicative of a corrupt "gitdir" file. To determine the path of the worktree itself one merely strips the "/.git" suffix, and this is indeed how the worktree path was determined from inception. However, 5193490442 (worktree: add a function to get worktree details, 2015-10-08) extended the path manipulation in a mysterious way. If it is unable to strip "/.git" from the path, then it instead reports the current working directory as the linked worktree's path: if (!strbuf_strip_suffix(&worktree_path, "/.git")) { strbuf_reset(&worktree_path); strbuf_add_absolute_path(&worktree_path, "."); strbuf_strip_suffix(&worktree_path, "/."); } This logic is clearly bogus; it can never be generally correct behavior. It materialized out of thin air in 5193490442 with neither explanation nor tests to illustrate a case in which it would be desirable. It's possible that this logic was introduced to somehow deal with a corrupt "gitdir" file, so that it returns _some_ sort of meaningful value, but returning the current working directory is not helpful. In fact, it is quite misleading (except in the one specific case when the current directory is the worktree whose "gitdir" entry is corrupt). Moreover, reporting the corrupt value to the user, rather than fibbing about it and hiding it outright, is more helpful since it may aid in diagnosing the problem. Therefore, drop this bogus path munging and restore the logic to the original behavior of merely stripping "/.git". Signed-off-by: Eric Sunshine --- worktree.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/worktree.c b/worktree.c index fa8366a3ca..355824bf87 100644 --- a/worktree.c +++ b/worktree.c @@ -82,13 +82,8 @@ static struct worktree *get_linked_worktree(const char *id) if (strbuf_read_file(&worktree_path, path.buf, 0) <= 0) /* invalid gitdir file */ goto done; - strbuf_rtrim(&worktree_path); - if (!strbuf_strip_suffix(&worktree_path, "/.git")) { - strbuf_reset(&worktree_path); - strbuf_add_absolute_path(&worktree_path, "."); - strbuf_strip_suffix(&worktree_path, "/."); - } + strbuf_strip_suffix(&worktree_path, "/.git"); worktree = xcalloc(1, sizeof(*worktree)); worktree->path = strbuf_detach(&worktree_path, NULL); From patchwork Fri Jul 31 23:32:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sunshine X-Patchwork-Id: 11695631 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B839114B7 for ; Fri, 31 Jul 2020 23:33:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9EDA420836 for ; Fri, 31 Jul 2020 23:33:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bwTqRWU0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727823AbgGaXd0 (ORCPT ); Fri, 31 Jul 2020 19:33:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727812AbgGaXdX (ORCPT ); Fri, 31 Jul 2020 19:33:23 -0400 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4769C06174A for ; Fri, 31 Jul 2020 16:33:23 -0700 (PDT) Received: by mail-io1-xd42.google.com with SMTP id l1so33257848ioh.5 for ; Fri, 31 Jul 2020 16:33:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fVt3E+hP/lbIR4ZzN16MFc73EE6QUrLi3ujSr+mBL4I=; b=bwTqRWU0mK6NCo9Ouz3N6JluSbvkl/DPAFlUMQgMzngp+VEiOe2KPxYQcrVgCNLHRY 3SpPa2cNAQrDrvTcivrOTX1CSD21Kp/bnHXEqXxidZ7sC26iN7f/iHlFWAH3Wr0Dw+yI dZmbiKfezNza+QHfmQ6ImdbCKfuCEXX2UVOpVbKdcsAVKkn+jTVUZoLEH0kRq6TwP1rJ osQTdu2boekn/p3R9lNrR1t1+r2pw+twZ5fqgr1WNP+2BVfs9MZC7ncPwDak67xoYDRV tLS/EAv6s28eNtG9F556YXFToRIZzcQh2QCA2JsBKKcxT4PF/muAaIy/Do8QtJ5FLPb6 0Jvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=fVt3E+hP/lbIR4ZzN16MFc73EE6QUrLi3ujSr+mBL4I=; b=J7adihrxGtpaRLLXq4THMZoBLE8xTHxiqXGhIjy1Q0mQXqaHkgzebH42Rjv6prvdiW C+lElUGj6m/hbqVec/MpxQVc40keAkq4aLwCAc+CQ+oPIu30H9bxhezvttu2HbCrNJ8i EI6+6LIoIB0g9V9KaJkG/WKYtnN5hQtN6Ckp9wP8SwZxNlYze4B5PWlH1/ULB44YyHdP 3eQ6nMV9UIwCGWIHCKV49Ck+WwICgmKKeQuYBGVt+Nqj/qHD50+Tf31VaFTbVShxPnd6 XnesUcjCoByG2BE/gzgqdpM6Y54XLdeOzFEShpTv5hBDsgZivTWaw/fbABSEGljI1s+I P6rg== X-Gm-Message-State: AOAM531ANa+0khvJkZCmWeyUAhmDX8GCrbx6Bzr9//++Eat7MoyqPvUy TSySZyEU2HshQTg1zDRVkvU5g7+YHj8= X-Google-Smtp-Source: ABdhPJzO8dFibZF8ffiRhmA02XmUwk68h2Ttg+h78R8AVyy1bVZEBtCXrDwj7oJUMXujvoqrBE+AMg== X-Received: by 2002:a5d:9051:: with SMTP id v17mr5747470ioq.88.1596238402742; Fri, 31 Jul 2020 16:33:22 -0700 (PDT) Received: from localhost.localdomain (user-12l2dpj.cable.mindspring.com. [69.81.55.51]) by smtp.gmail.com with ESMTPSA id t18sm3336758ild.46.2020.07.31.16.33.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jul 2020 16:33:22 -0700 (PDT) From: Eric Sunshine To: git@vger.kernel.org Cc: Junio C Hamano , Duy Nguyen , Michael Rappazzo , Eric Sunshine Subject: [PATCH 4/4] worktree: retire special-case normalization of main worktree path Date: Fri, 31 Jul 2020 19:32:14 -0400 Message-Id: <20200731233214.22131-5-sunshine@sunshineco.com> X-Mailer: git-send-email 2.28.0.203.gce1f2e0ef1 In-Reply-To: <20200731233214.22131-1-sunshine@sunshineco.com> References: <20200731233214.22131-1-sunshine@sunshineco.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In order for "git-worktree list" to present consistent results, get_main_worktree() performs manual normalization on the repository path (returned by get_common_dir()) after passing it through strbuf_add_absolute_path(). In particular, it cleans up the path for three distinct cases when the current working directory is (1) the main worktree, (2) the .git/ subdirectory, or (3) a bare repository. The need for such special-cases is a direct consequence of employing strbuf_add_absolute_path() which, for the sake of efficiency, doesn't bother normalizing the path (such as folding out redundant path components) after making it absolute. Lack of normalization is not typically a problem since redundant path elements make no difference when working with paths at the filesystem level. However, when preparing paths for presentation, possible redundant path components make it difficult to ensure consistency. Eliminate the need for these special cases by instead making the path absolute via strbuf_add_real_path() which normalizes the path for us. Once normalized, the only case we need to handle manually is converting it to the path of the main worktree by stripping the "/.git" suffix. This stripping of the "/.git" suffix is a regular idiom in worktree-related code; for instance, it is employed by get_linked_worktree(), as well. Signed-off-by: Eric Sunshine --- Notes: This is a followup to 5f4ee57ad9 (worktree: avoid dead-code in conditional, 2020-06-24) which dropped dead code from the manual normalization done by get_main_worktree() but which did not eliminate the special cases. It's also a direct response to Junio's observation[1] that it would be better if we didn't have to handle these special cases in the first place. [1]: https://lore.kernel.org/git/xmqqbll8569x.fsf@gitster.c.googlers.com/ worktree.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/worktree.c b/worktree.c index 355824bf87..62217b4a6b 100644 --- a/worktree.c +++ b/worktree.c @@ -49,10 +49,8 @@ static struct worktree *get_main_worktree(void) struct worktree *worktree = NULL; struct strbuf worktree_path = STRBUF_INIT; - strbuf_add_absolute_path(&worktree_path, get_git_common_dir()); - if (!strbuf_strip_suffix(&worktree_path, "/.git/.") && /* in .git */ - !strbuf_strip_suffix(&worktree_path, "/.git")) /* in worktree */ - strbuf_strip_suffix(&worktree_path, "/."); /* in bare repo */ + strbuf_add_real_path(&worktree_path, get_git_common_dir()); + strbuf_strip_suffix(&worktree_path, "/.git"); worktree = xcalloc(1, sizeof(*worktree)); worktree->path = strbuf_detach(&worktree_path, NULL);