From patchwork Sun Sep 19 01:57:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Aguilar X-Patchwork-Id: 12504061 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D07DC433EF for ; Sun, 19 Sep 2021 01:57:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F195060232 for ; Sun, 19 Sep 2021 01:57:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236202AbhISB7B (ORCPT ); Sat, 18 Sep 2021 21:59:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235288AbhISB7A (ORCPT ); Sat, 18 Sep 2021 21:59:00 -0400 Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5ACBDC061574 for ; Sat, 18 Sep 2021 18:57:33 -0700 (PDT) Received: by mail-qt1-x829.google.com with SMTP id 2so12348431qtw.1 for ; Sat, 18 Sep 2021 18:57:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ejMSf+qftt4yFNenbBF0xFEAOcAsqGiVPYO0OGTJgac=; b=Icdo4XjPRia3zrkPVC74OBA7AgtpRbbayjBfuJLDHq85pMMMn8Z44OuXN+5xsYKADS Vi3R0Lyq6YlMfisB52volTu4ZkWnlmkPfhNNZA2XmhHOOEgDU2DAiewE9hjASYY+RXPi Ig9O3eraC/CFqM4edHhA6LGh2q3+pGE8zPrwW0Ylj3VFdw2Cqn7zhxW3erHpCl/8lwAK dwpVbDwqolvFstkVTOZSbn8ztPEA0VKoQoKHy5/HFmC7fyX7XE53D13UC7v/n81cvceX iJBcRfEkuFOx0opTG0ZPIWUyW21F/j+bSl3j1+VnBd+3KfjHYh+3Hz8BvhUkkiLuWv8n vQEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ejMSf+qftt4yFNenbBF0xFEAOcAsqGiVPYO0OGTJgac=; b=bYyC8zqWSTnQC/OQSGbVKPFXxKK9mgShVf5a5BttxVttLJaQp1aKBcg3jlDxpNOJ73 AfsmjuiF8oe54hTOIYNIv+QedUjIxN7RMM6XFkIvBd2MBHNMUf6/fqhhNrVcYeS5A8UW EL7pZnS7A8cVhu/EshJiXCTIsqIWHn74MNBdnpHl03Nw5eo7WL4BKswwLSB7Ol4nw7yn 0M8ra1PkyKULT4EoQN/S5n0PPwa4rPfUB5/QfqadaOVrDISbHBhZTFHzJq5GVYdMvjRC bqpYteZPvSGeHEmMF45CVzcJDijZ2H19bnBPcXaCrs/sOEFLBXEmhTOFcZJv1J8xFl6j T9zA== X-Gm-Message-State: AOAM5304GSuap5QkNA9MHYleA+FnNn7y8oPa37MEf0KNNBtOx/KKFN2/ lmozqwfd+7Ed7ZwyFZKbt4U= X-Google-Smtp-Source: ABdhPJwaHz5/1t9I+oHAkdZCi5h8LGK3jZkznjrJW46JF8dCI/SNiJSnLQQbBSygv2Z//busMDCqow== X-Received: by 2002:a05:622a:48d:: with SMTP id p13mr17496773qtx.282.1632016652203; Sat, 18 Sep 2021 18:57:32 -0700 (PDT) Received: from sarawiggum.attlocal.net ([2600:1700:5d80:a320:4412:822d:c222:aea8]) by smtp.gmail.com with ESMTPSA id k10sm6759062qth.44.2021.09.18.18.57.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Sep 2021 18:57:31 -0700 (PDT) From: David Aguilar To: Junio C Hamano Cc: Git Mailing List , Johannes Schindelin , Alan Blotz , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= Subject: [PATCH 1/4] t7800-difftool: cleanup temporary repositories used by tests Date: Sat, 18 Sep 2021 18:57:26 -0700 Message-Id: <20210919015729.98323-1-davvid@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The "dirlinks" and "growing" repositories should not outlive the tests that use them. Signed-off-by: David Aguilar --- t/t7800-difftool.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index a173f564bc..a923f193da 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -414,6 +414,7 @@ test_expect_success 'setup change in subdirectory' ' test_expect_success 'difftool -d with growing paths' ' a=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa && git init growing && + test_when_finished rm -rf growing && ( cd growing && echo "test -f \"\$2/b\"" | write_script .git/test-for-b.sh && @@ -646,6 +647,7 @@ test_expect_success 'difftool properly honors gitlink and core.worktree' ' test_expect_success SYMLINKS 'difftool --dir-diff symlinked directories' ' test_when_finished git reset --hard && git init dirlinks && + test_when_finished rm -rf dirlinks && ( cd dirlinks && git config diff.tool checktrees && From patchwork Sun Sep 19 01:57:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Aguilar X-Patchwork-Id: 12504063 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C3B6C433F5 for ; Sun, 19 Sep 2021 01:57:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B382610CF for ; Sun, 19 Sep 2021 01:57:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237025AbhISB7C (ORCPT ); Sat, 18 Sep 2021 21:59:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235603AbhISB7A (ORCPT ); Sat, 18 Sep 2021 21:59:00 -0400 Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82111C061757 for ; Sat, 18 Sep 2021 18:57:34 -0700 (PDT) Received: by mail-qt1-x830.google.com with SMTP id r21so12282533qtw.11 for ; Sat, 18 Sep 2021 18:57:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hKbUAdZ2pFDQd+NsXCuY/9ZHnCPcqDJj51rmfbO5W70=; b=M4QMv1KaTScu6Tu3A3a480TfR/cgtz6jdRYLzjVPD9/W3hxfacSPt93+kX1LI1m2L8 zLWUdsN0Jaura4mHv049yvi8g9pvfoi84iTvYJmmtmLDDOeAg4FPm+hrgmmpBE+UEdBG K70JDKTGe37ovYmSyYlQgTjXyn8gXJ46LhsoyDr2BmK3lSYOunuyKvJo0+f+BxhGO9aR VbZQ57YPAJa7htO47/vQUwBYXuH1HYq119WRyO45reJM+3/0OtQV5Ot8VHHxghOW7ETi Ir7l4OMw2gfYmAYKloSV3AC/2PO5vF+yztSJQDWfg/tjHcqVE4KNLCFI+Ae/sf35T/5o Osmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hKbUAdZ2pFDQd+NsXCuY/9ZHnCPcqDJj51rmfbO5W70=; b=lUIw2AIwBW0vzDjnNVB9YnHKBe69unIUWreJFK1Nlo+GyiwSXSAEAOiiLdk7e00VbJ V9GrZj84IONQBnQR8+PbQG0mWvzIIX8dkH6zUmltH50wJZFcL1jVrP6YOFp8UMqF4QTG kXwqJS8qt70KUlGLOV9ofceaJl8nlhSBnsyPtcrnZoGsGFUP0bJk11VOuGsg556MQKBN MfFRMaTIeK5WL2Xt42CO5+G14Th8ZGOJ0al5loWYCShaOjnV86xah5HmHgoO/caqEzAn cuoVBA6zu/arF2Z1s6Xz5UOgaOIWsTKVI6utrdKPbEoD1KlnLEPHSmlk833VY2Zd7joS Hk7Q== X-Gm-Message-State: AOAM531rOwVyz8OQq2rZYCQXjsVfgGmllXJ8mBmGiC3on8MaIeGpM9a+ PuvK3T35YO6SCCnE4zJfdRY= X-Google-Smtp-Source: ABdhPJxD486CDdjYG8VvcF6meHeeYdx/TuL19A+HLiZjA6EcMF4lL8i8BlTt0zxYeoUZrNAC66XT2g== X-Received: by 2002:ac8:67d7:: with SMTP id r23mr17206577qtp.227.1632016653587; Sat, 18 Sep 2021 18:57:33 -0700 (PDT) Received: from sarawiggum.attlocal.net ([2600:1700:5d80:a320:4412:822d:c222:aea8]) by smtp.gmail.com with ESMTPSA id k10sm6759062qth.44.2021.09.18.18.57.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Sep 2021 18:57:33 -0700 (PDT) From: David Aguilar To: Junio C Hamano Cc: Git Mailing List , Johannes Schindelin , Alan Blotz , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= Subject: [PATCH 2/4] difftool: add a missing space to the run_dir_diff() comments Date: Sat, 18 Sep 2021 18:57:27 -0700 Message-Id: <20210919015729.98323-2-davvid@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20210919015729.98323-1-davvid@gmail.com> References: <20210919015729.98323-1-davvid@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: David Aguilar --- builtin/difftool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/difftool.c b/builtin/difftool.c index bb9fe7245a..4d2e772031 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -548,7 +548,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, } /* - * Symbolic links require special treatment.The standard "git diff" + * Symbolic links require special treatment. The standard "git diff" * shows only the link itself, not the contents of the link target. * This loop replicates that behavior. */ From patchwork Sun Sep 19 01:57:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Aguilar X-Patchwork-Id: 12504065 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B8EDC433FE for ; Sun, 19 Sep 2021 01:57:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 25EED61100 for ; Sun, 19 Sep 2021 01:57:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237531AbhISB7D (ORCPT ); Sat, 18 Sep 2021 21:59:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235840AbhISB7A (ORCPT ); Sat, 18 Sep 2021 21:59:00 -0400 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 524E1C06175F for ; Sat, 18 Sep 2021 18:57:35 -0700 (PDT) Received: by mail-qk1-x72e.google.com with SMTP id d207so5194705qkg.0 for ; Sat, 18 Sep 2021 18:57:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=shHH2in1AyjGg1OR3nV0C30/s6g7n+X1cF/rXjKEm1Y=; b=UCwWy+v+vZi8ATZj1UWdoYHJewO8FkOi32dtTR/rqhPkuYuKO3Cb9XlDHY8fjf1Ipb jbYycyc30ceullo8AU8FJ+rqpBX9duaFqVBxfrvOiBKfA1JSBxSaOqIwIbRPrnFlp2bL WyBCgejKcNE6q+o9LaFOE8ubBBZOHA/O/Ine6IYkLdlbKbNx/bSHSGiEEkg/1ShDs1EY HLRdn9Cgt8DPejIzDSKwFyP44Oe7ygEY2pRWEh+DWRg8k3vqPphRbGip/JOCn2YX5hLg 8wYc0Fu2lVOoCVRZd+K6aa2rZkJwAuZT96V8aJlo4H9KiOfRPin6wEh6xSoJewgOMkkD Y8wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=shHH2in1AyjGg1OR3nV0C30/s6g7n+X1cF/rXjKEm1Y=; b=n2n3rKP00LybOdeDBkmwuJOfBLikoLL/vqs4qfXjZLdh04gqUH9PV18UfKwVc1Rq9k CF8Y/M/mRUyTe5jg8Y1eg+uXDvf9wBkIpYTejkZKtH944zeQGGAWxXXBNk2SWa0jZ+xm Ga97f7QYlMYdRVApve+Dc5E5q5OaNc5OP3VUuYUElbUbHDxudWuSYD+8p2hkYbavOJow nAFbRchds9aEcItsK2eWqa2oPtT1IL+KG3kwY4zrwAAjBaEuLfa7Kqksh2cMCXty4L0i eUVOIcGGJYKKQ/p2Pn3rtbn7z4hNo+ohTOn+osBaDsQyJnd0MZQhGGcM0463H7M/4VxK ivRA== X-Gm-Message-State: AOAM531Bz0pc1lxY3GHonLlo7iiPQ3QAFYPM9tyy7eutMlq3rNPUCLgq idkp+o4uobS3zUXQ43L45VY= X-Google-Smtp-Source: ABdhPJwaxXkNp3X4gaJ7GEidPNF6U6gbo1FekFhhfH+JTG98xs6xcFiPh+v17WRKAL9p1mr9pEwUUA== X-Received: by 2002:a37:9e11:: with SMTP id h17mr17564255qke.370.1632016654840; Sat, 18 Sep 2021 18:57:34 -0700 (PDT) Received: from sarawiggum.attlocal.net ([2600:1700:5d80:a320:4412:822d:c222:aea8]) by smtp.gmail.com with ESMTPSA id k10sm6759062qth.44.2021.09.18.18.57.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Sep 2021 18:57:34 -0700 (PDT) From: David Aguilar To: Junio C Hamano Cc: Git Mailing List , Johannes Schindelin , Alan Blotz , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= Subject: [PATCH 3/4] difftool: use a strbuf to create the tmpdir path Date: Sat, 18 Sep 2021 18:57:28 -0700 Message-Id: <20210919015729.98323-3-davvid@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20210919015729.98323-1-davvid@gmail.com> References: <20210919015729.98323-1-davvid@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Use a strbuf to create the buffer used for the dir-diff tmpdir. Strip trailing slashes "/" from the value read from TMPDIR to avoid double-slashes in the calculated paths. Add a unit test to ensure that double-slashes are not present. Signed-off-by: David Aguilar --- builtin/difftool.c | 32 +++++++++++++++++++------------- t/t7800-difftool.sh | 7 +++++++ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/builtin/difftool.c b/builtin/difftool.c index 4d2e772031..2014a2bb9e 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -252,11 +252,10 @@ static void changed_files(struct hashmap *result, const char *index_path, strbuf_release(&buf); } -static NORETURN void exit_cleanup(const char *tmpdir, int exit_code) +static NORETURN void exit_cleanup(struct strbuf *buf, int exit_code) { - struct strbuf buf = STRBUF_INIT; - strbuf_addstr(&buf, tmpdir); - remove_dir_recursively(&buf, 0); + remove_dir_recursively(buf, 0); + strbuf_release(buf); if (exit_code) warning(_("failed: %d"), exit_code); exit(exit_code); @@ -333,11 +332,11 @@ static int checkout_path(unsigned mode, struct object_id *oid, static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, struct child_process *child) { - char tmpdir[PATH_MAX]; struct strbuf info = STRBUF_INIT, lpath = STRBUF_INIT; struct strbuf rpath = STRBUF_INIT, buf = STRBUF_INIT; struct strbuf ldir = STRBUF_INIT, rdir = STRBUF_INIT; struct strbuf wtdir = STRBUF_INIT; + struct strbuf tmpdir = STRBUF_INIT; char *lbase_dir, *rbase_dir; size_t ldir_len, rdir_len, wtdir_len; const char *workdir, *tmp; @@ -360,11 +359,17 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, /* Setup temp directories */ tmp = getenv("TMPDIR"); - xsnprintf(tmpdir, sizeof(tmpdir), "%s/git-difftool.XXXXXX", tmp ? tmp : "/tmp"); - if (!mkdtemp(tmpdir)) - return error("could not create '%s'", tmpdir); - strbuf_addf(&ldir, "%s/left/", tmpdir); - strbuf_addf(&rdir, "%s/right/", tmpdir); + strbuf_add_absolute_path(&tmpdir, tmp ? tmp : "/tmp"); + /* Remove trailing slashes when $TMPDIR ends in '/'. */ + while (tmpdir.len > 0 && tmpdir.buf[tmpdir.len - 1] == '/') { + strbuf_setlen(&tmpdir, tmpdir.len - 1); + } + strbuf_addstr(&tmpdir, "/git-difftool.XXXXXX"); + + if (!mkdtemp(tmpdir.buf)) + return error("could not create '%s'", tmpdir.buf); + strbuf_addf(&ldir, "%s/left/", tmpdir.buf); + strbuf_addf(&rdir, "%s/right/", tmpdir.buf); strbuf_addstr(&wtdir, workdir); if (!wtdir.len || !is_dir_sep(wtdir.buf[wtdir.len - 1])) strbuf_addch(&wtdir, '/'); @@ -612,7 +617,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, if (!indices_loaded) { struct lock_file lock = LOCK_INIT; strbuf_reset(&buf); - strbuf_addf(&buf, "%s/wtindex", tmpdir); + strbuf_addf(&buf, "%s/wtindex", tmpdir.buf); if (hold_lock_file_for_update(&lock, buf.buf, 0) < 0 || write_locked_index(&wtindex, &lock, COMMIT_LOCK)) { ret = error("could not write %s", buf.buf); @@ -642,11 +647,11 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, } if (err) { - warning(_("temporary files exist in '%s'."), tmpdir); + warning(_("temporary files exist in '%s'."), tmpdir.buf); warning(_("you may want to cleanup or recover these.")); exit(1); } else - exit_cleanup(tmpdir, rc); + exit_cleanup(&tmpdir, rc); finish: if (fp) @@ -658,6 +663,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, strbuf_release(&rdir); strbuf_release(&wtdir); strbuf_release(&buf); + strbuf_release(&tmpdir); return ret; } diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index a923f193da..3863afcaac 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -454,6 +454,13 @@ run_dir_diff_test 'difftool --dir-diff' ' grep "^file$" output ' +run_dir_diff_test 'difftool --dir-diff avoids double-slashes in TMPDIR' ' + TMPDIR="${TMPDIR:-/tmp}////" \ + git difftool --dir-diff $symlinks --extcmd echo branch >output && + grep -v // output >actual && + test_line_count = 1 actual +' + run_dir_diff_test 'difftool --dir-diff ignores --prompt' ' git difftool --dir-diff $symlinks --prompt --extcmd ls branch >output && grep "^sub$" output && From patchwork Sun Sep 19 01:57:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Aguilar X-Patchwork-Id: 12504067 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57069C4332F for ; Sun, 19 Sep 2021 01:57:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 34BE9610A8 for ; Sun, 19 Sep 2021 01:57:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240852AbhISB7G (ORCPT ); Sat, 18 Sep 2021 21:59:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235288AbhISB7B (ORCPT ); Sat, 18 Sep 2021 21:59:01 -0400 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E84D3C061574 for ; Sat, 18 Sep 2021 18:57:36 -0700 (PDT) Received: by mail-qk1-x732.google.com with SMTP id ay33so30357487qkb.10 for ; Sat, 18 Sep 2021 18:57:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CN2JF8fbiQSU8jbyNDRSCwbS8i3O+VfBt+qUz5Xl3Ig=; b=qCwcHj6vf/i7Q9q0c1QDteQ13A0nCCJ1cSlPEFcB4FSvJnbUhieofwejBglW655GLl cr1BJOKdpab+KftTGWNSKPkOqm1r6UxpIsGnVTBUnseRKXhFGy7NjIJLkSITQbLY1nt7 8gnENfuJFrhS/HjDb29q0JNCBBHzWtEsMpYDt0DOk9vACbP47EIfqzMBzJgkNe17FRpW 8W6tgRhqQAt5ERgwNvklzn/c46Ou0Km6Qo/z3FFoSVJ/MfeUeoL49TgVRH1F2wdt5rni OhFAmxSOEqNteeOC/oB/FZLhFcQIm/O/xVT6SBoCJ0/Ub+xFYEUtL2MJVeRHkOwDktbF 9RAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CN2JF8fbiQSU8jbyNDRSCwbS8i3O+VfBt+qUz5Xl3Ig=; b=y7x0jwZrb+tBgY2L32GjLNyobVXrgU4Unh6VRwyV4XpedtapmTpWRfC1VIpiSfq6aI f812mlK7jBG9nHfLMSZ5RsFP4JPZ5P3oxIojACIrjJBmtYyV4w41eGuUZTD09G7lC8V1 7umURZANcsS9n3I9nHDAMpMLXHjNueE/KQfLV0Tf+XPy/nyHInzyDXP0Pkqj8Yq7mj5H xgl0UecJ32R8ePbn65V5CHNYhaWo7JsU5LlOWFlQpXoFVZcFN0W5PzaG40gYc6WWR/8R 5+Q3Sqn4SU79Wt9bCzjzSHVzPZ5RE3cTVLk6Fi3dG7Nx0ya0nV9v9yCWjRSpmW9dXsrc 50aw== X-Gm-Message-State: AOAM530g/kjDyEIRau1ryAemoHIZV/K/vRPdyFJ25cJ6Ljc63Z4uE3Be Q2ptFZza0XZgsLf9I3VQW+OR5woQeO0= X-Google-Smtp-Source: ABdhPJzOMCy0hYJ3VF3FRue9oYTOaGk58UVmYfzWOHfHLaauBoY6Svb+peT2C/YrrUmhG0IjJr4QhA== X-Received: by 2002:a37:a605:: with SMTP id p5mr3815609qke.442.1632016656075; Sat, 18 Sep 2021 18:57:36 -0700 (PDT) Received: from sarawiggum.attlocal.net ([2600:1700:5d80:a320:4412:822d:c222:aea8]) by smtp.gmail.com with ESMTPSA id k10sm6759062qth.44.2021.09.18.18.57.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Sep 2021 18:57:35 -0700 (PDT) From: David Aguilar To: Junio C Hamano Cc: Git Mailing List , Johannes Schindelin , Alan Blotz , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= Subject: [PATCH 4/4] difftool: fix symlink-file writing in dir-diff mode Date: Sat, 18 Sep 2021 18:57:29 -0700 Message-Id: <20210919015729.98323-4-davvid@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20210919015729.98323-1-davvid@gmail.com> References: <20210919015729.98323-1-davvid@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The difftool dir-diff mode handles symlinks by replacing them with their readlink(2) values. This allows diff tools to see changes to symlinks as if they were regular text diffs with the old and new path values. This is analogous to what "git diff" displays when symlinks change. The temporary diff directories that are created initially contain symlinks because they get checked-out using a temporary index that retains the original symlinks as checked-in to the repository. A bug was introduced when difftool was rewritten in C that made difftool write the readlink(2) contents into the pointed-to file rather than the symlink itself. The write was going through the symlink and writing to its target rather than writing to the symlink path itself. Replace symlinks with raw text files by unlinking the symlink path before writing the readlink(2) content into them. When 18ec800512eb0634a0bf5e86b36ed156fbee73f3 added handling for modified symlinks this bug got recorded in the test suite. The tests included the pointed-to symlink target paths. These paths were being reported because difftool was erroneously writing to them, but they should have never been reported nor written. Correct the modified-symlinks test cases by removing the target files from the expected output. Add a test to ensure that symlinks are written with the readlink(2) values and that the target files contain their original content. Reported-by: Alan Blotz Helped-by: Đoàn Trần Công Danh Signed-off-by: David Aguilar --- builtin/difftool.c | 2 ++ t/t7800-difftool.sh | 70 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/builtin/difftool.c b/builtin/difftool.c index 2014a2bb9e..4cf454eca4 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -562,11 +562,13 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, if (*entry->left) { add_path(&ldir, ldir_len, entry->path); ensure_leading_directories(ldir.buf); + unlink(ldir.buf); write_file(ldir.buf, "%s", entry->left); } if (*entry->right) { add_path(&rdir, rdir_len, entry->path); ensure_leading_directories(rdir.buf); + unlink(rdir.buf); write_file(rdir.buf, "%s", entry->right); } } diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index 3863afcaac..97077f34a5 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -683,7 +683,6 @@ test_expect_success SYMLINKS 'difftool --dir-diff handles modified symlinks' ' rm c && ln -s d c && cat >expect <<-EOF && - b c c @@ -719,7 +718,6 @@ test_expect_success SYMLINKS 'difftool --dir-diff handles modified symlinks' ' # Deleted symlinks rm -f c && cat >expect <<-EOF && - b c EOF @@ -732,6 +730,74 @@ test_expect_success SYMLINKS 'difftool --dir-diff handles modified symlinks' ' test_cmp expect actual ' +test_expect_success SYMLINKS 'difftool --dir-diff writes symlinks as raw text' ' + # Start out on a branch called "init". + git init -b branch-init symlink-files && + test_when_finished rm -rf symlink-files && + ( + cd ./symlink-files && + + # This test ensures that symlinks are written as raw text. + # The "cat" tool cats the file only if it is not a symlink. + git config difftool.cat-left-link.cmd "cat \$LOCAL/link" && + git config difftool.cat-left-a.cmd "cat \$LOCAL/file-a" && + git config difftool.cat-right-link.cmd "cat \$REMOTE/link" && + git config difftool.cat-right-b.cmd "cat \$REMOTE/file-b" && + + # Record the empty start so that we can come back here later and + # not have to consider the any cases where difftool will create + # symlinks back into the worktree. + test_tick && + git commit --allow-empty -m init && + + # Create a file called "file-a" with a symlink pointing to it. + git switch -c branch-a && + echo a >file-a && + ln -s file-a link && + git add file-a link && + test_tick && + git commit -m link-to-file-a && + + # Create a file called "file-b" and point the symlink to it. + git switch -c branch-b && + echo b >file-b && + rm link && + ln -s file-b link && + git add file-b link && + git rm file-a && + test_tick && + git commit -m link-to-file-b && + + # Checkout the initial branch so that the --symlinks behavior is + # not activated. The two directories should be completely + # independent with no syminks pointing back here. + git switch branch-init && + + # The left link must be "file-a" and "file-a" must contain "a". + printf "%s\n" file-a >expect && + git difftool --symlinks --dir-diff --tool cat-left-link \ + branch-a branch-b >actual && + test_cmp expect actual && + + echo a >expect && + git difftool --symlinks --dir-diff --tool cat-left-a \ + branch-a branch-b >actual && + test_cmp expect actual && + + # The right link must be "file-b" and "file-b" must contain "b". + printf "%s\n" file-b >expect && + git difftool --symlinks --dir-diff --tool cat-right-link \ + branch-a branch-b >actual && + test_cmp expect actual && + + echo b >expect && + git difftool --symlinks --dir-diff --tool cat-right-b \ + branch-a branch-b >actual && + test_cmp expect actual + ) +' + + test_expect_success 'add -N and difftool -d' ' test_when_finished git reset --hard &&