From patchwork Wed Jun 24 14:47:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 11623333 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 971F6913 for ; Wed, 24 Jun 2020 14:47:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 758D920702 for ; Wed, 24 Jun 2020 14:47:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YoIUPDHL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391252AbgFXOrv (ORCPT ); Wed, 24 Jun 2020 10:47:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389400AbgFXOru (ORCPT ); Wed, 24 Jun 2020 10:47:50 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 039ACC061573 for ; Wed, 24 Jun 2020 07:47:50 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id r12so2527290wrj.13 for ; Wed, 24 Jun 2020 07:47:49 -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=OFkQKEmBASs9GmJDYmeQkG+bxfech4wZZcmDiXyvRZM=; b=YoIUPDHL+jEHAc5XzcILv6qqPDl0XBiXwCrBnYMH3MFDnKpnD5v6PML7MH7f5s+8cI NrO2x8CUUbByBcXYT8SJiGccv93aHoTIMwauWyaFFnREZPIwrgYqUo9DQxFjmjLKbt90 r5ir3A/4ufH7jjw82j8UxSsP51jll2TqFvqAfBrJd7siasfqWGHFHEUr7vzBHjSVMKFv PGcaBAIAyuLL01CWyuZkPe3b4XLmJHt+emuJzZnS+BTNJflmgHlTd025IEewwTAa6TYl ZXcgUquwW/Qp9TcZEBVvwsCz81/XUeT1IPj9Yv7BMERlYEn5ad7buQIVhA1XgLPtE9x1 ArXg== 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=OFkQKEmBASs9GmJDYmeQkG+bxfech4wZZcmDiXyvRZM=; b=cZjN8Dd7lUXt4wcIcPFom6a7A3vZhh6pGhtLoSbRvr9NwdwWJRK+GQYgqtEpwS4aI9 c/UMrtT5doGr7c9eL7inACUCDKeCyTABg7ccTz3yuzM+VWkSLfF51Z23X0oTlahfoHnl xO0a7QQW7I/qWEgrGKgT39VT385a+cFYQq6JsR7lqXzVT2E1iKrli7vEfyNDXr+eJ6bH L4SIR5XBswgs5f0NnZSkEiQekzwKQQYNi/NTrDOFjMpf43g0Q/06W8wPXj+mYhiBHfbY gnJN+gGQmJ/ZJ45QQYQS4/IEjunBKeo/LU0MXzgLCGT4PR+rCLEPJv4XhckAE9kG1fXy he8w== X-Gm-Message-State: AOAM533YaZ25UsexdCNKLRFgIppkNKdKkGT3oObyybQeXhdHVv+AP1Nx tz5A3P1kQrk36tpd8+HjuYfmuMyvn0E= X-Google-Smtp-Source: ABdhPJy5kv+E3WCFW8b2H/cQSN4ofz72jfAPLNGXfWObX63TR0Igkb+C+DE2+2ANHx5zZFbtTGquKw== X-Received: by 2002:a5d:4282:: with SMTP id k2mr31051831wrq.196.1593010068551; Wed, 24 Jun 2020 07:47:48 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j14sm27378971wrs.75.2020.06.24.07.47.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2020 07:47:48 -0700 (PDT) Message-Id: <8c27c78831be23fb560f3c012c014b11d32e75ca.1593010066.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Date: Wed, 24 Jun 2020 14:47:44 +0000 Subject: [PATCH v3 1/3] diff-files --raw: handle intent-to-add files correctly Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Srinidhi Kaushik , 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 This patch _also_ fixes the expectations set by the regression test introduced in feea6946a5b (diff-files: treat "i-t-a" files as "not-in-index", 2020-06-20). Signed-off-by: Johannes Schindelin --- diff-lib.c | 14 ++++++++++++++ t/t2203-add-intent.sh | 5 ++--- t/t4000-diff-format.sh | 10 ++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/diff-lib.c b/diff-lib.c index 61812f48c2..ea23169afa 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -217,6 +217,20 @@ int run_diff_files(struct rev_info *revs, unsigned int option) !is_null_oid(&ce->oid), 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; } else if (revs->diffopt.ita_invisible_in_index && ce_intent_to_add(ce)) { diff_addremove(&revs->diffopt, '+', ce->ce_mode, diff --git a/t/t2203-add-intent.sh b/t/t2203-add-intent.sh index 8a5d55054f..7d379bdbc6 100755 --- a/t/t2203-add-intent.sh +++ b/t/t2203-add-intent.sh @@ -240,7 +240,6 @@ test_expect_success 'i-t-a files shown as new for "diff", "diff-files"; not-new hash_e=$(git hash-object empty) && hash_n=$(git hash-object not-empty) && - hash_t=$(git hash-object -t tree /dev/null) && cat >expect.diff_p <<-EOF && diff --git a/empty b/empty @@ -259,8 +258,8 @@ test_expect_success 'i-t-a files shown as new for "diff", "diff-files"; not-new create mode 100644 not-empty EOF cat >expect.diff_a <<-EOF && - :000000 100644 0000000 $(git rev-parse --short $hash_t) A$(printf "\t")empty - :000000 100644 0000000 $(git rev-parse --short $hash_t) A$(printf "\t")not-empty + :000000 100644 0000000 $(git rev-parse --short $hash_e) A$(printf "\t")empty + :000000 100644 0000000 $(git rev-parse --short $hash_n) A$(printf "\t")not-empty EOF git add -N empty not-empty && diff --git a/t/t4000-diff-format.sh b/t/t4000-diff-format.sh index e5116a76a1..48ff4e250b 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 Wed Jun 24 14:47:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 11623337 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 B2CE014E3 for ; Wed, 24 Jun 2020 14:47:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9C10C20781 for ; Wed, 24 Jun 2020 14:47:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="D3jfn1vY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403926AbgFXOrx (ORCPT ); Wed, 24 Jun 2020 10:47:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391250AbgFXOrv (ORCPT ); Wed, 24 Jun 2020 10:47:51 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA5DEC061573 for ; Wed, 24 Jun 2020 07:47:50 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id s10so2532067wrw.12 for ; Wed, 24 Jun 2020 07:47:50 -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=zFO1EtvSmoAkJ5ah0iaCL/vvE8xnlN9KlBlryGuoJn4=; b=D3jfn1vYGfcZBktPZnxJfC0cd7SltmkmIIvfnIvcgdUo782IRyLxIwm/74tkgQXs3b tg/ZuCqcGlepsSZVvGMsm2WwJPtMIJBWUs69WAZxPlNaEveSR63avCOfFQr0FazkJ2vn 14mlHHPmMj9kVlPQG9rbiX0lUfeCQfZ6tX5TrhMQp2uQCCjZmu1e2LliXQKQdlZ+cn3o S5gESOL9X6t0dWmBq1tgUHbCBRrsNDIODUpSr200hrJgwIz+ot4p5gqyKmqxznlX07zM K3/zUF78WEKlEmDUcu/0iHiq4kTjH5phggqTzKcg+cA4lPuyMPqwQIrPnsYgkXHDYZ+B XXsQ== 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=zFO1EtvSmoAkJ5ah0iaCL/vvE8xnlN9KlBlryGuoJn4=; b=kz+erK0mLX4Y5E6WLUYMDxqLjfDWzJbvW6QBwDrmi1FwksbEzTHcQJa8z5r/8UKdBf x2qcvT0sqQ2pKhpVi6gC8Hy4pdZC6nZSqSqBfFuBHLXvcTNrB/XRzho/BTXNDqQlmLXy l6sTYHMnm65IkP4reRK+248ioTRCpNzXmzm6uVVyrEiELGz6PsXwNO1gLZM531LqJ2fp LDTrid3mYTWiImh+u4P1uEt+P9dwWfvzbW68umjohpkxSTKH4hyUvwIlnpwJxoj69P9q 09thiWqiP1VSXk45EXrgqgwhOz5LmtZ97XyrWYQsruICp5tQ8zGwzlKWtdJVxLcsecT1 p7wA== X-Gm-Message-State: AOAM530CWDY0nMulndHU69emTXjFNno0F2sCABgJL6sKdnXgxyrGPV5K HgRjY8aJjMAlMmPs3jzcu6YGpSfnQ+o= X-Google-Smtp-Source: ABdhPJzhbdVDDIIkUG2r7HiFbIFOKf+cYIzLgLhBg8/KChWg7ntvEzQHdJaZ044EwtzTYrN27jUYHA== X-Received: by 2002:adf:ef4d:: with SMTP id c13mr19580301wrp.315.1593010069469; Wed, 24 Jun 2020 07:47:49 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w7sm8783602wmc.32.2020.06.24.07.47.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2020 07:47:48 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Date: Wed, 24 Jun 2020 14:47:45 +0000 Subject: [PATCH v3 2/3] diff-files: fix incorrect usage of an empty tree Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Srinidhi Kaushik , 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. To be able to do that, we just taught the regression test introduced in feea6946a5b (diff-files: treat "i-t-a" files as "not-in-index", 2020-06-20) to _not_ expect the raw diff to contain the hash of the empty tree (we also had to fix the code to actually produce the expected output, but for the sake of this here patch, that's beside the point). 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 ea23169afa..7aafd7cc37 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -234,7 +234,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 Wed Jun 24 14:47:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 11623335 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 D974E913 for ; Wed, 24 Jun 2020 14:47:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BFFDE20702 for ; Wed, 24 Jun 2020 14:47:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g3vREqcI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391282AbgFXOry (ORCPT ); Wed, 24 Jun 2020 10:47:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391254AbgFXOrw (ORCPT ); Wed, 24 Jun 2020 10:47:52 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC0BAC061573 for ; Wed, 24 Jun 2020 07:47:51 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id s10so2532110wrw.12 for ; Wed, 24 Jun 2020 07:47:51 -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=jzq5Z8sPrMzIYKA6uw17FQivGsH+sEOsh8uUK5cMTDo=; b=g3vREqcIzVDhwOvHCgal7/VahdxccRXSXeN0nljgmFI8TB3B5uOJgf/jQDp3gFcisA oUv0vDZVDXJGt+zHUuLh/fBlWXgG9Ezu/c4Lv2Kum3dOVS5NzZLAIHFN5q/r8m6U6JCE p9DaPiTIHFfaN8aAoqJ38R7z4hxXDPuc5WVdF85iWrD3QSQA/kcbn5Uw7XEuqLVc0VK2 p2pJPBvNIjoGqXGkzH7eSkO+IkeGq1fP+rJsPE7qefzm1scbNxUEhiDs5bAXF4cGl9Uj OMBtF9VD5LyDLHKyrMyVURJ452b8b1z81otkJQ/o5pNEVjRyK9qMtu26UKIzH5cbx/kU 9Y8Q== 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=jzq5Z8sPrMzIYKA6uw17FQivGsH+sEOsh8uUK5cMTDo=; b=MCHfipCTPrNPwhUXE33Smt5cpYEWplyn1Y7olqxjTnaQ26KXth3o0p2MrvUhgfqdxS KuChpzIwNKKwx2NX4iXF6xuPQtoT3nWbAQ2KUHm4PTCU+5hSMlWaVcLrubrPDgTWS2vz bKYvzYxaetwIPJx7Jqfb44oG9rEhu3Cs7sj46dMeQ5MWpaxpMjqrRoJuWyD5xrnT7HFD qW87wjqgd5BdiMVzt+NXBo8UizD4yXBkegOqxwZDsRRXGdQS58jS9pUFaSgdExYilDFQ bKWZSaC4kqRL32WGRrB4bCLTuMF9/uUhwyLTHIJRjdDNo6J8XeOYClUIb/1zk8uhoRDd o16Q== X-Gm-Message-State: AOAM530fhNkDxNMLitKwrShgRLKXFeETcugW4FHaFyEzbJ7Frmjy4/o6 VfhEjs++dtS1XOKCXmMa0649lcA52Y4= X-Google-Smtp-Source: ABdhPJyNOeV4wwKRK2i2DfhEpC41+aJKCpFifNCt/gyaypTv8R/ExxYmjfK/S2sDNHbFZKVh5oJmMQ== X-Received: by 2002:adf:ea06:: with SMTP id q6mr26100548wrm.69.1593010070405; Wed, 24 Jun 2020 07:47:50 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x1sm1919377wrp.10.2020.06.24.07.47.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2020 07:47:49 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Date: Wed, 24 Jun 2020 14:47:46 +0000 Subject: [PATCH v3 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: Srinidhi Kaushik , 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 29b92907e2..524f30f7dc 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 &&