From patchwork Sun Mar 21 00:00:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152799 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.8 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 8CF9EC433E3 for ; Sun, 21 Mar 2021 00:02:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6A0DB601FE for ; Sun, 21 Mar 2021 00:02:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229951AbhCUACK (ORCPT ); Sat, 20 Mar 2021 20:02:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229766AbhCUAB3 (ORCPT ); Sat, 20 Mar 2021 20:01:29 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71B18C061574 for ; Sat, 20 Mar 2021 17:01:29 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id t4so2419447wrn.11 for ; Sat, 20 Mar 2021 17:01:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gVom+Y8fPmmqcyhJkpXP/lu/6g069lTjvPp3uzuLlSY=; b=V0fm8sGKUI7IEmqxdBKyCA9ok7LJ6RCl1aSLx1XmwK6PuK5gbc/do7b9ztHPD22+/s OX6F1f18eKMRpINCs6ZoxP9W6KQXzRUOb1V+CeFsk/jVh4gxstEvugr1pkusiNa1gsiI PFQBlHbvlvz8QrlPhAQeoxDivOTFWhOXYU7AyQ0jd6anZaOL2DXPPHsqF75oxP5o2hmW n9rfZzdNww6SFjTyUrCIFLVuLctk3yttwkFcitRmwBmIVkbSDb+ruHSY74nSsAIFj0rt V/hTdVygUjU9bHfHGgqOWj+EvtoOw5ezKWK1t6UFvPJmBrQNF0LWTglRNdKKn53e7fp6 N0lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gVom+Y8fPmmqcyhJkpXP/lu/6g069lTjvPp3uzuLlSY=; b=r8GZ4W9Mnl8iLwnPm19/897gz7cFea/4NEbqmAJmZiQkSio4b3+qecnHAJcAJgJ1qN mOnaA6x2hldui/bxF9LU2wrFLfsbAhqFpW9DCwGmWSgKgJpAo3DZGZCyV5rsV7o+yJs+ 0ZvvcPi8FppW5UEfIgqsNM7ALCEHjdtbXq5Qtv7Ma06UHEB/HHlmYp5vppKGTVraHmql 6dffnadshwll0UvqHw4SXC6hfOMjqchQ2y/FEdq9MJxfyJCLGgJezPWl5A3ryCTJV/46 W6QWLglTzL+ejM28pg/esPYxcZsc5IZoysoG7lU3hPjF/KrFNseOmINO4pFBgB2ZZrre Ow8A== X-Gm-Message-State: AOAM532ysPMR6jWT7Elote3pJiI9ktC+1EEHTFKj8MLFbg/Xk+t2Hx32 8/7BOS+9j/eCPUp5wMM0apIit2sXhufYUA== X-Google-Smtp-Source: ABdhPJzdw1yGOUpLE/MyObtmiRk4XH5cyx/G9UfyYhj7g3R07huNDao1ILSPtNVGFAGvhbNxe/LngQ== X-Received: by 2002:adf:ed46:: with SMTP id u6mr11161598wro.350.1616284887904; Sat, 20 Mar 2021 17:01:27 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:27 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 02/29] cache.h: add a comment to object_type() Date: Sun, 21 Mar 2021 01:00:35 +0100 Message-Id: <186f7a7a44b7d296b83421d703c74be5668b5d8a.1616282534.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a comment to the object_type() function to explain what it returns, and what the "mode" is in the "else" case. The object_type() function dates back to 4d1012c3709 (Fix rev-list when showing objects involving submodules, 2007-11-11). It's not immediately obvious to someone looking at its history and how it's come to be used. Despite what Linus noted in 4d1012c3709 (Fix rev-list when showing objects involving submodules, 2007-11-11) about wanting to move away from users of object_type() relying on S_ISLNK(mode) being true here we do currently rely on that. If this is changed to a condition to only return OBJ_BLOB on S_ISREG(mode) then t4008, t4023 and t7415 will have failing tests. Signed-off-by: Ævar Arnfjörð Bjarmason --- cache.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cache.h b/cache.h index c2f8a8eadf6..ae0c0bef5c2 100644 --- a/cache.h +++ b/cache.h @@ -451,11 +451,16 @@ enum object_type { OBJ_MAX }; +/* + * object_type() returns an object of a type that'll appear in a tree, + * so no OBJ_TAG is possible. This is mostly (and dates back to) + * consumers of the tree-walk.h API's "mode" field. + */ static inline enum object_type object_type(unsigned int mode) { return S_ISDIR(mode) ? OBJ_TREE : S_ISGITLINK(mode) ? OBJ_COMMIT : - OBJ_BLOB; + OBJ_BLOB; /* S_ISREG(mode) || S_ISLNK(mode) */ } /* Double-check local_repo_env below if you add to this list. */ From patchwork Sun Mar 21 00:00:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152811 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.8 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 7AC63C433F1 for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4716661937 for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230009AbhCUACR (ORCPT ); Sat, 20 Mar 2021 20:02:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229879AbhCUABi (ORCPT ); Sat, 20 Mar 2021 20:01:38 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 099E6C061762 for ; Sat, 20 Mar 2021 17:01:38 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id t4so2419475wrn.11 for ; Sat, 20 Mar 2021 17:01:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K76TXGnpVmMaZy+ataImqJLGLarHGA2byq8ElXBpqOM=; b=e7rxFOl3bhhTkks2/vvhm22jxCCFseiS2ZP+FTAmaEzekn1zLI5Ht0J6Yd/ntjPxzS ZKScCsqfofoP7X2OZGSLzDdNqOGRChFmp92InHHFjkONo19b1FkOR+6QqkMuuIrC6/NC P20kEJOkUSINE0u0z+lx7h2Cx7ZBVbMjVfe9OIz0ZbgK2u5eIJDhTaOC9wNK/QXK7gYg nsG/0JjhuhiD/vk5af/YI8hsogZWrYMaUcinI4vxdOI5uDFPVa7Ll2xoZ5VnMlWgCBoZ ET7YaE5wMxdXn6PaIU6d2tsFgbz0hzxL02k+6F6UPZRVyCdML/Nnh45YMFiD9hN+KvDY ejxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K76TXGnpVmMaZy+ataImqJLGLarHGA2byq8ElXBpqOM=; b=nGt2lFy18T5aqqxvWJ5oQjZC64+46zOQax3tJLfIwb8LZpWfZTp/TiO6G7R+xR+Zdx D/7b6dpH9xVpYCQ5laQjsFAFdM0aD7WB01M3IWKrZ41GO+ktt6XzuvyfVcN7X82RBoaR uhFh0tX2HCRWqOXLOuMx7RIFvaB5lnxEdlOpqkhdJoP9D7FWJYTN5jInKte1vEn0EwD+ SENLi7eWdEjYYksRuHoIxruEKyfnx+dbc5W2POqDAdIjhHAZgoxzntg+tMVjG3RdBdY/ qBGaeBp7TZaHWPI25y198VR2nYw2wXy4dYZHYm23CylHJo7nsjYbNYj3PHwtUdvMe5v3 PCmw== X-Gm-Message-State: AOAM530wRuGuIdJz59Lf5LASCMcYmPyFXwQFWn/gP36t56QAT+JrbRAz KOKmRJphjtKeygglFKKKewMRyHVD4x05cQ== X-Google-Smtp-Source: ABdhPJz/e/LdATGsYEkvHstmX8R6jFnOtYbNFmpJ2UWEnvvt3HwdohOyucOLKzYmgfabV6/owIBzSg== X-Received: by 2002:a5d:4203:: with SMTP id n3mr11090207wrq.116.1616284888671; Sat, 20 Mar 2021 17:01:28 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:28 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 03/29] tree-walk.h: add object_type member to name_entry Date: Sun, 21 Mar 2021 01:00:36 +0100 Message-Id: <4fed508f3cbb106c6359d31ca53d53e078fadfd7.1616282534.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Most users of the tree walking API don't care what the specific mode of an object in a tree is (e.g. if it's executable), they care if it's one of OBJ_{TREE,BLOB,COMMIT}. Let's add an "object_type" enum to the "name_entry" struct to help such callers. Ideally we'd have some subset of "enum object_type" here with just those three entries, so we could rely on the C compiler to exhaustively check our "switch" statements, but I don't know how to create such a enum subset without re-labeling OBJ_{TREE,BLOB,COMMIT} to e.g. "NE_OBJ_*" (an enum is just an int under the hood, so you can use such a struct with "OBJ_*", but the compiler will complain...). Signed-off-by: Ævar Arnfjörð Bjarmason --- tree-walk.c | 4 +++- tree-walk.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tree-walk.c b/tree-walk.c index 2d6226d5f18..b210967b73b 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -47,7 +47,9 @@ static int decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned l /* Initialize the descriptor entry */ desc->entry.path = path; - desc->entry.mode = canon_mode(mode); + mode = canon_mode(mode); + desc->entry.mode = mode; + desc->entry.object_type = object_type(mode); desc->entry.pathlen = len - 1; hashcpy(desc->entry.oid.hash, (const unsigned char *)path + len); diff --git a/tree-walk.h b/tree-walk.h index a5058469e9b..9f3825d2773 100644 --- a/tree-walk.h +++ b/tree-walk.h @@ -17,6 +17,8 @@ struct name_entry { const char *path; int pathlen; unsigned int mode; + /* simple 'mode': Only OBJ_{BLOB,TREE,COMMIT} */ + enum object_type object_type; }; /** From patchwork Sun Mar 21 00:00:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152837 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.8 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 C8E73C433E9 for ; Sun, 21 Mar 2021 00:02:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B5C4601FE for ; Sun, 21 Mar 2021 00:02:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229962AbhCUACL (ORCPT ); Sat, 20 Mar 2021 20:02:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229815AbhCUABb (ORCPT ); Sat, 20 Mar 2021 20:01:31 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5028C061574 for ; Sat, 20 Mar 2021 17:01:30 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id o16so12867125wrn.0 for ; Sat, 20 Mar 2021 17:01:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pj7qVBS8v9g3R8SADpWt/k+MQ4qCi0/ybT8BQi9BA2w=; b=ToP+itpeCf2AJtDnKxn5MFme0QqTFCvgogEoEps/EPl3aVYcvabP6+8EFkPIGlXPne imDHEGmFSrMjOUA70EPNUVI5V0jyf1rJcglWq6DG7QaSYe7ltUsfHP9npgu+LVtQUT7f b4+4qX4ww/JhUEVuyuf/UQi7p3IjmuCTY0tDujjGuHG/7qJv0CHJlynq6gsCtmGKz9Xv NRNS33Lvhaha675R2IWQlx0SfgN7KX0dxERweinwTGQf9UBDVq094Ust8KhTTg0d1DKl kYmiK6JJUJolcReyiG1393vytQrf8MnJj8P/0NV5SzeQzLSEG282Lw15EX9XE3jSYx9d KCsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pj7qVBS8v9g3R8SADpWt/k+MQ4qCi0/ybT8BQi9BA2w=; b=b0FlTAkPCabkKYn9cB1c0gd4FJvdEpElF+dJabihV0nn+2ndRpCAYXQzOXxjLnKKqE zkREc014V3YQyFT9NaayfhKnA+y3uwKZAz+ine+gY2R2eDR3m51CQXlX396m9BHXckYm ltv/QT4Y/svs+FU70vWSPi+TzQY6UsVAGrFMwkeiiWcKpd0l/T0AUsEDZEhp9ONBwNh1 JrRsvSGh+QpRktc65knDULtTBecm4NzbQwRwiYaLt4zeTY78enU0Dm7AwcAuDy765TVW 4U/Qy8Svi/deS+eW/Lb5Xb98cvY1fXzcRwZzYzF2FgRhiybHS95UyJ+lTTs+wQa5bUm5 TIGw== X-Gm-Message-State: AOAM530xtjpClSN3/ntA7LpzLpVYm6z8g/7+wHjPjXxlN+HEseKerQWu 9lrtQrzXWsYOyyGRlF7RIk/Yx7YLrlPpIQ== X-Google-Smtp-Source: ABdhPJzsUgzy6digLnrkWlZh+qRvH4Kfh0GUBYRwC4Q5A6bsVMYvz+rYObAdkOQ+bL6WuSxNm6uaUA== X-Received: by 2002:a5d:5043:: with SMTP id h3mr11085125wrt.120.1616284889399; Sat, 20 Mar 2021 17:01:29 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:28 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 04/29] tree-walk.c: migrate to using new "object_type" field when possible Date: Sun, 21 Mar 2021 01:00:37 +0100 Message-Id: X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: Ævar Arnfjörð Bjarmason --- tree-walk.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tree-walk.c b/tree-walk.c index b210967b73b..6e9161901d8 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -521,7 +521,7 @@ int traverse_trees(struct index_state *istate, if (!entry[i].path) continue; mask |= 1ul << i; - if (S_ISDIR(entry[i].mode)) + if (entry[i].object_type == OBJ_TREE) dirmask |= 1ul << i; e = &entry[i]; } @@ -892,8 +892,8 @@ static int match_entry(const struct pathspec_item *item, * nothing else (to handle 'submod/' and 'submod' * uniformly). */ - if (!S_ISDIR(entry->mode) && - (!S_ISGITLINK(entry->mode) || matchlen > pathlen + 1)) + if (entry->object_type != OBJ_TREE && + (entry->object_type != OBJ_COMMIT || matchlen > pathlen + 1)) return 0; } @@ -1038,7 +1038,7 @@ static enum interesting do_match(struct index_state *istate, ps->max_depth == -1) return all_entries_interesting; return within_depth(base->buf + base_offset, baselen, - !!S_ISDIR(entry->mode), + entry->object_type == OBJ_TREE, ps->max_depth) ? entry_interesting : entry_not_interesting; } @@ -1071,7 +1071,7 @@ static enum interesting do_match(struct index_state *istate, if (within_depth(base_str + matchlen + 1, baselen - matchlen - 1, - !!S_ISDIR(entry->mode), + entry->object_type == OBJ_TREE, ps->max_depth)) goto interesting; else @@ -1094,7 +1094,8 @@ static enum interesting do_match(struct index_state *istate, * Match all directories. We'll try to * match files later on. */ - if (ps->recursive && S_ISDIR(entry->mode)) + if (ps->recursive && + entry->object_type == OBJ_TREE) return entry_interesting; /* @@ -1105,7 +1106,7 @@ static enum interesting do_match(struct index_state *istate, * be performed in the submodule itself. */ if (ps->recurse_submodules && - S_ISGITLINK(entry->mode) && + entry->object_type == OBJ_COMMIT && !ps_strncmp(item, match + baselen, entry->path, item->nowildcard_len - baselen)) @@ -1154,7 +1155,8 @@ static enum interesting do_match(struct index_state *istate, * character. More accurate matching can then * be performed in the submodule itself. */ - if (ps->recurse_submodules && S_ISGITLINK(entry->mode) && + if (ps->recurse_submodules && + entry->object_type == OBJ_COMMIT && !ps_strncmp(item, match, base->buf + base_offset, item->nowildcard_len)) { strbuf_setlen(base, base_offset + baselen); @@ -1170,7 +1172,7 @@ static enum interesting do_match(struct index_state *istate, * in future, see * https://lore.kernel.org/git/7vmxo5l2g4.fsf@alter.siamese.dyndns.org/ */ - if (ps->recursive && S_ISDIR(entry->mode)) + if (ps->recursive && entry->object_type == OBJ_TREE) return entry_interesting; continue; interesting: @@ -1193,7 +1195,7 @@ static enum interesting do_match(struct index_state *istate, * can probably return all_entries_interesting or * all_entries_not_interesting here if matched. */ - if (S_ISDIR(entry->mode)) + if (entry->object_type == OBJ_TREE) return entry_interesting; strbuf_add(base, entry->path, pathlen); @@ -1269,7 +1271,7 @@ enum interesting tree_entry_interesting(struct index_state *istate, return positive; /* #15, #19 */ - if (S_ISDIR(entry->mode) && + if (entry->object_type == OBJ_TREE && positive >= entry_interesting && negative == entry_interesting) return entry_interesting; From patchwork Sun Mar 21 00:00:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152803 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.8 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 C7008C433E5 for ; Sun, 21 Mar 2021 00:02:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ADD1F61937 for ; Sun, 21 Mar 2021 00:02:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229984AbhCUACM (ORCPT ); Sat, 20 Mar 2021 20:02:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229826AbhCUABc (ORCPT ); Sat, 20 Mar 2021 20:01:32 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 957EDC061574 for ; Sat, 20 Mar 2021 17:01:31 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id 61so12829275wrm.12 for ; Sat, 20 Mar 2021 17:01:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UiMoyzx8hfw5OEv1ZGqAvzhkErw9ACfRbmCJyDNlFbw=; b=n+oIUa/96qyRLs9Flk5YQYHyOvfZIJHem2GKgaCBoAu/Vb8I51oXBd7DPsGW9v7pPn nRFdgHVXBqA/fE3rUE9oBFvKdmiWNwNomhCcJHlWo6c7G6n1WnxyO7M+D/WvLxKB6+4f CfjgJmKPrZhfRbkJJ+YNwJLMgSS8IP8fdmVCBREki43ABxSSqxu2rJq667TVgOAZOc/r TPj6NLw4ciX5leb/a8j/dLarphoCvdA0MORSisepZnbAoTAkfUQclPZDABE3gt+2BreR 0DVZv6fkZrYdhpH3SnzIc08Ig8MaBBzC5RoFJj1Qwb73AMSSHV2gLus/ffnmteNJWr3i 1Kmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UiMoyzx8hfw5OEv1ZGqAvzhkErw9ACfRbmCJyDNlFbw=; b=rPPXqvK/jAYVrUBdXmYHUFUUwZ4I3LUfZepk8NHExhIFVF6F50rxBgPSOFksiP9e2Z 4RdiscbeatGWyg0lfEsK3WjnTyQaF2ZEs+/ZeN17h1dMbOIU2HHfQVdnDSpjw+zWKQ0O FkL275YPkm32fpiCUGA4+Op3ViTL4oXugz5mWuFnjFuU63arRasXvRgZz3dXIG2l9QK/ HHTN416aM8l+XanY9VMUp3UjQjRuFFnNqs799gCiUqgsVeNktba7Dvy8G7y+BzSb8mGD On20V/08Zmt3xovBAajtbWJ2HBJaenB4v1po1Fzv4xGyk2aKIr7Aqq5DCM//j5inDp8J JtOQ== X-Gm-Message-State: AOAM533yj7IVEtct3b8vCawSWykV1FPQQsR8Z5vntK/f2kCMcqBtNiHf XywlwBCy9B07P071kBv8MUGM2ZTKD9DL3g== X-Google-Smtp-Source: ABdhPJwwbenwcrpKPvzjeJe9UaBgNCw+oJVTVSNBTzXk05yme9z6GH9+ZM4We0J3RFnB9Mj+Un5syA== X-Received: by 2002:a5d:5083:: with SMTP id a3mr4848508wrt.38.1616284890156; Sat, 20 Mar 2021 17:01:30 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:29 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 05/29] fast-import tests: test for sorting dir/file foo v.s. foo.txt Date: Sun, 21 Mar 2021 01:00:38 +0100 Message-Id: <7016008554aacc68b70d9bea92c454b1ac53e39c.1616282534.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a missing test for the sorting of "foo" v.s. "foo.txt" where "foo" can be either a file or a directory. If it's a file then "foo" should sort before "foo.txt", and the other way around if "foo" is a directory. See [1] for a reply to a patch of mine introducing such a regression. We now finally have a test for this code added back in 463acbe1c6 (Added tree and commit writing to fast-import., 2006-08-14). This tests both the tecmp1() and tecmp0() functions introduced inn 4cabf8583f (Implemented tree delta compression in fast-import., 2006-08-28). This will catch cases where the "mode" is the same, or reversed between a & b in both functions. There was an existing test for the tecmp1() function(s) just above this one added here. That existing test was added in e741130386 (New fast-import test case for valid tree sorting, 2007-03-12) and would catch cases where entries were reversed, but not if their mode (or rather, type) was the the same or otherwise wrong value. There were no tests at all for the tecmp0() function. As with the tecmp1() test the new test will catch cases where the "mode" is the same (e.g. "1"), or if the two are reversed. It won't catch a "return 0" from the function (i.e. already sorted), that case requires tecmp1() to also be broken. 1. https://lore.kernel.org/git/CABPp-BEZfG_pNNTWsnxEa1xG+kgpQfpXj=KHBkCBAMikrXj-aA@mail.gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t9300-fast-import.sh | 87 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index 5c47ac4465c..8bafb8cc515 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -955,6 +955,93 @@ test_expect_success 'L: verify internal tree sorting' ' test_cmp expect actual ' +test_expect_success 'L: verify internal tree sorting on bad input (tecmp1)' ' + test_create_repo L1-0 && + + cat >input <<-INPUT_END && + blob + mark :1 + data 0 + + reset refs/heads/L1-0 + commit refs/heads/L1-0 + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <expected <<-EXPECT_END && + x.txt + x + z + z.txt + EXPECT_END + + git -C L1-0 fast-import tmp && + cut -f 2 actual && + test_cmp expected actual && + git -C L1-0 fsck 2>err && + # Would happen if tecmp1() were broken + ! grep "error in tree .*: treeNotSorted: " err +' + +test_expect_success 'L: verify internal tree sorting on bad input (tecmp0)' ' + + test_create_repo L1-1 && + + cat >input <<-INPUT_END && + blob + mark :1 + data < $GIT_COMMITTER_DATE + data < $GIT_COMMITTER_DATE + data <expected <<-EXPECT_END && + another.txt + x.txt + x + z + z.txt + EXPECT_END + + git -C L1-1 fast-import tmp 2>err && + # Would happen if tecmp0() passed a fixed mode + ! grep "fatal: not a tree object" err && + cut -f 2 actual && + test_cmp expected actual && + git -C L1-1 fsck +' + test_expect_success 'L: nested tree copy does not corrupt deltas' ' cat >input <<-INPUT_END && blob From patchwork Sun Mar 21 00:00:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152807 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.8 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 20830C433ED for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 08074601FE for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229996AbhCUACP (ORCPT ); Sat, 20 Mar 2021 20:02:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229846AbhCUABd (ORCPT ); Sat, 20 Mar 2021 20:01:33 -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 66A16C061762 for ; Sat, 20 Mar 2021 17:01:32 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id t4so2419516wrn.11 for ; Sat, 20 Mar 2021 17:01:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=P6K9HooH2urrBKX6gfb+Z9MZ1cYKVhdJ/6XaBM0Rha4=; b=ef4b3N+JLMIlOZ+FeA/Bh4VQrFigE7r3iKwz1fdDEqeZxh+uq8wwWBG+v0YoWQjwA7 6FHbygoIS2b94hzP4UxNG09UmEzXT0um9cwVpDu+XtEbAmfljQiXHfOVCwpL8/tSysqd emAKBjVUJDA4vvSSkdP5E249oCfP2UJlFSU4L4usEEh4GDpVc1Lr/ceC+sI2sLSsY7Z+ UB4CsZX5Aq7Z0y4+bGd4TII9guvW/KajVkCnaieUdYTI+obuOYCu7kZHtOanlHzoDXdb +z2Me5KfD9J/NDyxzz5ELZRbs9gZ9/GZZMVUmVgNlcepn2zgpOAqvUdySdzkeRYs5Lft 1FEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=P6K9HooH2urrBKX6gfb+Z9MZ1cYKVhdJ/6XaBM0Rha4=; b=fB+8BUgCag1U5wCqGsu2NcYQG1hV7CbCUD+KkoF6Fxo83LCmC27bou0BYn0gANXatL XfSvDCLf9T0Fmg6ZBtaHxeF1XlFUP6I28ppTGWJG+uM/TdsO0AxP+gKqVS0YpKS/43OC +/mrJ0Nnn3RBHTJ4qAymp19C7WF9V4NIEFISwvK6TNskX1gkGv41RaKbLQXFRA7kWJTH TLeSTbdZlL33Zuq4a/gdCBsfXlchzSoLmUAx7DQwXOp4ZSO5DjPZW9slWseBwJv89nFz +/x3620tPR3uZHArk47G5sq+9rcuZgHK8tkrc1HJWSZ40CK7BMPvn32FfmfXHMIXEz+0 0tOQ== X-Gm-Message-State: AOAM533YQFnCw4Z3oEDLXod+WF1Ez1lVpk53ZiTA77OF8Tklepsd//WQ rW8IajbymSmTQQ4IkNJdOCNY6G+lO7VsVw== X-Google-Smtp-Source: ABdhPJzfGOqu7RCcIEi0Uu/l47ZJQAIUfHNKTFmperKJiBXurtrQO2AWPJfWcT49pfXM5YVDfoT9Eg== X-Received: by 2002:adf:f148:: with SMTP id y8mr10990927wro.107.1616284890911; Sat, 20 Mar 2021 17:01:30 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:30 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 06/29] mktree tests: test that "mode" is passed when sorting Date: Sun, 21 Mar 2021 01:00:39 +0100 Message-Id: X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a test for the mode being passed to ent_compare(). That code dates back to 83f50539a9 (git-mktree: reverse of git-ls-tree., 2006-02-20) and there's never been a test for that particular edge case. Now we have one. I don't see how anything could run into this in practice. In order for that mode sorting to matter as a tiebreaker we need to have a duplicate entry in the tree, i.e. two "foo" entries, one a blob and one a tree. This asserts that if that happens we'll sort on the modes we encounter in such an invalid entry, i.e. we expect the tree entry before the blob. As shown here we'd need to disable the fsck.duplicateEntries error to get to the point of running "mktree", so I doubt anyone's pushing this sort of data around. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t1450-fsck.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 5071ac63a5b..46125190b45 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -318,6 +318,50 @@ test_expect_success 'tree entry with type mismatch' ' test_i18ngrep ! "dangling blob" out ' +test_expect_success 'tree entry with duplicate type mismatching objects' ' + test_create_repo duplicate-entry && + ( + cd duplicate-entry && + blob="$(printf "foo" | git hash-object -w --stdin)" && + tree="$(printf "100644 blob $blob\tfoo" | git mktree)" && + commit="$(git commit-tree $tree -m "first commit")" && + git cat-file commit $commit >good-commit && + + # First bad commit, wrong type, but in the right order + printf "40000 A\0$(echo $tree | hex2oct)" >broken-tree-A && + printf "100644 A\0$(echo $blob | hex2oct)" >broken-tree-B && + cat broken-tree-A broken-tree-B >broken-tree.1 && + broken_tree1="$(git hash-object -w --literally -t tree broken-tree.1)" && + bad_commit1="$(git commit-tree $broken_tree1 -m "bad commit 1")" && + git cat-file commit $bad_commit1 >bad-commit.1 && + git update-ref refs/heads/broken-commit-1 $bad_commit1 && + + test_must_fail git fsck && + git -c fsck.duplicateEntries=warn fsck 2>err && + grep " in tree .*$broken_tree1: duplicateEntries" err && + + # Second bad commits, wrong types and order + cat broken-tree-B broken-tree-A >broken-tree.2 && + broken_tree2="$(git hash-object -w --literally -t tree broken-tree.2)" && + bad_commit2="$(git commit-tree $broken_tree2 -m "bad commit 2")" && + git cat-file commit $bad_commit2 >bad-commit.2 && + git update-ref refs/heads/broken-commit-2 $bad_commit2 && + + test_must_fail git fsck && + git -c fsck.duplicateEntries=warn fsck 2>err && + grep " in tree .*$broken_tree2: duplicateEntries" err && + + # git mktree should "fix" the order of this already broken data + git ls-tree broken-commit-1 >broken-tree-1-ls && + git ls-tree broken-commit-2 >broken-tree-2-ls && + ! test_cmp broken-tree-1-ls broken-tree-2-ls && + + git mktree broken-mktree-1 && + git mktree broken-mktree-2 && + test_cmp broken-mktree-1 broken-mktree-2 + ) +' + test_expect_success 'tag pointing to nonexistent' ' badoid=$(test_oid deadbeef) && cat >invalid-tag <<-EOF && From patchwork Sun Mar 21 00:00:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152845 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.8 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 175B0C433EB for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EBE396193A for ; Sun, 21 Mar 2021 00:02:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229990AbhCUACO (ORCPT ); Sat, 20 Mar 2021 20:02:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229854AbhCUABd (ORCPT ); Sat, 20 Mar 2021 20:01:33 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B260C061763 for ; Sat, 20 Mar 2021 17:01:33 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id v4so12834260wrp.13 for ; Sat, 20 Mar 2021 17:01:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kKueBp07VfWt3ROhSSuTzbz2ru3R0c4WTLIHPrsWT1k=; b=tal0JyIOYhmHnEm9F0JliVETz5WWNlgKpbBGnT39SZORbfCPJE394Des/ZJ+H+wsUU ykwNaiIRv01ULwIYSeiFimGo2K5ZOlKNsk532+ktjplw+b7gCpsYCNM1Zb5mZfj6JDBb Z6nU3b2EYL1sD3w69BcePMw5hU18blKSTuJOh5akKD8aBwnFU25IkeD3mFNxWK4EL52v 454rU0JeR7XZ+QoCVUR1LZuajCFCA4Es/GeDm+kYQ6ue/eVsbint8bca2IPUcJAsAXGQ 6RZy6WhOOQKKg/N4DdvDwsJzwyuTfHOcGiPnSLSYGjOrwj9tm3lX+lAkEwExY6WuFLqE 9F6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kKueBp07VfWt3ROhSSuTzbz2ru3R0c4WTLIHPrsWT1k=; b=k5MbKS4I7DqBbTBS6PNuSkN7/f/APHVC9yqaFwdDlGGmccxGGpxtMEYXf8GGX742gQ TfTEK49vjdTd2nrj5suPLs4gHsDVueaeQwHdluuLrRK8zrAP64oXpogsqRERUlcI41/a kgXNfAwcRam81npq2rIyZ2v/ANqGJPWRnD6CjTMGb+g6GO4fKkVmRQlHEtPBanXPrMB1 8k5qXw0YgtZOafPf//UYWoQ4/i9Jts5474UpCnUrbhX4guexX16uzEF0IYCAxETn6kLU EzYgkHbSZxq1nXLNOypRoltQ1XC6ifakY6zh8eS6lqZY0Rd+ZwpalyT/TVDh62o2Wlww 0V7g== X-Gm-Message-State: AOAM5309Bop51SYgRYynhTi2hDAleol8U9whCYL75qyjh6Si5bFVyZ0B fSLwWa9lTRrrLSgRnrn66wvqcrs/liNCxA== X-Google-Smtp-Source: ABdhPJw1t1mV+hUhyLCIQy58Ycj2X3tBbYcn510IF3k03chPSHQgCBR/BQjD1mXdBwasTma64cxBuQ== X-Received: by 2002:a5d:50c7:: with SMTP id f7mr11529806wrt.18.1616284891696; Sat, 20 Mar 2021 17:01:31 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:31 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 07/29] diff tests: test that "mode" is passed when sorting Date: Sun, 21 Mar 2021 01:00:40 +0100 Message-Id: <73e92ac187d3bdf82fe81b3a0ccd97ebe1fefa11.1616282534.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Piggy-back on the recently added fsck tests for mode comparisons in mktree and assert that diff-tree also does the right thing in this implausible scenario. As with the other tests I've added in preceding commits, these tests will fail if the mode is the same or reversed, respectively. The diff-tree code being tested here was originally added back in .9174026cfe (Add "diff-tree" program to show which files have changed between two trees., 2005-04-09). Unlike the other tests I've added there are existing tests for both of these scenarios. Breaking that function as described above will make tests in t4002-diff-basic.sh, t6409-merge-subtree.sh and t4037-diff-r-t-dirs.sh fail. I think it's good to have tests for this regardless, so let's add these. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t1450-fsck.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 46125190b45..5dd842bb82c 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -362,6 +362,28 @@ test_expect_success 'tree entry with duplicate type mismatching objects' ' ) ' +test_expect_success 'diff-tree stressing tree-diff.c::tree_entry_pathcmp(), not the same type' ' + zero=$(test_oid zero) && + git -C duplicate-entry diff-tree broken-commit-1 broken-commit-2 >1-to-2 && + grep "$zero" 1-to-2 >lines && + test_line_count = 2 lines && + + git -C duplicate-entry diff-tree broken-commit-2 broken-commit-1 >2-to-1 && + grep "$zero" 2-to-1 >lines && + test_line_count = 2 lines +' + +test_expect_success 'diff-tree stressing tree-diff.c::tree_entry_pathcmp(), types not reversed' ' + blob_ok=$(git -C duplicate-entry rev-parse broken-commit-2:A) && + git -C duplicate-entry diff-tree --diff-filter=A broken-commit-1 broken-commit-2 >1-to-2 && + grep "$blob_ok" 1-to-2 && + test_line_count = 1 1-to-2 && + + git -C duplicate-entry diff-tree --diff-filter=A broken-commit-2 broken-commit-1 >2-to-1 && + grep "$blob_ok" 2-to-1 && + test_line_count = 1 2-to-1 +' + test_expect_success 'tag pointing to nonexistent' ' badoid=$(test_oid deadbeef) && cat >invalid-tag <<-EOF && From patchwork Sun Mar 21 00:00:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152839 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.8 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 EC6C4C433EA for ; Sun, 21 Mar 2021 00:02:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D4E4261937 for ; Sun, 21 Mar 2021 00:02:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229986AbhCUACN (ORCPT ); Sat, 20 Mar 2021 20:02:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229863AbhCUABe (ORCPT ); Sat, 20 Mar 2021 20:01:34 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED5B7C061574 for ; Sat, 20 Mar 2021 17:01:33 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id t4so2419586wrn.11 for ; Sat, 20 Mar 2021 17:01:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zSJsxqi4+6c2eig9pQh4nuEV0h30elM4acKQyzBB6Jc=; b=BX7Z6GmWoA5jNvasCCrpX3aGfLbRTRxkHEv6GGWWGkj6tzrxTjH0N1PS/EmP26Wcwg QS1f/cZ2Dodz+Xu8ahnzmGbBF6XVVUmf5+uTgOt3kA3OAvoeTsFbBM/5nW8k/ZEfbP2L ekA9aOIga1QS2bqV1AjK6XHuY6OJntg/Kdq2QE4qFCKxSkewaznXtNbWb+4hZJwo8sFL 27oJHbOIqPBeA91OjmfrHJ0dcgnXj4+GTr9gDJadRD20W5bbz7hwSOm99zvJXj2QNL/d OxgJebpDN5BUxgiZTZydzj9TxMFak/5KA+XD/ScEnyWhS6xeAgojNVpg4EtsSudAbrJ4 AAPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zSJsxqi4+6c2eig9pQh4nuEV0h30elM4acKQyzBB6Jc=; b=MShaDKhfa6uAGpm2X0VS1q8Mxmv3OCbMRjMsm+g9onPNoDVocOSDET6Yd1fNcZlcTG P1HBuptTS5Bre7N7ZLtR+YU6DuGiYQpBVpPsbbVvFUDCjjM4yu3p9A7/b32ssDvcE+F6 kWAXkByDA9bnMpvBuxfktvPKdX5d9VPaeKtWEt39Tm80r/f9q7WjGHJIT+7E65xZqB42 u/lPxSF9jmxaO9iUkXLQIRTKOHUmNaKoLaOTFn6Ozbt8+tqDrji05dAHv3WiKyjcu1sy EIXP/Q1TfK4WyyChnHAM3FzfmWU1S3+OY63eaWWSsRZrljr/I9Xh0qLxx4MesjZ5wins w7nQ== X-Gm-Message-State: AOAM531YEHUELXwXMa9Ws3do3HfxKo7NlOas7N5FGD7RmQkroQGuHt3j zWN8fOmO6WJOUzeBf4JW5lpWhIRvn7Gn7A== X-Google-Smtp-Source: ABdhPJyWcPNuqfxIgrt58vRzZ89zbsf94wQRIQFQQIch9mYmWJrHoqt25aDJOf0DvT2uTRoOQ0cZSQ== X-Received: by 2002:a5d:6103:: with SMTP id v3mr10869842wrt.375.1616284892398; Sat, 20 Mar 2021 17:01:32 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:31 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 08/29] cache.h: have base_name_compare() take "is tree?", not "mode" Date: Sun, 21 Mar 2021 01:00:41 +0100 Message-Id: <1b6a10f814c17e6c303b553cc060022e6d954dc7.1616282534.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the base_name_compare() API and the related df_name_compare() function to take a boolean argument indicating whether the entry is a tree or not, instead of having them call S_ISDIR(mode) on their own. This makes use of the new "object_type" field in the "name_entry". The API being modified here was originally added way back in 958ba6c96eb (Introduce "base_name_compare()" helper function, 2005-05-20). None of these comparison functions used to have tests, but with preceding commits some of them now do. I thought the remainder was trivial enough to review without tests, and didn't want to spend more time on them. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/fast-import.c | 12 ++++++++---- builtin/mktree.c | 4 ++-- cache.h | 4 ++-- combine-diff.c | 8 +++++--- match-trees.c | 6 ++++-- merge-ort.c | 4 ++-- merge-recursive.c | 6 +++--- read-cache.c | 16 ++++++++-------- tree-diff.c | 7 +++++-- unpack-trees.c | 15 ++++++++------- 10 files changed, 47 insertions(+), 35 deletions(-) diff --git a/builtin/fast-import.c b/builtin/fast-import.c index 3afa81cf9ac..2fb56d6e9b7 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -1287,18 +1287,22 @@ static int tecmp0 (const void *_a, const void *_b) { struct tree_entry *a = *((struct tree_entry**)_a); struct tree_entry *b = *((struct tree_entry**)_b); + int istree_a = S_ISDIR(a->versions[0].mode); + int istree_b = S_ISDIR(b->versions[0].mode); return base_name_compare( - a->name->str_dat, a->name->str_len, a->versions[0].mode, - b->name->str_dat, b->name->str_len, b->versions[0].mode); + a->name->str_dat, a->name->str_len, istree_a, + b->name->str_dat, b->name->str_len, istree_b); } static int tecmp1 (const void *_a, const void *_b) { struct tree_entry *a = *((struct tree_entry**)_a); struct tree_entry *b = *((struct tree_entry**)_b); + int istree_a = S_ISDIR(a->versions[1].mode); + int istree_b = S_ISDIR(b->versions[1].mode); return base_name_compare( - a->name->str_dat, a->name->str_len, a->versions[1].mode, - b->name->str_dat, b->name->str_len, b->versions[1].mode); + a->name->str_dat, a->name->str_len, istree_a, + b->name->str_dat, b->name->str_len, istree_b); } static void mktree(struct tree_content *t, int v, struct strbuf *b) diff --git a/builtin/mktree.c b/builtin/mktree.c index 891991b00d6..2c1973229ac 100644 --- a/builtin/mktree.c +++ b/builtin/mktree.c @@ -37,8 +37,8 @@ static int ent_compare(const void *a_, const void *b_) { struct treeent *a = *(struct treeent **)a_; struct treeent *b = *(struct treeent **)b_; - return base_name_compare(a->name, a->len, a->mode, - b->name, b->len, b->mode); + return base_name_compare(a->name, a->len, S_ISDIR(a->mode), + b->name, b->len, S_ISDIR(b->mode)); } static void write_tree(struct object_id *oid) diff --git a/cache.h b/cache.h index ae0c0bef5c2..e38b1e1688c 100644 --- a/cache.h +++ b/cache.h @@ -1506,8 +1506,8 @@ int repo_interpret_branch_name(struct repository *r, int validate_headref(const char *ref); -int base_name_compare(const char *name1, int len1, int mode1, const char *name2, int len2, int mode2); -int df_name_compare(const char *name1, int len1, int mode1, const char *name2, int len2, int mode2); +int base_name_compare(const char *name1, int len1, int istree1, const char *name2, int len2, int istree2); +int df_name_compare(const char *name1, int len1, int istree1, const char *name2, int len2, int istree2); int name_compare(const char *name1, size_t len1, const char *name2, size_t len2); int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2); diff --git a/combine-diff.c b/combine-diff.c index 06635f91bc2..155d52971e6 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -16,11 +16,13 @@ static int compare_paths(const struct combine_diff_path *one, const struct diff_filespec *two) { - if (!S_ISDIR(one->mode) && !S_ISDIR(two->mode)) + int istree_one = S_ISDIR(one->mode); + int istree_two = S_ISDIR(two->mode); + if (!istree_one && !istree_two) return strcmp(one->path, two->path); - return base_name_compare(one->path, strlen(one->path), one->mode, - two->path, strlen(two->path), two->mode); + return base_name_compare(one->path, strlen(one->path), istree_one, + two->path, strlen(two->path), istree_two); } static int filename_changed(char status) diff --git a/match-trees.c b/match-trees.c index 1011357ad0c..a28c19a62a5 100644 --- a/match-trees.c +++ b/match-trees.c @@ -67,8 +67,10 @@ static void *fill_tree_desc_strict(struct tree_desc *desc, static int base_name_entries_compare(const struct name_entry *a, const struct name_entry *b) { - return base_name_compare(a->path, tree_entry_len(a), a->mode, - b->path, tree_entry_len(b), b->mode); + int istree_a = (a->object_type == OBJ_TREE); + int istree_b = (b->object_type == OBJ_TREE); + return base_name_compare(a->path, tree_entry_len(a), istree_a, + b->path, tree_entry_len(b), istree_b); } /* diff --git a/merge-ort.c b/merge-ort.c index 92dea35e57a..68eaa8f294f 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -2389,8 +2389,8 @@ static int tree_entry_order(const void *a_, const void *b_) const struct merged_info *ami = a->util; const struct merged_info *bmi = b->util; - return base_name_compare(a->string, strlen(a->string), ami->result.mode, - b->string, strlen(b->string), bmi->result.mode); + return base_name_compare(a->string, strlen(a->string), S_ISDIR(ami->result.mode), + b->string, strlen(b->string), S_ISDIR(bmi->result.mode)); } static void write_tree(struct object_id *result_oid, diff --git a/merge-recursive.c b/merge-recursive.c index ed31f9496cb..97520a88646 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -554,12 +554,12 @@ static int string_list_df_name_compare(const char *one, const char *two) * * To achieve this, we sort with df_name_compare and provide * the mode S_IFDIR so that D/F conflicts will sort correctly. - * We use the mode S_IFDIR for everything else for simplicity, + * We say we have a directory for everything else for simplicity, * since in other cases any changes in their order due to * sorting cause no problems for us. */ - int cmp = df_name_compare(one, onelen, S_IFDIR, - two, twolen, S_IFDIR); + int cmp = df_name_compare(one, onelen, 1, two, twolen, 1); + /* * Now that 'foo' and 'foo/bar' compare equal, we have to make sure * that 'foo' comes before 'foo/bar'. diff --git a/read-cache.c b/read-cache.c index 5a907af2fb5..6e0b41ed175 100644 --- a/read-cache.c +++ b/read-cache.c @@ -462,8 +462,8 @@ int ie_modified(struct index_state *istate, return 0; } -int base_name_compare(const char *name1, int len1, int mode1, - const char *name2, int len2, int mode2) +int base_name_compare(const char *name1, int len1, int istree1, + const char *name2, int len2, int istree2) { unsigned char c1, c2; int len = len1 < len2 ? len1 : len2; @@ -474,9 +474,9 @@ int base_name_compare(const char *name1, int len1, int mode1, return cmp; c1 = name1[len]; c2 = name2[len]; - if (!c1 && S_ISDIR(mode1)) + if (!c1 && istree1) c1 = '/'; - if (!c2 && S_ISDIR(mode2)) + if (!c2 && istree2) c2 = '/'; return (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0; } @@ -491,8 +491,8 @@ int base_name_compare(const char *name1, int len1, int mode1, * This is used by routines that want to traverse the git namespace * but then handle conflicting entries together when possible. */ -int df_name_compare(const char *name1, int len1, int mode1, - const char *name2, int len2, int mode2) +int df_name_compare(const char *name1, int len1, int istree1, + const char *name2, int len2, int istree2) { int len = len1 < len2 ? len1 : len2, cmp; unsigned char c1, c2; @@ -504,10 +504,10 @@ int df_name_compare(const char *name1, int len1, int mode1, if (len1 == len2) return 0; c1 = name1[len]; - if (!c1 && S_ISDIR(mode1)) + if (!c1 && istree1) c1 = '/'; c2 = name2[len]; - if (!c2 && S_ISDIR(mode2)) + if (!c2 && istree2) c2 = '/'; if (c1 == '/' && !c2) return 0; diff --git a/tree-diff.c b/tree-diff.c index 7cebbb327e2..6ec180331fb 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -50,6 +50,7 @@ static int tree_entry_pathcmp(struct tree_desc *t1, struct tree_desc *t2) { struct name_entry *e1, *e2; int cmp; + int istree_e1, istree_e2; /* empty descriptors sort after valid tree entries */ if (!t1->size) @@ -58,9 +59,11 @@ static int tree_entry_pathcmp(struct tree_desc *t1, struct tree_desc *t2) return -1; e1 = &t1->entry; + istree_e1 = (e1->object_type == OBJ_TREE); e2 = &t2->entry; - cmp = base_name_compare(e1->path, tree_entry_len(e1), e1->mode, - e2->path, tree_entry_len(e2), e2->mode); + istree_e2 = (e2->object_type == OBJ_TREE); + cmp = base_name_compare(e1->path, tree_entry_len(e1), istree_e1, + e2->path, tree_entry_len(e2), istree_e2); return cmp; } diff --git a/unpack-trees.c b/unpack-trees.c index 9298fe1d9b3..ea1ce7894ba 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -925,7 +925,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask, static int do_compare_entry_piecewise(const struct cache_entry *ce, const struct traverse_info *info, const char *name, size_t namelen, - unsigned mode) + unsigned istree) { int pathlen, ce_len; const char *ce_name; @@ -933,7 +933,7 @@ static int do_compare_entry_piecewise(const struct cache_entry *ce, if (info->prev) { int cmp = do_compare_entry_piecewise(ce, info->prev, info->name, info->namelen, - info->mode); + S_ISDIR(info->mode)); if (cmp) return cmp; } @@ -947,13 +947,13 @@ static int do_compare_entry_piecewise(const struct cache_entry *ce, ce_len -= pathlen; ce_name = ce->name + pathlen; - return df_name_compare(ce_name, ce_len, S_IFREG, name, namelen, mode); + return df_name_compare(ce_name, ce_len, 0, name, namelen, istree); } static int do_compare_entry(const struct cache_entry *ce, const struct traverse_info *info, const char *name, size_t namelen, - unsigned mode) + unsigned istree) { int pathlen, ce_len; const char *ce_name; @@ -965,7 +965,7 @@ static int do_compare_entry(const struct cache_entry *ce, * it is quicker to use the precomputed version. */ if (!info->traverse_path) - return do_compare_entry_piecewise(ce, info, name, namelen, mode); + return do_compare_entry_piecewise(ce, info, name, namelen, istree); cmp = strncmp(ce->name, info->traverse_path, info->pathlen); if (cmp) @@ -980,12 +980,13 @@ static int do_compare_entry(const struct cache_entry *ce, ce_len -= pathlen; ce_name = ce->name + pathlen; - return df_name_compare(ce_name, ce_len, S_IFREG, name, namelen, mode); + return df_name_compare(ce_name, ce_len, 0, name, namelen, istree); } static int compare_entry(const struct cache_entry *ce, const struct traverse_info *info, const struct name_entry *n) { - int cmp = do_compare_entry(ce, info, n->path, n->pathlen, n->mode); + int istree = (n->object_type == OBJ_TREE); + int cmp = do_compare_entry(ce, info, n->path, n->pathlen, istree); if (cmp) return cmp; From patchwork Sun Mar 21 00:00:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152801 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.8 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 3235EC433EC for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1D7DE61937 for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230006AbhCUACR (ORCPT ); Sat, 20 Mar 2021 20:02:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229865AbhCUABf (ORCPT ); Sat, 20 Mar 2021 20:01:35 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1F9BC061574 for ; Sat, 20 Mar 2021 17:01:34 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id f22-20020a7bc8d60000b029010c024a1407so9288244wml.2 for ; Sat, 20 Mar 2021 17:01:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vxlIkdXK1NKQp5S4aUeDP0WOB56xEK9kKX4TCwOaLO8=; b=XDnpFjWfFCNGhSKXeWVwMKdhwmXSSL6cCE8sc7wAyt6QRkMx8ZTe85X2YWbX9ULFjT OPSJkQbBz6UQXf4dwtGyfWvX04ZKh/3QmnRw/gNJ14lTIi+DToqx+kx7qq0x1JAUr0Q3 S+Ztcykyd9Bt009T5aogRNlMScOezded5AZpz4AzhjZMsWU7rjlJp/JyP/QuGh77KV4v y0aTguAuOI5jnPuzlu+eWi7RJCLMwinSqfWA32J35+spoiXY1nLi57Qd/WYZ063pmfye N5c5kiEL78zEH9WehSEWrca3Z/QN9fiu7nyNscpAPADMgWmIPFuibSBGQU1UReIQIlsw 4IRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vxlIkdXK1NKQp5S4aUeDP0WOB56xEK9kKX4TCwOaLO8=; b=AMkJqU0HJ3C275NPleNr1UeRDqrK3bXIVwYNj/w0BS/+vYZDb9KMXmB7scr4u6s3jS IY2uJ9JOYxXSkuo1p3G/ZyRgnSMI2jDenDXeUvoHAgUuVMJzNYW35+DN1Spc4bchH1aU k4gFJQ1ieUfuoLFuCimwwnbzIl7qqnbTLjmGW52aBYs1Euk16cmmBozDl6x1DC0mSixu 9fQDhSPNYQOL+q4UHBWI43rKQ8w+53wiV3oabF5uJ/JYOpPOHkvY81MWWxv91XAcc/Ol XjKqNSmU8gLy5D9nRNYjZOE+STesGEdYabJJWT72+cFiKOzG3yOdhbpuVmfn2JM9FGAX iSvg== X-Gm-Message-State: AOAM533YyMxYI+FG0LsSa2MySJNW8usvMJucsDGLvzbcHoYcuTb1lXBt 9VThpS8d1kgGVWG0br4G9qjnIZHJ4DxkOw== X-Google-Smtp-Source: ABdhPJx89BuN4mjjlO/FLtsUJf2vjJVURfKqSuHPjCL6HqqRJsipMCjB0B1UrpU49j/YJqk42UE9hg== X-Received: by 2002:a1c:32ca:: with SMTP id y193mr9433097wmy.56.1616284893278; Sat, 20 Mar 2021 17:01:33 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:32 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 09/29] tree-walk.h users: switch object_type(...) to new .object_type Date: Sun, 21 Mar 2021 01:00:42 +0100 Message-Id: X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change uses of object_type(entry.mode) to use the new entry.object_type field. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/pack-objects.c | 2 +- http-push.c | 6 ++++-- pack-bitmap-write.c | 8 +++++--- revision.c | 12 ++++++++---- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 4bb602688c1..12fcbb3b8d4 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1534,7 +1534,7 @@ static void add_pbase_object(struct tree_desc *tree, return; if (name[cmplen] != '/') { add_object_entry(&entry.oid, - object_type(entry.mode), + entry.object_type, fullname, 1); return; } diff --git a/http-push.c b/http-push.c index b60d5fcc85d..aeb011de8d4 100644 --- a/http-push.c +++ b/http-push.c @@ -1314,7 +1314,7 @@ static struct object_list **process_tree(struct tree *tree, init_tree_desc(&desc, tree->buffer, tree->size); while (tree_entry(&desc, &entry)) - switch (object_type(entry.mode)) { + switch (entry.object_type) { case OBJ_TREE: p = process_tree(lookup_tree(the_repository, &entry.oid), p); @@ -1323,9 +1323,11 @@ static struct object_list **process_tree(struct tree *tree, p = process_blob(lookup_blob(the_repository, &entry.oid), p); break; - default: + case OBJ_COMMIT: /* Subproject commit - not in this repository */ break; + default: + BUG("unreachable"); } free_tree_buffer(tree); diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c index 88d9e696a54..ac32bf2242c 100644 --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@ -353,7 +353,7 @@ static void fill_bitmap_tree(struct bitmap *bitmap, init_tree_desc(&desc, tree->buffer, tree->size); while (tree_entry(&desc, &entry)) { - switch (object_type(entry.mode)) { + switch (entry.object_type) { case OBJ_TREE: fill_bitmap_tree(bitmap, lookup_tree(the_repository, &entry.oid)); @@ -361,9 +361,11 @@ static void fill_bitmap_tree(struct bitmap *bitmap, case OBJ_BLOB: bitmap_set(bitmap, find_object_pos(&entry.oid)); break; - default: - /* Gitlink, etc; not reachable */ + case OBJ_COMMIT: + /* submodule commit - not in this repository */ break; + default: + BUG("unreachable"); } } diff --git a/revision.c b/revision.c index 99c859f7971..aba74cb65a2 100644 --- a/revision.c +++ b/revision.c @@ -72,16 +72,18 @@ static void mark_tree_contents_uninteresting(struct repository *r, init_tree_desc(&desc, tree->buffer, tree->size); while (tree_entry(&desc, &entry)) { - switch (object_type(entry.mode)) { + switch (entry.object_type) { case OBJ_TREE: mark_tree_uninteresting(r, lookup_tree(r, &entry.oid)); break; case OBJ_BLOB: mark_blob_uninteresting(lookup_blob(r, &entry.oid)); break; - default: + case OBJ_COMMIT: /* Subproject commit - not in this repository */ break; + default: + BUG("unreachable"); } } @@ -179,7 +181,7 @@ static void add_children_by_path(struct repository *r, init_tree_desc(&desc, tree->buffer, tree->size); while (tree_entry(&desc, &entry)) { - switch (object_type(entry.mode)) { + switch (entry.object_type) { case OBJ_TREE: paths_and_oids_insert(map, entry.path, &entry.oid); @@ -196,9 +198,11 @@ static void add_children_by_path(struct repository *r, child->object.flags |= UNINTERESTING; } break; - default: + case OBJ_COMMIT: /* Subproject commit - not in this repository */ break; + default: + BUG("unreachable"); } } From patchwork Sun Mar 21 00:00:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152827 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.8 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 C9429C433FC for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AE3906193A for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230032AbhCUACW (ORCPT ); Sat, 20 Mar 2021 20:02:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229897AbhCUABl (ORCPT ); Sat, 20 Mar 2021 20:01:41 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D072CC061762 for ; Sat, 20 Mar 2021 17:01:40 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id e18so12870178wrt.6 for ; Sat, 20 Mar 2021 17:01:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=umcHrBnfXprdU0FGYz0m2EUWU5nY8ZdC6Qi91xkLy0A=; b=fOmlVyn8j3PDwi2yX9F1XL0ylBcAAVZirl4uQy85pRQic1suNg2W1YiquH8/wGhsYl KmW5G5+Px6lhQdxRYjDd+ECtochW4PTMBZlptS282RZSPiL+tKCFgRZ28qZ1TgzxjUeU RDlWqmuRCJKNceA4Wg8VnawufoJguMghjPr4J3qca6WPUR4+EmknzRUUmTI4YvIeG00G +mnqt8nrIgugxJspV4EszQskUAW8lT/0Y2Bjnzkpkk9+N/0O6MLpNi6ZOE1avmiC0MHT hAg8pMvRk9uYScurKOoAgYLC9+n3q82GjMRoGM86i9H7DPTrtIAPgC78u8PrYY1C7RN0 AuQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=umcHrBnfXprdU0FGYz0m2EUWU5nY8ZdC6Qi91xkLy0A=; b=ESICdvxKbsbFjSiNlgUXxResZa/NpdhRQKArE6F//pczipF/yfecyi8MLrkQmHzLYG Vb91X3bA3yva5kNyyWyS2+3SNWlp5WNczt1yk/InWREhdxIzqkmr3x6w0gVnZZZGIvqD xTHtGmeN2PiiYt9Uf39NnivLC9dj9Pr95p3Sq2SifFjgwc34+S1b/yiHh7Oze1iBD2LG FlJ5xYdSr1iq98qBgQuPwwx16c+LeENs8YViIiQRvl4oNJaF0lSTg43JBdAMXQF8rAru rpIRtz1wjTJqEfBq8Cxy64KFHU3i8dGARd35Itimy+NivhF3OrMsPpX/S3wyFjToabvw 7tqw== X-Gm-Message-State: AOAM532bre0DP1bX53AhUrYWEl5yNOOR6ghY9R9vcJJX0EfBToB8AWJs AS+7W0Q3z0hekDs59Iy8bBgpPlwJf0K5mQ== X-Google-Smtp-Source: ABdhPJzLR1Y3apGLdlBF3bhEZ/GYLKtppavnDJ/8akN3scJCygQtkILT/1T2YBBl4CYTk3a5lcusbA== X-Received: by 2002:adf:cf0b:: with SMTP id o11mr11659828wrj.310.1616284893938; Sat, 20 Mar 2021 17:01:33 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:33 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 10/29] tree.h: format argument lists of read_tree_recursive() users Date: Sun, 21 Mar 2021 01:00:43 +0100 Message-Id: X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In preparation for adding a new argument to read_tree_fn_t re-indent and format the argument list of read_tree_recursive() callbacks, and the relevant functions they call. This is a whitespace-only change to make reading subsequent commits easier. I'll be adding a new argument on the "mode" line, so leave space on it. Signed-off-by: Ævar Arnfjörð Bjarmason --- archive.c | 13 ++++++++----- builtin/checkout.c | 4 +++- builtin/log.c | 5 +++-- builtin/ls-tree.c | 4 +++- merge-recursive.c | 3 ++- tree.h | 5 ++++- 6 files changed, 23 insertions(+), 11 deletions(-) diff --git a/archive.c b/archive.c index 4921dc8a69f..feed5c02fb2 100644 --- a/archive.c +++ b/archive.c @@ -137,8 +137,9 @@ static int check_attr_export_subst(const struct attr_check *check) } static int write_archive_entry(const struct object_id *oid, const char *base, - int baselen, const char *filename, unsigned mode, - void *context) + int baselen, const char *filename, + unsigned mode, + void *context) { static struct strbuf path = STRBUF_INIT; struct archiver_context *c = context; @@ -228,8 +229,9 @@ static int write_directory(struct archiver_context *c) } static int queue_or_write_archive_entry(const struct object_id *oid, - struct strbuf *base, const char *filename, - unsigned mode, void *context) + struct strbuf *base, const char *filename, + unsigned mode, + void *context) { struct archiver_context *c = context; @@ -375,7 +377,8 @@ struct path_exists_context { }; static int reject_entry(const struct object_id *oid, struct strbuf *base, - const char *filename, unsigned mode, + const char *filename, + unsigned mode, void *context) { int ret = -1; diff --git a/builtin/checkout.c b/builtin/checkout.c index 0e663905200..0887352db2a 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -114,7 +114,9 @@ static int post_checkout_hook(struct commit *old_commit, struct commit *new_comm } static int update_some(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, void *context) + const char *pathname, + unsigned mode, + void *context) { int len; struct cache_entry *ce; diff --git a/builtin/log.c b/builtin/log.c index 980de590638..b7b76856a9f 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -598,8 +598,9 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev) } static int show_tree_object(const struct object_id *oid, - struct strbuf *base, - const char *pathname, unsigned mode, void *context) + struct strbuf *base, const char *pathname, + unsigned mode, + void *context) { FILE *file = context; fprintf(file, "%s%s\n", pathname, S_ISDIR(mode) ? "/" : ""); diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index 3a442631c71..8d5c3fd0582 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -62,7 +62,9 @@ static int show_recursive(const char *base, int baselen, const char *pathname) } static int show_tree(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, void *context) + const char *pathname, + unsigned mode, + void *context) { int retval = 0; int baselen; diff --git a/merge-recursive.c b/merge-recursive.c index 97520a88646..57198b29fe7 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -453,7 +453,8 @@ static void unpack_trees_finish(struct merge_options *opt) static int save_files_dirs(const struct object_id *oid, struct strbuf *base, const char *path, - unsigned int mode, void *context) + unsigned int mode, + void *context) { struct path_hashmap_entry *entry; int baselen = base->len; diff --git a/tree.h b/tree.h index 6efff003e21..10c8637ab3e 100644 --- a/tree.h +++ b/tree.h @@ -31,7 +31,10 @@ struct tree *parse_tree_indirect(const struct object_id *oid); int cmp_cache_name_compare(const void *a_, const void *b_); #define READ_TREE_RECURSIVE 1 -typedef int (*read_tree_fn_t)(const struct object_id *, struct strbuf *, const char *, unsigned int, void *); +typedef int (*read_tree_fn_t)(const struct object_id *, struct strbuf *, + const char *, + unsigned int, + void *); int read_tree_at(struct repository *r, struct tree *tree, struct strbuf *base, From patchwork Sun Mar 21 00:00:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152809 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.8 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 60E64C433F2 for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2F8F5601FE for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230001AbhCUACQ (ORCPT ); Sat, 20 Mar 2021 20:02:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229870AbhCUABg (ORCPT ); Sat, 20 Mar 2021 20:01:36 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30D78C061762 for ; Sat, 20 Mar 2021 17:01:36 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id t4so2419633wrn.11 for ; Sat, 20 Mar 2021 17:01:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GQsDIqhsnFgfM2pTtgpyw209k/GK4YVOBLdHWTnw31A=; b=enGwJkYCmoUc5ow62Wp8WJkUQMf87aa+SltMu6htQr6m00OXpKRHA6Gqs75yJp2MN0 TMIqoBUl+TxFb9Ql1tM9j9dizoY5NK/TWYDyV6hUGMNwJaLiMI4y/Al9g7OpUbrlyjxo 9XqfloxMFE7S2GRtSIsJCGSL3CDXFjM15DGAXESjqDqSHCmOeRr7v2vwlvvh2dMruj+3 YvGXd2/lI9jTxoJp7RomxaMHbfzUx3XCp27ryNc0L6mQzTE0JdhaphfSnoCY7Hk3e3ve d4196vpS3skX+AcRhDrnEBlSWkSebKvSn5px7JTx+0P1ffHnEmEgxkG/iZ/mf82HAHw1 MMKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GQsDIqhsnFgfM2pTtgpyw209k/GK4YVOBLdHWTnw31A=; b=jpgpcIpeM5Ay+Uv4OU4rTNUWVSwlGk7EqG5Q6d4yr5S87cDDoIcUH80zduEKQqduux 4MSEVXuyqFTYyxG057n/zfIT/Bi1t8ZUxFqtSoF9+VPR11+h0ymM+kaQbkVFVSiZI4wQ 8rsMDkwAIKjPITWksLmwItkA1R3h/sMb6gEzVBWi28lyzgx85gvZtrY8xQEtWt6LH8b0 QUcIYlfmm118xe1fTQZEz6sN9KquSbeGuzQkJyLEdpxVCiEU7rPzoIZFi18Cw6ldcFs2 dTezQ4qJOHSzLPkpo3McYzsDaVoq1W8Mt1PI6TiakpzpyOBiGITQyVJFmBDJje3rzYq9 OcBQ== X-Gm-Message-State: AOAM533MXdxu8oZAH4X8uMlq5LYPklavlUQcjl+gafwQl0QqJweOoRz3 o5jOIs2JbsKHE/vmapIBVCmMbARLYbZDeg== X-Google-Smtp-Source: ABdhPJwi5hRISQV/Johi8Mflvclj4eJlXdiJyhllbrPq0SlheiSXu5cRyGb0nxIg4L52yCzqUsD8UA== X-Received: by 2002:adf:fbcc:: with SMTP id d12mr11077072wrs.151.1616284894589; Sat, 20 Mar 2021 17:01:34 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:34 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 11/29] tree.h API: make read_tree_fn_t take an "enum object_type" Date: Sun, 21 Mar 2021 01:00:44 +0100 Message-Id: <152c6d88542cbf88367f5a67b677c9ad293d28c0.1616282534.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Most of the users of the read_tree_fn_t callback do not care about the "mode" per-se, they just care what type it resolves to. Amend this callback mechanism added in 3c5e8468a93 (ls-tree: major rewrite to do pathspec, 2005-11-26) to pass the object_type, and use it whenever possible. In the archive.c code we could go much deeper with this refactoring, after getting the "mode" that code will pass it around itself and into archive-{tar,zip}.c. As far as I can tell we could drop the mode early, and just pass "enum_object_type type, int is_executable". That would be slightly redundant space-wise, but would assure us that we're not writing out raw modes found in trees, but are normalizing them. But that particular refactoring would be larger than what I'm trying to accomplish here, so let's leave it for now. Signed-off-by: Ævar Arnfjörð Bjarmason --- archive.c | 8 ++++---- builtin/checkout.c | 4 ++-- builtin/log.c | 4 ++-- builtin/ls-files.c | 6 ++++-- builtin/ls-tree.c | 12 +++++------- merge-recursive.c | 6 ++++-- tree.c | 19 ++++++++++++------- tree.h | 2 +- 8 files changed, 34 insertions(+), 27 deletions(-) diff --git a/archive.c b/archive.c index feed5c02fb2..ca28d6ca3b8 100644 --- a/archive.c +++ b/archive.c @@ -230,7 +230,7 @@ static int write_directory(struct archiver_context *c) static int queue_or_write_archive_entry(const struct object_id *oid, struct strbuf *base, const char *filename, - unsigned mode, + enum object_type object_type, unsigned mode, void *context) { struct archiver_context *c = context; @@ -243,7 +243,7 @@ static int queue_or_write_archive_entry(const struct object_id *oid, c->bottom = next; } - if (S_ISDIR(mode)) { + if (object_type == OBJ_TREE) { size_t baselen = base->len; const struct attr_check *check; @@ -378,13 +378,13 @@ struct path_exists_context { static int reject_entry(const struct object_id *oid, struct strbuf *base, const char *filename, - unsigned mode, + enum object_type object_type, unsigned mode, void *context) { int ret = -1; struct path_exists_context *ctx = context; - if (S_ISDIR(mode)) { + if (object_type == OBJ_TREE) { struct strbuf sb = STRBUF_INIT; strbuf_addbuf(&sb, base); strbuf_addstr(&sb, filename); diff --git a/builtin/checkout.c b/builtin/checkout.c index 0887352db2a..95b2b0edf22 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -115,14 +115,14 @@ static int post_checkout_hook(struct commit *old_commit, struct commit *new_comm static int update_some(const struct object_id *oid, struct strbuf *base, const char *pathname, - unsigned mode, + enum object_type object_type, unsigned mode, void *context) { int len; struct cache_entry *ce; int pos; - if (S_ISDIR(mode)) + if (object_type == OBJ_TREE) return READ_TREE_RECURSIVE; len = base->len + strlen(pathname); diff --git a/builtin/log.c b/builtin/log.c index b7b76856a9f..c25f75472ff 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -599,11 +599,11 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev) static int show_tree_object(const struct object_id *oid, struct strbuf *base, const char *pathname, - unsigned mode, + enum object_type object_type, unsigned mode, void *context) { FILE *file = context; - fprintf(file, "%s%s\n", pathname, S_ISDIR(mode) ? "/" : ""); + fprintf(file, "%s%s\n", pathname, object_type == OBJ_TREE ? "/" : ""); return 0; } diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 60a2913a01e..cb217870cbd 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -446,7 +446,8 @@ static int read_one_entry_opt(struct index_state *istate, } static int read_one_entry(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, + const char *pathname, + enum object_type object_type, unsigned mode, void *context) { struct index_state *istate = context; @@ -460,7 +461,8 @@ static int read_one_entry(const struct object_id *oid, struct strbuf *base, * the stage that will conflict with the entry being added. */ static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, + const char *pathname, + enum object_type object_type, unsigned mode, void *context) { struct index_state *istate = context; diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index 8d5c3fd0582..7176d2ae065 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -63,14 +63,13 @@ static int show_recursive(const char *base, int baselen, const char *pathname) static int show_tree(const struct object_id *oid, struct strbuf *base, const char *pathname, - unsigned mode, + enum object_type object_type, unsigned mode, void *context) { int retval = 0; int baselen; - const char *type = blob_type; - if (S_ISGITLINK(mode)) { + if (object_type == OBJ_COMMIT) { /* * Maybe we want to have some recursive version here? * @@ -80,22 +79,21 @@ static int show_tree(const struct object_id *oid, struct strbuf *base, retval = READ_TREE_RECURSIVE; * */ - type = commit_type; - } else if (S_ISDIR(mode)) { + } else if (object_type == OBJ_TREE) { if (show_recursive(base->buf, base->len, pathname)) { retval = READ_TREE_RECURSIVE; if (!(ls_options & LS_SHOW_TREES)) return retval; } - type = tree_type; } else if (ls_options & LS_TREE_ONLY) return 0; if (!(ls_options & LS_NAME_ONLY)) { + const char *type = type_name(object_type); if (ls_options & LS_SHOW_SIZE) { char size_text[24]; - if (!strcmp(type, blob_type)) { + if (object_type == OBJ_BLOB) { unsigned long size; if (oid_object_info(the_repository, oid, &size) == OBJ_BAD) xsnprintf(size_text, sizeof(size_text), diff --git a/merge-recursive.c b/merge-recursive.c index 57198b29fe7..6bc1e659a7b 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -453,7 +453,7 @@ static void unpack_trees_finish(struct merge_options *opt) static int save_files_dirs(const struct object_id *oid, struct strbuf *base, const char *path, - unsigned int mode, + enum object_type object_type, unsigned int mode, void *context) { struct path_hashmap_entry *entry; @@ -467,7 +467,9 @@ static int save_files_dirs(const struct object_id *oid, hashmap_add(&opt->priv->current_file_dir_set, &entry->e); strbuf_setlen(base, baselen); - return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0); + if (object_type != OBJ_TREE) + return 0; + return READ_TREE_RECURSIVE; } static void get_files_dirs(struct merge_options *opt, struct tree *tree) diff --git a/tree.c b/tree.c index 410e3b477e5..f48b170090f 100644 --- a/tree.c +++ b/tree.c @@ -28,6 +28,8 @@ int read_tree_at(struct repository *r, init_tree_desc(&desc, tree->buffer, tree->size); while (tree_entry(&desc, &entry)) { + struct commit *commit; + if (retval != all_entries_interesting) { retval = tree_entry_interesting(r->index, &entry, base, 0, pathspec); @@ -38,7 +40,7 @@ int read_tree_at(struct repository *r, } switch (fn(&entry.oid, base, - entry.path, entry.mode, context)) { + entry.path, entry.object_type, entry.mode, context)) { case 0: continue; case READ_TREE_RECURSIVE: @@ -47,11 +49,11 @@ int read_tree_at(struct repository *r, return -1; } - if (S_ISDIR(entry.mode)) + switch (entry.object_type) { + case OBJ_TREE: oidcpy(&oid, &entry.oid); - else if (S_ISGITLINK(entry.mode)) { - struct commit *commit; - + break; + case OBJ_COMMIT: commit = lookup_commit(r, &entry.oid); if (!commit) die("Commit %s in submodule path %s%s not found", @@ -64,9 +66,12 @@ int read_tree_at(struct repository *r, base->buf, entry.path); oidcpy(&oid, get_commit_tree_oid(commit)); - } - else + break; + case OBJ_BLOB: continue; + default: + BUG("unreachable"); + } len = tree_entry_len(&entry); strbuf_add(base, entry.path, len); diff --git a/tree.h b/tree.h index 10c8637ab3e..1675da7e85c 100644 --- a/tree.h +++ b/tree.h @@ -33,7 +33,7 @@ int cmp_cache_name_compare(const void *a_, const void *b_); #define READ_TREE_RECURSIVE 1 typedef int (*read_tree_fn_t)(const struct object_id *, struct strbuf *, const char *, - unsigned int, + enum object_type, unsigned int, void *); int read_tree_at(struct repository *r, From patchwork Sun Mar 21 00:00:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152825 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.8 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 B0AFDC43381 for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E64A601FE for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230021AbhCUACV (ORCPT ); Sat, 20 Mar 2021 20:02:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229893AbhCUABk (ORCPT ); Sat, 20 Mar 2021 20:01:40 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19AE5C061762 for ; Sat, 20 Mar 2021 17:01:40 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id o16so12867294wrn.0 for ; Sat, 20 Mar 2021 17:01:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bzhAk7HLL18ahxJavY+1axicfmQOL1UzRBQ9gOrev9g=; b=oG5jd8WAHTKpN+0rZullxUWugNx0IA49mla7nf5d4sB9uD37shD8SQ2q8NphTbizwF 23u5tf14XB5GDmnMaNBRpPfgLu7oOwK4CAlFO5Q4VQsk+nytpMBpWuvya0Si9NsRwR6M LnlyC6ULs1pzz0mh6gL0i2h/jOssnfjFQJyqDN8XQwbig21XUuqnPvqIV/ZqI2bZ0u3t 9WQ81UptXNgaGBiag7SvmcupOnBqQKyWoGQhMlD5RreqWTZ6UJbhfZDoKbXYTeGy6h2L n9RRhcKjAjGwsp5zc40SwCUl5+IhGCs39/Fp38DtP8DhBHFBw0UFLEJrWS0mdwL47laf 29Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bzhAk7HLL18ahxJavY+1axicfmQOL1UzRBQ9gOrev9g=; b=c+Sj3YKZAw6l2r29S7JHBz+tndYW9pU/fUlcF/uW1PiUqYcBGQ6oApLx/ePAKPWgAL fT/31t0oWZGNBvGYDaMRl84af2vgpP2V5eYARJuq+QOu7xGpo08cvw5gXgejZltAXcKR MRcvgkeSW9pAF+3qDTI3OEQWXmAqg4yTdjhfMLC28na1VEqJU7u2qtQuByrwGyKk7u9I o7m3Trz16n7/qdiltv/L052YEOtJ+cMNZc8YvpnNZzKLQx27v56b9pKq4JgnP9fnbz8P EB8rVUBfTodcInbnk6FJzFb3PkSQ+5H0PJXIyhfcCirNqu/YWFElXVOlkPQMWRpv/jZm Ot5g== X-Gm-Message-State: AOAM531tYhfGmrnLjBy913jkxPK4X3597KhDbtRrFIwKbWpCweBmGksD 8JKI/Rf3CM7ASID67N6jDrfNiuk5KWNr1Q== X-Google-Smtp-Source: ABdhPJx64wBra84//tkDX5V4HSgfUb/LLLiEApUJcg1dMxeSb3/AJj+WXp2dIyjhqKqNkT/sZtvVeQ== X-Received: by 2002:adf:e60a:: with SMTP id p10mr11250745wrm.291.1616284895526; Sat, 20 Mar 2021 17:01:35 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:34 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 12/29] tree-walk.h users: migrate "p->mode &&" pattern Date: Sun, 21 Mar 2021 01:00:45 +0100 Message-Id: <1c2f65cb674c538eb01152a6a26c64899cef1743.1616282534.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change code that depends on "p->mode" either being a valid mode or zero to use a p->object_type comparison to "OBJ_NONE". The object_type() function in cache.h will not return OBJ_NONE, but these API users are implicitly relying on the memzero() that happens in setup_traverse_info(). Since OBJ_NONE is "0" we can also rely on that being zero'd out here, along with the rest of the structure. I think this is slightly less clever than "mode not set", and helps to get rid of more uses of "mode". Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/merge-tree.c | 9 +++++---- merge-ort.c | 2 +- unpack-trees.c | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index de8520778d2..2de34c2d485 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -214,7 +214,7 @@ static void unresolved_directory(const struct traverse_info *info, void *buf0, *buf1, *buf2; for (p = n; p < n + 3; p++) { - if (p->mode && S_ISDIR(p->mode)) + if (p->object_type == OBJ_TREE) break; } if (n + 3 <= p) @@ -222,7 +222,7 @@ static void unresolved_directory(const struct traverse_info *info, newbase = traverse_path(info, p); -#define ENTRY_OID(e) (((e)->mode && S_ISDIR((e)->mode)) ? &(e)->oid : NULL) +#define ENTRY_OID(e) (((e)->object_type == OBJ_TREE) ? &(e)->oid : NULL) buf0 = fill_tree_descriptor(r, t + 0, ENTRY_OID(n + 0)); buf1 = fill_tree_descriptor(r, t + 1, ENTRY_OID(n + 1)); buf2 = fill_tree_descriptor(r, t + 2, ENTRY_OID(n + 2)); @@ -242,7 +242,7 @@ static struct merge_list *link_entry(unsigned stage, const struct traverse_info const char *path; struct merge_list *link; - if (!n->mode) + if (n->object_type == OBJ_NONE) return entry; if (entry) path = entry->path; @@ -265,7 +265,8 @@ static void unresolved(const struct traverse_info *info, struct name_entry n[3]) * Treat missing entries as directories so that we return * after unresolved_directory has handled this. */ - if (!n[i].mode || S_ISDIR(n[i].mode)) + if (n[i].object_type == OBJ_NONE || + n[i].object_type == OBJ_TREE) dirmask |= (1 << i); } diff --git a/merge-ort.c b/merge-ort.c index 68eaa8f294f..052231efdb2 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -668,7 +668,7 @@ static int collect_merge_info_callback(int n, * setup_path_info() for tracking. */ p = names; - while (!p->mode) + while (p->object_type == OBJ_NONE) p++; len = traverse_path_len(info, p->pathlen); diff --git a/unpack-trees.c b/unpack-trees.c index ea1ce7894ba..e6cb505fcb0 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -862,7 +862,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask, } p = names; - while (!p->mode) + while (p->object_type == OBJ_NONE) p++; newinfo = *info; @@ -1242,7 +1242,7 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str const struct name_entry *p = names; /* Find first entry with a real name (we could use "mask" too) */ - while (!p->mode) + while (p->object_type == OBJ_NONE) p++; if (o->debug_unpack) From patchwork Sun Mar 21 00:00:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152815 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.8 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 84D04C433F4 for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5C49A6193A for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230011AbhCUACS (ORCPT ); Sat, 20 Mar 2021 20:02:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229875AbhCUABi (ORCPT ); Sat, 20 Mar 2021 20:01:38 -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 C2BECC061574 for ; Sat, 20 Mar 2021 17:01:37 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id e9so12850690wrw.10 for ; Sat, 20 Mar 2021 17:01:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dSsKHOwKvAaAvQHyBfVfx9V3Tq8uWNBUvqTe54FP6UU=; b=TdwZB9RdK1A74XT/9jtChIAwQReOxArugdXKeZAWYDI5IDXWxgbrUuI6+2h1VXcRbk sgxMo35eJV5WSakCLvf1411onmVkpAo+leItkGbWAuushqD5HssRj3gD29b47bdHggqz EZBQUGYryMRPashtyM7uGSm8xX3ra72vSGgAD0Kckdhn9Fs1fg8mdZHBxNHRr+tS3yks jrVglEspdVXivR5VjGblWUpLpsMvWT37eACTz1AkHiEWzOTdO5dWA/Q4qEKT61MiDxev 4CnHYPy26v/9RluG9C+DK0H/3Ns9Zmi84Rn5ttMHJGt6ELdnT1eFbp1rx7S6Zmz+xhMi 2xQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dSsKHOwKvAaAvQHyBfVfx9V3Tq8uWNBUvqTe54FP6UU=; b=N640LqIg0dEDpdWbyWFTeXE18C+zQ09q8ZCd1c2XJlaLMAKzvxdeCrRoqbdf1E7FyO /PCU+eixGVQZqvmpdKZkvrbzhFHYTChrgyaIa3wvLD7PBlPGKTajxL0o8+g/JUHMxTUf fzvJIjKk0vWcK6SXet0Jwe7tSpBXYBxkYp3BRWEVaDJcxHO7zAi7/wgViS0Oj7FLapWc SY98ElHwVixbqJulJQ666HqDNPBmvKqI6ZHbZSx6Z4YHsXVGMQnW/6P5pvScGUTAZBHI 6KKVWAo893e2lEY3VLd7lRx2XKSamrhit1HdpaKSmwh/SbZpxBke6dGbiq2jx+uMaRWN lTKQ== X-Gm-Message-State: AOAM532T4lOSoMnbHkZ+JEPjS5zS2uNYuM+/6CzFTHkDUE+3ztyiqhc1 eEcW4m9eXY+jr1DOSQF+QAmT65JaPIzxsA== X-Google-Smtp-Source: ABdhPJxowwWjNb/STA0R3wqXNU19n4J2pv0CfgFO9ecyDrwb20It2q393YOY9AlnVyBsa4tAkdhhSw== X-Received: by 2002:a5d:61c9:: with SMTP id q9mr11051670wrv.219.1616284896302; Sat, 20 Mar 2021 17:01:36 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:35 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 13/29] tree-walk.h users: refactor chained "mode" if/else into switch Date: Sun, 21 Mar 2021 01:00:46 +0100 Message-Id: <163922d427c69d6fb62dea0ed8bb3a112379c7e7.1616282534.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor a couple of "switch" statements that previously relied on "entry.mode" to switch on "entry.object_type" instead. This is more obvious, and allows us to explicitly handle all the OBJ_* cases, not just have a wildcard "else". That doesn't matter for the behavior of this code, but for its readability and maintainability. Signed-off-by: Ævar Arnfjörð Bjarmason --- list-objects.c | 20 ++++++++++++++------ walker.c | 22 +++++++++++++--------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/list-objects.c b/list-objects.c index e19589baa04..37434ba89d3 100644 --- a/list-objects.c +++ b/list-objects.c @@ -111,6 +111,9 @@ static void process_tree_contents(struct traversal_context *ctx, init_tree_desc(&desc, tree->buffer, tree->size); while (tree_entry(&desc, &entry)) { + struct tree *t; + struct blob *b; + if (match != all_entries_interesting) { match = tree_entry_interesting(ctx->revs->repo->index, &entry, base, 0, @@ -121,8 +124,9 @@ static void process_tree_contents(struct traversal_context *ctx, continue; } - if (S_ISDIR(entry.mode)) { - struct tree *t = lookup_tree(ctx->revs->repo, &entry.oid); + switch (entry.object_type) { + case OBJ_TREE: + t = lookup_tree(ctx->revs->repo, &entry.oid); if (!t) { die(_("entry '%s' in tree %s has tree mode, " "but is not a tree"), @@ -130,12 +134,13 @@ static void process_tree_contents(struct traversal_context *ctx, } t->object.flags |= NOT_USER_GIVEN; process_tree(ctx, t, base, entry.path); - } - else if (S_ISGITLINK(entry.mode)) + break; + case OBJ_COMMIT: process_gitlink(ctx, entry.oid.hash, base, entry.path); - else { - struct blob *b = lookup_blob(ctx->revs->repo, &entry.oid); + break; + case OBJ_BLOB: + b = lookup_blob(ctx->revs->repo, &entry.oid); if (!b) { die(_("entry '%s' in tree %s has blob mode, " "but is not a blob"), @@ -143,6 +148,9 @@ static void process_tree_contents(struct traversal_context *ctx, } b->object.flags |= NOT_USER_GIVEN; process_blob(ctx, b, base, entry.path); + break; + default: + BUG("unreachable"); } } } diff --git a/walker.c b/walker.c index 4984bf8b3d6..7ba757244e6 100644 --- a/walker.c +++ b/walker.c @@ -45,21 +45,25 @@ static int process_tree(struct walker *walker, struct tree *tree) init_tree_desc(&desc, tree->buffer, tree->size); while (tree_entry(&desc, &entry)) { struct object *obj = NULL; + struct tree *tree; + struct blob *blob; - /* submodule commits are not stored in the superproject */ - if (S_ISGITLINK(entry.mode)) + switch (entry.object_type) { + case OBJ_COMMIT: + /* submodule commits are not stored in the superproject */ continue; - if (S_ISDIR(entry.mode)) { - struct tree *tree = lookup_tree(the_repository, - &entry.oid); + case OBJ_TREE: + tree = lookup_tree(the_repository, &entry.oid); if (tree) obj = &tree->object; - } - else { - struct blob *blob = lookup_blob(the_repository, - &entry.oid); + break; + case OBJ_BLOB: + blob = lookup_blob(the_repository, &entry.oid); if (blob) obj = &blob->object; + break; + default: + BUG("unreachable"); } if (!obj || process(walker, obj)) return -1; From patchwork Sun Mar 21 00:00:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152817 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.8 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 8FC41C433F7 for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7DF9B61936 for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230016AbhCUACU (ORCPT ); Sat, 20 Mar 2021 20:02:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229883AbhCUABi (ORCPT ); Sat, 20 Mar 2021 20:01:38 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9951BC061574 for ; Sat, 20 Mar 2021 17:01:38 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id a132-20020a1c668a0000b029010f141fe7c2so7059794wmc.0 for ; Sat, 20 Mar 2021 17:01:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vAgDRhhEA7Hx/tW2GL68h1c/JliDD3jfia5a3m3IN6Y=; b=TRv/1v8r2TOS8/vQH0mrjwXSHpzsbMU/n+gXfAYKvGJKcTjqU+lhM+VSGacrzaA6Cw tuqFP7RNE4IJwic3FgY26/2Kn+E56cPyJNN8/3tN3YjgAK+mOgVLG9CoCT2BO97qeFl0 SY9SOxp0nvW0rCPDDHL+PhJMNKHgmM5Xh+9zzfFa7FXzMqqr2Nq29x/sIUJFdsz6T/dB axW3qYMgnE/3KQ//jrQNp0qI/7E8Eoem2E/NPQROUyfBWnaJ4/eQD4ElwvE8aFjg/0Nq 5JA7sI7u27YLiY0GA/Rimph1/j6WUzrp0nuQGqQHvcltwNH9Wpda7uRRKzfeBwuMDLE2 ToZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vAgDRhhEA7Hx/tW2GL68h1c/JliDD3jfia5a3m3IN6Y=; b=FLhmULRG0005l3nEjGGfN9Ida8dg9a6hIoZe6Zt+OvPUwNoFkyor0louDK131cCtO/ MkOkfUL9whBvtrsqBBpgEgd6EAhS0mANoXihe3+yCoLchNEkgAqeTFlguHrasbKB/sla jvsP7SJmcXrcYWvZ/tjUfGZuNA7vn/ji1JECw1EI0DylxaX1TZ1uIWPDWhUZHCFalrVl 9iexFS4UgT/pLLgGIrdHVDzAux6evKwy1wSp+2TWNz25BwpiHLgHI9fbYjZRz/zBQwRm 0i9pfG1POBof4+N52odM1BGU4G//epxk8n8MZuG23k44MeLBHxjRKvkPVRMdbJyw2H9n /44Q== X-Gm-Message-State: AOAM533o1oO8ntcXmr6LmWlaA04Fy66Ud8slxTv8O4aJb1v2CfloQBXz uTcIL5SQ7SuRCrNcuDWMdhpazdBQqIPRDg== X-Google-Smtp-Source: ABdhPJwbB2GrRAiWIqMyhuGHLwqR7+JualVRartFA7UG00TbKbncPFkCi4kE054yG0pwwVwNJ01d6w== X-Received: by 2002:a1c:1f4c:: with SMTP id f73mr9359441wmf.25.1616284897050; Sat, 20 Mar 2021 17:01:37 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:36 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 14/29] tree-walk.h users: migrate miscellaneous "mode" to "object_type" Date: Sun, 21 Mar 2021 01:00:47 +0100 Message-Id: <21df7c668bedcd6e6008e783c2c6c1eb7cd13431.1616282534.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor more users of the "entry.mode" field to use the new "entry.object_type" field. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/grep.c | 6 +++--- builtin/merge-tree.c | 9 +++++---- builtin/pack-objects.c | 4 ++-- builtin/reflog.c | 3 ++- cache-tree.c | 2 +- delta-islands.c | 2 +- notes.c | 4 ++-- unpack-trees.c | 2 +- 8 files changed, 17 insertions(+), 15 deletions(-) diff --git a/builtin/grep.c b/builtin/grep.c index ccd8d08f3dd..6349bbf59ee 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -587,10 +587,10 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec, strbuf_add(base, entry.path, te_len); - if (S_ISREG(entry.mode)) { + if (entry.object_type == OBJ_BLOB) { hit |= grep_oid(opt, &entry.oid, base->buf, tn_len, check_attr ? base->buf + tn_len : NULL); - } else if (S_ISDIR(entry.mode)) { + } else if (entry.object_type == OBJ_TREE) { enum object_type type; struct tree_desc sub; void *data; @@ -606,7 +606,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec, hit |= grep_tree(opt, pathspec, &sub, base, tn_len, check_attr); free(data); - } else if (recurse_submodules && S_ISGITLINK(entry.mode)) { + } else if (recurse_submodules && entry.object_type == OBJ_COMMIT) { hit |= grep_submodule(opt, pathspec, &entry.oid, base->buf, base->buf + tn_len, 1); /* ignored */ diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index 2de34c2d485..12cb317c1ba 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -275,11 +275,11 @@ static void unresolved(const struct traverse_info *info, struct name_entry n[3]) if (dirmask == mask) return; - if (n[2].mode && !S_ISDIR(n[2].mode)) + if (n[2].object_type != OBJ_TREE) entry = link_entry(3, info, n + 2, entry); - if (n[1].mode && !S_ISDIR(n[1].mode)) + if (n[1].object_type != OBJ_TREE) entry = link_entry(2, info, n + 1, entry); - if (n[0].mode && !S_ISDIR(n[0].mode)) + if (n[0].object_type != OBJ_TREE) entry = link_entry(1, info, n + 0, entry); add_merge_entry(entry); @@ -324,7 +324,8 @@ static int threeway_callback(int n, unsigned long mask, unsigned long dirmask, s } if (same_entry(entry+0, entry+1)) { - if (!is_null_oid(&entry[2].oid) && !S_ISDIR(entry[2].mode)) { + if (!is_null_oid(&entry[2].oid) && + entry[2].object_type != OBJ_TREE) { /* We did not touch, they modified -- take theirs */ resolve(info, entry+1, entry+2); return mask; diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 12fcbb3b8d4..6079d1d7935 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1524,7 +1524,7 @@ static void add_pbase_object(struct tree_desc *tree, int cmp; while (tree_entry(tree,&entry)) { - if (S_ISGITLINK(entry.mode)) + if (entry.object_type == OBJ_COMMIT) continue; cmp = tree_entry_len(&entry) != cmplen ? 1 : memcmp(name, entry.path, cmplen); @@ -1538,7 +1538,7 @@ static void add_pbase_object(struct tree_desc *tree, fullname, 1); return; } - if (S_ISDIR(entry.mode)) { + if (entry.object_type == OBJ_TREE) { struct tree_desc sub; struct pbase_tree_cache *tree; const char *down = name+cmplen+1; diff --git a/builtin/reflog.c b/builtin/reflog.c index 09541d1c804..bcbca82aa90 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -95,7 +95,8 @@ static int tree_is_complete(const struct object_id *oid) complete = 1; while (tree_entry(&desc, &entry)) { if (!has_object_file(&entry.oid) || - (S_ISDIR(entry.mode) && !tree_is_complete(&entry.oid))) { + (entry.object_type == OBJ_TREE && + !tree_is_complete(&entry.oid))) { tree->object.flags |= INCOMPLETE; complete = 0; } diff --git a/cache-tree.c b/cache-tree.c index add1f077131..c15a6829585 100644 --- a/cache-tree.c +++ b/cache-tree.c @@ -726,7 +726,7 @@ static void prime_cache_tree_rec(struct repository *r, init_tree_desc(&desc, tree->buffer, tree->size); cnt = 0; while (tree_entry(&desc, &entry)) { - if (!S_ISDIR(entry.mode)) + if (entry.object_type != OBJ_TREE) cnt++; else { struct cache_tree_sub *sub; diff --git a/delta-islands.c b/delta-islands.c index aa98b2e5414..e7cf93acbe3 100644 --- a/delta-islands.c +++ b/delta-islands.c @@ -293,7 +293,7 @@ void resolve_tree_islands(struct repository *r, while (tree_entry(&desc, &entry)) { struct object *obj; - if (S_ISGITLINK(entry.mode)) + if (entry.object_type == OBJ_COMMIT) continue; obj = lookup_object(r, &entry.oid); diff --git a/notes.c b/notes.c index e2fec12a39e..8b03ace52bf 100644 --- a/notes.c +++ b/notes.c @@ -418,7 +418,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, if (path_len == 2 * (hashsz - prefix_len)) { /* This is potentially the remainder of the SHA-1 */ - if (!S_ISREG(entry.mode)) + if (entry.object_type != OBJ_BLOB) /* notes must be blobs */ goto handle_non_note; @@ -431,7 +431,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, /* This is potentially an internal node */ size_t len = prefix_len; - if (!S_ISDIR(entry.mode)) + if (entry.object_type != OBJ_TREE) /* internal nodes must be trees */ goto handle_non_note; diff --git a/unpack-trees.c b/unpack-trees.c index e6cb505fcb0..72b2cf5a741 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1300,7 +1300,7 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str if (dirmask) { /* special case: "diff-index --cached" looking at a tree */ if (o->diff_index_cached && - n == 1 && dirmask == 1 && S_ISDIR(names->mode)) { + n == 1 && dirmask == 1 && names->object_type == OBJ_TREE) { int matches; matches = cache_tree_matches_traversal(o->src_index->cache_tree, names, info); From patchwork Sun Mar 21 00:00:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152805 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.8 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 882BDC433F8 for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6E2FB601FE for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230014AbhCUACT (ORCPT ); Sat, 20 Mar 2021 20:02:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229884AbhCUABj (ORCPT ); Sat, 20 Mar 2021 20:01:39 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5413AC061574 for ; Sat, 20 Mar 2021 17:01:39 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id e9so12850721wrw.10 for ; Sat, 20 Mar 2021 17:01:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HACxaxtHfGPxTSK08wlnRVodGigvTfDuatPabd5wGhU=; b=R0bHZ3md/okMJ9jLNgkYGwg73Kobvl1zkg2+Mf4rA6ObHI4sLO7Q20m02+nEJmpsAW +UAZP/BA1LkWNXJNRDTrhQ/wI+T7RefOu2yIgkW8msg0uQpgx1d8O843vX776fM31izI hUcufa78BPaVEf1KUy745iRcOJSXK/WCGcVoEM5LBgo1upIT3pemprGN6AeWxliF40Go wAtApQAHzmyDUTKAhI/s/N10oa+hBhlyIqKUtyQBZSlJXaG2cxKFmkMl7QB7wpBnq1eT wgmt+0aMZ8BXpC4BLGvJBqWTL9c4mbsCnTfLOfwReQWDVWujtndSYuFHsYL/YyuQhmDB n90g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HACxaxtHfGPxTSK08wlnRVodGigvTfDuatPabd5wGhU=; b=pQspDLxRPhjiBgB0Ra7yCeYEZ6oSUCwNaInn9oztU+7E9xSFPNA/EcEQtDo7HAiQEU aA2orTLkluMjgzuYs/u6bV1TaX8UTEV6OY2TRY0MRHsKOTL7sygCa5B66JOxVx+kYc6j uznkQxq/2pLfZthJiGlf9jCU6i4OF5U9uK8jkDOWI4UNh7GmvMGzA3WEMr7OzOdO6A82 cp9WVOLMwJyjjngcH/XpBzV50RVj7kW0jjgt2R5aPboU+OkgZCLty4wDMbXOHvM+8JsU jGeYW4oICOk4CEUHB0VCSir9kEMmQmgrJeS3hPtE9uyZI/eN9/5fSgj35+fFy5kbPilI 9OPg== X-Gm-Message-State: AOAM5334mD53yGGqKtbdl5MgxFEY5DCvGjkpryAtnAKZoPhkrj96rDgG uwAZpk6keOZP5y+Ry2Z6L7sSpXhwPYxI8A== X-Google-Smtp-Source: ABdhPJygqAGKHp4J08HuoZ51fd6ys/xK7qH4x9AJF8oO/hZUzjYskNb4bkvp3PK8f4ZnaFys82eEfA== X-Received: by 2002:adf:fd48:: with SMTP id h8mr11261112wrs.229.1616284897898; Sat, 20 Mar 2021 17:01:37 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:37 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 15/29] merge-tree tests: test for the mode comparison in same_entry() Date: Sun, 21 Mar 2021 01:00:48 +0100 Message-Id: <592fecb7abc55ff17eed6b3bcc58a6d9991a337e.1616282534.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a test to stress the "a->mode == b->mode" comparison in merge-tree.c's same_entry(). That code was initially added by Linus in 33deb63a36f (Add "merge-tree" helper program. Maybe it's retarded, maybe it's helpful., 2005-04-14), and then again in its current form in 492e0759bfe (Handling large files with GIT, 2006-02-14). However, nothing was testing that we handled this case correctly. Simply removing the mode comparison left all tests passing, but as seen here it's important that we don't think a path with the same content but different modes is the same_entry(). The rest of this series will touch code that's relevant to this, but won't change its behavior. This test is just something I came up with in testing whether the mode test in same_entry() was needed at all. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t4300-merge-tree.sh | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/t/t4300-merge-tree.sh b/t/t4300-merge-tree.sh index e59601e5fe9..f783d784d02 100755 --- a/t/t4300-merge-tree.sh +++ b/t/t4300-merge-tree.sh @@ -40,6 +40,25 @@ test_expect_success 'file add A, B (same)' ' test_must_be_empty actual ' +test_expect_success 'file add A, B (different mode)' ' + git reset --hard initial && + test_commit "add-a-b-same-diff-mode-A" "ONE" "AAA" && + git reset --hard initial && + echo AAA >ONE && + test_chmod +x ONE && + test_tick && + git commit -m"add-a-b-same-diff-mode-B" && + git tag "add-a-b-same-diff-mode-B" HEAD && + git merge-tree initial add-a-b-same-diff-mode-A add-a-b-same-diff-mode-B >actual && + cat >expected <ONE && + test_chmod +x ONE && + test_tick && + git commit -m"add-a-b-diff-diff-mode-B" && + git tag "add-a-b-diff-diff-mode-B" && + git merge-tree initial add-a-b-diff-diff-mode-A add-a-b-diff-diff-mode-B >actual && + cat >expected <>>>>>> .their +EXPECTED + + test_cmp expected actual +' + test_expect_success 'file change A, !B' ' git reset --hard initial && test_commit "change-a-not-b" "initial-file" "BBB" && From patchwork Sun Mar 21 00:00:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152849 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.8 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 A22D5C433FB for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8E88261937 for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230024AbhCUACW (ORCPT ); Sat, 20 Mar 2021 20:02:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229886AbhCUABk (ORCPT ); Sat, 20 Mar 2021 20:01:40 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08BCAC061574 for ; Sat, 20 Mar 2021 17:01:40 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id e18so12870288wrt.6 for ; Sat, 20 Mar 2021 17:01:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7LUcJ13H/qcIZYRm+ZvXiCsD5nVzWQ83tNt06VplU08=; b=m4uItT45RsGk1fbmHh6fSuJD9TShFZRUmOoL1LUerCmqYqBf5beAGvqBi/eFUJO8xV PC3z/0UdoPVsvVusrXzYsGShDuIBhiLRL/P9ZW9Ea5v4eLuLOJGZItXFh8+WAqayDGoN Gaslqt06sNigdEarjpWmcEwUfW3b0l2x+b8zu3Ai2t7ZHq/b+8KuY6zEvik1no0PQjpM xhO3xlWIG/mgBQ1wK7M92gHZ7u9Taae10BkmXDWV1RolVU/GVnkC7BJVG7K3qy62tsY1 QNjCCZkF1zW6yWVEApM/j80kE1LBqKTzgsm5YsH3jfIlcdTUM4SHS7XaeKWvHufNAsG6 RonA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7LUcJ13H/qcIZYRm+ZvXiCsD5nVzWQ83tNt06VplU08=; b=npjsoVLr0S75aLms2FWWNzmrR3+IacsQ2hNYHWaUIc8CvB9Jax+npMZ7RHKls8Q4Hl 4rEd5dtFRRNyZ6Q+Jjq4NW3ECRuAtYQ5Vpto6EWZBGgtdwGdnBHwpmGRprt8/+N72qrb Ooomn18Zp3NGgcJUxCEydcIfmOT7YfhEqDyCJFuzqXX/TcnK+3mT1tOPMo0HufBMz9El OEMgZoSBn95r8EzLD+a9wTHd24I2vDWzY6xXomepjFBlrNDqH4jha9jfEZ+wGOTEmYJh 8BnTehOAExcvDnKput1fO/nV1E3p3eSLLXHoOHdG+sCfHRbbm6uiGghzYzvNHhjpvxPu M/Ww== X-Gm-Message-State: AOAM530J4zB43h/IiL5XHEtjFBkW3rBBogx/zWLmetydFemj77mr7SYs sYgEh1Q7kgUzzxQSAkq4JORnz4sg0xby/g== X-Google-Smtp-Source: ABdhPJwmLRGy3+UUKuH98sN8kTGrRtJOo+VKWp8ZqxpI9dxJhTkZ5a4ZB6Quu/EOMphCRL8G9GfSag== X-Received: by 2002:adf:c3c8:: with SMTP id d8mr11159941wrg.167.1616284898621; Sat, 20 Mar 2021 17:01:38 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:38 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 16/29] merge-ort: correct reference to test in 62fdec17a11 Date: Sun, 21 Mar 2021 01:00:49 +0100 Message-Id: <092472f3c8d92e7cd0195ab3068bd84eaabc9f9c.1616282534.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a comment added in 62fdec17a11 (merge-ort: flesh out implementation of handle_content_merge(), 2021-01-01). The test being referred to here was moved from t6036 in 919df319555 (Collect merge-related tests to t64xx, 2020-08-10). It has also had the plural of "mode" in the name ever since being introduced in 5d1daf30cce (t6036: add a failed conflict detection case: regular files, different modes, 2018-06-30). Signed-off-by: Ævar Arnfjörð Bjarmason --- merge-ort.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/merge-ort.c b/merge-ort.c index 052231efdb2..c9047e279c6 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -1079,7 +1079,7 @@ static int handle_content_merge(struct merge_options *opt, /* * FIXME: If opt->priv->call_depth && !clean, then we really * should not make result->mode match either a->mode or - * b->mode; that causes t6036 "check conflicting mode for + * b->mode; that causes t6416 "check conflicting modes for * regular file" to fail. It would be best to use some other * mode, but we'll confuse all kinds of stuff if we use one * where S_ISREG(result->mode) isn't true, and if we use From patchwork Sun Mar 21 00:00:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152841 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.8 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 D73A4C43445 for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C2E32601FE for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230035AbhCUACZ (ORCPT ); Sat, 20 Mar 2021 20:02:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229894AbhCUABl (ORCPT ); Sat, 20 Mar 2021 20:01:41 -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 AD419C061574 for ; Sat, 20 Mar 2021 17:01:40 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id k8so12841498wrc.3 for ; Sat, 20 Mar 2021 17:01:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IJcDJtxbIELT8ymRmWCDZyHv8UxNb50s38VEI9hP/+k=; b=vHkKx3sLZTMUxnp2NtFiLKpRF2Atm7yCtxZHvC75L9hX+ksKGphiXDstwbMkJHLcPO oQp5u32+bccdZg6BYdyrYJ9isDw0beCsrD8sApBYwVWZGTDYgIhY4UPfOC8vGKt3wbS1 UVlNDVtvXJRnB0yYjlDim/bpa42n5/MmLQXqOzQYlzvtW32to4kFoHPyRcEZtLeXgqva Svr1lDs0f0bYt/SJDBPP9wF3y7DhIsM8meycF+zxd31YY5a1c7KVyuWsy+RcMm/sdT2l pYd4X4aeHp/KyfyNPFcYtA96X65c/k0cct98lZyoEw+DiwnsEy9FogRNxrYajmPnGSuj y+dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IJcDJtxbIELT8ymRmWCDZyHv8UxNb50s38VEI9hP/+k=; b=ticRfQotFhlt4O52SmoylHOlQ0MTHijKESFNIcznHpIs/HRfCkgmTtfXsV2Tgt+ARA W/swMTxs/4HCSgOvwMDQ6BREzhr77JVEmmCAw4XEArePGOybFeNHDUNkca0CIZpqdiVC a/+GbF2+tiVcOhIcsDt80kvVtUzprPgj0tiU3fPIxDChkGptmgRaa7obxWJFF5uyu5BZ 7V1m4OBC4TY+Pe2gjNrQVX8J9wtIafp2AlWQV85kNPyhWA6CpRW/ezN8KRsl+OF2P2MP i7pmWMBIQPcXsRsa8kCtSq6a9EyOKgc1wiLxgguntHFJtpd8laGjk50d4EAAIp9cex6W I9KA== X-Gm-Message-State: AOAM530bygSsqOaWUvOZKn597agWht4i5lupTTOiITTEoR5P1Hm7Nd0b qhFn4ydWuP0pwc/HROYdfjj9GesYgaHGRQ== X-Google-Smtp-Source: ABdhPJzwGAXxVZq9qGkVu4BF6fgI8RvhnjX5faqzCQtaDXb0WjuipUxMjsKNETCfPlfGonjXhs6mbQ== X-Received: by 2002:a5d:64ae:: with SMTP id m14mr11336277wrp.153.1616284899278; Sat, 20 Mar 2021 17:01:39 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:38 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 17/29] fsck.c: switch on "object_type" in fsck_walk_tree() Date: Sun, 21 Mar 2021 01:00:50 +0100 Message-Id: <685da1abbdc639099731caec2a25980d0fe12616.1616282534.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Since 7146e66f086 (tree-walk: finally switch over tree descriptors to contain a pre-parsed entry, 2014-02-06) the "mode" is validated such that we'll never reach the "else" clause here. Good for us that fsck_tree() has its own FSCK_MSG_BAD_FILEMODE check which we can use, added way back in 64071805eda (git-fsck-cache: be stricter about "tree" objects, 2005-07-27). Except it really doesn't due to a regression in 7146e66f086. A follow-up commit will address that, but for now we can simply rewrite this code like the rest of the s/entry.mode/entry.object_type/g changes I'm making. Signed-off-by: Ævar Arnfjörð Bjarmason --- fsck.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/fsck.c b/fsck.c index e3030f3b358..7c74c49d329 100644 --- a/fsck.c +++ b/fsck.c @@ -396,28 +396,25 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op struct object *obj; int result; - if (S_ISGITLINK(entry.mode)) + switch (entry.object_type) { + case OBJ_COMMIT: continue; - - if (S_ISDIR(entry.mode)) { + case OBJ_TREE: obj = (struct object *)lookup_tree(the_repository, &entry.oid); if (name && obj) fsck_put_object_name(options, &entry.oid, "%s%s/", name, entry.path); - result = options->walk(obj, OBJ_TREE, data, options); - } - else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode)) { + break; + case OBJ_BLOB: obj = (struct object *)lookup_blob(the_repository, &entry.oid); if (name && obj) fsck_put_object_name(options, &entry.oid, "%s%s", name, entry.path); - result = options->walk(obj, OBJ_BLOB, data, options); - } - else { - result = error("in tree %s: entry %s has bad mode %.6o", - fsck_describe_object(options, &tree->object.oid), - entry.path, entry.mode); + break; + default: + BUG("unreachable"); } + result = options->walk(obj, entry.object_type, data, options); if (result < 0) return result; if (!res) From patchwork Sun Mar 21 00:00:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152829 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.8 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 E578DC43459 for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D31BB61937 for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230040AbhCUAC0 (ORCPT ); Sat, 20 Mar 2021 20:02:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229900AbhCUABm (ORCPT ); Sat, 20 Mar 2021 20:01:42 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 893AAC061574 for ; Sat, 20 Mar 2021 17:01:41 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id z2so12852821wrl.5 for ; Sat, 20 Mar 2021 17:01:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=k5D8Ht0MBj6e0d1PHR4k9iGzkgJqeIJh0lOlanB0R94=; b=kZZz5Bq+nrPdy6mulbQlkk/CACKBGx7HgwAungSjruqE8YZjfp4dpiqQZC70FTbEPF ECbShNPR+pguKGjX7U1Q3u0xEhwW40DgEYVP9mHKO9/KuE0z0Zom0dsoQ6dBv7wkECS+ JjfOHvTxGYmctxblyVBOk6r77wd9HmSZ2w9aF16Pa3MiUicfBpoOT7hmor1/j2ZQnwd7 jv/jl8JE0ev1KNRwry7usHeo6QvoXKHE7zOLjeJZI1fo9WS4Njqfa8lak++gf6onmVOG WliR8wSCiuYjlT5snLJgz30pakhxQiZIr6Z9/hlyshw1C5PBAorEmTQWeB0MDa9ognbH 6wAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=k5D8Ht0MBj6e0d1PHR4k9iGzkgJqeIJh0lOlanB0R94=; b=K0i0o0KHnq/MCXv6bHoCZvQdXueNJHKk8XqL4R3ZzEZ+BfwiaoJvYIn/R9gwlYayeE 1sWazG97DQwPaqspCRrv27+1Fp2jiN5ymW/KLkdarLNV28VvRJKK5PsAqggWIRorljN3 FaVbWh05k11k4NdvU35m0wZw0J3hai2jDYYEoFqRfqdQkfqgCwePxZHwxC4rKvHimMJF wjcQmX1TW6346wg2sKCIhQKo+QICWg/jdht/YbdFzb8ZaoankZsupsrWMEiVssKPPfUg nQkINhl+D0Hvfsc00QixUcRnUSjzWjnM0MX5NxVVQ5o8YPFUfALKw5B86lUuFKai3yUI ny/A== X-Gm-Message-State: AOAM532ep5z9odm31IWitBBW+AVm9HM/NFHWK8xKDbiemlDY0FKP/rmq xFIoXGOFwnx+zbNFzwY5KsUtPQAtJQf9zQ== X-Google-Smtp-Source: ABdhPJyrIQTw9v3VL1O3HoZa+psGUSrXtgyeMw/qqYkzumW5L8inwW16AkC6j3ugyRwdcmR70Hn3MQ== X-Received: by 2002:adf:a18a:: with SMTP id u10mr11167337wru.197.1616284899980; Sat, 20 Mar 2021 17:01:39 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:39 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 18/29] tree-walk.h users: use temporary variable(s) for "mode" Date: Sun, 21 Mar 2021 01:00:51 +0100 Message-Id: <4babecb78552a0fc111c6826ffbb125f5c65a4cb.1616282534.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In preparation for an eventual rename of the "mode" field, add temporary variable(s) in those places where it's used more than once. This will make a subsequent commits easier to read., since we're only going to need to modify the line on which the assignment happens. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/merge-tree.c | 12 +++++++++--- match-trees.c | 13 +++++++------ merge-ort.c | 5 +++-- notes.c | 3 ++- tree-diff.c | 13 ++++++++----- unpack-trees.c | 3 ++- 6 files changed, 31 insertions(+), 18 deletions(-) diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index 12cb317c1ba..eec5b906561 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -190,14 +190,17 @@ static void resolve(const struct traverse_info *info, struct name_entry *ours, s { struct merge_list *orig, *final; const char *path; + unsigned int orig_mode, final_mode; /* If it's already ours, don't bother showing it */ if (!ours) return; path = traverse_path(info, result); - orig = create_entry(2, ours->mode, &ours->oid, path); - final = create_entry(0, result->mode, &result->oid, path); + orig_mode = ours->mode; + orig = create_entry(2, orig_mode, &ours->oid, path); + final_mode = result->mode; + final = create_entry(0, final_mode, &result->oid, path); final->link = orig; @@ -241,6 +244,7 @@ static struct merge_list *link_entry(unsigned stage, const struct traverse_info { const char *path; struct merge_list *link; + unsigned int link_mode; if (n->object_type == OBJ_NONE) return entry; @@ -248,7 +252,9 @@ static struct merge_list *link_entry(unsigned stage, const struct traverse_info path = entry->path; else path = traverse_path(info, n); - link = create_entry(stage, n->mode, &n->oid, path); + link_mode = n->mode; + link = create_entry(stage, link_mode, &n->oid, path); + link->link = entry; return link; } diff --git a/match-trees.c b/match-trees.c index a28c19a62a5..f3e192ca74d 100644 --- a/match-trees.c +++ b/match-trees.c @@ -86,6 +86,8 @@ static int score_trees(const struct object_id *hash1, const struct object_id *ha for (;;) { int cmp; + unsigned int one_mode = one.entry.mode; + unsigned int two_mode = two.entry.mode; if (one.size && two.size) cmp = base_name_entries_compare(&one.entry, &two.entry); @@ -100,22 +102,21 @@ static int score_trees(const struct object_id *hash1, const struct object_id *ha if (cmp < 0) { /* path1 does not appear in two */ - score += score_missing(one.entry.mode); + score += score_missing(one_mode); update_tree_entry(&one); } else if (cmp > 0) { /* path2 does not appear in one */ - score += score_missing(two.entry.mode); + score += score_missing(two_mode); update_tree_entry(&two); } else { + /* path appears in both */ if (!oideq(&one.entry.oid, &two.entry.oid)) { /* they are different */ - score += score_differs(one.entry.mode, - two.entry.mode); + score += score_differs(one_mode, two_mode); } else { /* same subtree or blob */ - score += score_matches(one.entry.mode, - two.entry.mode); + score += score_matches(one_mode, two_mode); } update_tree_entry(&one); update_tree_entry(&two); diff --git a/merge-ort.c b/merge-ort.c index c9047e279c6..4ef03e605a3 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -544,11 +544,12 @@ static void add_pair(struct merge_options *opt, struct diff_filespec *one, *two; struct rename_info *renames = &opt->priv->renames; int names_idx = is_add ? side : 0; + const struct object_id *oid = &names[names_idx].oid; + unsigned int mode = names[names_idx].mode; one = alloc_filespec(pathname); two = alloc_filespec(pathname); - fill_filespec(is_add ? two : one, - &names[names_idx].oid, 1, names[names_idx].mode); + fill_filespec(is_add ? two : one, oid, 1, mode); diff_queue(&renames->pairs[side], one, two); } diff --git a/notes.c b/notes.c index 8b03ace52bf..970650431fb 100644 --- a/notes.c +++ b/notes.c @@ -478,6 +478,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, struct strbuf non_note_path = STRBUF_INIT; const char *q = oid_to_hex(&subtree->key_oid); size_t i; + unsigned int mode = entry.mode; for (i = 0; i < prefix_len; i++) { strbuf_addch(&non_note_path, *q++); strbuf_addch(&non_note_path, *q++); @@ -485,7 +486,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, } strbuf_add(&non_note_path, entry.path, path_len); add_non_note(t, strbuf_detach(&non_note_path, NULL), - entry.mode, entry.oid.hash); + mode, entry.oid.hash); } } free(buf); diff --git a/tree-diff.c b/tree-diff.c index 6ec180331fb..088ed52d6a3 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -466,17 +466,19 @@ static struct combine_diff_path *ll_diff_tree_paths( tp[0].entry.mode &= ~S_IFXMIN_NEQ; for (i = 1; i < nparent; ++i) { + unsigned int mode = tp[i].entry.mode; cmp = tree_entry_pathcmp(&tp[i], &tp[imin]); if (cmp < 0) { imin = i; - tp[i].entry.mode &= ~S_IFXMIN_NEQ; + mode &= ~S_IFXMIN_NEQ; } else if (cmp == 0) { - tp[i].entry.mode &= ~S_IFXMIN_NEQ; + mode &= ~S_IFXMIN_NEQ; } else { - tp[i].entry.mode |= S_IFXMIN_NEQ; + mode |= S_IFXMIN_NEQ; } + tp[i].entry.mode = mode; } /* fixup markings for entries before imin */ @@ -493,13 +495,14 @@ static struct combine_diff_path *ll_diff_tree_paths( /* are either pi > p[imin] or diff(t,pi) != ø ? */ if (!opt->flags.find_copies_harder) { for (i = 0; i < nparent; ++i) { + unsigned int mode = tp[i].entry.mode; /* p[i] > p[imin] */ - if (tp[i].entry.mode & S_IFXMIN_NEQ) + if (mode & S_IFXMIN_NEQ) continue; /* diff(t,pi) != ø */ if (!oideq(&t.entry.oid, &tp[i].entry.oid) || - (t.entry.mode != tp[i].entry.mode)) + (t.entry.mode != mode)) continue; goto skip_emit_t_tp; diff --git a/unpack-trees.c b/unpack-trees.c index 72b2cf5a741..4653e61c3e3 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1023,8 +1023,9 @@ static struct cache_entry *create_ce_entry(const struct traverse_info *info, is_transient ? make_empty_transient_cache_entry(len) : make_empty_cache_entry(istate, len); + unsigned int mode = n->mode; - ce->ce_mode = create_ce_mode(n->mode); + ce->ce_mode = create_ce_mode(mode); ce->ce_flags = create_ce_flags(stage); ce->ce_namelen = len; oidcpy(&ce->oid, &n->oid); From patchwork Sun Mar 21 00:00:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152819 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.8 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 02C83C43446 for ; Sun, 21 Mar 2021 00:02:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E3609601FE for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230046AbhCUAC2 (ORCPT ); Sat, 20 Mar 2021 20:02:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229901AbhCUABm (ORCPT ); Sat, 20 Mar 2021 20:01:42 -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 69BBBC061574 for ; Sat, 20 Mar 2021 17:01:42 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id x16so12845031wrn.4 for ; Sat, 20 Mar 2021 17:01:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0SGsfSLgm+6VjfV1q/Uy3tUGdl14k4fQ03TAS4b7q7M=; b=pEfcxOgvfo5g6QSUbHW7MuQyblNAJI+832owZX/EHxilJ11mnZpepaC3inbXIt9/DQ CXEI/rPo/Xk4Py8rYIWhNhmoGKinB0jTtTC/L+U+f/U+glEV2L69KkayCzxXCdtPR8gl Rad+JCLKtztFkuevtxP1BgYBI//zEJQz2BqkuLUu2+F70CaswQqiFUpqJRq18ISOu1ni cIw4rX5FfCv1fwcB7A6bgvy3NXueq63kX3Oq2yTc8wiP489sQEJ0GTy1TL4XJrYq4LsG C1HJWkg04+QYOg+pjxAGXBXP59+DeBi8ijuWos16HhWhvaZCI67QDEO75fyg/HMisgsp Yf0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0SGsfSLgm+6VjfV1q/Uy3tUGdl14k4fQ03TAS4b7q7M=; b=fA+ODABr2ByP60qtpb7Y3fDci/adOxeZhSX+KcW4ztMqWNah9VIO2JFvELqcjloO6v yIQ7vkTaom6eETu6GdIzBo5ztxA4Y6Ifyd8FrL+eyy2FQVUGAQkUjustF53lL+AvbA/C edLMXTfdfwrLFERwbyagn05Gy61EAeztMHo/vcVQkD4hXSh7a7JZtzZ5Jqz7hQZKRywh UQZ88Gtd7LJVADGW+VFgW7KWKOA8wCUl2GBbfs2vC/YJWeJzSsWSlUCF3oykRB5xvWqm /3PvhwkrTW/eqQcz2MC5MrxF99Ph6M/1sB8Ex9Lz20bR0DpZIjiVeB7ZIkcJXqt9HAF8 eWDQ== X-Gm-Message-State: AOAM532eLm+k4tXnDe0ChUdqxVg2j3PQ3ugF3TwgxO+vA2JZkqeA6P5f 3EVxSRIH7EveF2ky8tpnsWuvzexGl71j9A== X-Google-Smtp-Source: ABdhPJzTm/AlcaoVe3gqRuAVCPByxQ/kaSp8flQLnBuadoX7DiVtDbvhnfSkrwxpVuY0eg1te/ikUQ== X-Received: by 2002:a05:6000:2c4:: with SMTP id o4mr11206328wry.190.1616284900946; Sat, 20 Mar 2021 17:01:40 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:40 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 19/29] tree-walk.h API: formatting changes for subsequent commit Date: Sun, 21 Mar 2021 01:00:52 +0100 Message-Id: <7251654dd52ec131328ca4e2daef966dbb14f899.1616282534.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Do formatting (mainly whitespace) changes of code around the get_tree_entry() function to make a subsequent change where we'll add a sister function easier to read. Signed-off-by: Ævar Arnfjörð Bjarmason --- blame.c | 5 +++-- tree-walk.c | 9 ++++++--- tree-walk.h | 12 ++++++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/blame.c b/blame.c index 5018bb8fb2c..6ed1520e619 100644 --- a/blame.c +++ b/blame.c @@ -102,9 +102,10 @@ static void verify_working_tree_path(struct repository *r, const struct object_id *commit_oid = &parents->item->object.oid; struct object_id blob_oid; unsigned short mode; + int ret = get_tree_entry(r, commit_oid, path, &blob_oid, + &mode); - if (!get_tree_entry(r, commit_oid, path, &blob_oid, &mode) && - oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB) + if (!ret && oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB) return; } diff --git a/tree-walk.c b/tree-walk.c index 6e9161901d8..e88187e3714 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -591,7 +591,8 @@ static int find_tree_entry(struct repository *r, struct tree_desc *t, oidcpy(result, &oid); return 0; } - return get_tree_entry(r, &oid, name + entrylen, result, mode); + return get_tree_entry(r, &oid, name + entrylen, result, + mode); } return -1; } @@ -622,7 +623,8 @@ int get_tree_entry(struct repository *r, } else { struct tree_desc t; init_tree_desc(&t, tree, size); - retval = find_tree_entry(r, &t, name, oid, mode); + retval = find_tree_entry(r, &t, name, oid, + mode); } free(tree); return retval; @@ -748,7 +750,8 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r, /* Look up the first (or only) path component in the tree. */ find_result = find_tree_entry(r, &t, namebuf.buf, - ¤t_tree_oid, mode); + ¤t_tree_oid, + mode); if (find_result) { goto done; } diff --git a/tree-walk.h b/tree-walk.h index 9f3825d2773..478a659ee2b 100644 --- a/tree-walk.h +++ b/tree-walk.h @@ -169,10 +169,14 @@ struct traverse_info { /** * Find an entry in a tree given a pathname and the sha1 of a tree to - * search. Returns 0 if the entry is found and -1 otherwise. The third - * and fourth parameters are set to the entry's sha1 and mode respectively. - */ -int get_tree_entry(struct repository *, const struct object_id *, const char *, struct object_id *, unsigned short *); + * search. Returns 0 if the entry is found and -1 otherwise. + * + * The third and fourth parameters are set to the entry's sha1 and + * mode respectively. + */ +int get_tree_entry(struct repository *, const struct object_id *, const char *, + struct object_id *, + unsigned short *); /** * Generate the full pathname of a tree entry based from the root of the From patchwork Sun Mar 21 00:00:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152831 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.8 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 12702C4345B for ; Sun, 21 Mar 2021 00:02:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F41ED61936 for ; Sun, 21 Mar 2021 00:02:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230042AbhCUAC1 (ORCPT ); Sat, 20 Mar 2021 20:02:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229903AbhCUABn (ORCPT ); Sat, 20 Mar 2021 20:01:43 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F950C061574 for ; Sat, 20 Mar 2021 17:01:43 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id x13so12843600wrs.9 for ; Sat, 20 Mar 2021 17:01:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fVYR7+ZJQGuy7Th2bvXd6cyWQvZmCLbW0zUv3FNGY4c=; b=qm/okbkx/tQOnE2enY0WRHIwTFSoZHlSaTxLlu+XBOlReO0MPU7kxE5pL9a1GCYwDQ p8ESgg4TwLP2owYy4QyYJW9QC9ncXBxfrVH/Glx9/KyBKEUNL1fQjANXBaznyMCfjPry RBzJMzU/qfGSA87aZwvB96luCmG45vJ6ljSAb6+wpXXfTMe6xEJi32rz22Oiy92AX1jB VS2fcqfeNWqDoaFvdDXQqjXYvuZVEMIzYMllMj7r43qsfb2BQDxYTnOu9E+c4iqir/QQ YdvgX8uoPlsvv3TIGK5NhTrEfo5y534Dg6pMCHxrSEpc5jzLKukrRpdK9SBfqxU6mGei 8vQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fVYR7+ZJQGuy7Th2bvXd6cyWQvZmCLbW0zUv3FNGY4c=; b=iIMN7m0V/bs2eRjZEKz+8xaCqFyQgISz6Q7+UqV5rwwg5Px7Os4XEuknqA2+gJyLFJ GzmP/lNJaAPJszTNNjJhXPh4KvafyKFocVN3wHj2Jct5//UNC5YoyJFreNK6n9UIKU4K r9C9Dow/OENue1Ko6LgMb8km4ihjBIoQHO2ki8mDyMZ0Dn4trC37QFCtiEdMDhgvTQ4e 1SeLr8V01Tvm91l8CKo3a1AI76QAOyh9LshVZaZ6rRdt78CrcS9JpHeqP1SX6dN/di+D OxYnbCzptd9uom+KGBQFfKtdbjN92DsR+treynM1Rzp/QeDIJ8BJz1wRmefpGxDoX4KE 4j0w== X-Gm-Message-State: AOAM531D6BvMo9uxljK7dEhWQzIRwnmFjDrA69uPnnVTk6u082o7A8/M 7CR1OoOCgVIIOpmUFee+VQ5EhaHqdkMjtw== X-Google-Smtp-Source: ABdhPJz5+XYLMo1RfwiuUVLjrLmKECh8K3l1xCv7ZLbcUUGxYF7k0KdaDAI8cc/ZUde4EgcTqYKYMg== X-Received: by 2002:a5d:6587:: with SMTP id q7mr11166545wru.282.1616284901738; Sat, 20 Mar 2021 17:01:41 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:41 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 20/29] tree-walk.h API: rename get_tree_entry() to get_tree_entry_mode() Date: Sun, 21 Mar 2021 01:00:53 +0100 Message-Id: <9e521a3cbf23e16d49396793d33d10494dbdc799.1616282534.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Rename the get_tree_entry() function to get_tree_entry_mode(). This change is only a search-replacement of the name and indentation of the argument lists. A subsequent commits will add get_tree_entry_type() and get_tree_entry_all() functions. Those changes will be much easier to read if we do this rename first. Signed-off-by: Ævar Arnfjörð Bjarmason --- archive.c | 8 ++++---- blame.c | 6 +++--- builtin/rm.c | 2 +- builtin/update-index.c | 2 +- line-log.c | 2 +- match-trees.c | 6 +++--- merge-recursive.c | 18 +++++++++--------- notes.c | 2 +- object-name.c | 6 +++--- tree-walk.c | 14 +++++++------- tree-walk.h | 6 +++--- 11 files changed, 36 insertions(+), 36 deletions(-) diff --git a/archive.c b/archive.c index ca28d6ca3b8..14f8e694596 100644 --- a/archive.c +++ b/archive.c @@ -478,10 +478,10 @@ static void parse_treeish_arg(const char **argv, unsigned short mode; int err; - err = get_tree_entry(ar_args->repo, - &tree->object.oid, - prefix, &tree_oid, - &mode); + err = get_tree_entry_mode(ar_args->repo, + &tree->object.oid, + prefix, &tree_oid, + &mode); if (err || !S_ISDIR(mode)) die(_("current working directory is untracked")); diff --git a/blame.c b/blame.c index 6ed1520e619..13825b86e65 100644 --- a/blame.c +++ b/blame.c @@ -102,8 +102,8 @@ static void verify_working_tree_path(struct repository *r, const struct object_id *commit_oid = &parents->item->object.oid; struct object_id blob_oid; unsigned short mode; - int ret = get_tree_entry(r, commit_oid, path, &blob_oid, - &mode); + int ret = get_tree_entry_mode(r, commit_oid, path, &blob_oid, + &mode); if (!ret && oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB) return; @@ -1239,7 +1239,7 @@ static int fill_blob_sha1_and_mode(struct repository *r, { if (!is_null_oid(&origin->blob_oid)) return 0; - if (get_tree_entry(r, &origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode)) + if (get_tree_entry_mode(r, &origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode)) goto error_out; if (oid_object_info(r, &origin->blob_oid, NULL) != OBJ_BLOB) goto error_out; diff --git a/builtin/rm.c b/builtin/rm.c index 4858631e0f0..4617388b29a 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -179,7 +179,7 @@ static int check_local_mod(struct object_id *head, int index_only) * way as changed from the HEAD. */ if (no_head - || get_tree_entry(the_repository, head, name, &oid, &mode) + || get_tree_entry_mode(the_repository, head, name, &oid, &mode) || ce->ce_mode != create_ce_mode(mode) || !oideq(&ce->oid, &oid)) staged_changes = 1; diff --git a/builtin/update-index.c b/builtin/update-index.c index 79087bccea4..070510d6a88 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -603,7 +603,7 @@ static struct cache_entry *read_one_ent(const char *which, struct object_id oid; struct cache_entry *ce; - if (get_tree_entry(the_repository, ent, path, &oid, &mode)) { + if (get_tree_entry_mode(the_repository, ent, path, &oid, &mode)) { if (which) error("%s: not in %s branch.", path, which); return NULL; diff --git a/line-log.c b/line-log.c index 51d93310a4d..d8ba9229212 100644 --- a/line-log.c +++ b/line-log.c @@ -503,7 +503,7 @@ static void fill_blob_sha1(struct repository *r, struct commit *commit, unsigned short mode; struct object_id oid; - if (get_tree_entry(r, &commit->object.oid, spec->path, &oid, &mode)) + if (get_tree_entry_mode(r, &commit->object.oid, spec->path, &oid, &mode)) die("There is no path %s in the commit", spec->path); fill_filespec(spec, &oid, 1, mode); diff --git a/match-trees.c b/match-trees.c index f3e192ca74d..0faacd8f4ae 100644 --- a/match-trees.c +++ b/match-trees.c @@ -293,7 +293,7 @@ void shift_tree(struct repository *r, if (!*del_prefix) return; - if (get_tree_entry(r, hash2, del_prefix, shifted, &mode)) + if (get_tree_entry_mode(r, hash2, del_prefix, shifted, &mode)) die("cannot find path %s in tree %s", del_prefix, oid_to_hex(hash2)); return; @@ -321,12 +321,12 @@ void shift_tree_by(struct repository *r, unsigned candidate = 0; /* Can hash2 be a tree at shift_prefix in tree hash1? */ - if (!get_tree_entry(r, hash1, shift_prefix, &sub1, &mode1) && + if (!get_tree_entry_mode(r, hash1, shift_prefix, &sub1, &mode1) && S_ISDIR(mode1)) candidate |= 1; /* Can hash1 be a tree at shift_prefix in tree hash2? */ - if (!get_tree_entry(r, hash2, shift_prefix, &sub2, &mode2) && + if (!get_tree_entry_mode(r, hash2, shift_prefix, &sub2, &mode2) && S_ISDIR(mode2)) candidate |= 2; diff --git a/merge-recursive.c b/merge-recursive.c index 6bc1e659a7b..f5cccb8deab 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -487,7 +487,7 @@ static int get_tree_entry_if_blob(struct repository *r, { int ret; - ret = get_tree_entry(r, tree, path, &dfs->oid, &dfs->mode); + ret = get_tree_entry_mode(r, tree, path, &dfs->oid, &dfs->mode); if (S_ISDIR(dfs->mode)) { oidcpy(&dfs->oid, &null_oid); dfs->mode = 0; @@ -1886,9 +1886,9 @@ static int tree_has_path(struct repository *r, struct tree *tree, struct object_id hashy; unsigned short mode_o; - return !get_tree_entry(r, - &tree->object.oid, path, - &hashy, &mode_o); + return !get_tree_entry_mode(r, + &tree->object.oid, path, + &hashy, &mode_o); } /* @@ -2540,11 +2540,11 @@ static void apply_directory_rename_modifications(struct merge_options *opt, * the various handle_rename_*() functions update the index * explicitly rather than relying on unpack_trees() to have done it. */ - get_tree_entry(opt->repo, - &tree->object.oid, - pair->two->path, - &re->dst_entry->stages[stage].oid, - &re->dst_entry->stages[stage].mode); + get_tree_entry_mode(opt->repo, + &tree->object.oid, + pair->two->path, + &re->dst_entry->stages[stage].oid, + &re->dst_entry->stages[stage].mode); /* * Record the original change status (or 'type' of change). If it diff --git a/notes.c b/notes.c index 970650431fb..b7a5ddce3ae 100644 --- a/notes.c +++ b/notes.c @@ -1021,7 +1021,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref, return; if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, &object_oid)) die("Cannot use notes ref %s", notes_ref); - if (get_tree_entry(the_repository, &object_oid, "", &oid, &mode)) + if (get_tree_entry_mode(the_repository, &object_oid, "", &oid, &mode)) die("Failed to read notes tree referenced by %s (%s)", notes_ref, oid_to_hex(&object_oid)); diff --git a/object-name.c b/object-name.c index 64202de60b1..7e3b2d6d739 100644 --- a/object-name.c +++ b/object-name.c @@ -1704,7 +1704,7 @@ static void diagnose_invalid_oid_path(struct repository *r, if (is_missing_file_error(errno)) { char *fullname = xstrfmt("%s%s", prefix, filename); - if (!get_tree_entry(r, tree_oid, fullname, &oid, &mode)) { + if (!get_tree_entry_mode(r, tree_oid, fullname, &oid, &mode)) { die(_("path '%s' exists, but not '%s'\n" "hint: Did you mean '%.*s:%s' aka '%.*s:./%s'?"), fullname, @@ -1903,8 +1903,8 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo, filename, oid, &oc->symlink_path, &oc->mode); } else { - ret = get_tree_entry(repo, &tree_oid, filename, oid, - &oc->mode); + ret = get_tree_entry_mode(repo, &tree_oid, filename, oid, + &oc->mode); if (ret && only_to_die) { diagnose_invalid_oid_path(repo, prefix, filename, diff --git a/tree-walk.c b/tree-walk.c index e88187e3714..7819ff3e0ec 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -591,17 +591,17 @@ static int find_tree_entry(struct repository *r, struct tree_desc *t, oidcpy(result, &oid); return 0; } - return get_tree_entry(r, &oid, name + entrylen, result, - mode); + return get_tree_entry_mode(r, &oid, name + entrylen, result, + mode); } return -1; } -int get_tree_entry(struct repository *r, - const struct object_id *tree_oid, - const char *name, - struct object_id *oid, - unsigned short *mode) +int get_tree_entry_mode(struct repository *r, + const struct object_id *tree_oid, + const char *name, + struct object_id *oid, + unsigned short *mode) { int retval; void *tree; diff --git a/tree-walk.h b/tree-walk.h index 478a659ee2b..eb9b9de6ccc 100644 --- a/tree-walk.h +++ b/tree-walk.h @@ -174,9 +174,9 @@ struct traverse_info { * The third and fourth parameters are set to the entry's sha1 and * mode respectively. */ -int get_tree_entry(struct repository *, const struct object_id *, const char *, - struct object_id *, - unsigned short *); +int get_tree_entry_mode(struct repository *, const struct object_id *, const char *, + struct object_id *, + unsigned short *); /** * Generate the full pathname of a tree entry based from the root of the From patchwork Sun Mar 21 00:00:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152813 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.8 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 22623C4345A for ; Sun, 21 Mar 2021 00:02:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1012961937 for ; Sun, 21 Mar 2021 00:02:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230050AbhCUAC3 (ORCPT ); Sat, 20 Mar 2021 20:02:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229904AbhCUABo (ORCPT ); Sat, 20 Mar 2021 20:01:44 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F321C061574 for ; Sat, 20 Mar 2021 17:01:44 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id j18so12860402wra.2 for ; Sat, 20 Mar 2021 17:01:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=b2fQmiAYcWUUvS/92SmfRXI2NcSVSZCns4taAESp/0o=; b=rtylKM0tsXFJq+z2HHWlQMOUKUndf0mYIUgpovy4caayCDAraGxBMJ47uCgFIENbff 5iFex6+fOo48A+2XUXAZLNnAnatlrlD80+tF1XmUq3khQGAO+CXXxXjFnkfeshoLvdfR 2i6HjCbzseFrpc1tf/lJkqKOHtJxHy1aR4BaVFFqXQKRgF71i03Qf3VJWV7Ue6kvytmG 9odzV8Eq13TdtUBN9Z2M3gMIE30eeWjISpN/kK+KG8GJhF9h2jkjdHYxE9pQc0a6Fecd JCvML36l9c3VvSIuHmfq7a1LdAupkfUACMqn8rZvYgQZmPNmwSwl2ZaX/i8X3y7YLdMO GxoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=b2fQmiAYcWUUvS/92SmfRXI2NcSVSZCns4taAESp/0o=; b=WQDk8G+WfQFK+4jglFAAoHU0pHqXjx0yEC/LXjOYn7NuyxYia718+fBnMo5dLU5Kr1 dfgcNvGOX81q3qZVlhb4+tZOENiONg9j4IqLHjIeSfwASEEQhAEEpqGiOGgpm/0bot2+ 3VcJfp6VRpwSlZuHLxsS0mHEF0QxcHY0N1gS7RdXnORmcedBvpg1CuqVx/fNTJ0rGTOn GTrO5G0EFXk0fmKF2cm88A8g1zC+MGGBBO1n8IUHL6twrZtlC2TITsa0+1yyVAR4z9Rr V9iF3ej3VXdgqr0XMHS36HdS/WJyluy0Lewl9CJUAMfGFlf6CdZq4U3tZExVWIh3QV+L 51ng== X-Gm-Message-State: AOAM53349zLiOymNGc88ayCPHo3G66XqBVWlzBfxxbJVB+HqX4PWH4/l rKNpZPVwn87HWXnPfykF6nOhh33DsSQejQ== X-Google-Smtp-Source: ABdhPJyBRUTgNV1mxRJz/1eerpMEIQP4Yh/apC8gYUdvMiW7gOSQw5CouCAUmFDEpSLuFL/L91SdyA== X-Received: by 2002:adf:8b4e:: with SMTP id v14mr11065845wra.103.1616284902697; Sat, 20 Mar 2021 17:01:42 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:42 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 21/29] match-trees: use "tmp" for mode in shift_tree_by() Date: Sun, 21 Mar 2021 01:00:54 +0100 Message-Id: <40f37e99cd9a5384330a1155f6892b0d64b7bc49.1616282534.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor code added in 85e51b783c3 (Make "subtree" part more orthogonal to the rest of merge-recursive., 2008-06-30) to make it obvious that we don't care about the "mode" here outside of the if statement it appears in. That's opposed to the sub1 & sub2 variables, where we use the two object ids later in this function. Signed-off-by: Ævar Arnfjörð Bjarmason --- match-trees.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/match-trees.c b/match-trees.c index 0faacd8f4ae..e84f993a460 100644 --- a/match-trees.c +++ b/match-trees.c @@ -317,17 +317,17 @@ void shift_tree_by(struct repository *r, const char *shift_prefix) { struct object_id sub1, sub2; - unsigned short mode1, mode2; + unsigned short tmp; unsigned candidate = 0; /* Can hash2 be a tree at shift_prefix in tree hash1? */ - if (!get_tree_entry_mode(r, hash1, shift_prefix, &sub1, &mode1) && - S_ISDIR(mode1)) + if (!get_tree_entry_mode(r, hash1, shift_prefix, &sub1, &tmp) && + S_ISDIR(tmp)) candidate |= 1; /* Can hash1 be a tree at shift_prefix in tree hash2? */ - if (!get_tree_entry_mode(r, hash2, shift_prefix, &sub2, &mode2) && - S_ISDIR(mode2)) + if (!get_tree_entry_mode(r, hash2, shift_prefix, &sub2, &tmp) && + S_ISDIR(tmp)) candidate |= 2; if (candidate == 3) { From patchwork Sun Mar 21 00:00:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152823 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.8 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 538D4C4345D for ; Sun, 21 Mar 2021 00:02:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2DAA8601FE for ; Sun, 21 Mar 2021 00:02:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230053AbhCUAC3 (ORCPT ); Sat, 20 Mar 2021 20:02:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229905AbhCUABp (ORCPT ); Sat, 20 Mar 2021 20:01:45 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11910C061574 for ; Sat, 20 Mar 2021 17:01:45 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id b2-20020a7bc2420000b029010be1081172so7179531wmj.1 for ; Sat, 20 Mar 2021 17:01:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U0fcLPXcmTMQTenu7NP3f2x/BlZSl131f9NHZ6zP/Ag=; b=QR8QvmaxDLWdeMzZVa2HEpsjpZyTfUv6NYFbMj/5T8Ebb/Arl3DlV+2q6j+BTxlBE+ aYbOZyqwN631NTpk50Hr6LgR+aLm/PHZUOm20ykFqDI6RETfyZgy8TGtmfNl0xZmJIJK j7mInmQMNIyJiIM3PnL7tA0eNq+wE3CpT5jh+YyQrPj8Ut5864pg843teCpykqUtzYEZ 7lvEyk5aWummEOCwJFFiC7X0eDveVyX3IALfQ91ZQlzE6pciSqZA3XqNbUgdRMp5ZYqE 81eUa2cMkGdySkkYahD2CE44J9HKg0YodwxEVlbsr2Oz5uL5KGTMnRPj9PAX1lFp0m+T wXBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U0fcLPXcmTMQTenu7NP3f2x/BlZSl131f9NHZ6zP/Ag=; b=pCO81iLs6AgxZ0IR8BQPfWAkw/hufHQgujUIYEMC+PZh1GTm7/aAAcCCC5JVUntoED GbE0/slhGKqornpsgfX9zPVMNgPH2a4isZNBrmEYHGhVyCkE4f+yOapOUYnoF8M9iMFS SJ2JCW2hfhZkQHeikqgthfyVD2vGUKdlt2EFSklPN9wwHo3ZJIpENXmjuNK87ueV0Ror zFsYMutgAqcRuUCLozjXLL6uNd0vqwcVPbr2vbVD7/OClQwmJ1biI5ju8385FsSWF+6k 0E9XSxVZGcO3yggqeLjVH4/LwMOMYFT1pgXofhlYenJsSfMiJ4cisfWOTcPaSxPkU4eT 9KGQ== X-Gm-Message-State: AOAM533RmI4CTr2z8v4X5/oIV+UvmsTNXV9p157GvmTrGGLXGGeJxxGv O1/JXSZj+q1BR3LGGoSKFZWeWm27CI/ajw== X-Google-Smtp-Source: ABdhPJyMF3qZcIZeAbxRE+8XDLBMg438JkAXlxH7ZfI/cQuWHsMoErNOF5ykxshOcdzIHQaGjOTu4A== X-Received: by 2002:a7b:c0c7:: with SMTP id s7mr9610723wmh.5.1616284903498; Sat, 20 Mar 2021 17:01:43 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:42 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 22/29] tree-walk.h API: add get_tree_entry_type() Date: Sun, 21 Mar 2021 01:00:55 +0100 Message-Id: <7f699bf2d5c94121b214b9357b11182c096acfa9.1616282534.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a get_tree_entry_type() helper function to compliment the existing get_tree_entry(), and a static get_tree_entry_all() which it uses internally. Move those users of get_tree_entry_type() who didn't care about the mode specifically, but just want to know whether the tree entry is one of OBJ_{BLOB,COMMIT,TREE} over to the new get_tree_entry_type(). The get_tree_entry_all() function itself will be made non-static in a subsequent commit. I'm leaving its argument list indented accordingly to reduce churn when I do so. Signed-off-by: Ævar Arnfjörð Bjarmason --- archive.c | 8 ++++---- match-trees.c | 10 +++++----- tree-walk.c | 54 ++++++++++++++++++++++++++++++++++++++++----------- tree-walk.h | 11 +++++++++-- 4 files changed, 61 insertions(+), 22 deletions(-) diff --git a/archive.c b/archive.c index 14f8e694596..fb2791f4328 100644 --- a/archive.c +++ b/archive.c @@ -475,14 +475,14 @@ static void parse_treeish_arg(const char **argv, if (prefix) { struct object_id tree_oid; - unsigned short mode; + enum object_type object_type; int err; - err = get_tree_entry_mode(ar_args->repo, + err = get_tree_entry_type(ar_args->repo, &tree->object.oid, prefix, &tree_oid, - &mode); - if (err || !S_ISDIR(mode)) + &object_type); + if (err || object_type != OBJ_TREE) die(_("current working directory is untracked")); tree = parse_tree_indirect(&tree_oid); diff --git a/match-trees.c b/match-trees.c index e84f993a460..3177558313e 100644 --- a/match-trees.c +++ b/match-trees.c @@ -317,17 +317,17 @@ void shift_tree_by(struct repository *r, const char *shift_prefix) { struct object_id sub1, sub2; - unsigned short tmp; + enum object_type tmp; unsigned candidate = 0; /* Can hash2 be a tree at shift_prefix in tree hash1? */ - if (!get_tree_entry_mode(r, hash1, shift_prefix, &sub1, &tmp) && - S_ISDIR(tmp)) + if (!get_tree_entry_type(r, hash1, shift_prefix, &sub1, &tmp) && + tmp == OBJ_TREE) candidate |= 1; /* Can hash1 be a tree at shift_prefix in tree hash2? */ - if (!get_tree_entry_mode(r, hash2, shift_prefix, &sub2, &tmp) && - S_ISDIR(tmp)) + if (!get_tree_entry_type(r, hash2, shift_prefix, &sub2, &tmp) && + tmp == OBJ_TREE) candidate |= 2; if (candidate == 3) { diff --git a/tree-walk.c b/tree-walk.c index 7819ff3e0ec..46ce1ba8069 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -559,9 +559,17 @@ struct dir_state { struct object_id oid; }; +static int get_tree_entry_all(struct repository *r, + const struct object_id *tree_oid, + const char *name, + struct object_id *oid, + unsigned short *mode, + enum object_type *object_type); + static int find_tree_entry(struct repository *r, struct tree_desc *t, const char *name, struct object_id *result, - unsigned short *mode) + unsigned short *mode, + enum object_type *object_type) { int namelen = strlen(name); while (t->size) { @@ -585,23 +593,24 @@ static int find_tree_entry(struct repository *r, struct tree_desc *t, } if (name[entrylen] != '/') continue; - if (!S_ISDIR(*mode)) + if (*object_type != OBJ_TREE) break; if (++entrylen == namelen) { oidcpy(result, &oid); return 0; } - return get_tree_entry_mode(r, &oid, name + entrylen, result, - mode); + return get_tree_entry_all(r, &oid, name + entrylen, result, + mode, object_type); } return -1; } -int get_tree_entry_mode(struct repository *r, - const struct object_id *tree_oid, - const char *name, - struct object_id *oid, - unsigned short *mode) +static int get_tree_entry_all(struct repository *r, + const struct object_id *tree_oid, + const char *name, + struct object_id *oid, + unsigned short *mode, + enum object_type *object_type) { int retval; void *tree; @@ -624,12 +633,34 @@ int get_tree_entry_mode(struct repository *r, struct tree_desc t; init_tree_desc(&t, tree, size); retval = find_tree_entry(r, &t, name, oid, - mode); + mode, object_type); } free(tree); return retval; } +int get_tree_entry_mode(struct repository *r, + const struct object_id *tree_oid, + const char *name, + struct object_id *oid, + unsigned short *mode) +{ + enum object_type object_type; + return get_tree_entry_all(r, tree_oid, name, oid, + mode, &object_type); +} + +int get_tree_entry_type(struct repository *r, + const struct object_id *tree_oid, + const char *name, + struct object_id *oid, + enum object_type *object_type) +{ + unsigned short mode; + return get_tree_entry_all(r, tree_oid, name, oid, + &mode, object_type); +} + /* * This is Linux's built-in max for the number of symlinks to follow. * That limit, of course, does not affect git, but it's a reasonable @@ -674,6 +705,7 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r, int find_result; char *first_slash; char *remainder = NULL; + enum object_type object_type; if (!t.buffer) { void *tree; @@ -751,7 +783,7 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r, /* Look up the first (or only) path component in the tree. */ find_result = find_tree_entry(r, &t, namebuf.buf, ¤t_tree_oid, - mode); + mode, &object_type); if (find_result) { goto done; } diff --git a/tree-walk.h b/tree-walk.h index eb9b9de6ccc..f569960c6fb 100644 --- a/tree-walk.h +++ b/tree-walk.h @@ -171,12 +171,19 @@ struct traverse_info { * Find an entry in a tree given a pathname and the sha1 of a tree to * search. Returns 0 if the entry is found and -1 otherwise. * - * The third and fourth parameters are set to the entry's sha1 and - * mode respectively. + * There are variants of this function depending on what fields in the + * "struct name_entry" you'd like. You always need a pointer to an + * appropriate variable to fill in (NULL won't do!): + * + * get_tree_entry_mode(): unsigned int mode + * get_tree_entry_type(): enum object_type */ int get_tree_entry_mode(struct repository *, const struct object_id *, const char *, struct object_id *, unsigned short *); +int get_tree_entry_type(struct repository *, const struct object_id *, const char *, + struct object_id *, + enum object_type *); /** * Generate the full pathname of a tree entry based from the root of the From patchwork Sun Mar 21 00:00:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152821 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.8 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 67A5DC4345C for ; Sun, 21 Mar 2021 00:02:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 430F161937 for ; Sun, 21 Mar 2021 00:02:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230056AbhCUACb (ORCPT ); Sat, 20 Mar 2021 20:02:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229912AbhCUABq (ORCPT ); Sat, 20 Mar 2021 20:01:46 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D487DC061574 for ; Sat, 20 Mar 2021 17:01:45 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id d8-20020a1c1d080000b029010f15546281so6957469wmd.4 for ; Sat, 20 Mar 2021 17:01:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Xx3wfUsO0pas8hkBedRW0E2y9rCzJOX14wkb+nX7VCY=; b=rM4ejcvJSpht1M7zJmaY+cwrKcEsx8OOT9d5jKy3BQcOUddSXHH1PssHepEw2xiFPm cSIv7LqyXuqZTdQ7+zA4VRCsGW8QtHJeTAeaciFIi1UWYeCHXStBNxeZO4Qs7ZkDAdhc odR/Hbh2HQW8yLFVSjNhYHg5h90cRNE/QMt6ScDSYMpGxoALK7Abiy4NK9rjFbGtg8b/ EUyhXwXd6XmVwhDKAkqCYlS1nS72ZqlzekjRDMLvC0a+IXsjyuJA9LywlsQqfDnxIZ9B o4arYl++S58YGtJD8pyfmdm+4kut01kokApkvEkIo0JPEDT1c9K6RRTFXR3wIG2/xyaQ QcSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Xx3wfUsO0pas8hkBedRW0E2y9rCzJOX14wkb+nX7VCY=; b=dqclFT3He9SEMUCh+SbO+ADSMyDAkCvIDXndHwr42yggY6v3pWqbkPbOci0CKyMG5+ 1/M/ZvGbDW5kocfT47kAgZo6sDfmHh3E0MJoNsPMR1QdvS3hAzvVY3X6V8mnOsGXTmna RV2koGiK0cXUZirAXWrE6Ydz4yJ5bIrMuOMkjy+pJnLf1+ImRylEL3GIoSTPHl/0FqBx WMq5Ybz5+NPm2emSiyhbKwe/sFZqwtJQXIWrp/7f/iZVuG9Gve/3l2JLiX/5V7oIVIuo At0AtAiexHnYahl2qGGcBYtOPEwuW4oD4zchlYXIfPVK9e46dYgZyCDXZ1TLkMSKnQjJ MHxw== X-Gm-Message-State: AOAM532f0EyIHiEGh9CmlbMSu0SUWMIFUIGDFReNTGek49r5yrmWJfbW zeOVaTQvcplnMMdhgfs2aNcTRbuIOKtUkA== X-Google-Smtp-Source: ABdhPJxuSJ35TDo1YtWRQETMFIHa/5ly1/W1W4I3NAOpYlyBd/Oi+laXtvCNHieysy+VAKLt7kXsmA== X-Received: by 2002:a1c:a958:: with SMTP id s85mr9814435wme.4.1616284904410; Sat, 20 Mar 2021 17:01:44 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:43 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 23/29] tree-walk.h API: document and format tree_entry_extract() Date: Sun, 21 Mar 2021 01:00:56 +0100 Message-Id: <7ab7576cb16727d9aa9edb24a2c26b1f0b1e8880.1616282534.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Document and format the argument list of the tree_entry_extract() function in preparation for adding a sister function. Signed-off-by: Ævar Arnfjörð Bjarmason --- tree-walk.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tree-walk.h b/tree-walk.h index f569960c6fb..f51485250fb 100644 --- a/tree-walk.h +++ b/tree-walk.h @@ -40,11 +40,17 @@ struct tree_desc { /** * Decode the entry currently being visited (the one pointed to by - * `tree_desc's` `entry` member) and return the sha1 of the entry. The - * `pathp` and `modep` arguments are set to the entry's pathname and mode - * respectively. + * `tree_desc's` `entry` member) and return the OID of the entry. + * + * There are variants of this function depending on what fields in the + * "struct name_entry" you'd like. You always need a pointer to an + * appropriate variable to fill in (NULL won't do!): + * + * tree_entry_extract_mode(): const char *path, unsigned int mode */ -static inline const struct object_id *tree_entry_extract(struct tree_desc *desc, const char **pathp, unsigned short *modep) +static inline const struct object_id *tree_entry_extract(struct tree_desc *desc, + const char **pathp, + unsigned short *modep) { *pathp = desc->entry.path; *modep = desc->entry.mode; From patchwork Sun Mar 21 00:00:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152833 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.8 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 7901FC4345E for ; Sun, 21 Mar 2021 00:02:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 648B26193A for ; Sun, 21 Mar 2021 00:02:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230063AbhCUACc (ORCPT ); Sat, 20 Mar 2021 20:02:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229913AbhCUABr (ORCPT ); Sat, 20 Mar 2021 20:01:47 -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 90E3BC061574 for ; Sat, 20 Mar 2021 17:01:46 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id e9so12850858wrw.10 for ; Sat, 20 Mar 2021 17:01:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2/yNYOjyZLfE/PPCwEVbyxIQT/xDUDMzYPPMQIuBPvI=; b=b0o4t8+1d3VFNmH+6eShnBz/v13rrTDecgfwQj10RsAzY6y+4SomLVaPkm/wdDJ/Q1 lIKJQYchxqgdl4rzdjOkl+1ukhVKxanltbrIpF5ZLL3ckEdXCdM2JpX0eFRQQohQmw11 K3L+0vK+0HUJIyP357xlcdX0Yq073zgS2Bcx532kxtTWp/TYpmXee4XNS/VTOgvaLqlp 3QGV5kAhNdZ1EbNjMBdOYPDXcu6AC8C8Ug+Odzz0YZb9186W1rvJlVv3eIuMP5yof0hX FBoj9Pf186ycYfDOB8Dpb5YEycGImio7bim4PjLnBnnMbcsjgGEQRJdwO9SwUwgkAaT2 4/gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2/yNYOjyZLfE/PPCwEVbyxIQT/xDUDMzYPPMQIuBPvI=; b=ncX5mbOiQvxEgeD9agIenYK/KcSY39ZzRa5qG/13P+iAsxzzKMV6PkJvJ/iP84YUqU 4Gmx3ZzmtD6wDQL1KjBhsgZN1nVx6n8Y2TNqHUld3yWzAqkqg25WKxnDE/xYMyKgHJgQ aDPqBClzG02Tn8MBltaMZJMA38pIfcpPWVluH2ciTdisFbbX4206G6BfX9Q4CcYFdXDe kBKWlUzfMCk5ki79Sp2QCpn3bcoEG/SsykzJdvCXW+xKQbhAMD5L7l1+G7Zppys9mNx1 yKJKeV+r78uFrOR49gcOUae7XMIpaCHxyHMUCBzOjgfiJ2PZO88npvGCTXpoTMiP2pWM cIJw== X-Gm-Message-State: AOAM530tRwqGqfRb4D5rrvIL4piu62ROaPmmKjxTWmnwl9zA7MeQK1wt akC38oYHMHiCa3/xz1DYBqIAW/OSrVQoBg== X-Google-Smtp-Source: ABdhPJwUED1TIMQXWw1MrP2ujirjah/vCd7xpZksgZTWZxPUNUO3dDzxec9NZp3O3XoPvvfL6N+glg== X-Received: by 2002:adf:8562:: with SMTP id 89mr11265289wrh.101.1616284905109; Sat, 20 Mar 2021 17:01:45 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:44 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 24/29] tree-entry.h API: rename tree_entry_extract() to tree_entry_extract_mode() Date: Sun, 21 Mar 2021 01:00:57 +0100 Message-Id: X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As with the recent split of the get_tree_entry() function, rename the tree_entry_extract() function to *_mode() in preparation for adding other variants of it. Signed-off-by: Ævar Arnfjörð Bjarmason --- fsck.c | 2 +- match-trees.c | 4 ++-- tree-diff.c | 4 ++-- tree-walk.h | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/fsck.c b/fsck.c index 7c74c49d329..11678ba5826 100644 --- a/fsck.c +++ b/fsck.c @@ -670,7 +670,7 @@ static int fsck_tree(const struct object_id *oid, const char *name, *backslash; const struct object_id *oid; - oid = tree_entry_extract(&desc, &name, &mode); + oid = tree_entry_extract_mode(&desc, &name, &mode); has_null_sha1 |= is_null_oid(oid); has_full_path |= !!strchr(name, '/'); diff --git a/match-trees.c b/match-trees.c index 3177558313e..2afa4968109 100644 --- a/match-trees.c +++ b/match-trees.c @@ -146,7 +146,7 @@ static void match_trees(const struct object_id *hash1, unsigned short mode; int score; - elem = tree_entry_extract(&one, &path, &mode); + elem = tree_entry_extract_mode(&one, &path, &mode); if (!S_ISDIR(mode)) goto next; score = score_trees(elem, hash2); @@ -202,7 +202,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix, unsigned short mode; int len = tree_entry_len(&desc.entry); - tree_entry_extract(&desc, &name, &mode); + tree_entry_extract_mode(&desc, &name, &mode); if (len == toplen && !memcmp(name, prefix, toplen)) { if (!S_ISDIR(mode)) diff --git a/tree-diff.c b/tree-diff.c index 088ed52d6a3..65c7e4dbc8b 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -196,7 +196,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p, if (t) { /* path present in resulting tree */ - oid = tree_entry_extract(t, &path, &mode); + oid = tree_entry_extract_mode(t, &path, &mode); pathlen = tree_entry_len(&t->entry); isdir = S_ISDIR(mode); } else { @@ -207,7 +207,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p, * 1) all modes for tp[i]=tp[imin] should be the same wrt * S_ISDIR, thanks to base_name_compare(). */ - tree_entry_extract(&tp[imin], &path, &mode); + tree_entry_extract_mode(&tp[imin], &path, &mode); pathlen = tree_entry_len(&tp[imin].entry); isdir = S_ISDIR(mode); diff --git a/tree-walk.h b/tree-walk.h index f51485250fb..805cda649ee 100644 --- a/tree-walk.h +++ b/tree-walk.h @@ -48,9 +48,9 @@ struct tree_desc { * * tree_entry_extract_mode(): const char *path, unsigned int mode */ -static inline const struct object_id *tree_entry_extract(struct tree_desc *desc, - const char **pathp, - unsigned short *modep) +static inline const struct object_id *tree_entry_extract_mode(struct tree_desc *desc, + const char **pathp, + unsigned short *modep) { *pathp = desc->entry.path; *modep = desc->entry.mode; From patchwork Sun Mar 21 00:00:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152847 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.8 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 71579C4345F for ; Sun, 21 Mar 2021 00:02:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 52FBF61936 for ; Sun, 21 Mar 2021 00:02:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230060AbhCUACc (ORCPT ); Sat, 20 Mar 2021 20:02:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229920AbhCUABr (ORCPT ); Sat, 20 Mar 2021 20:01:47 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C3BAC061574 for ; Sat, 20 Mar 2021 17:01:47 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id m20-20020a7bcb940000b029010cab7e5a9fso9264651wmi.3 for ; Sat, 20 Mar 2021 17:01:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GKBnmRdfhiCxD0XyIYKb5JmvAJTdMHqi7orx86MGYdE=; b=WApyb0GMxoWjyfok/pbQvei+ZS6EHMMyR6VhuwMYUsfc3oRRNNLGbck2zrHw+VASqw bRYUNCOmPeHAk0nhM5OT15ORVPNastlKMWcUnMEdHpJOsrKGw3f2ih5Ovqezkz/sMc5O WAKdWq8UMdTthnhk5O1WBDhY/svM5G3KM5QoR8zeCK6ZyECOoDcdcVPs3OEdLu2hNrpC bLhNwjUVCWW1xk7ocywaPawrbMmHvOz733Q/A5P8Yg9Kq79DryScbwUhfD1EP++VDzcI tG6Oe3ixXTHkXH8M2SZke6a0xatoNPGw/kn789ftr91LUae4Kd4mR7mlW0m30lAP4xMv UxNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GKBnmRdfhiCxD0XyIYKb5JmvAJTdMHqi7orx86MGYdE=; b=ITwxbeFyVppXZ/9UGxm+GTkAioQfVtc6WOzSEC7I7Hf5hS8RPD4DGy8fkgOoP/1EjV xXuPoIUm0NgIxDQuGzGiSDu3UeFDraHkan+YY8CPjMqxmFiIM058lyNwc7rrj850a2uW L18373sl9Dbn2sooL0Xl8F17Zrs5EkoN3/KuJJPJPCnr9Jbx++Z4KPNHeQ2zJg8QaiJf gzNoMDr+AO2xdXqJsrjvLFHuu4qLxSAvspWxue5RFw2I4wDpvKh8itRFIBZ0za3fEnXD +gatOrJRftx90fcMvEcOZRIirUqFpeyRFFAnyRa4QwDyNKENp2f8KMdR04R1Py7qjT3s avqA== X-Gm-Message-State: AOAM533sNcvMzaj5HWY3x84oX6qa1TmoRtWptsLxD9Q9G+5YJSNIgdWk urGFNthfbRUYCj5zs7CD9JzOaMEzt1U/5Q== X-Google-Smtp-Source: ABdhPJzqO8xe/j22ZFJZGF3pad+5SKwmH+Y8Z6CIpQ6PzG+c/8cfLS4y2hgWOOZr1kfJ6pFT/9Wj/w== X-Received: by 2002:a1c:2683:: with SMTP id m125mr9624326wmm.178.1616284905875; Sat, 20 Mar 2021 17:01:45 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:45 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 25/29] tree-walk.h API: add a tree_entry_extract_all() function Date: Sun, 21 Mar 2021 01:00:58 +0100 Message-Id: X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a tree_entry_extract_all() sibling function to the existing tree_entry_extract_mode(). Having the OBJ_{BLOB,TREE,COMMIT} when you have the "mode" is strictly speaking redundant, but hopefully makes it easier to read the code. We'll now see which parts of the code are checking the types, v.s. those that care about the mode specifically. Only the first use of tree_entry_extract_mode() in emit_path() is converted here, the other branch will use a new get_tree_entry_mode_type() introduced in a subsequent commit. Signed-off-by: Ævar Arnfjörð Bjarmason --- tree-diff.c | 5 +++-- tree-walk.c | 2 +- tree-walk.h | 12 ++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/tree-diff.c b/tree-diff.c index 65c7e4dbc8b..918ad95fa61 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -195,10 +195,11 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p, assert(t || tp); if (t) { + enum object_type object_type; /* path present in resulting tree */ - oid = tree_entry_extract_mode(t, &path, &mode); + oid = tree_entry_extract_all(t, &path, &mode, &object_type); pathlen = tree_entry_len(&t->entry); - isdir = S_ISDIR(mode); + isdir = (object_type == OBJ_TREE); } else { /* * a path was removed - take path from imin parent. Also take diff --git a/tree-walk.c b/tree-walk.c index 46ce1ba8069..f4473276c9f 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -577,7 +577,7 @@ static int find_tree_entry(struct repository *r, struct tree_desc *t, struct object_id oid; int entrylen, cmp; - oidcpy(&oid, tree_entry_extract(t, &entry, mode)); + oidcpy(&oid, tree_entry_extract_all(t, &entry, mode, object_type)); entrylen = tree_entry_len(&t->entry); update_tree_entry(t); if (entrylen > namelen) diff --git a/tree-walk.h b/tree-walk.h index 805cda649ee..a4c54871747 100644 --- a/tree-walk.h +++ b/tree-walk.h @@ -47,6 +47,7 @@ struct tree_desc { * appropriate variable to fill in (NULL won't do!): * * tree_entry_extract_mode(): const char *path, unsigned int mode + * tree_entry_extract_all(): const char *path, unsigned int mode, enum object_type */ static inline const struct object_id *tree_entry_extract_mode(struct tree_desc *desc, const char **pathp, @@ -57,6 +58,17 @@ static inline const struct object_id *tree_entry_extract_mode(struct tree_desc * return &desc->entry.oid; } +static inline const struct object_id *tree_entry_extract_all(struct tree_desc *desc, + const char **pathp, + unsigned short *modep, + enum object_type *object_typep) +{ + *pathp = desc->entry.path; + *modep = desc->entry.mode; + *object_typep = desc->entry.object_type; + return &desc->entry.oid; +} + /** * Calculate the length of a tree entry's pathname. This utilizes the * memory structure of a tree entry to avoid the overhead of using a From patchwork Sun Mar 21 00:00:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152851 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.8 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 8EB6DC43460 for ; Sun, 21 Mar 2021 00:02:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7532961937 for ; Sun, 21 Mar 2021 00:02:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230070AbhCUACd (ORCPT ); Sat, 20 Mar 2021 20:02:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229926AbhCUABs (ORCPT ); Sat, 20 Mar 2021 20:01:48 -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 1474AC061574 for ; Sat, 20 Mar 2021 17:01:48 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id x13so12843685wrs.9 for ; Sat, 20 Mar 2021 17:01:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dgK2r6GAAW9Y+/RBNsBVlKA6hCMcQ2qa7kZ51ZcgCh4=; b=oJAUPLG4ySaKZMIflBOGtyzkFHRVx+C5TVPqQ6cUQRx9mags6umuiP59N9ogxZvNr1 tawPr4tu2gt2WfuPNnbhWo/JYQ+EkY3jBSb85gxueyCTgDZI/yQe4wWdovse2WZfYDip 53iiCmdeE6vUovY9fXocmOGts/5Y7XHYdo0o58C+8b4tEtWjuZw8LDBsnWHeWXne9r0J uqrKcjJGM9OjQv+GBTO3mat6AatUiXXmLmUev/js4AYdO97P7QaG+eCD5c3ESs8nms9U PsSlUAV6azFFxau7fBkjUJuNgUvI0aNZqOziaZGzGhJ/MpRc3oxkv2urrl2XLbNxTwfI WWaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dgK2r6GAAW9Y+/RBNsBVlKA6hCMcQ2qa7kZ51ZcgCh4=; b=qa1+K6YNIQiKb3pumro47zHtmS+XA3t13+WvXw3bSkB8DnzirhSU5v9AOtv7m7jSXQ VgIaPUE7eSBHIogcKFZp6xi0elvvnV+yhSOj2t83TOu9fP1Tn01AppLXQJedJPlRd8sU dH5cX1JlTqnIRVVH7Ysbcx+vk54mRmcz0ZascGaRqtLzD5b0/e+wkVk/vbW+tjpWjupi Y0LOg2vCm5QuZvenPgl/vUxRA+PwbC0WYruZzuUt/IwLRA6Rz6FMd9bCgBhSF+hFs3p/ q6EtqyX3Ga8N8d+zu+29Z891NNmnN3RGv7VKxKgqW0sbGxTqsvuKTOHkhHsU5/Hiujwv Dfmg== X-Gm-Message-State: AOAM5338qC6Wy2DuX2O7IFfUTzueU11Yelf2O6ZLA9XzctPX00HWThNr ActV6ar3dVTJqaRIRBqE06+uMoJNLLN2Uw== X-Google-Smtp-Source: ABdhPJyA2l67KrLkQS5MfqU8TCFy6fujVIGEO0bjmgBt/3WyyL0xhYqCFsfp4rAH/lf0PmcHOGjMiw== X-Received: by 2002:adf:8b45:: with SMTP id v5mr11103819wra.398.1616284906616; Sat, 20 Mar 2021 17:01:46 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:46 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 26/29] tree-walk.h API: add get_tree_entry_all() Date: Sun, 21 Mar 2021 01:00:59 +0100 Message-Id: <95eec961be8b49e4f2f68ee92f24e95fe6edc04d.1616282534.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a get_tree_entry_all() function and use it in the one caller who cares about both the mode and the object type. Refactor it accordingly to make it clear which parts care about the mode, and which about the object_type. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/update-index.c | 6 ++++-- tree-walk.c | 9 +-------- tree-walk.h | 4 ++++ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/builtin/update-index.c b/builtin/update-index.c index 070510d6a88..b489a876392 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -599,16 +599,18 @@ static struct cache_entry *read_one_ent(const char *which, struct object_id *ent, const char *path, int namelen, int stage) { + enum object_type object_type; unsigned short mode; struct object_id oid; struct cache_entry *ce; - if (get_tree_entry_mode(the_repository, ent, path, &oid, &mode)) { + if (get_tree_entry_all(the_repository, ent, path, &oid, + &mode, &object_type)) { if (which) error("%s: not in %s branch.", path, which); return NULL; } - if (mode == S_IFDIR) { + if (object_type == OBJ_TREE) { if (which) error("%s: not a blob in %s branch.", path, which); return NULL; diff --git a/tree-walk.c b/tree-walk.c index f4473276c9f..a90dbf87af4 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -559,13 +559,6 @@ struct dir_state { struct object_id oid; }; -static int get_tree_entry_all(struct repository *r, - const struct object_id *tree_oid, - const char *name, - struct object_id *oid, - unsigned short *mode, - enum object_type *object_type); - static int find_tree_entry(struct repository *r, struct tree_desc *t, const char *name, struct object_id *result, unsigned short *mode, @@ -605,7 +598,7 @@ static int find_tree_entry(struct repository *r, struct tree_desc *t, return -1; } -static int get_tree_entry_all(struct repository *r, +int get_tree_entry_all(struct repository *r, const struct object_id *tree_oid, const char *name, struct object_id *oid, diff --git a/tree-walk.h b/tree-walk.h index a4c54871747..55ef88ef2e5 100644 --- a/tree-walk.h +++ b/tree-walk.h @@ -195,6 +195,7 @@ struct traverse_info { * * get_tree_entry_mode(): unsigned int mode * get_tree_entry_type(): enum object_type + * get_tree_entry_all(): unsigned int mode, enum object_type */ int get_tree_entry_mode(struct repository *, const struct object_id *, const char *, struct object_id *, @@ -202,6 +203,9 @@ int get_tree_entry_mode(struct repository *, const struct object_id *, const cha int get_tree_entry_type(struct repository *, const struct object_id *, const char *, struct object_id *, enum object_type *); +int get_tree_entry_all(struct repository *, const struct object_id *, const char *, + struct object_id *, + unsigned short *, enum object_type *); /** * Generate the full pathname of a tree entry based from the root of the From patchwork Sun Mar 21 00:01:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152853 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.8 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 C4D3FC43462 for ; Sun, 21 Mar 2021 00:02:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B3737601FE for ; Sun, 21 Mar 2021 00:02:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230079AbhCUACg (ORCPT ); Sat, 20 Mar 2021 20:02:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229928AbhCUABt (ORCPT ); Sat, 20 Mar 2021 20:01:49 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C664EC061574 for ; Sat, 20 Mar 2021 17:01:48 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id n11-20020a05600c4f8bb029010e5cf86347so9750061wmq.1 for ; Sat, 20 Mar 2021 17:01:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gQh010G/6h9UOavYeSWV84b7N0iIjpj9pOcV/h2q6JU=; b=hupfLxF4e43TAib6FgbOUAJ8x1ra92rij9HNt+9qYVo5/Wg10FhgAjfRN7zUqOkYNR IuP0zC070oSXZbfz+BiYH32gij18N/VmpX1y/i/z2XftfnwJKrPe+5dNx+mR3DXY1DmK sr+uRZm59OtRIhQpKbmb5ZUWrFo0JThHZ/tq4+cMRXvKQK7Ie35u3img+cdEitHEuGak BahhRFxC9+HHfJTzhZeotHAX92cOmHTNz2uV92fRu5U/9tlLdFcKkFjkMdh5+/jDdJzF OOJiQ0gZ4Q4ujQR8eWV+LJHXjHVIe0PO8klYly6/PjbNKXbcrjdZux8s3LGskI3RLX9d +72g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gQh010G/6h9UOavYeSWV84b7N0iIjpj9pOcV/h2q6JU=; b=kSabS85h+cbl5ynYhv5xnX5soPNKZCaBsTrJWbbrzzmnx/00KjDuDluGiFeM2isfH5 86Mmo6uUJiGkkIKInwrmO/aW8bWrKlfpa6SXZTHCih6oMFjv/OEr4+M/B0gdUSWqsB3H k7nIX2JqKq7IIrxxFOn1pbRdAVgZ7upM+w3F3A1qDV65zXO3pFyC8Gb0ih60AygWLLi+ 29gtbWa1nFnpvjVpNWTFipPuPf3DnjvB9UEgoe44yZsxQEpQh/rB2LU2Wtwr0YSXT9v6 AWWWD+5SLmoKdiT1Tft2b5TSkyud7DHQsiNvj8ufSbSsEJ4iMArsRsht1Pcr0aURcfqc gv3A== X-Gm-Message-State: AOAM533xGXz8nwGkTilPeGnldDjQnuuPj09VHFPVe11qUd/Ooz1v4J1U H25q85qMdpP1qE2u4sSZwnKKsaYN4ByI+A== X-Google-Smtp-Source: ABdhPJx4tpOq3zawNDCWKHHT5dR4bBil2UxWhAf8nZ0w+lH2I8/Do2M2GZTvXyVdlWQqzO5iVq4Dmw== X-Received: by 2002:a05:600c:3643:: with SMTP id y3mr6428883wmq.159.1616284907272; Sat, 20 Mar 2021 17:01:47 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:46 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 27/29] tree-walk.h API: add a get_tree_entry_path() function Date: Sun, 21 Mar 2021 01:01:00 +0100 Message-Id: X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a get_tree_entry_path() variant in addition to get_tree_entry_path_{mode,type,all}(). This is for those callers that need neither the mode nor "enum object_type" parameters filled for them. There are callers here which don't need the "struct object_id" filled; forcing callers to pass one just requires they create a throwaway variable. See the following commits for the introduction of such code that's being modified here: - shift_tree(): 68faf68938e (A new merge stragety[sic] 'subtree'., 2007-02-15) for the shift_tree() - tree_has_path(): 96e7ffbdc31 (merge-recursive: check for directory level conflicts, 2018-04-19) - init_notes(): fd53c9eb445 (Speed up git notes lookup, 2009-10-09) - diagnose_invalid_oid_path(): 009fee4774d (Detailed diagnosis when parsing an object name fails., 2009-12-07) Those could potentially be refactored too, but I've got to stop at some point, and right now I'm focusing downstream code that depends on "mode" (or "enum object_type"). Signed-off-by: Ævar Arnfjörð Bjarmason --- match-trees.c | 4 +--- merge-recursive.c | 6 ++---- notes.c | 3 +-- object-name.c | 3 +-- tree-walk.c | 11 +++++++++++ tree-walk.h | 3 +++ 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/match-trees.c b/match-trees.c index 2afa4968109..25bfb46fb02 100644 --- a/match-trees.c +++ b/match-trees.c @@ -288,12 +288,10 @@ void shift_tree(struct repository *r, if (add_score < del_score) { /* We need to pick a subtree of two */ - unsigned short mode; - if (!*del_prefix) return; - if (get_tree_entry_mode(r, hash2, del_prefix, shifted, &mode)) + if (get_tree_entry_path(r, hash2, del_prefix, shifted)) die("cannot find path %s in tree %s", del_prefix, oid_to_hex(hash2)); return; diff --git a/merge-recursive.c b/merge-recursive.c index f5cccb8deab..e46eea9688e 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1884,11 +1884,9 @@ static int tree_has_path(struct repository *r, struct tree *tree, const char *path) { struct object_id hashy; - unsigned short mode_o; - - return !get_tree_entry_mode(r, + return !get_tree_entry_path(r, &tree->object.oid, path, - &hashy, &mode_o); + &hashy); } /* diff --git a/notes.c b/notes.c index b7a5ddce3ae..7ffae3a0f62 100644 --- a/notes.c +++ b/notes.c @@ -994,7 +994,6 @@ void init_notes(struct notes_tree *t, const char *notes_ref, combine_notes_fn combine_notes, int flags) { struct object_id oid, object_oid; - unsigned short mode; struct leaf_node root_tree; if (!t) @@ -1021,7 +1020,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref, return; if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, &object_oid)) die("Cannot use notes ref %s", notes_ref); - if (get_tree_entry_mode(the_repository, &object_oid, "", &oid, &mode)) + if (get_tree_entry_path(the_repository, &object_oid, "", &oid)) die("Failed to read notes tree referenced by %s (%s)", notes_ref, oid_to_hex(&object_oid)); diff --git a/object-name.c b/object-name.c index 7e3b2d6d739..9ff5f83c1ff 100644 --- a/object-name.c +++ b/object-name.c @@ -1693,7 +1693,6 @@ static void diagnose_invalid_oid_path(struct repository *r, int object_name_len) { struct object_id oid; - unsigned short mode; if (!prefix) prefix = ""; @@ -1704,7 +1703,7 @@ static void diagnose_invalid_oid_path(struct repository *r, if (is_missing_file_error(errno)) { char *fullname = xstrfmt("%s%s", prefix, filename); - if (!get_tree_entry_mode(r, tree_oid, fullname, &oid, &mode)) { + if (!get_tree_entry_path(r, tree_oid, fullname, &oid)) { die(_("path '%s' exists, but not '%s'\n" "hint: Did you mean '%.*s:%s' aka '%.*s:./%s'?"), fullname, diff --git a/tree-walk.c b/tree-walk.c index a90dbf87af4..fa846535dfb 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -632,6 +632,17 @@ int get_tree_entry_all(struct repository *r, return retval; } +int get_tree_entry_path(struct repository *r, + const struct object_id *tree_oid, + const char *name, + struct object_id *oid) +{ + unsigned short mode; + enum object_type object_type; + return get_tree_entry_all(r, tree_oid, name, oid, + &mode, &object_type); +} + int get_tree_entry_mode(struct repository *r, const struct object_id *tree_oid, const char *name, diff --git a/tree-walk.h b/tree-walk.h index 55ef88ef2e5..efcd7ccd10e 100644 --- a/tree-walk.h +++ b/tree-walk.h @@ -193,10 +193,13 @@ struct traverse_info { * "struct name_entry" you'd like. You always need a pointer to an * appropriate variable to fill in (NULL won't do!): * + * get_tree_entry_path(): * get_tree_entry_mode(): unsigned int mode * get_tree_entry_type(): enum object_type * get_tree_entry_all(): unsigned int mode, enum object_type */ +int get_tree_entry_path(struct repository *, const struct object_id *, const char *, + struct object_id *); int get_tree_entry_mode(struct repository *, const struct object_id *, const char *, struct object_id *, unsigned short *); From patchwork Sun Mar 21 00:01:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152835 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.8 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 9E8CEC43461 for ; Sun, 21 Mar 2021 00:02:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A624601FE for ; Sun, 21 Mar 2021 00:02:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230076AbhCUACf (ORCPT ); Sat, 20 Mar 2021 20:02:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229931AbhCUABt (ORCPT ); Sat, 20 Mar 2021 20:01:49 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7995DC061762 for ; Sat, 20 Mar 2021 17:01:49 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id f22-20020a7bc8d60000b029010c024a1407so9288414wml.2 for ; Sat, 20 Mar 2021 17:01:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pCid5IWtc0NNyD68WbH2bXdMV8cxF/t/ndDFxq8M+QE=; b=JYgTPwc8wXFlV63EIy6B3/+ULvXeqPO9i+Nm6fFwMLKmTyzYRlvGyURePsgOv0UrzX EI8y1LdAwj+ljPgBLCFlCtaSq45t/+xuUz2FCrCleYMBWb5NEi7usdu/c9RjLIkZ/Fjp YlUPdNMvWDYDF15OlufJtm2QNPTWT74tQKFf5xcom1Q7vLQrNI27ERhKsPVN7BG2SExg d4raLrMGJZC/lkGWxz4yOLcTx38K02MKxDrHDySKN1Zg/DWyaC4493v4j1Wy5OcF+A4W XLBHE5/Xs0ANdFABagqran0+M/Jwt4/LEhAw7BKCP5jvnvPDLTZ0iw0MyJyFSAwgTycX TfGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pCid5IWtc0NNyD68WbH2bXdMV8cxF/t/ndDFxq8M+QE=; b=K89F7xF3jjtEi/iMKgjZq6wPw8mRt7DvOAFRUlv9pmXR7aHgM25+dlnJ12eNIPr/dg oh6qhF5xpjGwYMP6olRlnUMsZCo55qaeBYPW/hWeIQNR6JUlCLqKml0bu7N9ezpCFeY6 uK5bQ7ufEaSYjEs9Q1i/k0zc6wklnOVP/RU1G9bQdzwVdU5kPGBFDc+kkr4ArdkMEHqP vjkZ7h4NqwgpZnAvsIzQbBb0uMHiCrEZ7gI0KHhvAUPvEFO2X0MVyc1+B53+zx6wo99/ HIm/35QitUqRWZsd32jRDJoTqQQUO2hhpPa5tPZMHTCQJnkujnSmFnFISZE49CYoKFJ/ VXbw== X-Gm-Message-State: AOAM532tOVsVjSAVMp/igWe1oQYaLi68AiE54b9gtdHEgZAnEHCJ+B4M mYyTbx1jKQ0OVwSZOXxK9CYtdpg6G7l+qA== X-Google-Smtp-Source: ABdhPJwFWXiy4QoehPL1WUc7Ku+l5GZcvvLX+M8Yinw1jcVdgXbVXc4IVncXC0+XPL6H3X2wVh16NQ== X-Received: by 2002:a05:600c:358c:: with SMTP id p12mr9843564wmq.159.1616284908036; Sat, 20 Mar 2021 17:01:48 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:47 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 28/29] blame: emit a better error on 'git blame directory' Date: Sun, 21 Mar 2021 01:01:01 +0100 Message-Id: <81da54902217891f8115cbad9194c88535615d65.1616282534.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change an early check for non-blobs in verify_working_tree_path() to let any such objects pass, and instead die shortly thereafter in the fake_working_tree_commit() caller's type check. Now e.g. doing "git blame t" in git.git emits: fatal: unsupported file type t Instead of: fatal: no such path 't' in HEAD The main point of this test is to assert that we're not doing something uniquely bad when in a conflicted merge. See cd8ae20195 (git-blame shouldn't crash if run in an unmerged tree, 2007-10-18) and 9aeaab6811 (blame: allow "blame file" in the middle of a conflicted merge, 2012-09-11) for the bug the t8004 test was originally meant to address. But when extending it let's grep out the specific error message for good measure. Having to change it in the future (e.g. as part of my parallel series to improve such 'OID does not match type' messages) is a small price for ensuring it doesn't regress. Signed-off-by: Ævar Arnfjörð Bjarmason --- blame.c | 8 ++------ t/t8004-blame-with-conflicts.sh | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/blame.c b/blame.c index 13825b86e65..3c3cb2f8f96 100644 --- a/blame.c +++ b/blame.c @@ -100,12 +100,8 @@ static void verify_working_tree_path(struct repository *r, for (parents = work_tree->parents; parents; parents = parents->next) { const struct object_id *commit_oid = &parents->item->object.oid; - struct object_id blob_oid; - unsigned short mode; - int ret = get_tree_entry_mode(r, commit_oid, path, &blob_oid, - &mode); - - if (!ret && oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB) + struct object_id oid; + if (!get_tree_entry_path(r, commit_oid, path, &oid)) return; } diff --git a/t/t8004-blame-with-conflicts.sh b/t/t8004-blame-with-conflicts.sh index 35414a53363..5e3dea35a50 100755 --- a/t/t8004-blame-with-conflicts.sh +++ b/t/t8004-blame-with-conflicts.sh @@ -73,4 +73,25 @@ test_expect_success 'blame does not crash with conflicted file in stages 1,3' ' git blame file1 ' +test_expect_success 'setup second case' ' + git merge --abort +' + +test_expect_success 'blame on directory/file conflict' ' + mkdir d && + test_commit second && + test_commit d/file && + test_must_fail git blame d 2>expected && + grep "unsupported file type d" expected && + + git reset --hard second && + >d && + git add d && + git commit -m"a not-a-dir" && + test_must_fail git merge d/file && + + test_must_fail git blame d 2>actual && + test_cmp expected actual +' + test_done From patchwork Sun Mar 21 00:01:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152843 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.8 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 B4F88C43470 for ; Sun, 21 Mar 2021 00:02:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9C6BC61937 for ; Sun, 21 Mar 2021 00:02:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230081AbhCUACh (ORCPT ); Sat, 20 Mar 2021 20:02:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229933AbhCUABu (ORCPT ); Sat, 20 Mar 2021 20:01:50 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A0DDC061574 for ; Sat, 20 Mar 2021 17:01:50 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id j4-20020a05600c4104b029010c62bc1e20so7163933wmi.3 for ; Sat, 20 Mar 2021 17:01:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=z3mnO3qhEMgg8gs0MModCdWFcXwab8OR7ro599Z03MA=; b=Tc0NJF1gnPEQQ0hxMI8OGNIzDjW+5O7P356pEif50D75Wwcs81SR5ohfK3lUGgNzZm NoYxmtmoQMQmSdQWPuERjBufu1SxrMNfxJl/yT/A82mxutwKKhlpq0VnxILeeYUSiZ8e fQn10GouE7kGuvYF1JcPPx6yDogqM398QbykuMme20TGmbRgRsDg/I49tQc2Z/R5kkac DfgZZozcGDT2Ip3z3Z5ccItNkhqJC5bsXcB7F+C2GESTNK8XzJNz2wFyIcuWTQMoRdzv KfBGOt1vk9JfSlxJ3/ZaIoUIVAvp21qI1tfYqcN1MSnZmpmjTwMQmNVZAYTOPdWKyFdF QZ0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z3mnO3qhEMgg8gs0MModCdWFcXwab8OR7ro599Z03MA=; b=CfLErl+ksLHq21X/NCE1dJBQC++gPOxq8SiDSak+8vTG79C9TzaGlkLNy/ESt5guak PG62EVwYQhLX43caF6TAu2Fz27rfaaiMG4msTWfILAgIOKO2VLh97SNBBHMMzJkCBBvR x485XG/fGQDO/QPZs7bI2hg5phXo7MwklmNlTSTNDMuj+Is4UxTRQGSJL5us8QacuF3c nHb5OT2UpSEp8RMAIC5FRPkuG+gsDg+Eq3aRKI/CtwJO6lnpp9HuroRdPhBWUGgYFN90 DwTZqcMzxVC4dDEtGDn0rzPd0f8sobaRLDAJki4sHRwo6Q/qtwCFP1zJV25X6zSt0kTI 6V0A== X-Gm-Message-State: AOAM531CzYZhf9U5MrJpamuq0k0lhs6dAhwNc225reZDQpFERBfDz+SW dr5AwEA5ZY355B/hsTLagka2eTEMbrgrjQ== X-Google-Smtp-Source: ABdhPJyTujJSmK3GbUzfQ5FdqFrJIAP1zfJ6SkXNymY6iQuL7KaDKp5vbZrsNT5aPGKyBtH2GC/u2w== X-Received: by 2002:a7b:cd8f:: with SMTP id y15mr9669879wmj.185.1616284908715; Sat, 20 Mar 2021 17:01:48 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g5sm15304834wrq.30.2021.03.20.17.01.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 17:01:48 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Kirill Smelkov , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH v4 29/29] tree-walk.h API: add a tree_entry_extract_type() function Date: Sun, 21 Mar 2021 01:01:02 +0100 Message-Id: <4d51da4ea39c11ac56972da8fa4e5becff7294f7.1616282534.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.282.gcc1ec606501 In-Reply-To: References: <20210316155829.31242-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add and use a tree_entry_extract_type() function. There were callers of tree_entry_extract() which didn't care about the mode, but just the type in the tree entry. In emit_path() the "mode" variable was not used after the "isdir" assignment, as can be seen in the diff with it being set to 0. Signed-off-by: Ævar Arnfjörð Bjarmason --- match-trees.c | 12 ++++++------ tree-diff.c | 5 +++-- tree-walk.h | 11 +++++++++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/match-trees.c b/match-trees.c index 25bfb46fb02..89109659aa3 100644 --- a/match-trees.c +++ b/match-trees.c @@ -143,11 +143,11 @@ static void match_trees(const struct object_id *hash1, while (one.size) { const char *path; const struct object_id *elem; - unsigned short mode; + enum object_type object_type; int score; - elem = tree_entry_extract_mode(&one, &path, &mode); - if (!S_ISDIR(mode)) + elem = tree_entry_extract_type(&one, &path, &object_type); + if (object_type != OBJ_TREE) goto next; score = score_trees(elem, hash2); if (*best_score < score) { @@ -198,14 +198,14 @@ static int splice_tree(const struct object_id *oid1, const char *prefix, rewrite_here = NULL; while (desc.size) { + enum object_type object_type; const char *name; - unsigned short mode; int len = tree_entry_len(&desc.entry); - tree_entry_extract_mode(&desc, &name, &mode); + tree_entry_extract_type(&desc, &name, &object_type); if (len == toplen && !memcmp(name, prefix, toplen)) { - if (!S_ISDIR(mode)) + if (object_type != OBJ_TREE) die("entry %s in tree %s is not a tree", name, oid_to_hex(oid1)); diff --git a/tree-diff.c b/tree-diff.c index 918ad95fa61..8409374f0ba 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -208,10 +208,11 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p, * 1) all modes for tp[i]=tp[imin] should be the same wrt * S_ISDIR, thanks to base_name_compare(). */ - tree_entry_extract_mode(&tp[imin], &path, &mode); + enum object_type object_type; + tree_entry_extract_type(&tp[imin], &path, &object_type); pathlen = tree_entry_len(&tp[imin].entry); - isdir = S_ISDIR(mode); + isdir = object_type == OBJ_TREE; oid = NULL; mode = 0; } diff --git a/tree-walk.h b/tree-walk.h index efcd7ccd10e..f5102ed5427 100644 --- a/tree-walk.h +++ b/tree-walk.h @@ -47,6 +47,7 @@ struct tree_desc { * appropriate variable to fill in (NULL won't do!): * * tree_entry_extract_mode(): const char *path, unsigned int mode + * tree_entry_extract_type(): const char *path, enum object_type * tree_entry_extract_all(): const char *path, unsigned int mode, enum object_type */ static inline const struct object_id *tree_entry_extract_mode(struct tree_desc *desc, @@ -58,6 +59,16 @@ static inline const struct object_id *tree_entry_extract_mode(struct tree_desc * return &desc->entry.oid; } +static inline const struct object_id *tree_entry_extract_type(struct tree_desc *desc, + const char **pathp, + enum object_type *object_typep) +{ + *pathp = desc->entry.path; + *object_typep = desc->entry.object_type; + return &desc->entry.oid; +} + + static inline const struct object_id *tree_entry_extract_all(struct tree_desc *desc, const char **pathp, unsigned short *modep,