From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS53758 23.128.96.0/24 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 5FBA71FB07 for ; Wed, 14 Jul 2021 13:14:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239469AbhGNNPu (ORCPT ); Wed, 14 Jul 2021 09:15:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239448AbhGNNPr (ORCPT ); Wed, 14 Jul 2021 09:15:47 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC136C061764 for ; Wed, 14 Jul 2021 06:12:53 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id t5so3138860wrw.12 for ; Wed, 14 Jul 2021 06:12:53 -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=F9hld1/qibK5cGkhpH/uSzU7Q9WiQGFiuYn3zgdMqkg=; b=XdJxY/rieILcWbJjQfmeNRQhg8iBvXGABb6muSCrO3G6+eha3J2gl4NhWUlqNYOrqg oc7nQgozl2bKudDKn2t8Vy+nlL13PgBmmL5FkhBTIG/v6I3BngfkPq5OW2KL3/EBN94I kljwRw/UbilByL4SYRzdiaVaWf77QRQz6wQd51Pa2aJYc5fG7oxh7jKl0l8sYOnyHrov 8JZJJUy5WNfXrTZtMrtLfaR+5PYpImSvOAc2dVh1q0iiVHNWbYZO234Z2kw4SJRO/WYG VPoI+J4BplENA0PAUCmDuGkF2xPkG7A990u/wIOC+FkjeCKzOJycZDbvXoUjtNH206KS AHTA== 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=F9hld1/qibK5cGkhpH/uSzU7Q9WiQGFiuYn3zgdMqkg=; b=XRK1NJdMwsfG3yWk6x9dLtFFkUdPZi2IEwXGCUbcJ91Fd4jBD6TvxnrgMVDOhvIOLu ehhCNoLfRf1KP4DfUM2q2t1eRTUPV94vLkISx/Oy8x5DdZSN743Rvny5SF1RCd55XAFg Bmt3aAOVip8acqliN7l1zjTeOINxfOKak32pyh4aoex3S9oKpnLT/B2uWU7mVbH30iG2 VS96CjrCMBmXtIk+sdW89W9b3qDhPeM5Y7LArOXv5krMAs8sT3KJm4aOB1LZ6LEdRN6J rY7FgLeuKL9w+ztTjtd4hxlHMlpvDRbfDaCcb2Xi8iLf3kaRRyKkIvti8HA86u0rc58O leYQ== X-Gm-Message-State: AOAM532RxGJ5MG4T3vpDziUxeRarqOt94rW7PsQNZJYuEsk1BtCeNiMv cso8GO524xslc6qsd5bGqjMPl6+UFzw= X-Google-Smtp-Source: ABdhPJxR1Ykq6nOPteoqyE4TV9yVfTilV4UmxvCBg9P9Hs8i7D0wXG3/xa71BvxOfJDQH0cjtTfqYA== X-Received: by 2002:a5d:6b91:: with SMTP id n17mr12910971wrx.385.1626268372311; Wed, 14 Jul 2021 06:12:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y66sm2127280wmy.39.2021.07.14.06.12.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 06:12:51 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Wed, 14 Jul 2021 13:12:35 +0000 Subject: [PATCH v9 11/16] diff-lib: handle index diffs with sparse dirs Fcc: Sent Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, newren@gmail.com, Matheus Tavares Bernardino , Derrick Stolee , git@jeffhostetler.com, johannes.schindelin@gmx.de, Bagas Sanjaya , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee While comparing an index to a tree, we may see a sparse directory entry. In this case, we should compare that portion of the tree to the tree represented by that entry. This could include a new tree which needs to be expanded to a full list of added files. It could also include an existing tree, in which case all of the changes inside are important to describe, including the modifications, additions, and deletions. Note that the case where the tree has a path and the index does not remains identical to before: the lack of a cache entry is the same with a sparse index. Use diff_tree_oid() appropriately to compute the diff. Reviewed-by: Elijah Newren Signed-off-by: Derrick Stolee --- diff-lib.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/diff-lib.c b/diff-lib.c index c2ac9250fe9..f9eadc4fc1a 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -325,6 +325,11 @@ static void show_new_file(struct rev_info *revs, unsigned dirty_submodule = 0; struct index_state *istate = revs->diffopt.repo->index; + if (new_file && S_ISSPARSEDIR(new_file->ce_mode)) { + diff_tree_oid(NULL, &new_file->oid, new_file->name, &revs->diffopt); + return; + } + /* * New file in the index: it might actually be different in * the working tree. @@ -347,6 +352,20 @@ static int show_modified(struct rev_info *revs, unsigned dirty_submodule = 0; struct index_state *istate = revs->diffopt.repo->index; + assert(S_ISSPARSEDIR(old_entry->ce_mode) == + S_ISSPARSEDIR(new_entry->ce_mode)); + + /* + * If both are sparse directory entries, then expand the + * modifications to the file level. If only one was a sparse + * directory, then they appear as an add and delete instead of + * a modification. + */ + if (S_ISSPARSEDIR(new_entry->ce_mode)) { + diff_tree_oid(&old_entry->oid, &new_entry->oid, new_entry->name, &revs->diffopt); + return 0; + } + if (get_stat_data(istate, new_entry, &oid, &mode, cached, match_missing, &dirty_submodule, &revs->diffopt) < 0) { if (report_missing) -- gitgitgadget