From patchwork Thu Jun 11 12:38:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: blanet via GitGitGadget X-Patchwork-Id: 11599925 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 5404960D for ; Thu, 11 Jun 2020 12:39:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 37696207C3 for ; Thu, 11 Jun 2020 12:39:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZW0LCgza" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727966AbgFKMjG (ORCPT ); Thu, 11 Jun 2020 08:39:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726868AbgFKMjE (ORCPT ); Thu, 11 Jun 2020 08:39:04 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7612DC08C5C1 for ; Thu, 11 Jun 2020 05:39:03 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id j10so5985731wrw.8 for ; Thu, 11 Jun 2020 05:39:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=9FZcy0kvOKkAf040rcyHHZkIhwa8WXzai6Li+gKu0+0=; b=ZW0LCgza8ZqMY/KD9DOYFaYuS7a5zDZV9eDBP5RSDl7C/9lIEzGqrVKkSt4trq+JfB d0rVL7YYc78lE0XRwTHQ+Do2DnK+s7c/J+5QpT1/srUWbFLifW3wvp3qcra7SGbe6ANX R0oQ6kdreMbN8axUbVhgvhxVTXm0ZSt9nJ/0Ks1zlyu4lizzEdcyf/UkDaPykS/YY9cS OmdsN/WDpuTn91iul3hAS6gHo19SO8ZRtUHdgpP35jDh+yYY2MhWs5xekGm8t7CG+/PR cp4DdOeMUYwDFs0YgWy1M3MYF43zikIEmLpRTkMxTf/gQtoQozCYAOEc36O5NslECnI+ rbmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=9FZcy0kvOKkAf040rcyHHZkIhwa8WXzai6Li+gKu0+0=; b=Rh48p1w5LVJ8cFolroKwVeYQKjIPfXX66DbNDvBQ9D3SMgluhWuhASioOB6oGtroM3 Iyl4OO9wfDR+5lRK6BPFvKttJh7TKSwBa0VUYowqtSQyHaZWPmh6PRiGae2Kk0Vm4KWM lakbwQYrp2gS2/Nt3GxwXuO6rI0svXLrR8DJn/55YejgoS+JhA9PWvOKxxGwtZ1i2gCi vhNSf1BWWhoUoangq2qzDmZIGEdc55pKMnbDOCV471V7V4qW6ey1a+87i8GiKdvw5eCa zDn3Wqs6R5OuWyDxbDwMg7YUDwA3jdf4LTZLimOPoiw5PXVXwWI2Oa9wvrOkLupUY9PL WuBg== X-Gm-Message-State: AOAM533G/kj8aWXWyNAcUBYP8ueCSZWSRzYskUx+QuzhKVIEoX7+kz+f iCX1BpK1+8NY19lBPcHrbmK/sjcu X-Google-Smtp-Source: ABdhPJwggMZTZxV4E+UbTVojopj2tyXT7QdwKN2fzcw7dRBME2cbqBc0ZKGtFmg2mLYD0t+y/xUMxg== X-Received: by 2002:adf:82cf:: with SMTP id 73mr8908360wrc.382.1591879141874; Thu, 11 Jun 2020 05:39:01 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v7sm4347640wme.46.2020.06.11.05.39.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 05:39:01 -0700 (PDT) Message-Id: <9c96c43f3d744a0f4f312bb466eaf54d372a56fb.1591879139.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Date: Thu, 11 Jun 2020 12:38:57 +0000 Subject: [PATCH 1/3] diff-files: fix incorrect usage of an empty tree Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin In c26022ea8f5 (diff: convert diff_addremove to struct object_id, 2017-05-30), the OID to use for intent-to-add files was inadvertently changed from the empty blob to the empty tree. Let's revert that. Signed-off-by: Johannes Schindelin --- diff-lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diff-lib.c b/diff-lib.c index 61812f48c27..15bb45776e4 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -220,7 +220,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option) } else if (revs->diffopt.ita_invisible_in_index && ce_intent_to_add(ce)) { diff_addremove(&revs->diffopt, '+', ce->ce_mode, - the_hash_algo->empty_tree, 0, + the_hash_algo->empty_blob, 0, ce->name, 0); continue; } From patchwork Thu Jun 11 12:38:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: blanet via GitGitGadget X-Patchwork-Id: 11599921 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 4427A912 for ; Thu, 11 Jun 2020 12:39:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 266B12078D for ; Thu, 11 Jun 2020 12:39:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nQqmkOFl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727771AbgFKMjE (ORCPT ); Thu, 11 Jun 2020 08:39:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726868AbgFKMjE (ORCPT ); Thu, 11 Jun 2020 08:39:04 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3787AC08C5C3 for ; Thu, 11 Jun 2020 05:39:04 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id k26so4886907wmi.4 for ; Thu, 11 Jun 2020 05:39:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=C6EvRzFuBwJOflnK1URyl96o6TiJfkCCV21wO3xyhnk=; b=nQqmkOFlLcy9ZvOX7LKCE5XPNUnDHtwiPKQE55Wd/EbQdBoHmLF77bJPY57KT4CBCd tjsPuQiNhT8ZFLp36Rzywq0EqxFSxOhcRk6Ku9e6CnEpG4aln3dd7voNFjewQ83McIkW zxaXvqeLU2W8aaQ4mJ3pLBjbAkawpM1PAHNOxSu3uKtjgjjUOw8FooLDvgKuvfwmiQvm ytQBv3ATVWC9QOzK9mkrEu7VyRXEEx4mWPINHxxGH5yZTkzd4+sN6Y6OtWqO7gqYbJWN GCaTWAJkuYondRtzqB1g7EcshK2ihKWR6PPKZ2ZyI4j1tf2v+sU1zV4+FVkRdw3YBlE3 f1PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=C6EvRzFuBwJOflnK1URyl96o6TiJfkCCV21wO3xyhnk=; b=gs7jRaH2io/7CNFVO9Nm0e3Zn22ysoogzaHLaHAr6ZbDN/K1hfkugfskmh4GY0rrFl fZxBKEYOXIpvQKjYG/XbJZGpLxxQ1gWOTP81cySta4mSaezAJo6vO+Q7kIL9HA96UK1C abo4VrGlR2UCRGgzODJ9gXB1nKW/K7c9lCMQHFhN216Bpiro3trUFEbZNjEuhARIGMlw F4ZWMxWWFzeBEQItPVEXxK+7h4PJ4TzUbNA5ncSEBa07JriyEoiss7KkVE9bc4lqTrpX b9ZhnYPs/RdG0y4YKN3Vhsh2u/97/QM3VQW4ZHArFlMTBOLF8oEOGai/0nvlLQPIWLoO BA7w== X-Gm-Message-State: AOAM530N5sKci+wKzd7P58X6GVBBUZoRbcLFBTf56mwqYHnWOgR6gVr7 Opi1IP8NJgMcWGDcUYWVOo5rGbuE X-Google-Smtp-Source: ABdhPJyWPLMWPClidrPJw1ERK3AMB9zzPXP9YHzKmyYQyUYBWqMBAjvN2kFQOWuj6IUKH88EpXZZbQ== X-Received: by 2002:a1c:6389:: with SMTP id x131mr7939768wmb.90.1591879142656; Thu, 11 Jun 2020 05:39:02 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e12sm4896269wro.52.2020.06.11.05.39.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 05:39:02 -0700 (PDT) Message-Id: <6d423928512e62c91ef1ae9b469aa8cc361ed080.1591879139.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Date: Thu, 11 Jun 2020 12:38:58 +0000 Subject: [PATCH 2/3] diff-files --raw: handle intent-to-add files correctly Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin In `run_diff_files()`, files that have been staged with the intention to add are queued without a valid OID in the `diff_filepair`. When the output mode is, say, `DIFF_FORMAT_PATCH`, the `diff_fill_oid_info()` function, called from `run_diff()`, will remedy that situation by reading the file contents from disk. However, when the output mode is `DIFF_FORMAT_RAW`, that does not hold true, and the output will contain a bogus OID (and the flag `M` for "modified" instead of the correct `A` for "added"). As a consequence, `git difftool -d` (which relies on `git diff-files --raw`'s output) does not work correctly. Let's fix this specifically by imitating `diff_fill_oid_info()`. Note: we can only do that for diff formats that do not actually need the file contents, such as `DIFF_FORMAT_PATCH`: `run_diff()` would try to read the blob contents, but that blob might not have been written to Git's object database. This fixes https://github.com/git-for-windows/git/issues/2677 Signed-off-by: Johannes Schindelin --- diff-lib.c | 14 ++++++++++++++ t/t4000-diff-format.sh | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/diff-lib.c b/diff-lib.c index 15bb45776e4..4af8f811ae8 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -223,6 +223,20 @@ int run_diff_files(struct rev_info *revs, unsigned int option) the_hash_algo->empty_blob, 0, ce->name, 0); continue; + } else if (ce_intent_to_add(ce) && + !(revs->diffopt.output_format & + ~(DIFF_FORMAT_RAW | DIFF_FORMAT_NAME_STATUS))) { + struct object_id oid; + int ret = lstat(ce->name, &st); + + if (ret < 0) + oidclr(&oid); + else + ret = index_path(istate, &oid, + ce->name, &st, 0); + diff_addremove(&revs->diffopt, '+', ce->ce_mode, + &oid, ret >= 0, ce->name, 0); + continue; } changed = match_stat_with_submodule(&revs->diffopt, ce, &st, diff --git a/t/t4000-diff-format.sh b/t/t4000-diff-format.sh index e5116a76a1c..48ff4e250b5 100755 --- a/t/t4000-diff-format.sh +++ b/t/t4000-diff-format.sh @@ -89,4 +89,14 @@ test_expect_success 'git diff-files --patch --no-patch does not show the patch' test_must_be_empty err ' +test_expect_success 'git diff-files --raw handles intent-to-add files correctly' ' + echo 123 >ita && + git add -N ita && + printf ":000000 100644 %s %s A\\tita\n" \ + $ZERO_OID $(git hash-object --stdin expect && + git diff-files --raw ita >actual && + test_cmp expect actual +' + + test_done From patchwork Thu Jun 11 12:38:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: blanet via GitGitGadget X-Patchwork-Id: 11599927 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 E754A60D for ; Thu, 11 Jun 2020 12:39:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC726207C3 for ; Thu, 11 Jun 2020 12:39:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cWqQ4+kW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727975AbgFKMjH (ORCPT ); Thu, 11 Jun 2020 08:39:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727820AbgFKMjF (ORCPT ); Thu, 11 Jun 2020 08:39:05 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF2A1C08C5C2 for ; Thu, 11 Jun 2020 05:39:04 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id q11so6009096wrp.3 for ; Thu, 11 Jun 2020 05:39:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=WsHlJyLJoomQg4k3zSlJOxtBruLcdOGTc+0HCWHriss=; b=cWqQ4+kW2ASrTu54L5v0oYf8BNu1tWNURVaDn6rLSmC30m8X8+oW0xq+X1T4QeXx4u nu57rRZnqXzEzVWH8y5gbhrv4EgCcpVwz/2ks6fSsD44cCYMQxY8zD3sfSGrRx6/Fbcz cJ6LGdP0eQfjE7r+uOTgOGnetoFB+Lmc3xj+2rhT4DQFLC66nYi4fTeQJsF8xXH7RE8q kLs3jhaa2P3koAeSN1UX+JrTTtnjPdOKC1nSiqWYd9tWVjabSeydK+e+cFmwjtRigzP7 h5D843J/pR+bZn80cDtHrzMoQAf3r0T7Ah/7EUex9DtTWVvDmWoqlAKtm+MMuyd72Ln+ PBug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=WsHlJyLJoomQg4k3zSlJOxtBruLcdOGTc+0HCWHriss=; b=UsTrVvN7cL3dRe2RBSwM9sRypK/aSmrga1o8ckJAfa6eJi8Fe7J6KZI7f1y8leBQXf gowuo1UKS2NPM6ADG40oxMYJet9V39Y8ht81JuOvScv0jfm7r/57VCDwXAhugG6wErs5 jI+Spusg4rNJ7yS8JiDj5XsI1/KWcpuHuBi3nKV7geBGiFBtssQ6K9hxfrvg6cDRH5z5 H6T3/4KX1hQvC47kgDLkROqA+UVXpzYtoXmQ0fbvZMwdD7Tu7Dwmk4dLEzDoDdPlI5kx TImmDWjR7Hn3A2TlUWsUUJ9QrTb6MJZhPhuAScvK2P4HSsOL1NPf9b8exfqgg9JpgktA yuxQ== X-Gm-Message-State: AOAM531ND+pM17m54hJ52PJ4JOJhjitcuYKxyHKoi5pFlTpPoDkRiFda ycBzlRfq7S8LO5SmIfffaAbgNnFV X-Google-Smtp-Source: ABdhPJzzfMrdRmrz988a2t0Bz+8RBV0NPLAnouzPduxcBdSu63LT2hiAPbYFjQGVgzg000VVCu4dJQ== X-Received: by 2002:a5d:4948:: with SMTP id r8mr9131153wrs.290.1591879143575; Thu, 11 Jun 2020 05:39:03 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o15sm3934273wmm.31.2020.06.11.05.39.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 05:39:03 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Date: Thu, 11 Jun 2020 12:38:59 +0000 Subject: [PATCH 3/3] difftool -d: ensure that intent-to-add files are handled correctly Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin In https://github.com/git-for-windows/git/issues/2677, a `git difftool -d` problem was reported. The underlying cause was a bug in `git diff-files --raw` that we just fixed. Make sure that the reported `difftool` problem stays fixed. Signed-off-by: Johannes Schindelin --- t/t7800-difftool.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index 29b92907e2a..524f30f7dc7 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -720,6 +720,14 @@ test_expect_success SYMLINKS 'difftool --dir-diff handles modified symlinks' ' test_cmp expect actual ' +test_expect_success 'add -N and difftool -d' ' + test_when_finished git reset --hard && + + test_write_lines A B C >intent-to-add && + git add -N intent-to-add && + git difftool --dir-diff --extcmd ls +' + test_expect_success 'outside worktree' ' echo 1 >1 && echo 2 >2 &&