From patchwork Fri Feb 10 10:28:34 2023 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: 13135651 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD46DC636D3 for ; Fri, 10 Feb 2023 10:28:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232024AbjBJK26 (ORCPT ); Fri, 10 Feb 2023 05:28:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232013AbjBJK2x (ORCPT ); Fri, 10 Feb 2023 05:28:53 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4FBF47402 for ; Fri, 10 Feb 2023 02:28:51 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id o15so1279979wrc.9 for ; Fri, 10 Feb 2023 02:28:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZUDG+FAg6dNgJrZyVZNRFENNI5v6z5zIgFmf9KfvVfI=; b=JGBbyVGeSGYLeVqvVbtF78RUrKMW6kHSsC1yAY/yy7RMwvF9kAR7zxtRuzaQE4T+K1 LZDCCAvt9b2r3AxN1vLmx8Wk+63ZZPkD7YyqEklbTWGPE6UV0/g7AZIckuhjvMfJplnr SdnFtRScnchNwV8RZW0+NoVsG4NeBmjhmbCkFbgTzHnI53bCbaBua8zSJ4svbLKHhmP+ rJRr90lWb4S4+PNOidjsvgDeJe55dMKh2sb+qx9i4bed3BoSMm/H9cw7Oek4IaVnaI9f 3hkwR1yh72R4laZkYvIbQPJ3ga/+t7dDnktVlfW5o7COdSNRzqyCv992MHwiDhL4uNVP VOqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZUDG+FAg6dNgJrZyVZNRFENNI5v6z5zIgFmf9KfvVfI=; b=d+oQXeg1NhZFUXo7uLJ2dyyNKC5zsnr8jQdxtZLmnGzAgQgPeMdvO0G8t1sZcV1QWj MW9GJs0k0Geh4ZOCyhZLVMLdT7QoGFfD81CQKW5aAV1m6fBwvHAadLmJ5dqiweyupyoY ku1d0YFayMkNeT6CbqY/m1hE9DdcvceU9fYO36ebwuwOfRfcI+F5z+pta01q3oPIMEgv sZy5RgZc3yEkMnHRN3XIqBbBcU+YqsSa9vAUj53a4eNaxpPnHhv2QjX2V2hRvngX0kzc 8SyAWrZ3+XhirRJjNe2syn462nxcCl1dbT6HEVDSgaNL/G6TKEKSLH+A2FYSpF9RCKng H7Hw== X-Gm-Message-State: AO0yUKXFyItKUbUVtBAo9ZzxQn9muDPINYL0lFsed+6VGm73BIIJARxt ZXqkiuNHbMl2S3oyjg2NSC7EFcuuK5JVWb+j X-Google-Smtp-Source: AK7set8FvfIw2zfCsODkFmCtdzLjWn3sE9bn099NIdQEWrV7o0Cm9I3tvaQ6RtfSBVYHoflS0bNYZg== X-Received: by 2002:a05:6000:1c1d:b0:2c5:4c9f:cf3b with SMTP id ba29-20020a0560001c1d00b002c54c9fcf3bmr8940wrb.7.1676024929564; Fri, 10 Feb 2023 02:28:49 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u13-20020a5d514d000000b002c3f50228afsm3244792wrt.3.2023.02.10.02.28.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 02:28:48 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 1/6] builtin/rm.c: use narrower "USE_THE_INDEX_VARIABLE" Date: Fri, 10 Feb 2023 11:28:34 +0100 Message-Id: X-Mailer: git-send-email 2.39.1.1475.gc2542cdc5ef In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Replace the "USE_THE_INDEX_COMPATIBILITY_MACROS" define with the narrower "USE_THE_INDEX_VARIABLE". This could have been done in 07047d68294 (cocci: apply "pending" index-compatibility to some "builtin/*.c", 2022-11-19), but I missed it at the time. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/rm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/rm.c b/builtin/rm.c index 4a4aec0d00e..8844f906557 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -3,7 +3,7 @@ * * Copyright (C) Linus Torvalds 2006 */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "advice.h" #include "config.h" From patchwork Fri Feb 10 10:28:35 2023 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: 13135652 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C2CAC05027 for ; Fri, 10 Feb 2023 10:29:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232040AbjBJK3A (ORCPT ); Fri, 10 Feb 2023 05:29:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232018AbjBJK24 (ORCPT ); Fri, 10 Feb 2023 05:28:56 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF12971645 for ; Fri, 10 Feb 2023 02:28:52 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id h16so4553642wrz.12 for ; Fri, 10 Feb 2023 02:28:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=irGsXh5R8IOMD1vCH2Z1Uvc85DMxsNHpIsfoMDdO7KI=; b=C0+djIfeet00Ey3c6smjVHgulsGXyaPKPite8V0Rmf2mXe+2FBCosfuGmlmwpRYwxD J1nnTGagKsd5WHCT67n90lrASeKqmxhUpOpNyV1sjb9LPotybIB+RNCtfIotjsQ3AdML ttXye6LT1E8rq/j2V0A/9Ik6jq+yW0TQOBaPfVhmwaBVmVn8ExnNVARKmWaJNSQVhpzz hWxjlIoesy0L83gNHBRi7x3OGWr7PurIQRzO1ZhYlCFHh5VwlhPvLke3YCQCknBYYRCA IPGlPp3+BR1cFfprM2uBrZNKZ9pjCSy6JRN34KdS9SvMARgX9ognDytzJZpSMoR5oiev pz8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=irGsXh5R8IOMD1vCH2Z1Uvc85DMxsNHpIsfoMDdO7KI=; b=f8IRqLHS6TqLLSSUEIdDf3bhhirJyx4B95gLDxSkY2KTvwv7RW0UhFWTSz687yulTh h077LPlfCyeqmJw2lGxE4N6N7dS/XyqwpAjWjmNLAsC8iGP/Qv+AC05SKATjvI8LCM2q DFruFNbKpYRum/ld4QIHAFOYMmUmQcpg8XeOMnp6q7jkMCMJ+Zgklh/altITpZrHqVPG zM/bIpnAdrkVo8nBMz/fpO501/UAmJ9JRKNHQ++OLOJcxoCakjorVo7fCkPPE0+YYSGm 9ew1v0Dl7SPwN3AICeAE9ZUb5FKv/GvBeSzPQyuYFv/SbkVU506uE5VL01/vlUGepYxK 4Gjg== X-Gm-Message-State: AO0yUKVn/Cb/ynHEucbKcg3DpHQ8qj/iMQUR2h5gKm/Uz4f5zrCAsmST sY+l7f8VioeSRnkazvBgPR3ZkFi7QkmVqIT/ X-Google-Smtp-Source: AK7set9W/0v7t0elAnUq2kjSH8HzVxORMPrucVytA4NrIh/ZRkDmI8S9eKWlBTeJffX97KqqglfCXQ== X-Received: by 2002:adf:dd82:0:b0:2bf:b199:c7eb with SMTP id x2-20020adfdd82000000b002bfb199c7ebmr13380799wrl.54.1676024930714; Fri, 10 Feb 2023 02:28:50 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u13-20020a5d514d000000b002c3f50228afsm3244792wrt.3.2023.02.10.02.28.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 02:28:49 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 2/6] cocci & cache.h: fully apply "active_nr" part of index-compatibility Date: Fri, 10 Feb 2023 11:28:35 +0100 Message-Id: X-Mailer: git-send-email 2.39.1.1475.gc2542cdc5ef In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Apply the "active_nr" part of "index-compatibility.pending.cocci", which was left out in [1] due to an in-flight conflict. As of [2] the topic we conflicted with has been merged to "master", so we can fully apply this rule. 1. dc594180d9e (cocci & cache.h: apply variable section of "pending" index-compatibility, 2022-11-19) 2. 9ea1378d046 (Merge branch 'ab/various-leak-fixes', 2022-12-14) Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/commit.c | 2 +- cache.h | 2 -- contrib/coccinelle/index-compatibility.cocci | 13 ++++--------- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 44b763d7cd0..57a95123dff 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -991,7 +991,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, struct object_id oid; const char *parent = "HEAD"; - if (!active_nr) { + if (!the_index.cache_nr) { discard_cache(); if (read_cache() < 0) die(_("Cannot read index")); diff --git a/cache.h b/cache.h index 4bf14e0bd94..b0bbecf35ef 100644 --- a/cache.h +++ b/cache.h @@ -454,8 +454,6 @@ extern struct index_state the_index; #ifndef USE_THE_INDEX_VARIABLE #ifdef USE_THE_INDEX_COMPATIBILITY_MACROS -#define active_nr (the_index.cache_nr) - #define read_cache() repo_read_index(the_repository) #define discard_cache() discard_index(&the_index) #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen)) diff --git a/contrib/coccinelle/index-compatibility.cocci b/contrib/coccinelle/index-compatibility.cocci index 8520f03128a..028ff53354a 100644 --- a/contrib/coccinelle/index-compatibility.cocci +++ b/contrib/coccinelle/index-compatibility.cocci @@ -1,6 +1,7 @@ // the_index.* variables @@ identifier AC = active_cache; +identifier AN = active_nr; identifier ACC = active_cache_changed; identifier ACT = active_cache_tree; @@ @@ -8,6 +9,9 @@ identifier ACT = active_cache_tree; - AC + the_index.cache | +- AN ++ the_index.cache_nr +| - ACC + the_index.cache_changed | @@ -15,15 +19,6 @@ identifier ACT = active_cache_tree; + the_index.cache_tree ) -@@ -identifier AN = active_nr; -identifier f != prepare_to_commit; -@@ - f(...) {<... -- AN -+ the_index.cache_nr - ...>} - // "the_repository" simple cases @@ @@ From patchwork Fri Feb 10 10:28:36 2023 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: 13135653 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90951C636CD for ; Fri, 10 Feb 2023 10:29:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232042AbjBJK3B (ORCPT ); Fri, 10 Feb 2023 05:29:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232020AbjBJK24 (ORCPT ); Fri, 10 Feb 2023 05:28:56 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 081A642BE6 for ; Fri, 10 Feb 2023 02:28:53 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id o18so4597908wrj.3 for ; Fri, 10 Feb 2023 02:28:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9+lIjCE3jh7jHy0hXF4Z5ItT3qtfTITHLgxTi4d9C4Y=; b=OT/jBWazUf99yq8E1JmRDQa4js7deR64tcf13rg8/uBhSnWgTUIrKglqoLs5WGR0lH B8MRe3cYD65So7ip/cdK+Q5BuT6yTKA6uH/XWe+ZzUHPal5qOpfVyb8gok18VAS3s+la pQDdRxO1kDMXOqgRoz7LR4YfR5gqOTd/khdTUXhOZOSFbEp0kasCEwZJAJiYAmUfXSYW xHkGmUKht3vR5pTiQItTn932e2Y5qN/N3PkZySUPr44retmuRHDM/G6j9YjKWhse7cnW bwowtCm07pZ1gxVFhtDZRUR4YGKHht0ugzEl5Nk9TvJdZmCSbzfJ2IGCpjeQI9jDWhlw oZcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9+lIjCE3jh7jHy0hXF4Z5ItT3qtfTITHLgxTi4d9C4Y=; b=fUy5dJO8cdqTpPdkNLwy4ydy/29DTVKw7JEKga0AkwcHqVJ9x/ms0gdOzVpF5F71G8 xC5WnZ0ArDJTsNix9KhEiLWe2JpIYhSVLpRRHe+UAU3zDisRQGxV2mJlVQsK1bdjfJDc yprtYcdxILbP++gk+dodOk+he2/nPWNLk/08eykKLW7qbSqUxN+X4L8jO9lXRiBZjwfg PziWe3hvoMthTZatKwuXNwD9FDs31pA99JFsCCauC9UrCekXks8yY+sbzhS6mcVbz3Rw jY4u9YGWdbl7BIxUuFaOqASPvLWeD5VZzKBBQSVoCDrNlDF3A3dH6/Bc2bJK1ZEV11JV IBBw== X-Gm-Message-State: AO0yUKU1IqWlh8YLQwnOZBL6scdxwICMtL2SwP86aeeoidll4rglaO7w xC4Xt4XdhzRVozCv8smsxSIjA7KS4ihdLH4R X-Google-Smtp-Source: AK7set8Pe2114/4h2hD/lGE2rJLfSp20cUWeivkUzRlzHiwW8lEz1/3Mm1L+fZi+XmyQSKOCn3QGDw== X-Received: by 2002:adf:d0c2:0:b0:2bb:f88b:43b6 with SMTP id z2-20020adfd0c2000000b002bbf88b43b6mr15007019wrh.3.1676024932133; Fri, 10 Feb 2023 02:28:52 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u13-20020a5d514d000000b002c3f50228afsm3244792wrt.3.2023.02.10.02.28.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 02:28:51 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 3/6] cocci & cache.h: apply pending "index_cache_pos" rule Date: Fri, 10 Feb 2023 11:28:36 +0100 Message-Id: X-Mailer: git-send-email 2.39.1.1475.gc2542cdc5ef In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Apply the rule added in [1] to change "cache_name_pos" to "index_name_pos", which allows us to get rid of another "USE_THE_INDEX_COMPATIBILITY_MACROS" macro. The replacement of "USE_THE_INDEX_COMPATIBILITY_MACROS" here with "USE_THE_INDEX_VARIABLE" is a manual change on top, now that these files only use "&the_index", and don't need any compatibility macros (or functions). 1. 0e6550a2c63 (cocci: add a index-compatibility.pending.cocci, 2022-11-19) Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/mv.c | 8 +++++--- builtin/update-index.c | 4 ++-- cache.h | 1 - contrib/coccinelle/index-compatibility.cocci | 3 +++ contrib/coccinelle/index-compatibility.pending.cocci | 3 --- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/builtin/mv.c b/builtin/mv.c index 19790ce38fa..edd7b931fdb 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -3,7 +3,7 @@ * * Copyright (C) 2006 Johannes Schindelin */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "config.h" #include "pathspec.h" @@ -489,7 +489,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix) if ((mode & SPARSE) && path_in_sparse_checkout(dst, &the_index)) { /* from out-of-cone to in-cone */ - int dst_pos = cache_name_pos(dst, strlen(dst)); + int dst_pos = index_name_pos(&the_index, dst, + strlen(dst)); struct cache_entry *dst_ce = the_index.cache[dst_pos]; dst_ce->ce_flags &= ~CE_SKIP_WORKTREE; @@ -500,7 +501,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix) !(mode & SPARSE) && !path_in_sparse_checkout(dst, &the_index)) { /* from in-cone to out-of-cone */ - int dst_pos = cache_name_pos(dst, strlen(dst)); + int dst_pos = index_name_pos(&the_index, dst, + strlen(dst)); struct cache_entry *dst_ce = the_index.cache[dst_pos]; /* diff --git a/builtin/update-index.c b/builtin/update-index.c index 82d5902cc8b..bf38885d546 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -3,7 +3,7 @@ * * Copyright (C) Linus Torvalds, 2005 */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "cache.h" #include "bulk-checkin.h" #include "config.h" @@ -381,7 +381,7 @@ static int process_path(const char *path, struct stat *st, int stat_errno) if (has_symlink_leading_path(path, len)) return error("'%s' is beyond a symbolic link", path); - pos = cache_name_pos(path, len); + pos = index_name_pos(&the_index, path, len); ce = pos < 0 ? NULL : the_index.cache[pos]; if (ce && ce_skip_worktree(ce)) { /* diff --git a/cache.h b/cache.h index b0bbecf35ef..c44aef1af7c 100644 --- a/cache.h +++ b/cache.h @@ -456,7 +456,6 @@ extern struct index_state the_index; #ifdef USE_THE_INDEX_COMPATIBILITY_MACROS #define read_cache() repo_read_index(the_repository) #define discard_cache() discard_index(&the_index) -#define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen)) #endif #endif #endif diff --git a/contrib/coccinelle/index-compatibility.cocci b/contrib/coccinelle/index-compatibility.cocci index 028ff53354a..1d37546fdbd 100644 --- a/contrib/coccinelle/index-compatibility.cocci +++ b/contrib/coccinelle/index-compatibility.cocci @@ -91,6 +91,9 @@ identifier ACT = active_cache_tree; | - resolve_undo_clear + resolve_undo_clear_index +| +- cache_name_pos ++ index_name_pos ) ( + &the_index, diff --git a/contrib/coccinelle/index-compatibility.pending.cocci b/contrib/coccinelle/index-compatibility.pending.cocci index 01f875d0060..ecf3b45deca 100644 --- a/contrib/coccinelle/index-compatibility.pending.cocci +++ b/contrib/coccinelle/index-compatibility.pending.cocci @@ -15,9 +15,6 @@ ( - discard_cache + discard_index -| -- cache_name_pos -+ index_name_pos ) ( + &the_index, From patchwork Fri Feb 10 10:28:37 2023 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: 13135654 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3705C6379F for ; Fri, 10 Feb 2023 10:29:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232047AbjBJK3C (ORCPT ); Fri, 10 Feb 2023 05:29:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232025AbjBJK25 (ORCPT ); Fri, 10 Feb 2023 05:28:57 -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 2895F6E542 for ; Fri, 10 Feb 2023 02:28:55 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id by3so3269220wrb.10 for ; Fri, 10 Feb 2023 02:28:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=j5QV+iTrSMDoxuiLHawSlz3sCsUGoJxLZmxxbYK5Lkw=; b=jK++3tDbTy+T3wy5jXU85mFCcFy7J6CqcUm3xdzw2ypNY9Fk2Ekr6JcjRc5u2t5tVq BHVjSLvTLx2NyVKjQIwBe4a6J5p3HWkRiKA7+W5V6cCm+UlsRadcZFGjHGQzf5sZBwoP LIexSRCgdluz2gp4ky3l1d6axjshv4U288Kuj4UzaiMfpMJvssLmp+KmljcbbGCGTdBl ZrZKAricRHNHcpt04QB5R8ifBCbcBDG5oy73tOd5wHgSfNC6+OzAug33CeQ6lsTH4sQt 2W2huXuOX8dTNdzxxG9soQvUVh7oz3LpxXuUgIbHGzMF0G2yH+VEwdUlOJuNmZkaF9/J mz0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j5QV+iTrSMDoxuiLHawSlz3sCsUGoJxLZmxxbYK5Lkw=; b=NSmq19DLFnZmuAyPpAIvrwLbMzsrMXmx5sE+jW7HIkt8OCIjjB+VXp+4BMTreVKPBT fi12RSXe27XX02Jpu9awcCCxFKl+3rdbkKaG9hUTwC+WnrXcrTAj7CLw3PVLGoALIpJo 1lCW+gQNK0DyX3APe62gBnRm8pCeL0Ij9r6jB5u2sh+6uo/3QmIC7FYgupCWWw1dwri2 AXt2gCAT/cqlratFCCkjoQOE/twwCrIZjkjvjSd9+4bH5j+NH+sRn8MOUXYm/1EmNCBR I1wWgAv6XqmQ40J9qTF+B+0gZIOqUMyDeCDAom2jB/3EspAcSJx8S3ZpjNosl3kTWt5e C68w== X-Gm-Message-State: AO0yUKXMg5j9uhm3ppQZSfC/aMiSr+NaJ6TIAldTjOVmP/mjctY4QyqW HytShS3CUlf2W7ByH6lyDsKXhxyQ+iS74qi3 X-Google-Smtp-Source: AK7set/7Hhpmh6tAkJqILsfiDQUXonkrsOc15NWvg3Xa2KBUkCXvipvlRY8c3srMV0VbPybRIdKi7A== X-Received: by 2002:adf:e0c6:0:b0:2c3:f026:9085 with SMTP id m6-20020adfe0c6000000b002c3f0269085mr13635998wri.13.1676024933211; Fri, 10 Feb 2023 02:28:53 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u13-20020a5d514d000000b002c3f50228afsm3244792wrt.3.2023.02.10.02.28.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 02:28:52 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 4/6] cocci & cache-tree.h: migrate "write_cache_as_tree" to "*_index_*" Date: Fri, 10 Feb 2023 11:28:37 +0100 Message-Id: X-Mailer: git-send-email 2.39.1.1475.gc2542cdc5ef In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a trivial rule for "write_cache_as_tree" to "index-compatibility.cocci", and apply it. This was left out of the rules added in 0e6550a2c63 (cocci: add a index-compatibility.pending.cocci, 2022-11-19) because this compatibility wrapper lived in "cache-tree.h", not "cache.h" But it's like the other "USE_THE_INDEX_COMPATIBILITY_MACROS", so let's migrate it too. The replacement of "USE_THE_INDEX_COMPATIBILITY_MACROS" here with "USE_THE_INDEX_VARIABLE" is a manual change on top, now that these files only use "&the_index", and don't need any compatibility macros (or functions). The wrapping of some argument lists is likewise manual, as coccinelle would otherwise give us overly long argument lists. The reason for putting the "O" in the cocci rule on the "-" and "+" lines is because I couldn't get correct whitespacing otherwise, i.e. I'd end up with "oid,&the_index", not "oid, &the_index". Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/am.c | 6 +++--- builtin/merge.c | 2 +- builtin/stash.c | 11 +++++++---- builtin/write-tree.c | 5 +++-- cache-tree.h | 5 ----- contrib/coccinelle/index-compatibility.cocci | 11 +++++++++++ 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 82a41cbfc4e..8b3dcb66f08 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -3,7 +3,7 @@ * * Based on git-am.sh by Junio C Hamano. */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "cache.h" #include "config.h" #include "builtin.h" @@ -1655,7 +1655,7 @@ static void do_commit(const struct am_state *state) if (!state->no_verify && run_hooks("pre-applypatch")) exit(1); - if (write_cache_as_tree(&tree, 0, NULL)) + if (write_index_as_tree(&tree, &the_index, get_index_file(), 0, NULL)) die(_("git write-tree failed to write a tree")); if (!get_oid_commit("HEAD", &parent)) { @@ -2063,7 +2063,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem if (fast_forward_to(head_tree, head_tree, 1)) return -1; - if (write_cache_as_tree(&index, 0, NULL)) + if (write_index_as_tree(&index, &the_index, get_index_file(), 0, NULL)) return -1; index_tree = parse_tree_indirect(&index); diff --git a/builtin/merge.c b/builtin/merge.c index 74de2ebd2b3..d7cc8dc8aed 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -706,7 +706,7 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head, static void write_tree_trivial(struct object_id *oid) { - if (write_cache_as_tree(oid, 0, NULL)) + if (write_index_as_tree(oid, &the_index, get_index_file(), 0, NULL)) die(_("git write-tree failed to write a tree")); } diff --git a/builtin/stash.c b/builtin/stash.c index 839569a9803..78d69da8cf7 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -1,4 +1,4 @@ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "config.h" #include "parse-options.h" @@ -528,7 +528,8 @@ static int do_apply_stash(const char *prefix, struct stash_info *info, NULL, NULL, NULL)) return -1; - if (write_cache_as_tree(&c_tree, 0, NULL)) + if (write_index_as_tree(&c_tree, &the_index, get_index_file(), 0, + NULL)) return error(_("cannot apply a stash in the middle of a merge")); if (index) { @@ -552,7 +553,8 @@ static int do_apply_stash(const char *prefix, struct stash_info *info, discard_index(&the_index); repo_read_index(the_repository); - if (write_cache_as_tree(&index_tree, 0, NULL)) + if (write_index_as_tree(&index_tree, &the_index, + get_index_file(), 0, NULL)) return error(_("could not save index tree")); reset_head(); @@ -1377,7 +1379,8 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b strbuf_addf(&commit_tree_label, "index on %s\n", msg.buf); commit_list_insert(head_commit, &parents); - if (write_cache_as_tree(&info->i_tree, 0, NULL) || + if (write_index_as_tree(&info->i_tree, &the_index, get_index_file(), 0, + NULL) || commit_tree(commit_tree_label.buf, commit_tree_label.len, &info->i_tree, parents, &info->i_commit, NULL, NULL)) { if (!quiet) diff --git a/builtin/write-tree.c b/builtin/write-tree.c index 45d61707e7d..078010315f0 100644 --- a/builtin/write-tree.c +++ b/builtin/write-tree.c @@ -3,7 +3,7 @@ * * Copyright (C) Linus Torvalds, 2005 */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "cache.h" #include "config.h" @@ -38,7 +38,8 @@ int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix) argc = parse_options(argc, argv, cmd_prefix, write_tree_options, write_tree_usage, 0); - ret = write_cache_as_tree(&oid, flags, tree_prefix); + ret = write_index_as_tree(&oid, &the_index, get_index_file(), flags, + tree_prefix); switch (ret) { case 0: printf("%s\n", oid_to_hex(&oid)); diff --git a/cache-tree.h b/cache-tree.h index 8efeccebfc9..84890c9ff32 100644 --- a/cache-tree.h +++ b/cache-tree.h @@ -55,11 +55,6 @@ void prime_cache_tree(struct repository *, struct index_state *, struct tree *); int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info); #ifdef USE_THE_INDEX_COMPATIBILITY_MACROS -static inline int write_cache_as_tree(struct object_id *oid, int flags, const char *prefix) -{ - return write_index_as_tree(oid, &the_index, get_index_file(), flags, prefix); -} - static inline int update_main_cache_tree(int flags) { if (!the_index.cache_tree) diff --git a/contrib/coccinelle/index-compatibility.cocci b/contrib/coccinelle/index-compatibility.cocci index 1d37546fdbd..e245d805dcd 100644 --- a/contrib/coccinelle/index-compatibility.cocci +++ b/contrib/coccinelle/index-compatibility.cocci @@ -135,3 +135,14 @@ identifier ACT = active_cache_tree; ... + , NULL, NULL, NULL ) + +@@ +expression O; +@@ +- write_cache_as_tree ++ write_index_as_tree + ( +- O, ++ O, &the_index, get_index_file(), + ... + ) From patchwork Fri Feb 10 10:28:38 2023 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: 13135655 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90877C05027 for ; Fri, 10 Feb 2023 10:29:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232009AbjBJK3M (ORCPT ); Fri, 10 Feb 2023 05:29:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232014AbjBJK25 (ORCPT ); Fri, 10 Feb 2023 05:28:57 -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 4403C7094C for ; Fri, 10 Feb 2023 02:28:56 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id o18so4598065wrj.3 for ; Fri, 10 Feb 2023 02:28:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xHT04WDN1A7+bbNgqH1hA/NFn/q3snf/tEgR+WZQmsY=; b=YyvRYrQjgMIOD24XeekeoT4r0WnavrJnUMvs0OGCeHGwt5CYDgdUzJbJCZmehzefVD Kiog8wSLb+mHOpvMfu3S8M9KaMhMAMU1rgv7cu3GyqMwzkASePzSUKFw6CHqXTljV3c9 SJwgzYN2vabm+zhZNv6jzQiBhu9o547Dk6yvhgAn78Xswu5aX88Ux84/7hSARS2Gg8rS juXS04y2Z5iYwOGIdfWdN/dZSQq3PxLBUumjXP8F2Mrr52V9depr/Ge6GrUV2hEs4VB3 dNzwYXxtejWjFoEy8tm8PdeKpCpgEC6ABsMe2jNsgtLxzRaIaoyrh0rqW7kJzQr21ci1 +8wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xHT04WDN1A7+bbNgqH1hA/NFn/q3snf/tEgR+WZQmsY=; b=jHET8bTgEepVBd1lWrveBPk/f3lUf4XvRaXYKDT2DQ0/fBTHRra6M2X5msZrGioqBj njQFQKL/bqXCC+VKf6jQwBZj/vXot1rXMKQJwRTM/kGDTaS8g5NIb6rykoC+Hc+wMCgQ Q/CeTL6geQkbi4BiCHHWc7Nb4E8LgUaH+sultaZrVQY+x68YU2Epmb+XNYr1p5amsSqt yWVGAg7GFYRBnFl2llF6EOYuE8/wYrnXMSoALtgD3jzDGNE1wnXqEGuL9Hhz2EW3MWmN PK9cmc3IUiLmf8Gdvc+hVmGEzvWgl1hJs7sSXJ8Ux4ggZMfWecnxZELytCGsbpCuq3+P nPxw== X-Gm-Message-State: AO0yUKWNQKjuMihr71vf/1t5QsVQeG5xRzqY7KignDOTwe0k7uKQbap5 DGQtK3mIKYWIuqpW7FC+FPdRaUyNFSMdOZGM X-Google-Smtp-Source: AK7set+3p1a6h8zQnZ/lSDjNGlDaNVpkmN+FtnsUvTV7Rwu1GgkGyuZqS3TIzQDsx2DAlQxWGadcHg== X-Received: by 2002:adf:edce:0:b0:2c3:f11b:a9ea with SMTP id v14-20020adfedce000000b002c3f11ba9eamr4461699wro.25.1676024934461; Fri, 10 Feb 2023 02:28:54 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u13-20020a5d514d000000b002c3f50228afsm3244792wrt.3.2023.02.10.02.28.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 02:28:53 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 5/6] cache-tree API: remove redundant update_main_cache_tree() Date: Fri, 10 Feb 2023 11:28:38 +0100 Message-Id: X-Mailer: git-send-email 2.39.1.1475.gc2542cdc5ef In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Remove the redundant update_main_cache_tree() function, and make its users use cache_tree_update() instead. The behavior of populating the "the_index.cache_tree" if it wasn't present already was needed when this function was introduced in [1], but it hasn't been needed since [2]; The "cache_tree_update()" will now lazy-allocate, so there's no need for the wrapper. 1. 996277c5206 (Refactor cache_tree_update idiom from commit, 2011-12-06) 2. fb0882648e0 (cache-tree: clean up cache_tree_update(), 2021-01-23) Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/commit.c | 10 +++++----- cache-tree.h | 10 ---------- contrib/coccinelle/index-compatibility.cocci | 3 +++ 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 57a95123dff..31fbbd73d16 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -414,7 +414,7 @@ static const char *prepare_index(const char **argv, const char *prefix, discard_index(&the_index); read_index_from(&the_index, get_lock_file_path(&index_lock), get_git_dir()); - if (update_main_cache_tree(WRITE_TREE_SILENT) == 0) { + if (cache_tree_update(&the_index, WRITE_TREE_SILENT) == 0) { if (reopen_lock_file(&index_lock) < 0) die(_("unable to write index file")); if (write_locked_index(&the_index, &index_lock, 0)) @@ -444,7 +444,7 @@ static const char *prepare_index(const char **argv, const char *prefix, LOCK_DIE_ON_ERROR); add_files_to_cache(also ? prefix : NULL, &pathspec, 0); refresh_cache_or_die(refresh_flags); - update_main_cache_tree(WRITE_TREE_SILENT); + cache_tree_update(&the_index, WRITE_TREE_SILENT); if (write_locked_index(&the_index, &index_lock, 0)) die(_("unable to write new_index file")); commit_style = COMMIT_NORMAL; @@ -467,7 +467,7 @@ static const char *prepare_index(const char **argv, const char *prefix, refresh_cache_or_die(refresh_flags); if (the_index.cache_changed || !cache_tree_fully_valid(the_index.cache_tree)) - update_main_cache_tree(WRITE_TREE_SILENT); + cache_tree_update(&the_index, WRITE_TREE_SILENT); if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK | SKIP_IF_UNCHANGED)) die(_("unable to write new_index file")); @@ -516,7 +516,7 @@ static const char *prepare_index(const char **argv, const char *prefix, repo_hold_locked_index(the_repository, &index_lock, LOCK_DIE_ON_ERROR); add_remove_files(&partial); refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL); - update_main_cache_tree(WRITE_TREE_SILENT); + cache_tree_update(&the_index, WRITE_TREE_SILENT); if (write_locked_index(&the_index, &index_lock, 0)) die(_("unable to write new_index file")); @@ -1079,7 +1079,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, } read_index_from(&the_index, index_file, get_git_dir()); - if (update_main_cache_tree(0)) { + if (cache_tree_update(&the_index, 0)) { error(_("Error building trees")); return 0; } diff --git a/cache-tree.h b/cache-tree.h index 84890c9ff32..bd97caa07b0 100644 --- a/cache-tree.h +++ b/cache-tree.h @@ -53,14 +53,4 @@ int write_index_as_tree(struct object_id *oid, struct index_state *index_state, void prime_cache_tree(struct repository *, struct index_state *, struct tree *); int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info); - -#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS -static inline int update_main_cache_tree(int flags) -{ - if (!the_index.cache_tree) - the_index.cache_tree = cache_tree(); - return cache_tree_update(&the_index, flags); -} -#endif - #endif diff --git a/contrib/coccinelle/index-compatibility.cocci b/contrib/coccinelle/index-compatibility.cocci index e245d805dcd..9fca870162d 100644 --- a/contrib/coccinelle/index-compatibility.cocci +++ b/contrib/coccinelle/index-compatibility.cocci @@ -94,6 +94,9 @@ identifier ACT = active_cache_tree; | - cache_name_pos + index_name_pos +| +- update_main_cache_tree ++ cache_tree_update ) ( + &the_index, From patchwork Fri Feb 10 10:28:39 2023 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: 13135656 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0668CC636CD for ; Fri, 10 Feb 2023 10:29:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232035AbjBJK3O (ORCPT ); Fri, 10 Feb 2023 05:29:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232029AbjBJK25 (ORCPT ); Fri, 10 Feb 2023 05:28:57 -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 3CD2F6C7F8 for ; Fri, 10 Feb 2023 02:28:56 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id ba1so4583971wrb.5 for ; Fri, 10 Feb 2023 02:28:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lM73e8G/KhlpJi9V3ECMrJg5XNhSBzWE/I6Aeue8Mzw=; b=d8ssDvHwc67GaZMoe2VxK9Si5b0S+/NNKC9k6yNWtdUGmI0PKhd/e6ZdCXjjMtZUf4 mo3ZGKaVAqO6WnQiIkdHsTVLBjUobhb/odIsdxV+Z3QjDjJdwy83nFPoYlXMmk36RS5c N+hoKbrQEJGqjn9GXC9ADtmt5YDuMXlPftXAvfzXTzp7jPj+5/Ye0u74dqjKQXl8qZuG c8H3v9mN9VB5nRjSQ7Wx39yEVlHjC3mdIMnN/snFibd/C9/5nLjS2DkKX0SBtn58nbtP ws/kbXLC0M2Nl3pkW+IkiRwkiBddunmpMM8IOHoAtoLsdAT9beIzkUW0E9tebrGrlcUf ey+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lM73e8G/KhlpJi9V3ECMrJg5XNhSBzWE/I6Aeue8Mzw=; b=vPx1Y9at8eXAa5OuPqtOGCIqAgFpTVbqFsfd8IkRm5kgT938iOsWS24XKVvYcgayY1 vP+zlIMMlcyfwPJ9/qvqadVNdwhkgbUCrmMW7lTLkzKFEKOqjIQH0ckQSd1rWjrDNcGZ OQAXtoizTn1aXYDOHm0J4o8uXfgAYrgWLYa065u0SWo0bVFyhKqkNji172s9aeFnXIYW NKIxoGmJzLTgkmI1sxJyXwJR7RPZocLOdcrtdB5iZYpw9JPGlIGKVt5l/oaslydUi9Wi 5Ne/z0X+0Gr+Visn9LCGl2Vq1A5TtXNKnfYjIdhkVUW/NNP2m7SWiF/O3LVaQBUgi3JS Gaag== X-Gm-Message-State: AO0yUKUgF1kQpTwpMeskR5sJgVmEKCWLT7x/dPoLjlvRp11ovr9zk7HX zwAY6/KrN+GAG3wB/UAhASQTMdn+Vs1nN8+S X-Google-Smtp-Source: AK7set9eyjrg68U1Iux/yFS1EMkFzZHu11uHpivkFjnOk8GeIm4TgCr+8zDDYrQeRLNUk8MHfIm2rQ== X-Received: by 2002:adf:e88b:0:b0:2c4:4dd:b9ee with SMTP id d11-20020adfe88b000000b002c404ddb9eemr9011905wrm.71.1676024935508; Fri, 10 Feb 2023 02:28:55 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u13-20020a5d514d000000b002c3f50228afsm3244792wrt.3.2023.02.10.02.28.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 02:28:54 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Phillip Wood , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 6/6] cocci & cache.h: remove "USE_THE_INDEX_COMPATIBILITY_MACROS" Date: Fri, 10 Feb 2023 11:28:39 +0100 Message-Id: X-Mailer: git-send-email 2.39.1.1475.gc2542cdc5ef In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Have the last users of "USE_THE_INDEX_COMPATIBILITY_MACROS" use the underlying *_index() variants instead. Now all previous users of "USE_THE_INDEX_COMPATIBILITY_MACROS" have been migrated away from the wrapper macros, and if applicable to use the "USE_THE_INDEX_VARIABLE" added in [1]. Let's leave the "index-compatibility.cocci" in place, even though it won't be doing anything on "master". It will benefit any out-of-tree code that need to use these compatibility macros. We can eventually remove it. 1. bdafeae0b9c (cache.h & test-tool.h: add & use "USE_THE_INDEX_VARIABLE", 2022-11-19) Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/commit.c | 6 +++--- builtin/merge.c | 6 +++--- cache.h | 9 +------- contrib/coccinelle/index-compatibility.cocci | 6 ++++++ .../index-compatibility.pending.cocci | 21 ------------------- 5 files changed, 13 insertions(+), 35 deletions(-) delete mode 100644 contrib/coccinelle/index-compatibility.pending.cocci diff --git a/builtin/commit.c b/builtin/commit.c index 31fbbd73d16..985a0445b78 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -5,7 +5,7 @@ * Based on git-commit.sh by Junio C Hamano and Linus Torvalds */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "cache.h" #include "config.h" #include "lockfile.h" @@ -992,8 +992,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix, const char *parent = "HEAD"; if (!the_index.cache_nr) { - discard_cache(); - if (read_cache() < 0) + discard_index(&the_index); + if (repo_read_index(the_repository) < 0) die(_("Cannot read index")); } diff --git a/builtin/merge.c b/builtin/merge.c index d7cc8dc8aed..2aafbf67450 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -6,7 +6,7 @@ * Based on git-merge.sh by Junio C Hamano. */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "cache.h" #include "config.h" #include "parse-options.h" @@ -390,8 +390,8 @@ static void restore_state(const struct object_id *head, run_command(&cmd); refresh_cache: - discard_cache(); - if (read_cache() < 0) + discard_index(&the_index); + if (repo_read_index(the_repository) < 0) die(_("could not read index")); } diff --git a/cache.h b/cache.h index c44aef1af7c..2f643cf5309 100644 --- a/cache.h +++ b/cache.h @@ -449,15 +449,8 @@ typedef int (*must_prefetch_predicate)(const struct cache_entry *); void prefetch_cache_entries(const struct index_state *istate, must_prefetch_predicate must_prefetch); -#if defined(USE_THE_INDEX_COMPATIBILITY_MACROS) || defined(USE_THE_INDEX_VARIABLE) +#ifdef USE_THE_INDEX_VARIABLE extern struct index_state the_index; - -#ifndef USE_THE_INDEX_VARIABLE -#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS -#define read_cache() repo_read_index(the_repository) -#define discard_cache() discard_index(&the_index) -#endif -#endif #endif #define TYPE_BITS 3 diff --git a/contrib/coccinelle/index-compatibility.cocci b/contrib/coccinelle/index-compatibility.cocci index 9fca870162d..31e36cf3c41 100644 --- a/contrib/coccinelle/index-compatibility.cocci +++ b/contrib/coccinelle/index-compatibility.cocci @@ -23,6 +23,9 @@ identifier ACT = active_cache_tree; @@ @@ ( +- read_cache ++ repo_read_index +| - read_cache_unmerged + repo_read_index_unmerged | @@ -97,6 +100,9 @@ identifier ACT = active_cache_tree; | - update_main_cache_tree + cache_tree_update +| +- discard_cache ++ discard_index ) ( + &the_index, diff --git a/contrib/coccinelle/index-compatibility.pending.cocci b/contrib/coccinelle/index-compatibility.pending.cocci deleted file mode 100644 index ecf3b45deca..00000000000 --- a/contrib/coccinelle/index-compatibility.pending.cocci +++ /dev/null @@ -1,21 +0,0 @@ -// "the_repository" simple cases -@@ -@@ -( -- read_cache -+ repo_read_index -) - ( -+ the_repository, - ...) - -// "the_index" simple cases -@@ -@@ -( -- discard_cache -+ discard_index -) - ( -+ &the_index, - ...)