From patchwork Mon Mar 8 15:06:21 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: 12122577 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 7EA02C43381 for ; Mon, 8 Mar 2021 15:08:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 61B5E6521F for ; Mon, 8 Mar 2021 15:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231388AbhCHPHn (ORCPT ); Mon, 8 Mar 2021 10:07:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229805AbhCHPHN (ORCPT ); Mon, 8 Mar 2021 10:07:13 -0500 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 1B0C5C06175F for ; Mon, 8 Mar 2021 07:07:11 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id l11so8416769wrp.7 for ; Mon, 08 Mar 2021 07:07:11 -0800 (PST) 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=J8SJpdZXvhjz3KvI81hs3I4U3avYYllXpPlcxHz3RtI=; b=lYR/GbWGX97K1X5Xi9DMZ+/GyflxR02ewqQ7w0D28sCr5SpVAROh1RcMKhROWBz/6H 9y/utZytnLlM6nLcFX0CzWK5BKM/KK9oYyOoZYyZQfbERqHty9WMmeY4nOTbebZGGGwN rbPTbs9RTslQB+5ZRqq/LwUN3HCSglPfiGdQAM3hPRsrbRIBWO7+C3mzfJFMbwIs0mFK DjZlT/dMFSN0/id5hBhaCM9k48lcrR6I2qTBBo460B61KymrPorPPVPKUdlpLRcmFxUs 4PHjjpGOpqy54spwd1jZTTr/q27b1SQmww21K5u+6azpz5EVqeo3CxWxqjASgVVwT+Pe vUaw== 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=J8SJpdZXvhjz3KvI81hs3I4U3avYYllXpPlcxHz3RtI=; b=Cs4FnebqoNF7GvD7QEkfezdRYAOXA8XP9cvX8GPfbf25WaBkD0wYIuuNg5PGW0E6g0 YHrlHt6k2LixVzvMGjoeX6FbFFYLpkSxTt8kWy75nZ5Tiop6xMNkBMzYYyx51BgzTQwp jsEyc8il4r2JBkTaB1yfsRaX2FTLZl/Ojp431q+WI0QyIy0RHNjg2d6FSzhFeVScksu7 nrQCVrgTAdgZo/FqEfCjld4AOxx+5mzldBCZPpLhDJsZP6hqiDUow7x4hPbKp5uAuIHF /z3MqRxan0KvR3i4vRlOcBquJ9V84SBGXa/K2xDvuRVyjukf4CloJ/HY3b7P7QuXGXXC yfyg== X-Gm-Message-State: AOAM533ZB0pkaB+CTmIAHWGKuwPyhGEfGtYEU5hIN2UA8123F4osvQI7 g3+RhK3OadH4Qcg+EUMc3MesuLmEoT+MwQ== X-Google-Smtp-Source: ABdhPJxTE9G1rcGb3BFxAbn0+rMcXWVldyYUsk8j+8hSjqKUlO1D/aRgrcy8ElQ+p+K1pwO0ILkDHg== X-Received: by 2002:adf:8341:: with SMTP id 59mr22552012wrd.130.1615216029663; Mon, 08 Mar 2021 07:07:09 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:09 -0800 (PST) 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 01/30] diff.c: remove redundant canon_mode() call Date: Mon, 8 Mar 2021 16:06:21 +0100 Message-Id: <20210308150650.18626-2-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Remove a call to canon_mode() from fill_filespec(). This has been redundant since the tree-walk.c API supplies it pre-canonicalized since 7146e66f086 (tree-walk: finally switch over tree descriptors to contain a pre-parsed entry, 2014-02-06). This call to the predecessor of canon_mode() was added back in 4130b995719 ([PATCH] Diff updates to express type changes, 2005-05-26). This was the only such call in the codebase. The rest are all either one of these sorts of forms: canon_mode(st.st_mode); /* a stat(2) struct */ canon_mode(S_IFREG | 0644) /* A compile-time literal */ Signed-off-by: Ævar Arnfjörð Bjarmason --- diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diff.c b/diff.c index 6956f5e335c..bf46e6a4d8c 100644 --- a/diff.c +++ b/diff.c @@ -3846,7 +3846,7 @@ void fill_filespec(struct diff_filespec *spec, const struct object_id *oid, int oid_valid, unsigned short mode) { if (mode) { - spec->mode = canon_mode(mode); + spec->mode = mode; oidcpy(&spec->oid, oid); spec->oid_valid = oid_valid; } From patchwork Mon Mar 8 15:06:22 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: 12122573 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 A1E6EC433E0 for ; Mon, 8 Mar 2021 15:08:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6FED46521F for ; Mon, 8 Mar 2021 15:08:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231377AbhCHPHm (ORCPT ); Mon, 8 Mar 2021 10:07:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229813AbhCHPHN (ORCPT ); Mon, 8 Mar 2021 10:07:13 -0500 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 2FF1FC061760 for ; Mon, 8 Mar 2021 07:07:12 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id l11so8416834wrp.7 for ; Mon, 08 Mar 2021 07:07:12 -0800 (PST) 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=1LkmuWBCtFzTqo+05uB6OBB8XVwpv+VAUv1vZy5ADS4=; b=mNpnlJBqS5xxRYJmNytcKafhl7DBQbq6wXIjXP9ogcI0GT3oldpZTslTMLHCWgLPv3 M1lmLpJVTyvls5bggyoDiUzzZBzEBRq+DcyCRNGSd8lWPjcqWCy9WEmnrU9VJHGgny9a 7B54/EUUWAWocHjFsl3q14iwwAq4LVrShl3Jzh792mBZoYkdNeTqPKlN2HkbWRTsDUZD e4ON7JfAIgUkoOidShGnjZcy0zAOX7iJaUGy5afPfm1EWmjznBiVJUplMJqQ80fvPasg X7sC1w+mS4RqsxqbzF8FOBuJXizqlS12p199SaTCt8brpoyTcsd+nHsHYj+E7XyPCzLJ MQUg== 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=1LkmuWBCtFzTqo+05uB6OBB8XVwpv+VAUv1vZy5ADS4=; b=i3V1vBxCB4jGY7UfimW/JRe1R89yRdzIjWktmuVORXm4P81IIKhD6o2tkGcEWElOvL G71+1rksC466yoZL/wSLJM9Wk30pMbDihPHhp7WDrdzVZI/P/r4xQca0lIZSuN9VBw2Z nsoERy8TknlrWu0XdikNuueE3gauNop4KTA16sHHqAD11qEYmc4rBfLN5kjOKF0fbOUs USTkUZISEXwJez5hen07qQzXxbW8ifX6TViwYaDJ+xqbIRwJasBDZ4YDFpymGjRrNv5A RhrDUDcP3triWjfrTJdjSbzdE5BVx8E0yhp7ciRYcCD3PcvoDF8Uvt0OuT/eh9q+Mx+6 eg4w== X-Gm-Message-State: AOAM531E5bDrOKFU7P3fVpOiOTve2b4UdDoe4fdyMKY6uAMi7q5Lhndd aW79R39DFWHUNxvVYv9BWVKBrgyyt1C3MA== X-Google-Smtp-Source: ABdhPJwftsSo6BFwYYrAtLOzdiamWEz90j1TU/ph3UpI2J2JeAI25FHHwlSFltnHu2gCvuQGP0irPA== X-Received: by 2002:adf:e64d:: with SMTP id b13mr23725837wrn.204.1615216030524; Mon, 08 Mar 2021 07:07:10 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:09 -0800 (PST) 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 02/30] notes & match-trees: use name_entry's "pathlen" member Date: Mon, 8 Mar 2021 16:06:22 +0100 Message-Id: <20210308150650.18626-3-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change code that was doing a strlen() on the "path" from a name_entry struct to instead use the pathlen given to us by decode_tree_entry(). Signed-off-by: Ævar Arnfjörð Bjarmason --- match-trees.c | 7 +++---- notes.c | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/match-trees.c b/match-trees.c index f6c194c1cca..1011357ad0c 100644 --- a/match-trees.c +++ b/match-trees.c @@ -197,9 +197,10 @@ static int splice_tree(const struct object_id *oid1, const char *prefix, while (desc.size) { const char *name; unsigned short mode; + int len = tree_entry_len(&desc.entry); tree_entry_extract(&desc, &name, &mode); - if (strlen(name) == toplen && + if (len == toplen && !memcmp(name, prefix, toplen)) { if (!S_ISDIR(mode)) die("entry %s in tree %s is not a tree", name, @@ -214,9 +215,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix, * - to discard the "const"; this is OK because we * know it points into our non-const "buf" */ - rewrite_here = (unsigned char *)(desc.entry.path + - strlen(desc.entry.path) + - 1); + rewrite_here = (unsigned char *)(name + len + 1); break; } update_tree_entry(&desc); diff --git a/notes.c b/notes.c index d5ac081e76d..0a5b4fa1dbb 100644 --- a/notes.c +++ b/notes.c @@ -413,7 +413,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, while (tree_entry(&desc, &entry)) { unsigned char type; struct leaf_node *l; - size_t path_len = strlen(entry.path); + int path_len = entry.pathlen; if (path_len == 2 * (hashsz - prefix_len)) { /* This is potentially the remainder of the SHA-1 */ @@ -483,7 +483,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, strbuf_addch(&non_note_path, *q++); strbuf_addch(&non_note_path, '/'); } - strbuf_addstr(&non_note_path, entry.path); + strbuf_add(&non_note_path, entry.path, path_len); add_non_note(t, strbuf_detach(&non_note_path, NULL), entry.mode, entry.oid.hash); } From patchwork Mon Mar 8 15:06:23 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: 12122579 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 5F410C433E9 for ; Mon, 8 Mar 2021 15:08:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2871365229 for ; Mon, 8 Mar 2021 15:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231204AbhCHPHl (ORCPT ); Mon, 8 Mar 2021 10:07:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230135AbhCHPHN (ORCPT ); Mon, 8 Mar 2021 10:07:13 -0500 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 7DD2FC06174A for ; Mon, 8 Mar 2021 07:07:13 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id l22so6260872wme.1 for ; Mon, 08 Mar 2021 07:07:13 -0800 (PST) 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=fp5bPLAzp8al4K7NhdNtDrIXlPwcTYIwQbVmRRryFuU=; b=TcMWRIIm0qVwhFItEUi4J8CzL2YK/DONVONo8guOKgur7czwFh3scP5OoI/unlHr+g 4zY7xWjIPkoRxNU4KWXhycqobOe6mebSq10qqzj6a87/JOBwffEpqc9fikLL3adXBfpt elOsogvpcjElwcmFzHCKTh8Fm+06BTXqwcxZcWO9w0j4ZsmR5qFluKQ/388pYN60BZ9d AbZXNeS51Mw9eH+UXntVPhsX8sEvonk7JiAAL6pVpTfGzTnR6SujgFsr8DBNsJuSQWcV vfGlm4LckeQRtxxSL0Afg/b0lRhKoWVKLQ/A9UrclUTdtNkD94EfcJ/ysFmZFzxXaYxA G4SA== 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=fp5bPLAzp8al4K7NhdNtDrIXlPwcTYIwQbVmRRryFuU=; b=uSCuTWxhQcL0p0pPl9jsuaEihSF0DaUPri3nHtBHm1aF9/1WwkXmJMYx5ZnmSHfuWz 9jd0Di5bEuCrKsbGxq6S4GM8k6veBfqbU97YoX+ubdxy/QkelT+lOsS48EOnXYxKKmBz VeTUAdQ50cEFroIDExH1QMu+tqsgZ/1bEoQ7PtYk8MclpYKJwrR/G1UvDNUzL7xUVClx NyGaLQgIbKQkM9W/pNy4VEWX/+fHy/RErMkYMBondkijpXEj0lxSNIcQckzDZ3MMX54Y MZc2IgG1BvH2XYR4SfVCah1GbIEYa3+0E22oDeFAy+CYO8qNPCa2uPh2SlRro4Z5/5WL +htA== X-Gm-Message-State: AOAM531/QHPcsLHad77y+1ZIPCxiSTvYJ/Y2gxaVCLDP8bq/hYCW1bun thq1p62dkbH67yNSjmKaXpIH1eXquWUDPA== X-Google-Smtp-Source: ABdhPJz1InqGlkddGuzTSZ7xZRFc624Iz8ZI3njwACUu3AfevCHHYLvL+7DuQ/qfbcoSP8mNsZZjEQ== X-Received: by 2002:a7b:c3c1:: with SMTP id t1mr22389295wmj.47.1615216031527; Mon, 08 Mar 2021 07:07:11 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:10 -0800 (PST) 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 03/30] cache.h: add a comment to object_type() Date: Mon, 8 Mar 2021 16:06:23 +0100 Message-Id: <20210308150650.18626-4-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-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 whet 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 d9281496140..e513f0ee5b4 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 Mon Mar 8 15:06:24 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: 12122581 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 92688C4332B for ; Mon, 8 Mar 2021 15:08:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 721AD6522F for ; Mon, 8 Mar 2021 15:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229468AbhCHPHo (ORCPT ); Mon, 8 Mar 2021 10:07:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230511AbhCHPHO (ORCPT ); Mon, 8 Mar 2021 10:07:14 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5D6CC06175F for ; Mon, 8 Mar 2021 07:07:13 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id h98so11772302wrh.11 for ; Mon, 08 Mar 2021 07:07:13 -0800 (PST) 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=B+iRuURr+afdNjDjp/7XcvgdMkhCWEtNJRJ7P/VPoLE=; b=o6VWtkIvaaKrR+TJlL9ODGUNDSMbdVhi2hvc9D7pT5oyZbJ2+MA1c4nNiHSXFjFJYi TwtopzolqXkPtD5QgdDT7YFVgjVX3XxfVxalhKvJ4fgnVZPnPH/V0kzWvbZxChtageB8 F/xedhjC0/JUxF6YPpvXEVagq68O03+uKeHOFRs8rgTC79WRFkgLnstt2+xmmO6KxNEr akqeDVoG1tgK8i6fFrpjSVOebrnLCtW25DR5RfXZJRA5o4ESlZaFc6wQsBv1eGuyLGhw tyUPLWwmCHafuWjY71FAD+/3CKIRTjEaBD1j8OiAzqdOb5mEFKYYkZ3Pwq0nOFfeH9Cl Hy5g== 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=B+iRuURr+afdNjDjp/7XcvgdMkhCWEtNJRJ7P/VPoLE=; b=FcbEc106bIHp81R5oD3UYJhlImWOEmDrMZHnepur75Y4bwfPa/qUFLxTkRDXwonm+P KPwXIOZpvjB1HWdhieFk3f0vubcM+NpLp59NKQY7dn0B988N9d8md3evXzVTeOFhOIwf KRJu81Mh71LFO+A8SQ4OEfRn1pyAkvhMbW4ek2ppCsnwrFE6Asr5hAClh7foKpbkyMTG K6XYYKiwg09S7+d2N/SQe8phYy/X6K9KuS6HzjGdHANVNGtYjdyBGlznp86WUpiHaIYA YPUw2ZKAKlaqEp5mtDchexggyovphFvKWrzi//LouXyf6V1b6Vga4emzLvPDaiwclYgv Rc2g== X-Gm-Message-State: AOAM533AgthjmJ2hdIQvy6LA6fM5Ca7Bp3JUNODUkme46kgPCf9xopAP lcqC4MAFBKEWlO7zr6EKlDd2eyayssorWw== X-Google-Smtp-Source: ABdhPJw3SHUXiHF70bq8Qyl2MxFwu0cshcVzyzoyNZT4M+3SRAUufzWXgBJGKT0P8UrPGtbL6qEL0g== X-Received: by 2002:a5d:6304:: with SMTP id i4mr22884667wru.155.1615216032277; Mon, 08 Mar 2021 07:07:12 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:11 -0800 (PST) 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 04/30] tree-walk.h: add object_type member to name_entry Date: Mon, 8 Mar 2021 16:06:24 +0100 Message-Id: <20210308150650.18626-5-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-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 Mon Mar 8 15:06:25 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: 12122583 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 B710DC43331 for ; Mon, 8 Mar 2021 15:08:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9C3FA6522B for ; Mon, 8 Mar 2021 15:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231433AbhCHPHp (ORCPT ); Mon, 8 Mar 2021 10:07:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229528AbhCHPHP (ORCPT ); Mon, 8 Mar 2021 10:07:15 -0500 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 BD1EEC06174A for ; Mon, 8 Mar 2021 07:07:14 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id a18so11766463wrc.13 for ; Mon, 08 Mar 2021 07:07:14 -0800 (PST) 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=v5GfDL+DkvYTyYZeZ1uEAAOtJODBBbRD8EpNiHANoAo=; b=FEK7T/g0nsXJIh5WCKzcNRQEjwRYg4QjiFjDql9P1hBhNJzLYSc49ooslVC/v24Hsu a16NxEzdVWFsIUsgP+8KK+ugAA5cihjUGIaDRIurAhHQrk1NBJACte3MywHqsyZMWrD3 gE54O9+7lEO4gsX+GL6pZyT5qSSFh6x4eeiNVG+Cl/wdSQj4NdDf72htfRV7YUjYbaws wEFOGBRiNAkcWryQ1Ru3Jdh9kY61JhNgEX84MtK4WpI3OiC9/8952raLOgA3K05zYXhl MzPJmCJH6Eqe5ouSq884RrfsmFvsRevO6f+rbNfv0sUhSMewfvuBf7SL2IzRgo6UQ/It BlDA== 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=v5GfDL+DkvYTyYZeZ1uEAAOtJODBBbRD8EpNiHANoAo=; b=QGOh3OqzSWlB4UMuDOxeN1r6cVgbTOgCSXHJgZg4US/c2DxxZe/0Qe8o1UQmEL1vnx geB4O0JkHxKAi3HGwGS8o2WYoFCQ22c+EOZrcD5tbdnjqd4O1EJx/OFaLjRIRTHjkKAs jlUgU8V4GEFmwOchbyPCzVbGGiyYKXRhQ/WGXKozPTyY31fiUfCP/YCWCtpIcoel1ukQ jMLegylUln6/SQ/nRTYCDo1rkyAF/HlKDz3JUET2SV7PWP80hRkcV8A7qL5QQEVqckIN EREZmVX843SDwrgxFj8bGLx3lag8wOvS/3CQeiu8BnelGpbmhpuNibxnlMP1B6wtQLFb txsQ== X-Gm-Message-State: AOAM530ymqLeI02bKU8A6WU/3NBuxGBg2X8eTmmkiP0EHq/xeFP+4amU sQ2akWiY6jDSrphTpD9UEngFlJ5F+n2d2g== X-Google-Smtp-Source: ABdhPJzXxIe+YIW9RM1tUlHHidYYhpjQ/T4Lc9Pe2hMhFmpCl8gfTDWQdSXC7ufM0QUBl2xPH8gT8w== X-Received: by 2002:adf:ef4a:: with SMTP id c10mr22656660wrp.427.1615216033195; Mon, 08 Mar 2021 07:07:13 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:12 -0800 (PST) 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 05/30] tree-walk.c: migrate to using new "object_type" field when possible Date: Mon, 8 Mar 2021 16:06:25 +0100 Message-Id: <20210308150650.18626-6-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-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 Mon Mar 8 15:06:26 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: 12122589 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 EAF55C432C3 for ; Mon, 8 Mar 2021 15:08:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BBD1565234 for ; Mon, 8 Mar 2021 15:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231520AbhCHPHq (ORCPT ); Mon, 8 Mar 2021 10:07:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231389AbhCHPHQ (ORCPT ); Mon, 8 Mar 2021 10:07:16 -0500 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 F3FC4C06174A for ; Mon, 8 Mar 2021 07:07:15 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id u14so11830849wri.3 for ; Mon, 08 Mar 2021 07:07:15 -0800 (PST) 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=+/xUqGxpPsHeXsVnfIMYk6eHQJ/PXQHhu1Yna3mB2gs=; b=s3s0YjJ0Ohb4FE9HCsLOyrNEqm359lwImwXYcdJBbi3xgWCH6fi+MiDB9H554Oxa7c 10Y6S0CoaBKxynmmAxI4vYYO23sEEBvWdb4cdI61xxe9oD1/vh2YnldCSvwuHJmgt97o Bcq5dIM2Q/TUDLd3iifyoojcj48tNAzMYqgRTLguIQWtwxLC6xkq55FNjqwsxj2ng4xA 09/gbDRIaMGGRsX01OJghOst6lsIyrKynpt0C1F5cfQzMGXqftOllBagAbrOkCW+BjXV HtzNkY1xwdkwdKl+ZdyjzMykzWC80J1Hh1Szlenul+pnPhwOJVKLVjEcm5MroC16Mcf6 /ZtA== 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=+/xUqGxpPsHeXsVnfIMYk6eHQJ/PXQHhu1Yna3mB2gs=; b=jxiDGWfWLyzDD9JaD29Izg//4pHQ6DWKmeGpkM3wQhXEJvpNdp54cM7DccojQPxWys gPeXjHTQXXODIX6eAC+JCzEOSHCELr6KjuyDRV6j5QLwLaeUz46gIRihOpylTa2qWwQ4 8Jas3LsXgF/hayFsPthg37JRzp/98hW9AnnJR3bA2IQE8QUC3lyimqyvBNoiQj6mWIQ6 UST162KBjKqF7I3QIw0Gvy8sb6tcz07Z7kDfnCtMYLSqEHMXa220plug0Qgwz8txrkk/ z51ChYTW0GwAe+DoAfnuxh5mV0k3VAplOUwLWrz/Y9FrfafjyORNN7dOmj3smpUi6xiB ltvg== X-Gm-Message-State: AOAM530kdEhIeSUcZ3G7RtDW9F7xQ/CPaVhPZr6L8CebgmYDvuPbagmz WGEoDBwnhnrtOFZ++1bspH2S4s4p5jZiVg== X-Google-Smtp-Source: ABdhPJwQ8W85AbIOFzFmzEd1CmyFrFPXXssySi3OSdHp87NpXhsLEzlSIYQ6eDABN+EOSQDb0w+A0A== X-Received: by 2002:a5d:6989:: with SMTP id g9mr6626250wru.198.1615216034133; Mon, 08 Mar 2021 07:07:14 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:13 -0800 (PST) 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 06/30] cache.h: have base_name_compare() take "is tree?", not "mode" Date: Mon, 8 Mar 2021 16:06:26 +0100 Message-Id: <20210308150650.18626-7-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-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). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/fast-import.c | 8 ++++---- 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, 43 insertions(+), 35 deletions(-) diff --git a/builtin/fast-import.c b/builtin/fast-import.c index dd4d09ceceb..ce4613c1595 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -1288,8 +1288,8 @@ 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); 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, 1, + b->name->str_dat, b->name->str_len, 1); } static int tecmp1 (const void *_a, const void *_b) @@ -1297,8 +1297,8 @@ 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); 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, 1, + b->name->str_dat, b->name->str_len, 1); } 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 e513f0ee5b4..49994dae916 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 isdir1, const char *name2, int len2, int isdir2); +int df_name_compare(const char *name1, int len1, int isdir1, const char *name2, int len2, int isdir2); 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 9228aebc16b..64d7aaf1710 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 isdir_one = S_ISDIR(one->mode); + int isdir_two = S_ISDIR(two->mode); + if (!isdir_one && !isdir_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), isdir_one, + two->path, strlen(two->path), isdir_two); } static int filename_changed(char status) diff --git a/match-trees.c b/match-trees.c index 1011357ad0c..4d124a0fd1b 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 isdira = a->object_type == OBJ_TREE; + int isdirb = b->object_type == OBJ_TREE; + return base_name_compare(a->path, tree_entry_len(a), isdira, + b->path, tree_entry_len(b), isdirb); } /* diff --git a/merge-ort.c b/merge-ort.c index 603d30c5217..4075d13aaab 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -2390,8 +2390,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 1593f374495..0baa6b5ca56 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 1e9a50c6c73..edfce1f0cb8 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 isdir1, + const char *name2, int len2, int isdir2) { 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 && isdir1) c1 = '/'; - if (!c2 && S_ISDIR(mode2)) + if (!c2 && isdir2) 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 isdir1, + const char *name2, int len2, int isdir2) { 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 && isdir1) c1 = '/'; c2 = name2[len]; - if (!c2 && S_ISDIR(mode2)) + if (!c2 && isdir2) c2 = '/'; if (c1 == '/' && !c2) return 0; diff --git a/tree-diff.c b/tree-diff.c index 7cebbb327e2..f133834597c 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 e1_is_tree, e2_is_tree; /* 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; + e1_is_tree = 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); + e2_is_tree = e2->object_type == OBJ_TREE; + cmp = base_name_compare(e1->path, tree_entry_len(e1), e1_is_tree, + e2->path, tree_entry_len(e2), e2_is_tree); return cmp; } diff --git a/unpack-trees.c b/unpack-trees.c index f5f668f532d..802f7771d75 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -922,7 +922,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 is_tree) { int pathlen, ce_len; const char *ce_name; @@ -930,7 +930,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; } @@ -944,13 +944,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, is_tree); } static int do_compare_entry(const struct cache_entry *ce, const struct traverse_info *info, const char *name, size_t namelen, - unsigned mode) + unsigned is_tree) { int pathlen, ce_len; const char *ce_name; @@ -962,7 +962,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, is_tree); cmp = strncmp(ce->name, info->traverse_path, info->pathlen); if (cmp) @@ -977,12 +977,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, is_tree); } 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 is_tree = n->object_type == OBJ_TREE; + int cmp = do_compare_entry(ce, info, n->path, n->pathlen, is_tree); if (cmp) return cmp; From patchwork Mon Mar 8 15:06:27 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: 12122601 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 A8EA9C4332D for ; Mon, 8 Mar 2021 15:08:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 888FC65232 for ; Mon, 8 Mar 2021 15:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231460AbhCHPHq (ORCPT ); Mon, 8 Mar 2021 10:07:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231395AbhCHPHQ (ORCPT ); Mon, 8 Mar 2021 10:07:16 -0500 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 4F27FC06175F for ; Mon, 8 Mar 2021 07:07:16 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id h98so11772431wrh.11 for ; Mon, 08 Mar 2021 07:07:16 -0800 (PST) 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=DiUgvF5gaDU/CnclRudjbSlYBEppYZeQvpzv3YQOLj4=; b=DqisSue5aQTKSBPkyAoNvOvgQ4jU9WjyTvMtYFB/ilFPganw/qWpMB++wJyvR3aVT9 Yk1bEaykUDMjyBht8su9iGyoPiFdxdT+jWaOdGeqQjOIo0HqiyvGpTPpifALMpnXUCEA J9qijLHhopBMrbgab5vyDWS5C8AZ2YgEYCUKs6ax6XsEAcY4x/Ken/Ugt1k+SkI1dfbD XRbotOp0FXmZoXt6iDyWeo2uFmJeTDCUpvp97NB69l10edJ3j5BcDzNM86PL2DO8U7LA UL3GJ2AIBtupXBe9hZAGx/ORsCWd8jUoWGWXrQ4vgi+gKqpa+ynBF6AHfZYPYfDGCXBJ ppvQ== 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=DiUgvF5gaDU/CnclRudjbSlYBEppYZeQvpzv3YQOLj4=; b=VsP2+V9FFptvpcvKBIjBGeE+RbxP8lOEbvyJBBPagN5/4UTEHwVexW0Up7Vl8XUNK5 WvlNgQqFecDuUeXXgbXMUzVXEmSxasF5lopj82iwLVIrCV0AOZrGC5NbGuieJemf28XR eCk4+4293VBw3PUqPO8jphR2wUyzIeE7s8AUv7wezR4+ThHcfrO5fa88zXweDUvpF18f /HrYB3ovFdYLZKHubZZgO8C7LEdpjipO/MSMk7aNFpSZXhXCe8ZSo4flCjqA4wcc9BxG Gzbx4+0iY7EEu4Y+wx9vR2RtdlZ5H3cVvRPyOz+DMVCmn2kqCUiTVp5/jW0RRqElRQrr ZeZA== X-Gm-Message-State: AOAM5324auKgK/S5RHd6rcl68BVljvUHgqfkvy7zvKAHl9BQ8YUQL4Ds Vrbn1K3IGsKlZD7TOYg5NVoBWpwP1T+Cig== X-Google-Smtp-Source: ABdhPJzAbZUBwkgmieUy0kUf4zGq+/ShhRqgbzVAhfkg2kU/hgq51Aoqoa5IQijbSdBeIQ7pX2D/DA== X-Received: by 2002:adf:ba87:: with SMTP id p7mr24004607wrg.298.1615216034822; Mon, 08 Mar 2021 07:07:14 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:14 -0800 (PST) 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 07/30] tree-walk.h users: switch object_type(...) to new .object_type Date: Mon, 8 Mar 2021 16:06:27 +0100 Message-Id: <20210308150650.18626-8-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-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 6d62aaf59a0..d3ba1d4a4a6 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 6a4a43e07f2..234b79a5dba 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 b78733f5089..1db4e4e90a2 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 Mon Mar 8 15:06:28 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: 12122619 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 CD8A9C4332E for ; Mon, 8 Mar 2021 15:08:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AD0676521F for ; Mon, 8 Mar 2021 15:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231531AbhCHPHr (ORCPT ); Mon, 8 Mar 2021 10:07:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231397AbhCHPHR (ORCPT ); Mon, 8 Mar 2021 10:07:17 -0500 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 1855DC06174A for ; Mon, 8 Mar 2021 07:07:17 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id a18so11766602wrc.13 for ; Mon, 08 Mar 2021 07:07:17 -0800 (PST) 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=T1MbgDpaV0RQO60S8/kTJfOJiXg8NmINhu2GVxjiBkk=; b=RUAlgGdkEd96TZQNThxcx+jIZKHs+Hcn9B6S+/Gm8MjouajUGApM2NmUYCCZ/BDaxD Pi0i1YSGogy+vgFyngMckWTcDsoeXIgBXGtulLTxkwi9IVlLxkIWna9R0CZowqIvJC0I 0wZvAMzbf2I1jwaVGhrBZeveLeZfzaVP23mUN/VsFApHSYM+xrAt1CqOqAFHaGSyts2l LFLZiW6C9J2CoEXOdygWVjiSfK3q7Tx6EUxxSXoSG5TSECsKxhlEVqMyhto24fOjc4Pl X4+YVvRXwZxq9wS7OF0ZWZHKSlFY7yrYEQiEkiknhL81WVu8cPzEyNdLSrreLzNoHK/h lD3w== 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=T1MbgDpaV0RQO60S8/kTJfOJiXg8NmINhu2GVxjiBkk=; b=A3LfebV7H++V98/ZM5LcIRMfHUo9u53uVm3KcAcm1rk/C77DHBJ1rb7Xx+ozE2mtK1 xZaC7zRPsrAvXgKohwb2x1zcq+lrNRihmfiXCG24G0m1+PUgX78giBzsDtHox0j5o9eD YnX+S+Gp4XvsBtrYz8+jCH2nX3G0bQ3VGBrwdjvt02H3eGpUVND7iRsE9C8VUaTY5xF3 fhQhFP9iAnApulqBVVy8v5pGDwNhz2oqmRw6LyFCo/YWE16iNo5TD/+IPjZXcIcV+NCG g2VKK4NRuYk7ED72Fl7mc4/s1tQp5TS+yfgj1+GYsQ9WTO4VmCCEA9s0gYpIipSqYFgG BteQ== X-Gm-Message-State: AOAM531JMVl9ZrJ/8Ut10OZrPpCYtdqDKkMvRYcoNYjH6VB3Q4oDWmSa PZnIiNR1/Dw6Br3qnBIewSeo78vWL3iO7g== X-Google-Smtp-Source: ABdhPJyuEO1Qn4GXUF10JD+D4C8cEjK8TILNXuspFV6zIlhwWLEWiB/SOAHgCEyVUSVBQgtWF9fTlw== X-Received: by 2002:adf:d217:: with SMTP id j23mr23917849wrh.113.1615216035572; Mon, 08 Mar 2021 07:07:15 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:15 -0800 (PST) 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 08/30] tree.h: format argument lists of read_tree_recursive() users Date: Mon, 8 Mar 2021 16:06:28 +0100 Message-Id: <20210308150650.18626-9-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-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 6669a4bd147..db69a8acadb 100644 --- a/archive.c +++ b/archive.c @@ -138,8 +138,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, int stage, - void *context) + int baselen, const char *filename, + unsigned mode, + int stage, void *context) { static struct strbuf path = STRBUF_INIT; struct archiver_context *c = context; @@ -230,8 +231,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; int stage = 0; @@ -378,7 +380,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 2c2d58a230f..a78b54624b0 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 58acb2b76ab..3766f553971 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 dbb31217beb..aaa41e66234 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 0baa6b5ca56..aa12543ecc9 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 1309ab997e5..a7030e52679 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_recursive(struct repository *r, struct tree *tree, From patchwork Mon Mar 8 15:06:29 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: 12122585 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 27593C4321A for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 032E66522F for ; Mon, 8 Mar 2021 15:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231545AbhCHPHr (ORCPT ); Mon, 8 Mar 2021 10:07:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231400AbhCHPHS (ORCPT ); Mon, 8 Mar 2021 10:07:18 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE13AC06174A for ; Mon, 8 Mar 2021 07:07:17 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id d139-20020a1c1d910000b029010b895cb6f2so4006811wmd.5 for ; Mon, 08 Mar 2021 07:07:17 -0800 (PST) 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=nwskF67xloNuhMklsYoycBl3qw5F4keeyG+IkH/K5r8=; b=iLoupZSY/tQWbXuj9/NmDTatV90BYUygHTD1oP/xB/hstthPYPGKs7muWPWlEtBE3G H7hexc0FbbB1NGYGTh+xgmHel41OyBGwGiKDUTNR6ZlXADNojuT1mys86yDNTL6zd7WX 6moYke65kHD57/ccTkhljUhkWLhdWt9d3H8PZc8w+sdIyus6SznzKAt6emqIAhoruC0+ Od3l/gMcpVQUnSkhb2bo6S9xVGojpU1s1wxw6wuFdny/BxTBvJLIUkhBGXUirq0n5C5l YnBZLNxZcCV9amj2Q7vcLnO2Kf1PEhMlLJLELsdezCERQ9LBiCzyqU46zACymnXpHZyF n+NQ== 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=nwskF67xloNuhMklsYoycBl3qw5F4keeyG+IkH/K5r8=; b=tcJ1LzW97YvNnfB0PkK9Ryj/N+oUvRQ/FTEh+TGVUTtvSukLT+prCfVw8T5YoMbELn ZS8nhbuHkOjsK5Qfqu/ncMCrsIE1B1iYnaPKBlA9PBUYR9MpQxs3ihAlTOy7L/3zZ/Vl xtldDrVY3j31pi3eA/clzlwlOV/gcE5HrwDgIx7Pk3zGBeSz/6DkU5gSYcVEJ9e+Yqmq jwNZYwrpdo/S60DOoRLNdl8qO/+iBR/mfAhTzvnRMGerCT5vuA8m5R01QeyS3WE5SXoX 63ME6WfL5BJD4fR73QfuM8IKkntuFceHRJsTw2kR2fO3xkUGXhv3Lf6Bj/aLRph6DBm1 shIg== X-Gm-Message-State: AOAM532wInoCu7et3WwPIubmQQSrlCaBioU6JTPHmRDTt68ZEXM68It1 DXC9uwXJwl7nN0R5kt+A0B0Ogn10S5qDHA== X-Google-Smtp-Source: ABdhPJzmLXRrIEyXRPAyzT6amdD5Hvaso1wDCI3CpfZ3wBVKbRaxmbWz+KxZ5sKbz1x1p2jHoQ9+hQ== X-Received: by 2002:a05:600c:290b:: with SMTP id i11mr23178865wmd.129.1615216036416; Mon, 08 Mar 2021 07:07:16 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:15 -0800 (PST) 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 09/30] tree.h users: format argument lists in archive.c Date: Mon, 8 Mar 2021 16:06:29 +0100 Message-Id: <20210308150650.18626-10-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Re-indent and re-flow the argument lists archive.c has downstream of its read_tree_recursive() call to make subsequent commits easier to read, as I only expect to be modifying the "stage" and "mode" lines. Signed-off-by: Ævar Arnfjörð Bjarmason --- archive.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/archive.c b/archive.c index db69a8acadb..e245c0d5a54 100644 --- a/archive.c +++ b/archive.c @@ -140,7 +140,8 @@ 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, - int stage, void *context) + int stage, + void *context) { static struct strbuf path = STRBUF_INIT; struct archiver_context *c = context; @@ -197,8 +198,10 @@ static int write_archive_entry(const struct object_id *oid, const char *base, } static void queue_directory(const unsigned char *sha1, - struct strbuf *base, const char *filename, - unsigned mode, int stage, struct archiver_context *c) + struct strbuf *base, const char *filename, + unsigned mode, + int stage, + struct archiver_context *c) { struct directory *d; size_t len = st_add4(base->len, 1, strlen(filename), 1); @@ -224,8 +227,10 @@ static int write_directory(struct archiver_context *c) ret = write_directory(c) || write_archive_entry(&d->oid, d->path, d->baselen, - d->path + d->baselen, d->mode, - d->stage, c) != READ_TREE_RECURSIVE; + d->path + d->baselen, + d->mode, + d->stage, + c) != READ_TREE_RECURSIVE; free(d); return ret ? -1 : 0; } @@ -259,14 +264,18 @@ static int queue_or_write_archive_entry(const struct object_id *oid, if (check_attr_export_ignore(check)) return 0; queue_directory(oid->hash, base, filename, - mode, stage, c); + mode, + stage, + c); return READ_TREE_RECURSIVE; } if (write_directory(c)) return -1; - return write_archive_entry(oid, base->buf, base->len, filename, mode, - stage, context); + return write_archive_entry(oid, base->buf, base->len, filename, + mode, + stage, + context); } struct extra_file_info { From patchwork Mon Mar 8 15:06:30 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: 12122595 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 09DE1C43333 for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DFEC76522D for ; Mon, 8 Mar 2021 15:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231549AbhCHPHs (ORCPT ); Mon, 8 Mar 2021 10:07:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231405AbhCHPHT (ORCPT ); Mon, 8 Mar 2021 10:07:19 -0500 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 AE8FCC06174A for ; Mon, 8 Mar 2021 07:07:18 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id l12so11812529wry.2 for ; Mon, 08 Mar 2021 07:07:18 -0800 (PST) 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=0Bx4s6ATrka3mqVeBxhUQ+fmxWRFwnOnfjlh/4X0RpU=; b=du8uiEAn3+gFPvUpgoImMwrAzkPrY5OOdY+WNVwJo2iiR08G4E4iqjbiqXRLZbcP2t 0O9C+RJeFk6zoSiQTIXOySpRpn1Pk2JtsBs7X9rwAcBUL23q4aE1Vew3lyhyKGHYEUW3 i+m4JYWXJK5wKbsIaetRqCn/NFAEoeSIHsYz2XVtgq4/0jSlsyq6Vw8SuNvnjnNdZd8Y Li0Z045R71JhYvJWFBxe4OO8X0W2/630+778hx77rf82fWeaRvP2x7ePbYWn9jt+IVT8 z3XQe0YvEjg+OuvgUhZJRqVKvzJ4OHnFx5PG8wZ3jys8DrkBJvexQd5TIwtJaKtN/kgi q/Og== 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=0Bx4s6ATrka3mqVeBxhUQ+fmxWRFwnOnfjlh/4X0RpU=; b=K/oYxlh53B+JAZmm1ZBha3LAhLQPB7NiLVC9AkF80X27Fd4qDu3xYvI4HupdRa1k3Q ScHrbj3v9cxGWk/xmXY81/wbQBzqEkj883PallmOYHS3kc6WLs5/zWlxevVMPsmQZB8v o8A8kaOhZdnXRnOOxn8caA4hKocFY/kvr4rKOk4WbZTgr4JKTeLrBWMdDIRAt6VoPoTR mKgxbq/GRaumkXbDJtQWuTIDuH4Xh9meuNceoPfVspXqPIc3RpRjfesx1fpq3A+bx0th bW96d6gkqOviXT2AhEvlGx7JMTzDRUPOcOJJOLuz/Gm0S8rGjNIE1YYCxV4ce3GFTxr/ hfuA== X-Gm-Message-State: AOAM531r8zXprABtbxfDFQXCwIhMOUWZYdyKw7WUwxkdIskOFAt+vP4T tKv6YVN0FfD9hGDRiBymW2wETUEDACQidw== X-Google-Smtp-Source: ABdhPJx7cdnOJXyTUymmeaJUt39ixAuVzdxqsq5pUNvG5NNlTL4DSr0ptPnRoPLG47MkW6F731ofmQ== X-Received: by 2002:adf:b1c9:: with SMTP id r9mr23814946wra.51.1615216037133; Mon, 08 Mar 2021 07:07:17 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:16 -0800 (PST) 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 10/30] archive: get rid of 'stage' parameter Date: Mon, 8 Mar 2021 16:06:30 +0100 Message-Id: <20210308150650.18626-11-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Stop passing the "stage" parameter around in archive.c. This parameter existed because the read_tree_recursive() function used to provide it, but no longer does. See my in-flight commit to remove it. (tree.h API: remove "stage" parameter from read_tree_recursive(), 2021-03-06). As can be seen in 562e25abea9 (archive: centralize archive entry writing, 2008-07-14) and ed22b4173bd (archive: support filtering paths with glob, 2014-09-21) it was never used by this code. We simply added it as a boilerplate, and then later added it to our own "directory "struct. Signed-off-by: Ævar Arnfjörð Bjarmason --- archive.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/archive.c b/archive.c index e245c0d5a54..26534a30d3b 100644 --- a/archive.c +++ b/archive.c @@ -107,7 +107,6 @@ struct directory { struct object_id oid; int baselen, len; unsigned mode; - int stage; char path[FLEX_ARRAY]; }; @@ -140,7 +139,6 @@ 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, - int stage, void *context) { static struct strbuf path = STRBUF_INIT; @@ -200,7 +198,6 @@ static int write_archive_entry(const struct object_id *oid, const char *base, static void queue_directory(const unsigned char *sha1, struct strbuf *base, const char *filename, unsigned mode, - int stage, struct archiver_context *c) { struct directory *d; @@ -209,7 +206,6 @@ static void queue_directory(const unsigned char *sha1, d->up = c->bottom; d->baselen = base->len; d->mode = mode; - d->stage = stage; c->bottom = d; d->len = xsnprintf(d->path, len, "%.*s%s/", (int)base->len, base->buf, filename); hashcpy(d->oid.hash, sha1); @@ -229,7 +225,6 @@ static int write_directory(struct archiver_context *c) write_archive_entry(&d->oid, d->path, d->baselen, d->path + d->baselen, d->mode, - d->stage, c) != READ_TREE_RECURSIVE; free(d); return ret ? -1 : 0; @@ -241,7 +236,6 @@ static int queue_or_write_archive_entry(const struct object_id *oid, void *context) { struct archiver_context *c = context; - int stage = 0; while (c->bottom && !(base->len >= c->bottom->len && @@ -265,7 +259,6 @@ static int queue_or_write_archive_entry(const struct object_id *oid, return 0; queue_directory(oid->hash, base, filename, mode, - stage, c); return READ_TREE_RECURSIVE; } @@ -274,7 +267,6 @@ static int queue_or_write_archive_entry(const struct object_id *oid, return -1; return write_archive_entry(oid, base->buf, base->len, filename, mode, - stage, context); } From patchwork Mon Mar 8 15:06:31 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: 12122593 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 2C661C4360C for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1662D6522D for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231561AbhCHPHt (ORCPT ); Mon, 8 Mar 2021 10:07:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231209AbhCHPHU (ORCPT ); Mon, 8 Mar 2021 10:07:20 -0500 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 C0A27C06174A for ; Mon, 8 Mar 2021 07:07:19 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id e10so11773816wro.12 for ; Mon, 08 Mar 2021 07:07:19 -0800 (PST) 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=m1DEudJkxr160UNtr0+Bc4d83nR7jJt+Lf4NNxdQYgo=; b=GqVnIOLlK94GoVtJfIBuxMkUOwOz8my56j5ZaXnjuec5xc9kco6XcikE6Gyu3OyauL v4P7jzptlLkY0Zlc/nJwEIcHMQH90jxnOETnNuptYhuqDQ7+/Ki0pGXPSHkDyP+HJ19k q0yz2gZrC9id11Da0nx1w4t4p7F2ySYWArZ5NfTjylNbQyIX8vRLgKojC7t08jSp5qce mX8EKw4eO9g29c3InK5BXXYegIFw64eIzv1swaQOJ33mBsPzJGV8crPzbtFKLhzbwqAe OyItkK0IPYlgXoWxmRJkZ+OFZsSMyUSQ7rHvmRgC0fqgP+UkHXpwh7lJeLrJ98PyNj/u M1rQ== 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=m1DEudJkxr160UNtr0+Bc4d83nR7jJt+Lf4NNxdQYgo=; b=BFidOgkOFv4+crKWsNWUNFYmUEMV3z5leiY6c9iD/Caw4aB+SzdoB8iqWYadS1oViS nDlLjRoWYNK2N2C85OSkxhOam6gaLXSgh1Mdf2fKlpbIw+gG+DqedKKfQ2/YrFs4Rt5U iu3nvTM3+35+SJi9fJqsjIskLcP5qwWNJDbcUWMORXgVr5QTt+ceWrO9AK/vyuJ1FKTT esvUSu+fViFszebDzeqEeHraalcoiseQnOtU1cLZQY01vaAZjKtpP1K1DoAX+hRSwiRw UpsYHlaWqudWNFRNhLn7vJseWE+ZT2v+ct92Tu1l/uePNrZbetNficgxaNChlLkzqJfV /0HA== X-Gm-Message-State: AOAM533Zdlo5jxgFJpyvEkaT4QEJYr1rJLzwtP2kQvgAy4o7bXZw0woA 1zuoI484LsqkzkqMYyhotlnmA+ofuwXVLA== X-Google-Smtp-Source: ABdhPJxso7gpaCJJQ9MK9frHzFgbutkXxHwwNEg+IKkwrOKTs43xDXCUh7fJu9bIYufzGJMNQbaRWA== X-Received: by 2002:a5d:55c4:: with SMTP id i4mr23495953wrw.84.1615216037991; Mon, 08 Mar 2021 07:07:17 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:17 -0800 (PST) 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 11/30] tree.h API: make read_tree_fn_t take an "enum object_type" Date: Mon, 8 Mar 2021 16:06:31 +0100 Message-Id: <20210308150650.18626-12-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-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 26534a30d3b..64abe736f93 100644 --- a/archive.c +++ b/archive.c @@ -232,7 +232,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; @@ -245,7 +245,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; @@ -382,13 +382,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 a78b54624b0..d4adfdb5046 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 3766f553971..19a916221d5 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 fa9b01b6cc7..f38df439410 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 aaa41e66234..c6ec3ca751e 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 aa12543ecc9..31c080538ef 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 fb4985f22ca..e4402fad69b 100644 --- a/tree.c +++ b/tree.c @@ -28,6 +28,8 @@ static int read_tree_1(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 @@ static int read_tree_1(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 @@ static int read_tree_1(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 @@ static int read_tree_1(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 a7030e52679..eba51417d26 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_recursive(struct repository *r, From patchwork Mon Mar 8 15:06:32 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: 12122587 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 EA1B6C43332 for ; Mon, 8 Mar 2021 15:08:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CE82465231 for ; Mon, 8 Mar 2021 15:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231558AbhCHPHs (ORCPT ); Mon, 8 Mar 2021 10:07:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231411AbhCHPHU (ORCPT ); Mon, 8 Mar 2021 10:07:20 -0500 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 58B0FC06175F for ; Mon, 8 Mar 2021 07:07:20 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id f12so11801728wrx.8 for ; Mon, 08 Mar 2021 07:07:20 -0800 (PST) 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=dqZJb5VcTCxvRphJVHXc26pgXJGj04zKVMdc5+0NWkM=; b=XXIccVwieny1zZfZHFV/So+5mqPHEia7e5CGsRGzCzNXagK5SDxHBuTuYfKPyZuwSh Lm1MxLaE7qqIIZiso0IqcTS9hnhPwg5ZTvO8caN8X/wKBfrlgiftyIQ6koSYceTUvH3u IKSnlYnf4a7/yBsB99wvKbHQ9S8VFflJ3E90+GTywKj9/C+13DHUOH+dRYE6GoJYKbTv eJu8SpP6y++owtXDyLvGaNsFjlezASY2mWshmCrxcqA+Tx34prV8GKjSFg1uwT0rjZlx RnkVkGZXrja4w0U9u0czjeb4bGOzm5vDimk4OAOKTW81Gkv0NsMFH8ywcLJDBCaxQct+ sSnA== 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=dqZJb5VcTCxvRphJVHXc26pgXJGj04zKVMdc5+0NWkM=; b=fYNE4awlioVP3lenuM6MqaixZ9kXKD8IFJs6VtDMh/e9OeEfBQwsAssebPs2hT9O5k FC47MMyRLTovp3MNFH/Klf8SwJRBn8+t/gIp98roJ3B7eYb9yi2em/vpTxlpjrihq+HT CsNs6DuBuFmd1Z7vfWSlibCMzEdtMw2mTMiUSqULfK96AnmtRYXrp91x6mDegcDYTWYE /WcWIMR4V68vYjmjveFoeJHTup41Rqqoh6ej6PA+ZfuB68g1yRQF4OYDwvbU4N+EbUBW Ux2xba19YWttzg4y8+vR8Fx/+Y7/c2sf8bDndXRsNj0okDnSl3GgS5ZE50fT5wjRbMzr NuOg== X-Gm-Message-State: AOAM532GeWUIHqDNBZksayEX/s6uQq3w491F6jJzdLnwLbb8MqmkJsIb 5kBL3fs7b9U8twmxhuBQeaaob7cDtueUxA== X-Google-Smtp-Source: ABdhPJz5XHVvTGH9U11GUihUdR9tPi9p2LKtNR/hNxzksxDWtnYki6O1i0mMOtZvpgNzxqmhNVLoyA== X-Received: by 2002:adf:ee4f:: with SMTP id w15mr23418505wro.199.1615216038559; Mon, 08 Mar 2021 07:07:18 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:18 -0800 (PST) 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 12/30] tree-walk.h users: migrate "p->mode &&" pattern Date: Mon, 8 Mar 2021 16:06:32 +0100 Message-Id: <20210308150650.18626-13-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change code that dpends 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 in this 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 4075d13aaab..4375027914c 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 802f7771d75..92105135522 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -859,7 +859,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; @@ -1239,7 +1239,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 Mon Mar 8 15:06:33 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: 12122591 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 66D18C43619 for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4DEA765237 for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231573AbhCHPHt (ORCPT ); Mon, 8 Mar 2021 10:07:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231424AbhCHPHV (ORCPT ); Mon, 8 Mar 2021 10:07:21 -0500 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 3FBC9C06174A for ; Mon, 8 Mar 2021 07:07:21 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id 124-20020a1c00820000b029010b871409cfso3998431wma.4 for ; Mon, 08 Mar 2021 07:07:21 -0800 (PST) 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=LKOl172f0szZDOK4L874N/sT6mhDzVTQVWxMqG4032M=; b=rZyzwV+RBtoqwP+TQMfADVgijTK50Tq3Ad8nb2aMJ/V25mRqdUnhawTYBXsCwa4gBG zU+uhnZ7/OsNdugePzY8dBb6eC362QQqL/T3u+jFJhzWccwTQGhOz+tA73QKrTa1Gni1 G30+kIqdr1tsbaetlk/k++yAffXImAMOTbQn7AN0p9eg1VVZ3s30ObEJauYRMGOLd739 hSCbG4+X7pm9kO3hG/NKtaWuyp/venXyVceZLyi7/tmhvsSEHY/qqIy0CmafNSp5Bk9l 8lupFkd0tItI9zlJDMwF318dq39mmhUysarHjyUvAKs72KIEkjLdvX2j4lwmKReqFtbs 0eWA== 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=LKOl172f0szZDOK4L874N/sT6mhDzVTQVWxMqG4032M=; b=d/Kb97d2YWy8MZezAp9WKNYJ8eMsqRa1EqBH8ckXSSB3NdFidKZOJlkzRFq/+jammN b7hisYKK65bAYbG/4GrnSQMq8dZK6TgsymIpzItP1RExqkXNGaO6O4/0TptjFrJt99J+ wdiTg3H+89PXwNJiIRNc/kBazkE9C/x8FsP0/qCrkeodakLVIN10wJtVU8H52zIyfV+R QuOzE5jsNdR0iBdx0z11YL4Rg2fEiyA4fFdeTiqVbjdG83Ar/tEBwbSgHbyc6Rg/sqQt hHRwzZl5g17Fbzw7kuDqqd7EUCWa0yKzE11YthcmK6L1J/KAJVSX7EeFNAKegZ8sqaJf ku7g== X-Gm-Message-State: AOAM532SnXLEQMOCAtWZqcDL/iBrmoBMElOxn+fCyeNJvnzuWvlgRPKR FRt6vPbcgUTInzY3GaOR01tHLSFbcpZt7Q== X-Google-Smtp-Source: ABdhPJwzCQpEs3FED2+SXPzDGg6UpurVsHk/l7rlgjG1CEYmw2MStGcDIa7KPi8d2ad0C/2Cdsalug== X-Received: by 2002:a1c:195:: with SMTP id 143mr22003077wmb.81.1615216039149; Mon, 08 Mar 2021 07:07:19 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:18 -0800 (PST) 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 13/30] tree-walk.h users: refactor chained "mode" if/else into switch Date: Mon, 8 Mar 2021 16:06:33 +0100 Message-Id: <20210308150650.18626-14-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-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 Mon Mar 8 15:06:34 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: 12122613 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 54B7DC4361A for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3821E6522D for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231579AbhCHPHu (ORCPT ); Mon, 8 Mar 2021 10:07:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231426AbhCHPHV (ORCPT ); Mon, 8 Mar 2021 10:07:21 -0500 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 6432BC06175F for ; Mon, 8 Mar 2021 07:07:21 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id j2so11800266wrx.9 for ; Mon, 08 Mar 2021 07:07:21 -0800 (PST) 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=FvEwz2r/CLCKi13PL9PYfULIdNAqi1HXN58Jits22SI=; b=o1LFb9MOYe6oGIy6fW9zkTN2it6a5PnoHhVYw9Gfn93LygV/n2XeexMO7vDFGgjsF6 Hx1sshegjd/qAgAefS30fvE4SD/hTt8pZSoomRxaPr3YW2TitIh2/bVL0gh+vFQ1wzD3 pqkxS2G07XUjN2kg1rDXjAIiiABD1fZKk+T8DufeG3wGEaHLFaEci6ALLyRF+izWDmOf xkCAfiqDHcFNZUNrQgIwsRaloAywLR+LbspK8mfh/qZgKt/qSMFuOURdDYov90ndUkKf m6YO8rV3s1Cj+vyUhABL+21+iAFR6dd2O2tRFeQXLYcaUH+YRcglYHJx+T/ZXKCREbnV FZyA== 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=FvEwz2r/CLCKi13PL9PYfULIdNAqi1HXN58Jits22SI=; b=Vw90OUuv4EFPe6z2SR0xrJRM1pwTDhBKpuX571TNnCwoc4/UfUn8qfhtj400k/HtKD DQc6Uq06MG7AdJJKqvzX3fp4LpxDzwgEAUEuOdanirtk5XUM310VtUgnzzGmyP9OEOW/ PM8ndXZvyoiqgIHeHF6snOPLJXVMykkzEeuRWEHQPRId7YISoORuZi5dkCEoHaj65S6N BnW6zMFn/IBeu66xkPh8mBhqnBSCljetmE64sHpazVbuEL6hww4j/NAUKYVJKHqEvFaS qWwG4nEHwVoQWm/bc/4aLrPiz/Li5zJD3h/p/zbSuQuJvdYySii633ZK44vNt5ufPACU eRkA== X-Gm-Message-State: AOAM5312JbV4zCzKGiPJriybsW/rxUhnRtz44kD/rr0ovEKXu8zjebFK UrWnZOkkmPjN1z2LHC8fMK9HFW5oiMpaRQ== X-Google-Smtp-Source: ABdhPJz2H2Lugpb9PGayn1AGfauLWQ1qlw0xc5hiJZFejYPN4fGLX2bQcxArcQcaKJvHDdevRJNwzA== X-Received: by 2002:a05:6000:11c1:: with SMTP id i1mr13216781wrx.215.1615216039801; Mon, 08 Mar 2021 07:07:19 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:19 -0800 (PST) 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 14/30] tree-walk.h users: migrate miscellaneous "mode" to "object_type" Date: Mon, 8 Mar 2021 16:06:34 +0100 Message-Id: <20210308150650.18626-15-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-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 4e91a253ac3..5a317cdd2f4 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 d3ba1d4a4a6..f92722c12d4 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 2fb483d3c08..fbe93dd2a5f 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 0a5b4fa1dbb..d631dc5623e 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 92105135522..e24302f45ba 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1297,7 +1297,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 Mon Mar 8 15:06: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: 12122629 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41C51C43603 for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2929265237 for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231589AbhCHPHu (ORCPT ); Mon, 8 Mar 2021 10:07:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231430AbhCHPHW (ORCPT ); Mon, 8 Mar 2021 10:07:22 -0500 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 35538C06174A for ; Mon, 8 Mar 2021 07:07:22 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id l12so11812717wry.2 for ; Mon, 08 Mar 2021 07:07:22 -0800 (PST) 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=I3LnH92Sz39Uu8wL08QqyaMqZLcFfLakiQuSWxmp7l0=; b=HbSgXUYLPPmJez/rcAs7mitup2oNSLpPbva7bGCEyibziLwYvV+cf0xD8x2KX5O6BV kRJFRvCn+EzndI4fdXzA2G3OyVmacOA1mAMyElHxzQjQkbwb6oUSegf+ZYIpwGbhDH9e 2ggMnYxu4uo7XYowKwBMk2Ji2rNC3wbfw+4Q7m/9rm9ZnDdOMtqAGRXd5mljELmjB2wl l0Xh2iRz4qrQliKiGrSOHstpoJSHqZYJPv3Mmpvk2WpIEEScICoC6O8EsLzJcDedPR7N KJLFPJX/890loSbpkU93qjs1SRjFQPNPuHYcHgQK3oQzIV8rbW9tO5ZHnfOTczSi8jMH 9Ehw== 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=I3LnH92Sz39Uu8wL08QqyaMqZLcFfLakiQuSWxmp7l0=; b=gA9HjvjFVrSZyrPUbdfIU0UOKLLbXdHqQXP0N7ppiZgD9xqbcpq5OyAEQ0wF36K74O gVHPFaa4DLJA/EOXzzpYpP/XMs2x4MWqtDMpdx2JtsjJn7MZTANeHFKy6CqXPq+heaYQ IdK3Xp5M4jP4qvGdTSjUuFaz2SZt64MtZLyIGqYFq469bMxjjEKyxe8d0o00H/1BpEs3 Cz10AxluuMsRwGaXqvZz43Y/n5FsYwrU4KasP0czFXw/hiqEB+WIKSWQK4i9+vABUqBH DQfufbC0QtQGeg32pLbouCfhZ+lZud+KSoGqJPADslLe0QGZb1Wgdw6HZrs5EfJ0Py/7 sllA== X-Gm-Message-State: AOAM533rwR47/SG5Cwui/4LATyprcW868GqOQYI/2W4DErcHd0wvgACL 5S9BZv/UxLO7bZPMgkcsAf0wYL5jp2kDFA== X-Google-Smtp-Source: ABdhPJzsvffD+Q+PcO3LGtIdA+m3qlLFYMe9SSuBS0fX64Id3p4emssT/eqkmzyoBOAo9NIeOqQSqA== X-Received: by 2002:adf:e482:: with SMTP id i2mr23374412wrm.392.1615216040756; Mon, 08 Mar 2021 07:07:20 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:20 -0800 (PST) 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 15/30] merge-tree tests: test for the mode comparison in same_entry() Date: Mon, 8 Mar 2021 16:06:35 +0100 Message-Id: <20210308150650.18626-16-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-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 Mon Mar 8 15:06: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: 12122607 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 DD156C15509 for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C38D36523C for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231624AbhCHPHx (ORCPT ); Mon, 8 Mar 2021 10:07:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231472AbhCHPH2 (ORCPT ); Mon, 8 Mar 2021 10:07:28 -0500 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 AE4E7C06174A for ; Mon, 8 Mar 2021 07:07:27 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id t5-20020a1c77050000b029010e62cea9deso4008006wmi.0 for ; Mon, 08 Mar 2021 07:07:27 -0800 (PST) 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=CdqmR7KLMJeWPDXFpE59QQAr6eprHl1xZmch5w6tjaY=; b=PloEV3IWxSsKoH45X8dkiU0i/DKeScgKtpTSl4kA7mTatL4wgAy9zliIwWuRlLFRQ1 dpIQgwR82RP+qkBzpnPyLmZajNLtlqioWPHV3vHRfuwk5qIrOr7JwhJHUZNdKQZpPt9m haRq1+9XQ5Du8065tVRrAeg1FzKCqLUnhJWkxTykN/7pQ2OihqOsa4GK4rrsTTr/r0Rc U1R+eFDPy8j6MGlO7fpNwd4dHY70Uvd7pOVL7MpxLH+xjkNI8eVtpgap+XiR85Qf+G9z v0KsI1qmr8woTw06m/T6gWggcONlxVSlTlouzCwx73lIicd4fJlx79mov8EsjlCt21M0 uECA== 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=CdqmR7KLMJeWPDXFpE59QQAr6eprHl1xZmch5w6tjaY=; b=mjV4/uyTWyjNV9khL9BtqF5CDrAJHSrxUICP8ZwYNBsInRr26LumwTzqVFjJY4iE3i YDolSbXWmZl8C90CwIewq45ZLBXIqh77lLCYNiXjZqpQCgTIpey5b6bUi8dk9uHzQjWo k1EzRTUb/I+s8TiUUjR9JEqcIWajBBdH9cwUqgkQrgv/GCBUWqyRTgZc3VBvvNef1Cmv oTtCnjYKJupxcf4XcEWfu2EsClqgwTwBtDea+kJ/8GXxkRIZZGnwODsaLbAMcdO6/OYO Qhj9iZ3g7dO82f+QZ2/fBQj4lGBZmcB36aTSpf14Hjh9x9Vv3ukxWqW8YH06RYJ5bQd6 CA1A== X-Gm-Message-State: AOAM532czz+behqYuuRTY6WMIwqL0EK13Ypj1M2+2yvHHN9WmnOzsIaG Ilmql+ZQzY0DEMR091oxaXOJ8Zsjvqrx8w== X-Google-Smtp-Source: ABdhPJwEYdPqcoBsCR+zd7QC/LRCSW/dK+X6pin/8rNrVNGJ1KJKCXQC5XVYFRghbxfpl7sFWT6zXA== X-Received: by 2002:a7b:c24e:: with SMTP id b14mr22736455wmj.73.1615216041436; Mon, 08 Mar 2021 07:07:21 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:20 -0800 (PST) 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 16/30] merge-ort: correct reference to test in 62fdec17a11 Date: Mon, 8 Mar 2021 16:06:36 +0100 Message-Id: <20210308150650.18626-17-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-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 4375027914c..e54be179bd5 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 Mon Mar 8 15:06: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: 12122627 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 77F31C43142 for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6144F65239 for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231598AbhCHPHv (ORCPT ); Mon, 8 Mar 2021 10:07:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230047AbhCHPHX (ORCPT ); Mon, 8 Mar 2021 10:07:23 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B0B4C06174A for ; Mon, 8 Mar 2021 07:07:23 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id e23so6250540wmh.3 for ; Mon, 08 Mar 2021 07:07:23 -0800 (PST) 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=d9klyRnnzVvknYOXub4tFfZ+7goWz26qrhIOQPJFtzA=; b=TdvKN8MMMzL9gGkFuILPJ5AuYILrg12J2wfX51TrOm2i6Yko5+ZUdB9mD2U7L+2aSb rWoXwl2cIJCwPB+jN7ZY3aYyYBLHugZIZZryYcthKFRifyJI6aeic3eg0lKWPBB3UnSR klC8BIM8MoxQAoHQFqJjKveErpHgJ77CeF7bfaHETgqLwNjLBmN58iLjddvWeWqn9jrv 5Je/FIOjTIlUPg+55opXmw0VsVdwUve9HCzKlDA8l2DWzebdwMmsrAaUTeRGFG+R/+s/ dG8EX2d6z1WEuRyKOQQ9YnGepkanyaaGTsNHx3hF/MI3ZCj14B5RHRijcKVWloCtFEWR MPwQ== 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=d9klyRnnzVvknYOXub4tFfZ+7goWz26qrhIOQPJFtzA=; b=CdkMz5MUfXOwParrlIRw16DM7x6D0RjDCi9UusWWHXwGR4A7FJr2dDeJwq0gpzkslt VBWo1R+f8vX7kdbTPBDpqzgfs46rfJMVnzBD1nQoW4nxyK4RGzyIwx676DxeLbSIVjVJ ZsL8cu+b8ILUgSx8PWEmmr9qjfd4yEkx6SCJbPr+AltH5IZRk/vJNp5rsTg6cQNK3kWM Y7IJUW7moxPy/XbvfeDf1f1IJmYRo18zprlkPTfRF6xGD4bhrxDqzNBZBC2wcKhpyA6X XKddODG28ER0RS5b7A93o4YEkzDoKgzW7mqIuvjU4qOg+2IMWoNpC0mnDMEX1IXdMHWA tTVQ== X-Gm-Message-State: AOAM531kZv0gfk1tnw1TLwZNayIA9140Nbhbx0Th5Ke9PAxfj27dy24f xSk4H3yn8IVdluPQ6ltGmyJh5vMSsrOLbw== X-Google-Smtp-Source: ABdhPJxa+w44++vHXEzvjMbqaVuI1tEKVXPH9OYPi93htS8Du5OqziVVBJ5VsRN1eIcip+7X77YNGg== X-Received: by 2002:a1c:1d82:: with SMTP id d124mr23079226wmd.1.1615216042080; Mon, 08 Mar 2021 07:07:22 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:21 -0800 (PST) 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 17/30] fsck.c: switch on "object_type" in fsck_walk_tree() Date: Mon, 8 Mar 2021 16:06:37 +0100 Message-Id: <20210308150650.18626-18-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-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 Mon Mar 8 15:06: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: 12122603 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 9073FC4361B for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 718F76523C for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231592AbhCHPHu (ORCPT ); Mon, 8 Mar 2021 10:07:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231458AbhCHPHY (ORCPT ); Mon, 8 Mar 2021 10:07:24 -0500 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 75F4BC06174A for ; Mon, 8 Mar 2021 07:07:24 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id u14so11831341wri.3 for ; Mon, 08 Mar 2021 07:07:24 -0800 (PST) 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=xEYmLds7rR17cu6aeuDbhLhcc4SY6dic/WOmyGpLhEw=; b=I5hC8sFBrYnbFMFcGP3fnhwhh52XFgR0RnUFh5RPCS/EeP4J6n37pg1jWvvYP8ZZ4g 8PZKrJ1ZAXDd6fiv4QTwRS/Xu6c28RG+5Pcnrcv3Mh2f7TopPYXBd7kunLFlCaJmrU4/ 0tO0Zpg1g/0zCbcQ7YWzZArOfi53CWcR/Yew5iz3GHNWy5irNeKQ7N+QYH5X9jrQm8Hh vExPMGUnIv4iqXtDygabilM59U8dYw5alVDTqQDvgegeMix58W1IwO+Lt7Z3LeosgBNc S/rNPvk6wG5vfeuggH+R0ggYVXiZhyVELmTKd4NTHMbP9HwZq7zv5Vr+5bfFvh4NV18G Poqg== 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=xEYmLds7rR17cu6aeuDbhLhcc4SY6dic/WOmyGpLhEw=; b=WpDU8tErcj8QbL3OMawuLfZ4o6jhMc5dOrZydM1jxydtSaF8F48e5gWlqzqvfIIsVV EWc/IzSikjYAxSBu7RWO58qlT+sBULtkpc12PZNARIyhzAAxRYQvgCWnJgQxpU1la5az MXOLAKjfaDccbF4Lb9pA+ac2FqATcgt37SSp15Dv9Qv7PU2e6sAwC+qZ+l0H9MA4CJaZ 5b+dfiWW28CFHjY5DM94USlouxd8fevT1e6Hl+2SoNI877ax2N7Ng74y3mS0EPcsK68e oAZ5uY2C+bJbhap99BfquEQOZG9ZuY9Ml7+aj0TfcRFh2zkEjgtXDWsj5Y4H69oCI1CM 5X5A== X-Gm-Message-State: AOAM532wL9DGG/4c6yH5BLjSQV+qxcXixY1EyqV9eZrVU0/RAfFkd6ws FXGLQGipcK5K90qG63DjYoIWInGRJqTW+g== X-Google-Smtp-Source: ABdhPJy7DqBHxty8TIGd1MSD9EzAHJlviG97q1WUT7gVu38dcKMdsdRK1lszUdMbElJAGoxp1bug4g== X-Received: by 2002:a5d:6304:: with SMTP id i4mr22885650wru.155.1615216042838; Mon, 08 Mar 2021 07:07:22 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:22 -0800 (PST) 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 18/30] tree-walk.h users: use temporary variable(s) for "mode" Date: Mon, 8 Mar 2021 16:06:38 +0100 Message-Id: <20210308150650.18626-19-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-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 4d124a0fd1b..07159172b63 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 e54be179bd5..cad10436504 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 d631dc5623e..688d03ee9cd 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 f133834597c..f145ff84c68 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 e24302f45ba..9471c19de72 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1020,8 +1020,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 Mon Mar 8 15:06: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: 12122625 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 B8BD7C1550B for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9BAB86523C for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231605AbhCHPHv (ORCPT ); Mon, 8 Mar 2021 10:07:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231464AbhCHPHZ (ORCPT ); Mon, 8 Mar 2021 10:07:25 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CEE1C06174A for ; Mon, 8 Mar 2021 07:07:25 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id d15so11824544wrv.5 for ; Mon, 08 Mar 2021 07:07:25 -0800 (PST) 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=w+QpdmLliqbSLlapaOlfBFBxLUjIso5zyUbCIrHEZxE=; b=eNXlkHAQOkgzZHSmnsuWKG7kYPa7Ox/DDl8wlZra7UiicqyhabQBWNMpDkRe2co9qV fOb/XFTCw+EZMS7JYxhJPrD49c3eXtb5AFo2qPwD/Y7bRWmKva0db7so5VUuSu8E3dKl H/E8EEubM/+xsZMNdYbtSYwjGT+Yq/4//KQxfcSr5U1xjz4ba9Gj6REB/uH4/35IfHz8 m4IY6nOLHpK+ZS9Vgnyei+vTTgd/lUR57rtni9/WPggx99nzLeh5GzCNZzpEP/+jOvDj s31Dsk0K8bMDeXQ3uOpm2OEeBmedsg/E3v3w/r2zHLM5F5T6ljXRY4PF64vMCjNKnQDF 1XmQ== 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=w+QpdmLliqbSLlapaOlfBFBxLUjIso5zyUbCIrHEZxE=; b=amQdJ8KM6zwnMv1sFS6I8Fc3Izcq4YDtKFCd10NS8xaZ1spHQZdv88MLthClIqmEhz 6zgCKUVhz4CSutL4eEEhnXGwqcV0Dc0MUmNq63fntTvDnG0rOMOP1QpkENWlbuwdHi4z 1/wAR2l/l2SvXiFV6z06USkIxpuSz/M0mwolcfzxvhj8FWiZwMHjFYvcXYL0sa63W5t/ /PQcQHRE+blB62pvs/AYe1iLcsuV4thNH7xZmFMch9Ts63cHxhLhqpEkZ3sPiyD4U2bb iGF6gT47V3Xkk1JZh1/EJcWJtBWMrh4D9cEgWfRA8NwBVU0upx9ilmurpEuF4ciIHel2 k+mg== X-Gm-Message-State: AOAM532vtSO1wRBARwP+KnUp6irD0s4czxTwrHVhBCA/yeSGo3IpNYfr eVgh3lpoi8FGaGj8CLywewIZHpmD1TeWeQ== X-Google-Smtp-Source: ABdhPJzKYrSzfwlqqV9EBLASW6e1irJ3fEDzfl9Mcfig4VS/6xkcNuURLXRd2vfnT8hx4L55ckdVvg== X-Received: by 2002:a5d:6989:: with SMTP id g9mr6627209wru.198.1615216043857; Mon, 08 Mar 2021 07:07:23 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:23 -0800 (PST) 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 19/30] tree-walk.h API: formatting changes for subsequent commit Date: Mon, 8 Mar 2021 16:06:39 +0100 Message-Id: <20210308150650.18626-20-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-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 a5044fcfaa6..83babc41d08 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 Mon Mar 8 15:06: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: 12122605 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 A012CC15500 for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 869A265239 for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231610AbhCHPHw (ORCPT ); Mon, 8 Mar 2021 10:07:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231463AbhCHPH1 (ORCPT ); Mon, 8 Mar 2021 10:07:27 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF68AC06174A for ; Mon, 8 Mar 2021 07:07:26 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id u5-20020a7bcb050000b029010e9316b9d5so1049930wmj.2 for ; Mon, 08 Mar 2021 07:07:26 -0800 (PST) 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=qu8iuIYeJv5nYaKU4/3+43N0tKqKBTwCkwyks30anok=; b=If0KjIePBeEUxRlLeqPflWlb3ob84HLW6zo+my96oRozSr1YEIxC5UdhxWcBGpwwaE QG7NAfcEFUXe9iXZu/56+o3dRHT4UvZL9SY5mJK6Dt/miz+pyWUohj6yZJG84S3qD2Vq j9qUL0C4VkOCNkij93RyyVM98bRWE0VdWtMEjhoEcYMA8DErQtj7pOj5uf2OqNqK084Q j12O2NKvP+aM4c6xOrkndPtgp1NjXlqXsrEulNbk9000sJBocrflU7s5sT+8tn1n17kA tPKbpDiXOxQE3plNF0D/4Z48YUkyOQmurxpYSKeW7rPM55D7Op7tecYGvh08zE6ooxOG vGZw== 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=qu8iuIYeJv5nYaKU4/3+43N0tKqKBTwCkwyks30anok=; b=hHT2QwBQuacmqat1hO2Rk6JK6rbQ+0Q3/WXRXZAwqIz68UJcOMPd2ab+cVsMMDqb2c 6nRxIHJbQD1pblc0QdMTK0bAv9bkDxIFv1fbsakvgMlcQ/3UFtmVeFHoAxvhV3wpLLOs 7Y7sPRqtoGMFsOtw4LeRfIkFBXK75ILPkE5XMvT7CGE/uM1UYCYUxTxwwxz9ru8LQ0d1 /viSiP+QP9Q0YDgQPRPn1PaCe+s158HlhXj6A8mJBovgWtMVTcwPjVuo6EMcruP4jiPR BKfD+d6q9VQuIQw2i1k1Zq0suTI8nChTbikxCLtRkSk5lG/cQFTiKRYdVOZjnq/0V9Av 3J3w== X-Gm-Message-State: AOAM533SFJscUeqriDNSVVdfEnG4qq+5CmLJ9A2BIkmHagPgFQFsqBWg Y4bsRD29ABd7wCJ0x30/KFHt1BV8mq2lWQ== X-Google-Smtp-Source: ABdhPJyL1EWV/SG0/z6/8fXTaLCsuYxmm7k3dAhzgsE7ZtJaAALA0n0LWzrD5u+f+svo3FRd81DVkw== X-Received: by 2002:a05:600c:4a06:: with SMTP id c6mr14521163wmp.35.1615216045194; Mon, 08 Mar 2021 07:07:25 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:24 -0800 (PST) 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 20/30] tree-walk.h API: rename get_tree_entry() to get_tree_entry_mode() Date: Mon, 8 Mar 2021 16:06:40 +0100 Message-Id: <20210308150650.18626-21-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-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 64abe736f93..95fa759e1fb 100644 --- a/archive.c +++ b/archive.c @@ -482,10 +482,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 83babc41d08..9e0543e13d4 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 75c8b1acfff..4790dda4607 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 07159172b63..ba4aabf39d1 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 31c080538ef..0e891360e7e 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); } /* @@ -2541,11 +2541,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 688d03ee9cd..ef138606146 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 Mon Mar 8 15:06: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: 12122597 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 EEAD9C4161F for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D8A1A6521F for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231614AbhCHPHw (ORCPT ); Mon, 8 Mar 2021 10:07:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231478AbhCHPH2 (ORCPT ); Mon, 8 Mar 2021 10:07:28 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 042D0C06175F for ; Mon, 8 Mar 2021 07:07:28 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id t5-20020a1c77050000b029010e62cea9deso4008028wmi.0 for ; Mon, 08 Mar 2021 07:07:27 -0800 (PST) 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=BpFPlFlIgNAfFpcUypYtSrDBnDDqPXCmux7wqklUOjw=; b=oArmSk9TBlEU6Qafbf0hlR/JTtSoK3sCF5eUHI3iDE+IBGUsfiUnw/GN/56ZJ2dset RYL6wbAIiaa3VXEtdQf34110iozSFB3Re4uzczl2dTHzZ5OIPUXnczRfeZLPHEWhE88q B9jgCZo5WNpksLPusXuSaieQTcQh1bpF2dOmg+m1HZ/LRwJXmIliDPEkZaiD0FFswgAN uAl3yd1hmMInhIpDOxpz/hi+3jPbdPOFBmgEuNXW8CvXQe0m5NNVOpEW396BgPxlSScw PHfAdXvhTzJOS/ZnIzqNRsMJy5kLhMvq6RwiMXWbL1s8bBrl0WkAQFw5HyZAr9f6kgzO eDPQ== 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=BpFPlFlIgNAfFpcUypYtSrDBnDDqPXCmux7wqklUOjw=; b=otxWf97gASFUcdKJGRmb+vzuVW0hRngbPvmlTOsl3ZdBh91FoaP6iRr3bI8hK4Z2Fg GOgGQLmwRopWCBaBRtuqpCLnoHbIJaDCLjsLJ5ICYmZFYcLziTCVw8O02bUf/lQodmzh 8e0kzVvtDBDOpwHktmJtQVCDmcmmc/H96+h5IVnxpdVadeDTIX3xTpLPYfMxCaplkbS5 FdFqBUrDcbKoggrI9EYKl3fissgjizZNiW/2V0woLB2TfqA66Jed80EqcBf2u44FY2c+ gsKxSZJ+cwhDoONCQ94UxZcLOFbr9FbeAdtOBcd1dC8Cz3GULrNKlZs5K3152JUb+j2X oi+A== X-Gm-Message-State: AOAM53369621Hy0qitidHGCcXkpR6cvGvLcVxv+TdnNab2qVsR6UuCSQ 2o3cw0pMHohqHX1L6/hPS07QtJV+Qh2LIQ== X-Google-Smtp-Source: ABdhPJxW72ZSTmLtxZiwXDxkFRsPqhV3Y57wuZjzdh+MahhMcl56dlZkGbCOGGlKHtbP1AUa3TeC1A== X-Received: by 2002:a1c:c282:: with SMTP id s124mr22226269wmf.99.1615216046520; Mon, 08 Mar 2021 07:07:26 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:25 -0800 (PST) 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 21/30] tree-walk.h API users: use "tmp" for mode in shift_tree_by() Date: Mon, 8 Mar 2021 16:06:41 +0100 Message-Id: <20210308150650.18626-22-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-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 ba4aabf39d1..4f02768c01e 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 Mon Mar 8 15:06: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: 12122611 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 C8856C4160E for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2BB065239 for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231626AbhCHPHx (ORCPT ); Mon, 8 Mar 2021 10:07:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231481AbhCHPH3 (ORCPT ); Mon, 8 Mar 2021 10:07:29 -0500 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 DEBC4C06174A for ; Mon, 8 Mar 2021 07:07:28 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id l12so11813138wry.2 for ; Mon, 08 Mar 2021 07:07:28 -0800 (PST) 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=a5OeElF/8X9lUyQkP6jxwNcmAHpV4bwil/IYKEq2SJ8=; b=pRiRdsTS8DkNAKnhua1A+ZhfdfkBy0GaISBuT6qJCJ7GUcQEjG96LWO/HK5a3EZYHN ipUnlWHU3rQnqmLjNyZUotmc86SD9caCHmb6/XaCfaYV33gAkRBzYKBkT5K5OmmTSU5S czm56lMuBtXKafGGIEIdYh8g/XIOo5O+FbI8j29Jld5ziI5anqLXaM3B9JWsu8zEGBad jtPHk9uFMVvQiuwknmxk8UgNAqOoTBf+I8roVcs+pKry8thkODcA+6GHLlQLfXVO3TRB Pj/LyrGlt1zqwhPiuPhdw30ug0mX8H1YTxdNhTUQvxxYHehDWylaFZb2MdolU7eUFKDm j1RQ== 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=a5OeElF/8X9lUyQkP6jxwNcmAHpV4bwil/IYKEq2SJ8=; b=b/Bn3s/mQ3xzrLzA2QsA+WL5RTTJZwXHvbg1s3LBlTrqk/5H2KoncvPwuqc0UAdo7L y60Fxo+4sJBvTV1cMOQZj427UZtKqQmtfiNBwizId884Tu6Q6YUlLCG1OXWIazmORaJb glP6q8A/fbjBUw0niv8IhKkV+0nro2sdxgs4rJImJOjMrg5uq4m/SiPB1n253qeIET0U QS2izkK+OdeBWoZ/xTc8RS6hdLSQipuCMSL1HEbXHdRBdy0t2hbb3LfPCQ73Dydz1mxd nhF7OmI8+lt6uCcHhbhPOAkOAMz/Vr8rkFfSjGCjg+lkZpEqC1QinhHlBDjFAEmjR87z j/4g== X-Gm-Message-State: AOAM533FX7ne+N9Y4OBtv3NIokcF2nh3hvfuD6xdyjyb8HRFp6zJms1Q fV/jdoQBu69Ir6FCS2Q5uIYyzgaFFl7GwQ== X-Google-Smtp-Source: ABdhPJzju3Wu5Kr/ch2Za/GfI8x8ZYmfTpcWdX5l6qGQjgjG7CA9/zCCyGMj/2p02UoQR6cxsJlxtQ== X-Received: by 2002:adf:b1c9:: with SMTP id r9mr23815888wra.51.1615216047340; Mon, 08 Mar 2021 07:07:27 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:26 -0800 (PST) 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 22/30] tree-walk.h API: Add get_tree_entry_type() Date: Mon, 8 Mar 2021 16:06:42 +0100 Message-Id: <20210308150650.18626-23-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-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(). 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 it. Signed-off-by: Ævar Arnfjörð Bjarmason --- archive.c | 8 ++++---- blame.c | 8 ++++---- match-trees.c | 10 +++++----- tree-walk.c | 47 ++++++++++++++++++++++++++++++++++++----------- tree-walk.h | 15 +++++++++++++-- 5 files changed, 62 insertions(+), 26 deletions(-) diff --git a/archive.c b/archive.c index 95fa759e1fb..bc8f1c7546f 100644 --- a/archive.c +++ b/archive.c @@ -479,14 +479,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/blame.c b/blame.c index 9e0543e13d4..4944582dc3c 100644 --- a/blame.c +++ b/blame.c @@ -101,11 +101,11 @@ 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); + enum object_type object_type; + int ret = get_tree_entry_type(r, commit_oid, path, &blob_oid, + &object_type); - if (!ret && oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB) + if (!ret && object_type == OBJ_BLOB) return; } diff --git a/match-trees.c b/match-trees.c index 4f02768c01e..ce3f811ec04 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..0ad3d80593e 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -561,7 +561,8 @@ struct dir_state { 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 +586,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) +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 +626,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 +698,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 +776,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..5db38fcb575 100644 --- a/tree-walk.h +++ b/tree-walk.h @@ -171,12 +171,23 @@ 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 to 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 + * 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 *, unsigned short *); +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 Mon Mar 8 15:06: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: 12122615 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 3BDDCC1550D for ; Mon, 8 Mar 2021 15:08:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1C9276523C for ; Mon, 8 Mar 2021 15:08:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231629AbhCHPHx (ORCPT ); Mon, 8 Mar 2021 10:07:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231484AbhCHPHa (ORCPT ); Mon, 8 Mar 2021 10:07:30 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 188EBC06174A for ; Mon, 8 Mar 2021 07:07:30 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id n11-20020a05600c4f8bb029010e5cf86347so2889581wmq.1 for ; Mon, 08 Mar 2021 07:07:30 -0800 (PST) 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=ZtqTatYVCXnVJXxjymt/1n44U2yhdYmydkzTPyVBlaQ=; b=dzGzh+99qEH8Qe412R6JAD0x7sfAbHrsmuOGuFAqvj/9uHhai6CBSuMmeAfCXm1Be+ lISoAaRw/LJX4xF1XyQdk+KePEPAjnKEDQyJZELX3uyuPvDdHDcKVjMfzMwKFFYYl04q MmyvOG1ACh39sAcWDHYivgx+rBnu91qIcFx80RcEwXQ05XGD3In5vRRAGOlqheqpVNQ7 m1XUtHOSFhnP/jRc9mBHbCmg5gBX3hUriPHrg3E8R2yZTw7M/au/gs5g1P0T05/C4nqT w3G68D1dwfMtfse8QIGCI5aRkx8q87iiAhxlTGbK+UOYHPVBvoMI/+f4NYVCFoFPjhRJ 0xyw== 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=ZtqTatYVCXnVJXxjymt/1n44U2yhdYmydkzTPyVBlaQ=; b=pgQBOS04+0pTPeMfsBi4JhzIsYoP7CKhVxB76Sf/QlFo4rwNT1zhPs595fZ7gneJAw LuMiEeIaW/+4gGAm49xAhCTuAB+ZdT03KJ5wSlHWSfdZdhkHGQDt6cDdyJ0SaJnddfmj k4Qi4t3upFAyoIgqMMFv+3KDwfAqDzAuvHd3cRY3mFPC6nP5YyTMnVAfdezNKvSfnZj/ 2mi/FCtWXI8HPEvt+qSnImlcVchuoQ5ShfilurYdRKgK0iFR9EVlgQi+nkXgTNZof1ZQ cWSOJ7CkFXiwMef9s/KrclyfttYJoX3tfVYhVbQOZ6U/GLMG587LfhFzQRS+xQiKJg2G CPkw== X-Gm-Message-State: AOAM5307hjlJnxZSAU2RpS3+K0TnNZP7TFr49mh/LfiM4DLRcyzIVohh ceoJMVLuZ62k4Xk1eUI+XdTiT9Qmuqy/8w== X-Google-Smtp-Source: ABdhPJzffId8v97ez3kT7lIk72imsEi+0JttBZNjZVy9O2ShDt54ABnRoNl1eZuCN+iciRHsrlVZjw== X-Received: by 2002:a05:600c:204f:: with SMTP id p15mr22797261wmg.165.1615216048562; Mon, 08 Mar 2021 07:07:28 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:27 -0800 (PST) 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 23/30] tree-walk.h API: add a get_tree_entry_path() function Date: Mon, 8 Mar 2021 16:06:43 +0100 Message-Id: <20210308150650.18626-24-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-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's callers here which doesn't need the "struct object_id" filled either, and provides a throwaway variable for us. See the following commits for the introduction of such code that's being modified here: - shift_tree(): 68faf68938e (A new merge stragety '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 ce3f811ec04..60a17b92d70 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 0e891360e7e..b26d9d418f9 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 ef138606146..aa46cb2b09e 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 0ad3d80593e..83737634770 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 5db38fcb575..1bfa839b275 100644 --- a/tree-walk.h +++ b/tree-walk.h @@ -175,10 +175,13 @@ struct traverse_info { * "struct name_entry" you'd like. You always need to 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 Mon Mar 8 15:06: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: 12122599 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 1B0CBC1550C for ; Mon, 8 Mar 2021 15:08:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 047CB65240 for ; Mon, 8 Mar 2021 15:08:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231633AbhCHPHy (ORCPT ); Mon, 8 Mar 2021 10:07:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231486AbhCHPHb (ORCPT ); Mon, 8 Mar 2021 10:07:31 -0500 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 5A6DAC06174A for ; Mon, 8 Mar 2021 07:07:31 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id l12so11813271wry.2 for ; Mon, 08 Mar 2021 07:07:31 -0800 (PST) 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=Gsch7+D5XioVjRaPI/HDT9iSBwQKY5WoWjqpMCIafvw=; b=LOCgLeHUtxildwKM260p2Qbl6wGCRilA7FP3DhAICl+qowPAKkiVd0Xh8tAvOOx1Fn LQfgW2gAE9M/Ya7V6DjoHgoMhdo3RgnJTzS8NxY4JRXaB8ElWRAM7htbwSwq+Bo8vbJH 3S1FbKUwdVBpa7kyTcqg0BjHHtzoQ/RXLanowKhJQHV2hyCm3/RyFo47tE8QLd2vp+WQ /vDK0fts9cijsxYFGY+df+kb5c1PBbNP1Q5K47+SipMc8sTuWFxnwa9mSYyUEKDOpZAa GyVG3ZVwD6Xffsxqw+6pq7UavvdfTY40CAHsOC9R1mck2+DTRg4eAaRIClXpNN2pM5vu R/Kw== 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=Gsch7+D5XioVjRaPI/HDT9iSBwQKY5WoWjqpMCIafvw=; b=ovxPW7K9YD0dNnbd6ssVbNz+LqwDvZAjehw+kbwG7FU7l/ZFvVCeVzDUv/3KcHcSNM vjX+NRaddLc6hE5w3od36kl8V6ud5qQWl0fYx8mMft8rTrirqT2sMcVJ4ag219iPniTN 01DxYcjfid5gh+3zn1sy/w034opVvekLu15OJ2g8gXu6piYKr0PKZAAad0jPvuBCBaB3 p0voKzC15w3TnsfE3eldQ7j5BZ6Fc78tbCcZkltqOo9DRKNxsPUYKAvDekOYTmbxcY8w 5PG+v/ANNi1gGsHvbTMvUb2HM7ngfjBVpMcpX/rC1l81LPDTJrcX/AaDbQbQueAOHUvz jl4Q== X-Gm-Message-State: AOAM532JRnjuqp+ksYZsuxW6aw2PJQw0BVausN3+TZF3dwuF2OM6nfo4 WTD1oJRkP/0vAlYB6gsQ7E24VWBtOzdQXQ== X-Google-Smtp-Source: ABdhPJygLQqKfk4ar8Wh3zx5qkK3F3Mj/0r7N58v49y40chmkHJh+ZikWWADjMM0ZhxSoz8l8YoC1w== X-Received: by 2002:adf:ee92:: with SMTP id b18mr22164711wro.275.1615216049802; Mon, 08 Mar 2021 07:07:29 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:28 -0800 (PST) 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 24/30] tree-walk.h API: document and format tree_entry_extract() Date: Mon, 8 Mar 2021 16:06:44 +0100 Message-Id: <20210308150650.18626-25-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-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 1bfa839b275..61fdcb166d2 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 to 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 Mon Mar 8 15:06: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: 12122609 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 08E49C41620 for ; Mon, 8 Mar 2021 15:08:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E96106523C for ; Mon, 8 Mar 2021 15:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231638AbhCHPHy (ORCPT ); Mon, 8 Mar 2021 10:07:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231355AbhCHPHc (ORCPT ); Mon, 8 Mar 2021 10:07:32 -0500 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 3E685C06174A for ; Mon, 8 Mar 2021 07:07:32 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id 124-20020a1c00820000b029010b871409cfso3998831wma.4 for ; Mon, 08 Mar 2021 07:07:32 -0800 (PST) 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=1fiENbx5A1ZdSUENVW/qmNIfg0o5M0pzIzvtxMQYsSk=; b=Rj5cNHnObfFUqVI5f2aWKamHFQHsSTMmHWPPMNxJ3l28wHSq/IJJ2g3Yks32mIw5Od 1TYq42vTu6cxWJuhQ267trqHc8NwPyxKyEECs7089EH/oDrYRKta3ZwAEjnkvTbKe412 AZUK266AvBmXk0+3qIVKmRprrwCwE4uSEVBE4QRQnsbUtDgVCh7BThhb+IwuvCiQez6L qWvfdr8Z+I3rSAHXC3JQOZHODmYWMQo6rQzPZKivRUpHcJ7orwoKuQvDfOVdN+klJrkN 7E7JJUnjYzjvtXeI2EmInwK5uDNRsA2u5R+yG1Sh+DE57QVasA4YFPB9pljT4U1iO8Gr 4lWw== 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=1fiENbx5A1ZdSUENVW/qmNIfg0o5M0pzIzvtxMQYsSk=; b=addT496qecNBoNxbcNW7UfVYBDrXTJneqgsDPcCyElEoKmdHsNz/NY8TtDU0zHbDqz BKh708Rrgdg8CT/rNCLV+QtkJXaE2i/qoaCdvEKLlqTKmINYf4O/ErrLIT9ypOb4MGIk cPoSUDaoEVYqqzN8YqLZB/FZBJgQrAoZMfS2o0pbhoSOduA116wuOS5rogOPvzeviQT9 4AX5NR4f0AjTDp9tBPrVwBXu2s6V18jkZUtJ2894jcTnADEg4Diai/i64G4Gh/cFeWVZ isEGFu7BPPVN8Yy3hicNc0gKeoggj1WWrqxnXkMku3wrxiveC4InHc0wi6kJYkw0tkGW 5QrQ== X-Gm-Message-State: AOAM532UwJKZWytdWi9FFvNIQJveHEMlJmV1gQLZUfgamJa+4RRjZiNN J24cYe9qmgB0p0OAp851K8ttMZptfVmwKg== X-Google-Smtp-Source: ABdhPJzm/s/vNfpFr3P4YTviIq3dq5pnUO39ExAGAKFH7TDdFaMMUxTpvJ4xmA4OswxEubt258+gAA== X-Received: by 2002:a05:600c:49aa:: with SMTP id h42mr23260791wmp.49.1615216050785; Mon, 08 Mar 2021 07:07:30 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:30 -0800 (PST) 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 25/30] tree-entry.h API: rename tree_entry_extract() to tree_entry_extract_mode() Date: Mon, 8 Mar 2021 16:06:45 +0100 Message-Id: <20210308150650.18626-26-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-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.c | 2 +- tree-walk.h | 6 +++--- 5 files changed, 9 insertions(+), 9 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 60a17b92d70..3d2c74a44ac 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 f145ff84c68..b37348b7908 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.c b/tree-walk.c index 83737634770..e613f273767 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -570,7 +570,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_mode(t, &entry, mode)); entrylen = tree_entry_len(&t->entry); update_tree_entry(t); if (entrylen > namelen) diff --git a/tree-walk.h b/tree-walk.h index 61fdcb166d2..892e77eda23 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 Mon Mar 8 15:06: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: 12122617 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 62E2EC1550E for ; Mon, 8 Mar 2021 15:08:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3C69B65239 for ; Mon, 8 Mar 2021 15:08:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231643AbhCHPHz (ORCPT ); Mon, 8 Mar 2021 10:07:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231303AbhCHPHd (ORCPT ); Mon, 8 Mar 2021 10:07:33 -0500 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 F3C22C06174A for ; Mon, 8 Mar 2021 07:07:32 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id h98so11773468wrh.11 for ; Mon, 08 Mar 2021 07:07:32 -0800 (PST) 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=gj0D29LoGXgZ+tn506ngmF7+nhvhhWboLN/+rqA0wBM=; b=JOEIC9/8MUY9eh5Ye5Lr5UdzsJpV/ofeMca5ij08z+jvTcj8Xfwa6Mph5FHTHgQJw4 ZddI9sfd4g066pLiEGanrl5nYlV9ls97UNq6CMwluEFlJaPXc0tyVbEaFECUVbIg+m9T m70i1wEQS+uycT48JNQNsypYjGwh1Q/FkzGTH7gXF+EXzSjmzP3ahOzY1yKl6V6FDsk3 bsUR3WryWpu315MkD1Q4huKy15UiQ7VNtqs10jTMFU37Dze8h8m6wD6dmpBz6kJ0ZcmA Epzjrt0r7zWNyvTcUWbunrX9Gzl0Qbvsewg9CVch6JC3Vz88fCksAD4To6XRxYqPetAO 5gnw== 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=gj0D29LoGXgZ+tn506ngmF7+nhvhhWboLN/+rqA0wBM=; b=q99v5p6Le1S+Tqs0aYYEWK4yAVxheFDfWfvF0GGH1lrF7dwM3/iKF7RbbaMqbYtPgL FLoUEeN3Y4a3o01z52fITCqaauDZ9l270ZBtTTw8zIrEcIai1bdpwasenPRU7CEKsiOi HbRG0VsvnYf7nPEjce7MSnkFfiCaN7x6z8k8K6ipNuHEIbTJZqN6Kf3K9gVzkhaMhvdL 3J0AGY8BGMkwqCy0hQaP40/cyY1++6qWQdzWwcNqG+izYehIrwmW0zd32VgK2EA8JnkL 1bdUrWf9G4mSNUf+fANT0au37GDRz9eXdkOH6A0A+UgtPn0Uu76W56XyWDP8wM6BItJu pU1g== X-Gm-Message-State: AOAM530F0PG04j99oR9JZHIPZHa+yHeNptpgRJF77uO+6IDFnh1po4Tk CIYyh+17yg90oX/SO0sgm1cj9p6t7o3KNA== X-Google-Smtp-Source: ABdhPJxvDYt4JxkOS1QqdRm23d49cRJaaXnJcuIm3RNweHgUJbzq/b99x9D9mBA4SeNE7QoibWACGA== X-Received: by 2002:a5d:64ac:: with SMTP id m12mr23016121wrp.138.1615216051471; Mon, 08 Mar 2021 07:07:31 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:31 -0800 (PST) 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 26/30] tree-walk.h API: add a tree_entry_extract_all() function Date: Mon, 8 Mar 2021 16:06:46 +0100 Message-Id: <20210308150650.18626-27-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-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 --- builtin/update-index.c | 6 ++++-- tree-diff.c | 5 +++-- tree-walk.c | 3 ++- tree-walk.h | 12 ++++++++++++ 4 files changed, 21 insertions(+), 5 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-diff.c b/tree-diff.c index b37348b7908..b25095c1164 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 e613f273767..12e0ed4e250 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -570,7 +570,8 @@ static int find_tree_entry(struct repository *r, struct tree_desc *t, struct object_id oid; int entrylen, cmp; - oidcpy(&oid, tree_entry_extract_mode(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 892e77eda23..06ad40ab2f1 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 Mon Mar 8 15:06: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: 12122633 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 553A2C433E0 for ; Mon, 8 Mar 2021 15:08:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2BCDB6521F for ; Mon, 8 Mar 2021 15:08:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231648AbhCHPHz (ORCPT ); Mon, 8 Mar 2021 10:07:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231490AbhCHPHe (ORCPT ); Mon, 8 Mar 2021 10:07:34 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D87A6C06174A for ; Mon, 8 Mar 2021 07:07:33 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id 124-20020a1c00820000b029010b871409cfso3998865wma.4 for ; Mon, 08 Mar 2021 07:07:33 -0800 (PST) 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=KFeEOmsFZJPbSy/QcU7L4jdMb/+AWwLbq9RwsyCQvX8=; b=FP9YDo7DqMuAa6e5YRPnuUgbLZX2SA0KLoCPqoRB711eWpI2Cqy2RH2Vh9F2iyustH xNtg/s7A4Ulo6SVLyfM7W6XqaRcKINv9ESr4NgEx8LbI8Rzhg9s9TgFchC0/xQsc7pgF LrFREml+Pq3i6iMNlxhjXnJBWHp2LJdMBY8ZdOFD/42jGZ9mohfYGSMp8meDRcEJMay8 Shk/H2mUgQsJHWB7Aco1NywxuJBjePR+jX0Ha5hCC3FhM09hLIotirUUSt4GAC6nk2eE 43C29xhSKz1Vs8fYrxDbLhl1yd8cd0tReMzUznSy55kPf/mvsbEGzpE2HnAjDueqQBlt TNyQ== 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=KFeEOmsFZJPbSy/QcU7L4jdMb/+AWwLbq9RwsyCQvX8=; b=oa+EcCBTu11VRMIS/iCMqh4XYj8SoUfyL6v28/cBr5Mo9KOa9EUgLVQ1YEiyHe/v9R NDQTwk14SFTVN+P8RRSVNnOAJOmJDsUVwGLQEeLUYS0514RGRIpHTgUvCaeOBf9YjF9O bi4eM+GuP6HrTLCnpmt184vdUyN9I3boZ0WZsNWAyHdUNXqLTvM/JdgNkxVRixSUMFkQ cmgL0py53wZw82PDQL+bhAakA2YNyMkmNkpgQ0ndcszTFXdMNXm36xDb956ucnbntt1D 6BilFlA9vwu1eSVhAJSfXMvW7R1IYNRcAJXo1nt9HrwLMN2UW8kCC+US504+1P37Hw09 0CaA== X-Gm-Message-State: AOAM532nK8pSI3ZBG2gRWnHDvJZL6ntQrQ0WLDEwf2V4ZD8xQj+hgwtK cdpSthPtHfFJI45IZNZF7qov86pf1g8N9A== X-Google-Smtp-Source: ABdhPJx8jytEdIs+Qpsx2wue+KvFsAvH+xoMjCrzcmU59ZxQzOA5Hxap2zXthyibXY7Dle7T34cyFw== X-Received: by 2002:a05:600c:2301:: with SMTP id 1mr23253533wmo.36.1615216052331; Mon, 08 Mar 2021 07:07:32 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:31 -0800 (PST) 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 27/30] tree-walk.h API: add a tree_entry_extract_type() function Date: Mon, 8 Mar 2021 16:06:47 +0100 Message-Id: <20210308150650.18626-28-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-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 3d2c74a44ac..0636f6e58e9 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 b25095c1164..10c92d39c42 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 06ad40ab2f1..1f69e57db4c 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, From patchwork Mon Mar 8 15:06: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: 12122621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B5FAC41518 for ; Mon, 8 Mar 2021 15:08:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4BAC765237 for ; Mon, 8 Mar 2021 15:08:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231659AbhCHPH4 (ORCPT ); Mon, 8 Mar 2021 10:07:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231494AbhCHPHf (ORCPT ); Mon, 8 Mar 2021 10:07:35 -0500 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 F0032C06174A for ; Mon, 8 Mar 2021 07:07:34 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id b18so11816423wrn.6 for ; Mon, 08 Mar 2021 07:07:34 -0800 (PST) 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=eZqHk5KMJvfunVnzQodCfjZPBsAadG4w4oVKXWOkCf0=; b=RC/uj0e2tKk2GktRt4RiPJcQd8FVUek/BTZbnKz62tZ7/Hebb7j2t2PVWZAb7QxfXU VduJQQBugQ1dFyjruS7m0xNLfRV1EC0FAFU91E0bSiALpYAE0pQmOLnPGWxP1CZ5nPUj 5rtc3aoCCv3apwOrbEhHpKVjceJTh8oTpQR1l+qTmTEYpSkR2X+jpaJ7xJkNMG1/bCU0 7VvOeM+ZYcdrzxyjZgoG/16SErPbIrti54ymM/sAPPibVXz3X0gyuS23EY6dCO/hp8Az +GeXj1rmFtkM6efFkvNXZhIUmZLoFj+0H/gxfhQkPzgN9SAhLk9B12ILo2wvtezqehrB A/ww== 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=eZqHk5KMJvfunVnzQodCfjZPBsAadG4w4oVKXWOkCf0=; b=FAmKy/cJXo+Y6ADDnYarN88pE8ulYGH80t1fsCEXFFOSmzNbtQ+xBQvrkT6eHfMR87 21LqkUN2Nguu21WkGzOjjxd99tHaGg7+AgU3mJzOLmfbk5XJssADUDvccY33x4M9AKN1 lEAtBRFetkjKs86pWhSZnuLAR0WheM2cJWfAnNM5nsPIJUTylLBWZDX+gD7N888JoQcB UazTmLqEMJJV1vTRPnCUo2mBcCpbDSNKNDI/WafQmGk1asrjz/ckJF+P8OxKlSmKMWRN Zt8y+cW34FtwdhABIqZ+w914LZV1yvo6ZXBX/oqxwyRfTO+KGcpW+51AaQj2G8m1msNy JPgw== X-Gm-Message-State: AOAM530BVAMHLL2PsdZpDyCVC+qM2WOhWhWXl+WMrPKlgz3VXpiqKOWL CSX0SR9ycAvNrOpvJANOgv2jYBiAq3jd1Q== X-Google-Smtp-Source: ABdhPJwKEXUXF2qQiouchlMJQnytPdpfX56A9i5FfDqSq5es/KdKNrreBEi02AO7u2QYNFoWXwzMKw== X-Received: by 2002:adf:8341:: with SMTP id 59mr22554152wrd.130.1615216053068; Mon, 08 Mar 2021 07:07:33 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:32 -0800 (PST) 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 28/30] tree-walk.h API users: rename "struct name_entry"'s "mode" to "raw_mode" Date: Mon, 8 Mar 2021 16:06:48 +0100 Message-Id: <20210308150650.18626-29-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Now that most of the users of the "mode" variable have been moved to use "object_type" instead let's rename it to "raw_mode" in preparation for a revert of 7146e66f086 (tree-walk: finally switch over tree descriptors to contain a pre-parsed entry, 2014-02-06). This will allow API users who care about the actual mode bits in tree objects to get access to them, such as fsck, the merge algorithm etc. But most users will not want to have such potentially un-sanitized, so let's indicate that by giving the variable a more scary name. I am not renaming the variables being assigned to, i.e. it's now going to be "int mode = entry.raw_mode", not "int raw_mode = [...]". This is because we're going to be getting a sanitized "mode" via "canon_mode()" in many of these functions soon, so renaming the local variable back and forth will result in needless churn. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/merge-tree.c | 8 ++++---- match-trees.c | 4 ++-- merge-ort.c | 12 ++++++------ notes.c | 2 +- tree-diff.c | 22 +++++++++++----------- tree-walk.c | 2 +- tree-walk.h | 6 +++--- tree.c | 2 +- unpack-trees.c | 6 +++--- 9 files changed, 32 insertions(+), 32 deletions(-) diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index eec5b906561..b4e736e4b72 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -160,7 +160,7 @@ static int same_entry(struct name_entry *a, struct name_entry *b) return !is_null_oid(&a->oid) && !is_null_oid(&b->oid) && oideq(&a->oid, &b->oid) && - a->mode == b->mode; + a->raw_mode == b->raw_mode; } static int both_empty(struct name_entry *a, struct name_entry *b) @@ -197,9 +197,9 @@ static void resolve(const struct traverse_info *info, struct name_entry *ours, s return; path = traverse_path(info, result); - orig_mode = ours->mode; + orig_mode = ours->raw_mode; orig = create_entry(2, orig_mode, &ours->oid, path); - final_mode = result->mode; + final_mode = result->raw_mode; final = create_entry(0, final_mode, &result->oid, path); final->link = orig; @@ -252,7 +252,7 @@ static struct merge_list *link_entry(unsigned stage, const struct traverse_info path = entry->path; else path = traverse_path(info, n); - link_mode = n->mode; + link_mode = n->raw_mode; link = create_entry(stage, link_mode, &n->oid, path); link->link = entry; diff --git a/match-trees.c b/match-trees.c index 0636f6e58e9..d45c76ffa79 100644 --- a/match-trees.c +++ b/match-trees.c @@ -86,8 +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; + unsigned int one_mode = one.entry.raw_mode; + unsigned int two_mode = two.entry.raw_mode; if (one.size && two.size) cmp = base_name_entries_compare(&one.entry, &two.entry); diff --git a/merge-ort.c b/merge-ort.c index cad10436504..ea20bbe2af3 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -502,7 +502,7 @@ static void setup_path_info(struct merge_options *opt, mi->basename_offset = current_dir_name_len; mi->clean = !!resolved; if (resolved) { - mi->result.mode = merged_version->mode; + mi->result.mode = merged_version->raw_mode; oidcpy(&mi->result.oid, &merged_version->oid); mi->is_null = !!is_null; } else { @@ -512,7 +512,7 @@ static void setup_path_info(struct merge_options *opt, ASSIGN_AND_VERIFY_CI(ci, mi); for (i = MERGE_BASE; i <= MERGE_SIDE2; i++) { ci->pathnames[i] = fullpath; - ci->stages[i].mode = names[i].mode; + ci->stages[i].mode = names[i].raw_mode; oidcpy(&ci->stages[i].oid, &names[i].oid); } ci->filemask = filemask; @@ -545,7 +545,7 @@ static void add_pair(struct merge_options *opt, 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; + unsigned int mode = names[names_idx].raw_mode; one = alloc_filespec(pathname); two = alloc_filespec(pathname); @@ -616,13 +616,13 @@ static int collect_merge_info_callback(int n, unsigned side1_null = !(mask & 2); unsigned side2_null = !(mask & 4); unsigned side1_matches_mbase = (!side1_null && !mbase_null && - names[0].mode == names[1].mode && + names[0].raw_mode == names[1].raw_mode && oideq(&names[0].oid, &names[1].oid)); unsigned side2_matches_mbase = (!side2_null && !mbase_null && - names[0].mode == names[2].mode && + names[0].raw_mode == names[2].raw_mode && oideq(&names[0].oid, &names[2].oid)); unsigned sides_match = (!side1_null && !side2_null && - names[1].mode == names[2].mode && + names[1].raw_mode == names[2].raw_mode && oideq(&names[1].oid, &names[2].oid)); /* diff --git a/notes.c b/notes.c index aa46cb2b09e..2817325651a 100644 --- a/notes.c +++ b/notes.c @@ -478,7 +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; + unsigned int mode = entry.raw_mode; for (i = 0; i < prefix_len; i++) { strbuf_addch(&non_note_path, *q++); strbuf_addch(&non_note_path, *q++); diff --git a/tree-diff.c b/tree-diff.c index 10c92d39c42..df8301d806a 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -232,7 +232,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p, * tp[i] is valid, if present and if tp[i]==tp[imin] - * otherwise, we should ignore it. */ - int tpi_valid = tp && !(tp[i].entry.mode & S_IFXMIN_NEQ); + int tpi_valid = tp && !(tp[i].entry.raw_mode & S_IFXMIN_NEQ); const struct object_id *oid_i; unsigned mode_i; @@ -245,7 +245,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p, if (tpi_valid) { oid_i = &tp[i].entry.oid; - mode_i = tp[i].entry.mode; + mode_i = tp[i].entry.raw_mode; } else { oid_i = &null_oid; @@ -283,7 +283,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p, FAST_ARRAY_ALLOC(parents_oid, nparent); for (i = 0; i < nparent; ++i) { /* same rule as in emitthis */ - int tpi_valid = tp && !(tp[i].entry.mode & S_IFXMIN_NEQ); + int tpi_valid = tp && !(tp[i].entry.raw_mode & S_IFXMIN_NEQ); parents_oid[i] = tpi_valid ? &tp[i].entry.oid : NULL; } @@ -404,7 +404,7 @@ static inline void update_tp_entries(struct tree_desc *tp, int nparent) { int i; for (i = 0; i < nparent; ++i) - if (!(tp[i].entry.mode & S_IFXMIN_NEQ)) + if (!(tp[i].entry.raw_mode & S_IFXMIN_NEQ)) update_tree_entry(&tp[i]); } @@ -465,10 +465,10 @@ static struct combine_diff_path *ll_diff_tree_paths( * mark entries whether they =p[imin] along the way */ imin = 0; - tp[0].entry.mode &= ~S_IFXMIN_NEQ; + tp[0].entry.raw_mode &= ~S_IFXMIN_NEQ; for (i = 1; i < nparent; ++i) { - unsigned int mode = tp[i].entry.mode; + unsigned int mode = tp[i].entry.raw_mode; cmp = tree_entry_pathcmp(&tp[i], &tp[imin]); if (cmp < 0) { imin = i; @@ -480,12 +480,12 @@ static struct combine_diff_path *ll_diff_tree_paths( else { mode |= S_IFXMIN_NEQ; } - tp[i].entry.mode = mode; + tp[i].entry.raw_mode = mode; } /* fixup markings for entries before imin */ for (i = 0; i < imin; ++i) - tp[i].entry.mode |= S_IFXMIN_NEQ; /* pi > p[imin] */ + tp[i].entry.raw_mode |= S_IFXMIN_NEQ; /* pi > p[imin] */ @@ -497,14 +497,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; + unsigned int mode = tp[i].entry.raw_mode; /* p[i] > p[imin] */ if (mode & S_IFXMIN_NEQ) continue; /* diff(t,pi) != ø */ if (!oideq(&t.entry.oid, &tp[i].entry.oid) || - (t.entry.mode != mode)) + (t.entry.raw_mode != mode)) continue; goto skip_emit_t_tp; @@ -536,7 +536,7 @@ static struct combine_diff_path *ll_diff_tree_paths( /* ∀i pi=p[imin] -> D += "-p[imin]" */ if (!opt->flags.find_copies_harder) { for (i = 0; i < nparent; ++i) - if (tp[i].entry.mode & S_IFXMIN_NEQ) + if (tp[i].entry.raw_mode & S_IFXMIN_NEQ) goto skip_emit_tp; } diff --git a/tree-walk.c b/tree-walk.c index 12e0ed4e250..099a9b3bd77 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -48,7 +48,7 @@ static int decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned l /* Initialize the descriptor entry */ desc->entry.path = path; mode = canon_mode(mode); - desc->entry.mode = mode; + desc->entry.raw_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 1f69e57db4c..885ced74258 100644 --- a/tree-walk.h +++ b/tree-walk.h @@ -16,7 +16,7 @@ struct name_entry { struct object_id oid; const char *path; int pathlen; - unsigned int mode; + unsigned int raw_mode; /* simple 'mode': Only OBJ_{BLOB,TREE,COMMIT} */ enum object_type object_type; }; @@ -55,7 +55,7 @@ static inline const struct object_id *tree_entry_extract_mode(struct tree_desc * unsigned short *modep) { *pathp = desc->entry.path; - *modep = desc->entry.mode; + *modep = desc->entry.raw_mode; return &desc->entry.oid; } @@ -75,7 +75,7 @@ static inline const struct object_id *tree_entry_extract_all(struct tree_desc *d enum object_type *object_typep) { *pathp = desc->entry.path; - *modep = desc->entry.mode; + *modep = desc->entry.raw_mode; *object_typep = desc->entry.object_type; return &desc->entry.oid; } diff --git a/tree.c b/tree.c index e4402fad69b..215d17e1295 100644 --- a/tree.c +++ b/tree.c @@ -40,7 +40,7 @@ static int read_tree_1(struct repository *r, } switch (fn(&entry.oid, base, - entry.path, entry.object_type, entry.mode, context)) { + entry.path, entry.object_type, entry.raw_mode, context)) { case 0: continue; case READ_TREE_RECURSIVE: diff --git a/unpack-trees.c b/unpack-trees.c index 9471c19de72..dcdf8130745 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -867,7 +867,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask, newinfo.pathspec = info->pathspec; newinfo.name = p->path; newinfo.namelen = p->pathlen; - newinfo.mode = p->mode; + newinfo.mode = p->raw_mode; newinfo.pathlen = st_add3(newinfo.pathlen, tree_entry_len(p), 1); newinfo.df_conflicts |= df_conflicts; @@ -1020,7 +1020,7 @@ 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; + unsigned int mode = n->raw_mode; ce->ce_mode = create_ce_mode(mode); ce->ce_flags = create_ce_flags(stage); @@ -1209,7 +1209,7 @@ static void debug_path(struct traverse_info *info) static void debug_name_entry(int i, struct name_entry *n) { printf("ent#%d %06o %s\n", i, - n->path ? n->mode : 0, + n->path ? n->raw_mode : 0, n->path ? n->path : "(missing)"); } From patchwork Mon Mar 8 15:06: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: 12122623 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 76065C15510 for ; Mon, 8 Mar 2021 15:08:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6054A6523F for ; Mon, 8 Mar 2021 15:08:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231655AbhCHPHz (ORCPT ); Mon, 8 Mar 2021 10:07:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231504AbhCHPHf (ORCPT ); Mon, 8 Mar 2021 10:07:35 -0500 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 45B21C06175F for ; Mon, 8 Mar 2021 07:07:35 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id e10so11774712wro.12 for ; Mon, 08 Mar 2021 07:07:35 -0800 (PST) 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=a0WhpeKVinvDVZW2Pgr4IK7FFj6o05fXWt1Qooe4/5Y=; b=EojScPcseCuI5ewT5DEau2KJ30z8UY/kB0q1yk9Mzg/4JHWeR223c68z3nX4nw841P MWJIxDRlh38yO9J+1p+6XZnJ0V1EBEFQD0HJazf3dDw1Cwc2AMS4T9v47eHH7Ml4b6u7 NSJ146kmhH/Btz1XOu1VbGouDSmS5xmW0Bc9t3ZYJL40MZ6b6TsMDTzNhSUGBG8hMrcj NKS/n3PnE5srA1FqTelq9BJMEUukBQ6+Ng9BnhR2fkiAzkt49UB2kr2R22O8Axy4yVoW MWdJ4BJHt96nODt00GEIAq4C2imxDO0btfdBOlvVOl2363AlQjDFtoHNqqFx7PsLXdjH zBqw== 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=a0WhpeKVinvDVZW2Pgr4IK7FFj6o05fXWt1Qooe4/5Y=; b=W2OAzUDmvpQWUSzoHZXq2OzqqTFr19GbiuhhXMDpiXimXJABA3MJGCsQQScVCuA82R 0CjWM9dsg5uz4BXzQxiJh2u5OwmsYYWxwDGynVHFwHWe+63TRacxSjTj9P8WRtHnIv2x y088nmIrJ3usa5P5O7ig7OZHXQBcWptiL/PqrxBHB4uM/52LSgMJeeQJBiWPgw0vYLy4 +bOOsab9Aq3qNJxSMuezQ+MXU0VJfWgTR0tKNRHeZut9boNXweXTA6KntgyRn9EfY8bJ N//qRbhQEFmuoQiDviIDYAbHGQ17F92GpNuZ/nR/ZCdwYo7fq3BSi27bYgCu4X4gqA0i Sw/Q== X-Gm-Message-State: AOAM530RT14IkeKflvf+MdxXnaqlcBOGPPk1nfDxcDj6xSOQ8qQuwvCp cArda1NdcMqViP9vvJq3fQfCidVxTelyXQ== X-Google-Smtp-Source: ABdhPJxyzl5DxOqtF/MJs2T78os/ocJb4nTySH4qh+0tXQeAjza94sE80v2zla9CzEd32Hld8Tuqjg== X-Received: by 2002:a5d:6602:: with SMTP id n2mr23729501wru.262.1615216053765; Mon, 08 Mar 2021 07:07:33 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:33 -0800 (PST) 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 29/30] tree.h API users: rename read_tree_fn_t's "mode" to "raw_mode" Date: Mon, 8 Mar 2021 16:06:49 +0100 Message-Id: <20210308150650.18626-30-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Rename the "mode" variable passed to read_tree_fn_t callbacks to "raw_mode". This variable comes to us from the tree-walk.h API. By renaming this variable we can easily see where its downstream users are in a subsequent commit where we'll sprinkle some canon_mode() here. Signed-off-by: Ævar Arnfjörð Bjarmason --- archive.c | 5 +++-- builtin/log.c | 2 +- builtin/ls-files.c | 11 ++++++----- builtin/ls-tree.c | 6 +++--- merge-recursive.c | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/archive.c b/archive.c index bc8f1c7546f..5b85aae8106 100644 --- a/archive.c +++ b/archive.c @@ -232,10 +232,11 @@ 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, - enum object_type object_type, unsigned mode, + enum object_type object_type, unsigned raw_mode, void *context) { struct archiver_context *c = context; + unsigned mode = raw_mode; while (c->bottom && !(base->len >= c->bottom->len && @@ -382,7 +383,7 @@ struct path_exists_context { static int reject_entry(const struct object_id *oid, struct strbuf *base, const char *filename, - enum object_type object_type, unsigned mode, + enum object_type object_type, unsigned raw_mode, void *context) { int ret = -1; diff --git a/builtin/log.c b/builtin/log.c index 19a916221d5..c3ef1b3e22d 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -599,7 +599,7 @@ 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, - enum object_type object_type, unsigned mode, + enum object_type object_type, unsigned raw_mode, void *context) { FILE *file = context; diff --git a/builtin/ls-files.c b/builtin/ls-files.c index f38df439410..391e6a9f141 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -425,10 +425,11 @@ static int read_one_entry_opt(struct index_state *istate, const struct object_id *oid, struct strbuf *base, const char *pathname, - unsigned mode, int opt) + unsigned raw_mode, int opt) { int len; struct cache_entry *ce; + unsigned mode = raw_mode; if (S_ISDIR(mode)) return READ_TREE_RECURSIVE; @@ -447,12 +448,12 @@ 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, - enum object_type object_type, unsigned mode, + enum object_type object_type, unsigned raw_mode, void *context) { struct index_state *istate = context; return read_one_entry_opt(istate, oid, base, pathname, - mode, + raw_mode, ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK); } @@ -462,12 +463,12 @@ static int read_one_entry(const struct object_id *oid, struct strbuf *base, */ static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base, const char *pathname, - enum object_type object_type, unsigned mode, + enum object_type object_type, unsigned raw_mode, void *context) { struct index_state *istate = context; return read_one_entry_opt(istate, oid, base, pathname, - mode, + raw_mode, ADD_CACHE_JUST_APPEND); } diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index c6ec3ca751e..3f84603d391 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -63,7 +63,7 @@ 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, - enum object_type object_type, unsigned mode, + enum object_type object_type, unsigned raw_mode, void *context) { int retval = 0; @@ -103,11 +103,11 @@ static int show_tree(const struct object_id *oid, struct strbuf *base, "%"PRIuMAX, (uintmax_t)size); } else xsnprintf(size_text, sizeof(size_text), "-"); - printf("%06o %s %s %7s\t", mode, type, + printf("%06o %s %s %7s\t", raw_mode, type, find_unique_abbrev(oid, abbrev), size_text); } else - printf("%06o %s %s\t", mode, type, + printf("%06o %s %s\t", raw_mode, type, find_unique_abbrev(oid, abbrev)); } baselen = base->len; diff --git a/merge-recursive.c b/merge-recursive.c index b26d9d418f9..30fbe72ca06 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, - enum object_type object_type, unsigned int mode, + enum object_type object_type, unsigned int raw_mode, void *context) { struct path_hashmap_entry *entry; From patchwork Mon Mar 8 15:06: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: 12122631 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F3E9C1550F for ; Mon, 8 Mar 2021 15:08:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 71A666521F for ; Mon, 8 Mar 2021 15:08:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231675AbhCHPH4 (ORCPT ); Mon, 8 Mar 2021 10:07:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231512AbhCHPHg (ORCPT ); Mon, 8 Mar 2021 10:07:36 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A601C06174A for ; Mon, 8 Mar 2021 07:07:36 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id 124-20020a1c00820000b029010b871409cfso3998954wma.4 for ; Mon, 08 Mar 2021 07:07:36 -0800 (PST) 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=gJLudztODFKzoIhgtxZ28nICKp+MPrebrA5U6dRSsmw=; b=dz9gLElDp8IUO9WJ7M5huyK6Rp7m7PCdTRW90x17OkBabju7yFoFSl31ffY/3ton0V eEhFWSJbSSkNzerGDyak7sk4PVmAorbvv2MKJzHpuuAY1iy1yIxnCG+dvctN/wrF5N/u TRlZQ/0qBrT4LJt3Emo5IKd6TwsWNOBWRl2dJmV6H7DXxxiJp2Jt3WbLIGVqUiys+kJP VBE24OdfUMTkBJLs7oZgevymwyaPg3GhYD2NUCKnHDnQ+VgYD3jlTzG6KSw+Pb8dp4z6 0Zb/TO/sViOLMRTZAZZMYyVMkIoqNp1MKPkXYp0T0UalIiN2nwvD1IrUTVMziShANZBJ Xozw== 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=gJLudztODFKzoIhgtxZ28nICKp+MPrebrA5U6dRSsmw=; b=LY+Itlp4Pq3GokhslOlqlQL4tetu+I4UR3sF+/JPvw1WJKvP5OCh1/BuCUgFQAqJoF bL5ANNEujkaiivfKWraTP/Qwv5LzSRizWxnB4bcsyM+s+N1ogzDY7aXL3ggdVplzj9jM NlKIFGMSGCmUixSWca4VupLJTFFON5HyIcgy9z0SIJDI6QuKaFqH78eYI02ajAdpcb5e hDD9A/iCQjusDCgl6KRJRjQSmM86fPcHUln7QdUARIEZ6CU1UIcsWyfcABQ+wpC0pdQq DiYKz1Tiko1WsT00u+CKmgoL5CCwlijBFUvSpnHjpIRYDTzrYNgGoYW4xC1s6AFtqwop f8xA== X-Gm-Message-State: AOAM532zaVW6JD6g+dt+SBh/OoJBcoUuhPNMzuhzxG0ytIdPK+Kvzsnp g35BOuBpOtl5zzrjqSL/QpwaOqVT7XQDNg== X-Google-Smtp-Source: ABdhPJz4u2pT54X7xcPcN+WLRI0U//PYah5hNHIBHteI8tGThrmigVgzDJd0aYp2CmcwYZUNUD3RpQ== X-Received: by 2002:a1c:4802:: with SMTP id v2mr23077311wma.139.1615216054548; Mon, 08 Mar 2021 07:07:34 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j13sm3820488wrt.29.2021.03.08.07.07.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 07:07:34 -0800 (PST) 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 30/30] tree-walk.h API: move canon_mode() back out of decode_tree_entry() Date: Mon, 8 Mar 2021 16:06:50 +0100 Message-Id: <20210308150650.18626-31-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.rc0.126.g04f22c5b82 In-Reply-To: <20210308022138.28166-1-avarab@gmail.com> References: <20210308022138.28166-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move the canon_mode() call back out of decode_tree_entry(), and instead make it the responsibility of its callers to canonicalize the tree modes we get. This effectively reverts 7146e66f086 (tree-walk: finally switch over tree descriptors to contain a pre-parsed entry, 2014-02-06), with the recent of most callers away from "mode" (now "raw_mode") towards "enum object_id" in recent commit the motivation for that commit effectively doesn't exist anymore. I.e. I'm not adding the canon_mode() call back to tree_entry_extract(), instead it's now become sane to move this responsibility to those callers that still care about the "raw_mode". That change was meant as a pure optimization change, but it actually introduced a subtle bug. We were left without any low-level API to get non-standard mode bits out of trees. Having non-standard modes isn't the norm, and fsck should warn about it. Except after 7146e66f086 it couldn't anymore, since the modes fsck_tree() got would be pre-sanitized for it. I believe that fsck issue is per-se a serious bug, the "bad mode" was a default warning, not an error. This change makes that fsck check work again, why aren't there any test changes for fsck here? Because we didn't have a test for that fsck feature in the first place, which is why the regression in 7146e66f086 snuck by us. A follow-up commit will add such a test. It is possible that this commit is introducing some subtle regression that I've missed. We are now propagating the "raw_mode" outside of everything downstream of decode_tree_entry(), which is everything we have that decodes trees. It's our most low-level tree decoding API. As shown here we rely parsing out a "raw" (and possibly something fsck would complain about) mode as-is, but when we run merge, add something new to the index, create an archive etc. we don't want to propagate that bad mode when we create new data. We want to canon_mode() it. I'm also pretty sure that we don't have good enough test coverage for those scenarios. We barely have tests for these bad mode bits at all (not even one for fsck). We definitely are not testing all merge/index/archive etc. interactions. Still, I think this change is worth it overall, because: 1. We must have a way to get at these raw modes in some way, even if just for fsck. There's also other things that care, see e.g. the FIXME comment in 62fdec17a11 (merge-ort: flesh out implementation of handle_content_merge(), 2021-01-01) 2. #1 is not a justification for this change, I could have e.g. just added the ability to pass some "want_raw" flag into decode_tree_entry() for use in fsck. But I think with the migration of most tree iteration towards "enum object_type" it's become worth it. 3. Yes our test coverage sucks, but before 7146e66f086 we were also spreading what's now the "raw_mode" all over the place. That commit was first released with Git v2.0.0 in mid-2014. A while ago for sure, but most of this code existed in something approximating its current form then. This isn't new territory. Signed-off-by: Ævar Arnfjörð Bjarmason --- archive.c | 2 +- builtin/checkout.c | 1 + builtin/ls-files.c | 2 +- builtin/merge-tree.c | 6 +++--- builtin/update-index.c | 1 + merge-ort.c | 13 ++++++++++++- notes.c | 1 + tree-walk.c | 1 - unpack-trees.c | 4 +++- 9 files changed, 23 insertions(+), 8 deletions(-) diff --git a/archive.c b/archive.c index 5b85aae8106..8083f15f3ba 100644 --- a/archive.c +++ b/archive.c @@ -236,7 +236,7 @@ static int queue_or_write_archive_entry(const struct object_id *oid, void *context) { struct archiver_context *c = context; - unsigned mode = raw_mode; + unsigned mode = canon_mode(raw_mode); while (c->bottom && !(base->len >= c->bottom->len && diff --git a/builtin/checkout.c b/builtin/checkout.c index d4adfdb5046..7f25b955616 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -132,6 +132,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base, memcpy(ce->name + base->len, pathname, len - base->len); ce->ce_flags = create_ce_flags(0) | CE_UPDATE; ce->ce_namelen = len; + mode = canon_mode(mode); ce->ce_mode = create_ce_mode(mode); /* diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 391e6a9f141..926523d77a7 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -429,7 +429,7 @@ static int read_one_entry_opt(struct index_state *istate, { int len; struct cache_entry *ce; - unsigned mode = raw_mode; + unsigned mode = canon_mode(raw_mode); if (S_ISDIR(mode)) return READ_TREE_RECURSIVE; diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index b4e736e4b72..f8733a86eb7 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -197,9 +197,9 @@ static void resolve(const struct traverse_info *info, struct name_entry *ours, s return; path = traverse_path(info, result); - orig_mode = ours->raw_mode; + orig_mode = canon_mode(ours->raw_mode); orig = create_entry(2, orig_mode, &ours->oid, path); - final_mode = result->raw_mode; + final_mode = canon_mode(result->raw_mode); final = create_entry(0, final_mode, &result->oid, path); final->link = orig; @@ -252,7 +252,7 @@ static struct merge_list *link_entry(unsigned stage, const struct traverse_info path = entry->path; else path = traverse_path(info, n); - link_mode = n->raw_mode; + link_mode = canon_mode(n->raw_mode); link = create_entry(stage, link_mode, &n->oid, path); link->link = entry; diff --git a/builtin/update-index.c b/builtin/update-index.c index b489a876392..1996fdd97af 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -621,6 +621,7 @@ static struct cache_entry *read_one_ent(const char *which, memcpy(ce->name, path, namelen); ce->ce_flags = create_ce_flags(stage); ce->ce_namelen = namelen; + mode = canon_mode(mode); ce->ce_mode = create_ce_mode(mode); return ce; } diff --git a/merge-ort.c b/merge-ort.c index ea20bbe2af3..d1e8a2823e0 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -502,7 +502,7 @@ static void setup_path_info(struct merge_options *opt, mi->basename_offset = current_dir_name_len; mi->clean = !!resolved; if (resolved) { - mi->result.mode = merged_version->raw_mode; + mi->result.mode = canon_mode(merged_version->raw_mode); oidcpy(&mi->result.oid, &merged_version->oid); mi->is_null = !!is_null; } else { @@ -512,6 +512,16 @@ static void setup_path_info(struct merge_options *opt, ASSIGN_AND_VERIFY_CI(ci, mi); for (i = MERGE_BASE; i <= MERGE_SIDE2; i++) { ci->pathnames[i] = fullpath; + /* + * We must not use canon_mode() here. Will + * fail on an the is_null assertion in + * 6a02dd90c99 (merge-ort: add a preliminary + * simple process_entries() implementation, + * 2020-12-13) when combined with the tests in + * "[PATCH 00/11] Complete merge-ort + * implementation...almost" (see + * https://lore.kernel.org/git/pull.973.git.git.1614905738.gitgitgadget@gmail.com/) + */ ci->stages[i].mode = names[i].raw_mode; oidcpy(&ci->stages[i].oid, &names[i].oid); } @@ -546,6 +556,7 @@ static void add_pair(struct merge_options *opt, int names_idx = is_add ? side : 0; const struct object_id *oid = &names[names_idx].oid; unsigned int mode = names[names_idx].raw_mode; + mode = canon_mode(mode); one = alloc_filespec(pathname); two = alloc_filespec(pathname); diff --git a/notes.c b/notes.c index 2817325651a..78b1b38d36b 100644 --- a/notes.c +++ b/notes.c @@ -479,6 +479,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, const char *q = oid_to_hex(&subtree->key_oid); size_t i; unsigned int mode = entry.raw_mode; + mode = canon_mode(mode); for (i = 0; i < prefix_len; i++) { strbuf_addch(&non_note_path, *q++); strbuf_addch(&non_note_path, *q++); diff --git a/tree-walk.c b/tree-walk.c index 099a9b3bd77..3175430d049 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -47,7 +47,6 @@ static int decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned l /* Initialize the descriptor entry */ desc->entry.path = path; - mode = canon_mode(mode); desc->entry.raw_mode = mode; desc->entry.object_type = object_type(mode); desc->entry.pathlen = len - 1; diff --git a/unpack-trees.c b/unpack-trees.c index dcdf8130745..2fb346714b3 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -868,6 +868,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask, newinfo.name = p->path; newinfo.namelen = p->pathlen; newinfo.mode = p->raw_mode; + newinfo.mode = canon_mode(newinfo.mode); newinfo.pathlen = st_add3(newinfo.pathlen, tree_entry_len(p), 1); newinfo.df_conflicts |= df_conflicts; @@ -1020,7 +1021,8 @@ 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->raw_mode; + unsigned int mode = canon_mode(n->raw_mode); + mode = canon_mode(mode); ce->ce_mode = create_ce_mode(mode); ce->ce_flags = create_ce_flags(stage);