From patchwork Sat Nov 19 13:07:28 2022 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: 13049732 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 C7BE1C4332F for ; Sat, 19 Nov 2022 13:07:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233066AbiKSNHv (ORCPT ); Sat, 19 Nov 2022 08:07:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230398AbiKSNHu (ORCPT ); Sat, 19 Nov 2022 08:07:50 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A3348FE41 for ; Sat, 19 Nov 2022 05:07:49 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id s12so10601599edd.5 for ; Sat, 19 Nov 2022 05:07:49 -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=kbXksdhX732h1dNfu6usEkedXSar4hKae7BowflEMX4=; b=cKwGSGril4Bd9qZZLOSVMLOtQQF7bQo0XoCRC1S8bD42SKINg8B3aEsgQJxPXmMAEa ArHSgEyngyW6ucS1egzHaNhqi2Q5pIZ80RtUKLpnzI4PssBF82fPmMAFjaAqZmHhcgrI /lw/GEudEgCjtxks1v32oGKmN/NL9/4vGQwBKg/bfNq3XYy7b91R4oh+1nUEGROCX27O bBuAs8CjEHNaP4eilWSQ7SQ+sLJgjMGn7XxewK+77bZJRW6ud3eVtwJfq4CT3CIc48oC BEIgjHllKajMcY0hpnYKHeTj7TQd/ltVJxef7NAaz1091xFjrz09JNQ0rV+hbzVaomhC PvJg== 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=kbXksdhX732h1dNfu6usEkedXSar4hKae7BowflEMX4=; b=eAox76dAvmuQ8YZ4BXcVyL4zHEBUulXZ8bkKs5ihrog+tKkyNpvjtBtGwq7b8AoVU3 yvG8KLdlI6d/88h4dURr66hJ6ON49g7FnhxCapuklYq8f0NKLHmgQCxX09/N1MnBlIpo DYvIZP4XcBVyJK92b4vdtCs4a2jNHiCPClF9mEmVeQHDwtQw91FyEXR2a3+iJejfnqbY AFUV3Lghkz5SW1fN5Mnjl4ehNaPepu0DDumbR0tR9aDOBF34TzsPqYW7Iw2F+6M0bRfo lJVER11vDg3GyHEEdyhhfAv0Kf8utuUf4n9aATuVNBcf+jq9BG5q1YKRGT7TPkPRwQmu b1Ng== X-Gm-Message-State: ANoB5pnRz9nkq1114Ww031haD8s5pfbEJjpKzQ3WbqUrK1tgHMT0ppky iPuEw775vHV+PiGjD3soxuul5i0I/F9R8w== X-Google-Smtp-Source: AA0mqf6AsicjqSLG4kr303C0FfkGoGvfT144uLtfjZ0sYEKfHhyuxGUE1mVbjlhG2IdIsQMsLU2g5Q== X-Received: by 2002:aa7:d0d4:0:b0:461:b1b9:bed0 with SMTP id u20-20020aa7d0d4000000b00461b1b9bed0mr1130483edo.122.1668863267664; Sat, 19 Nov 2022 05:07:47 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id ch28-20020a0564021bdc00b0045d74aa401fsm2923802edb.60.2022.11.19.05.07.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Nov 2022 05:07:47 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 01/11] cache.h: remove unused "the_index" compat macros Date: Sat, 19 Nov 2022 14:07:28 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1509.g9445af83948 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The "active_alloc" macro added in 228e94f9357 (Move index-related variables into a structure., 2007-04-01) has not been used since 4aab5b46f44 (Make read-cache.c "the_index" free., 2007-04-01). Let's remove it. The rest of these are likewise unused, so let's not keep them around. E.g. 12cd0bf9b02 (dir: stop using the index compatibility macros, 2017-05-05) is the last use of "cache_dir_exists". Signed-off-by: Ævar Arnfjörð Bjarmason --- cache.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/cache.h b/cache.h index 26ed03bd6de..29bb0ad2b41 100644 --- a/cache.h +++ b/cache.h @@ -438,7 +438,6 @@ extern struct index_state the_index; #define active_cache (the_index.cache) #define active_nr (the_index.cache_nr) -#define active_alloc (the_index.cache_alloc) #define active_cache_changed (the_index.cache_changed) #define active_cache_tree (the_index.cache_tree) @@ -452,7 +451,6 @@ extern struct index_state the_index; #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen)) #define add_cache_entry(ce, option) add_index_entry(&the_index, (ce), (option)) #define rename_cache_entry_at(pos, new_name) rename_index_entry_at(&the_index, (pos), (new_name)) -#define remove_cache_entry_at(pos) remove_index_entry_at(&the_index, (pos)) #define remove_file_from_cache(path) remove_file_from_index(&the_index, (path)) #define add_to_cache(path, st, flags) add_to_index(&the_index, (path), (st), (flags)) #define add_file_to_cache(path, flags) add_file_to_index(&the_index, (path), (flags)) @@ -461,13 +459,10 @@ extern struct index_state the_index; #define refresh_and_write_cache(refresh_flags, write_flags, gentle) repo_refresh_and_write_index(the_repository, (refresh_flags), (write_flags), (gentle), NULL, NULL, NULL) #define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options)) #define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options)) -#define cache_dir_exists(name, namelen) index_dir_exists(&the_index, (name), (namelen)) #define cache_file_exists(name, namelen, igncase) index_file_exists(&the_index, (name), (namelen), (igncase)) #define cache_name_is_other(name, namelen) index_name_is_other(&the_index, (name), (namelen)) #define resolve_undo_clear() resolve_undo_clear_index(&the_index) #define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at) -#define unmerge_cache(pathspec) unmerge_index(&the_index, pathspec) -#define read_blob_data_from_cache(path, sz) read_blob_data_from_index(&the_index, (path), (sz)) #define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags)) #endif From patchwork Sat Nov 19 13:07:29 2022 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: 13049733 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 22058C433FE for ; Sat, 19 Nov 2022 13:07:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233521AbiKSNHx (ORCPT ); Sat, 19 Nov 2022 08:07:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232923AbiKSNHv (ORCPT ); Sat, 19 Nov 2022 08:07:51 -0500 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 702A78FE72 for ; Sat, 19 Nov 2022 05:07:50 -0800 (PST) Received: by mail-ed1-x535.google.com with SMTP id y24so5581583edi.10 for ; Sat, 19 Nov 2022 05:07:50 -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=jJOkBSTkAasoV7n9eEuw+rwhopFqR9JYGgBJ61xdu18=; b=gH7CCgTE9sHF6XlkdihQpTVOT5sQoatSvFQKlURlcn3W9CCIZKLlp099AFw1ZTq862 n5rNDAqr/1Ct5Axn0fdxHh3wrc9wlmYQXu8UXttrCiwAFb9tNlLViLTP+6VMUfCcvMNJ TfMmpMxiOnKrPrVbm+qxOcp/RekGLFtBTM+/NtvZnhUe29l+sXCgtsbDoz3PjlV+8QlJ 8Phhcz6QF7cNbDD0SQAwmSkP+KP2naK64dxRK5eGQXauJa9ANqK5VsJzaXhBzvNuBgR0 MNLdKL6gv3oP/a248f/X5JwlCEQCRtpliEg08frVNjkGhq6JTAbcv0W8WGtiO4m535a7 6kQw== 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=jJOkBSTkAasoV7n9eEuw+rwhopFqR9JYGgBJ61xdu18=; b=owryRiBsZst4PutJChLtOjx2mJ4XuF08OzxvAgk+MB+mhiM+y8Y1AMuNzIY0mOE2D9 rig0c0lIrbu4tMetfUVg9QOtjLDep9GSsBXsETqaByG1eI9CchBc4G9W5kibbqixQfMk M0gfcv1APIBKPUy761iHH0Rmezt9r2iT5cdPJhRrWaxfWKhCKDsAWs6G1WmQgPE5z/ix mydwxdpr5vaGB6XBGkhvHlUfTQhD3pBS2UQVXtSdiasj0sCxIOwoX6rUM7CdaFXXoWui iVZ2oE2AnphpGqQjJdvnfGiwMhZd67TNAVxOwIHpqt5cx2cEpXdoQ3CTL0bvvViL//4V Gjkg== X-Gm-Message-State: ANoB5pmq8a0Zpcy/SCoEV5nNvXjjuOG4ritxmf3SGSiCjzZej/rdeKEY zMPDJK+rdVz9zrP0OcDJ4O25GrHEci52Tg== X-Google-Smtp-Source: AA0mqf51BOC328JUxOH+ypkK1M7bVvLUQ4TaLpOR+l5h3Y8+CNavi3WkvzV4EbKkqxFJqDZLme4Mmw== X-Received: by 2002:aa7:d88c:0:b0:468:ffca:6982 with SMTP id u12-20020aa7d88c000000b00468ffca6982mr7177031edq.282.1668863268661; Sat, 19 Nov 2022 05:07:48 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id ch28-20020a0564021bdc00b0045d74aa401fsm2923802edb.60.2022.11.19.05.07.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Nov 2022 05:07:47 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 02/11] builtin/{grep,log}.: don't define "USE_THE_INDEX_COMPATIBILITY_MACROS" Date: Sat, 19 Nov 2022 14:07:29 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1509.g9445af83948 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Adding "USE_THE_INDEX_COMPATIBILITY_MACROS" to these two appears to have been unnecessary from the start, as going back and compiling f8adbec9fea (cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch, 2019-01-24) without that addition works. Let's not have these ask for the compatibility macros from cache.h that they don't need. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/grep.c | 1 - builtin/log.c | 1 - 2 files changed, 2 deletions(-) diff --git a/builtin/grep.c b/builtin/grep.c index 5fa927d4e22..f7821c5fbba 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -3,7 +3,6 @@ * * Copyright (c) 2006 Junio C Hamano */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "repository.h" #include "config.h" diff --git a/builtin/log.c b/builtin/log.c index 5eafcf26b49..89447a50838 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -4,7 +4,6 @@ * (C) Copyright 2006 Linus Torvalds * 2006 Junio Hamano */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "refs.h" From patchwork Sat Nov 19 13:07:30 2022 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: 13049734 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 37AA8C4332F for ; Sat, 19 Nov 2022 13:07:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233638AbiKSNH4 (ORCPT ); Sat, 19 Nov 2022 08:07:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233499AbiKSNHx (ORCPT ); Sat, 19 Nov 2022 08:07:53 -0500 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EEF78FE41 for ; Sat, 19 Nov 2022 05:07:51 -0800 (PST) Received: by mail-ej1-x629.google.com with SMTP id f18so19184983ejz.5 for ; Sat, 19 Nov 2022 05:07: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=ImsvhYVaspNdzTOXY0WsvIgWeVuWWo9dlLFG7aK8Fs0=; b=XtWA1wO4s0yJp6vtIJpG6wMHfnIm1btodwkKDMxttdyFyPOyVUFLfiUhAmY7sb5VoU RWf0d/cfrWTn4nAxezbMBIhkItFhofr+7O7lP2W4EXrKPfrHCnq5dKAlGDS30P0VgP7U WjB4cSCEMuyQmAzctrok0e7kzOriGm/1+buYj/YYS/2HkBgTaRFR18y7cP1ROgmZ8koO oibbCx0aBNh0UXDrHzpKxMMWlDOJ+lwqxcmhcBd42MO0L4dkCNvBT3j+KGDQGT5SgoLr afx2HpkIGo8G6+jEWxa317wLbADKwWYXfZhSVrG6Bovg+z2JLDtP7O/nKw8Id7kJQVqW 4TUw== 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=ImsvhYVaspNdzTOXY0WsvIgWeVuWWo9dlLFG7aK8Fs0=; b=iN5BpMt83BrmS4OBqGocmgvBj/AgYBMnhhNLlmd8pqSkhlz0L5WHSeuTnqGuJmNVc5 AuU5/2ZgFQuE6Ljz2eMAw1JBRpf9zoe17/B/8q601q5Jt72qZp+8hHztSzL96s2rl5io Frd8IibxBhzwatcYCpSnPycLeeH59jOpATV6azFr5ni7dN25ol+RqHSq6kC+psWkRlt4 66DwibjAopo9yVNV/j0Wa/BcLMSiCsN3z3RAXEs5HaRjjrmLUYmddLhszXbY3dk+bbAQ yJNwlAMSdylACNNNb0RPBDU5WSSVQdEpbTo1BEOZ3qg4RwlmTFD0urW7PbMvUVy/0lt4 PkFA== X-Gm-Message-State: ANoB5pkMTVT1js0ZkmYFvw0M5pycfPWYGv79ACctflkkTZIpJ99IHMPK GasOZtWf2GHiIt7ChL6M9Kedm7h+rmedIA== X-Google-Smtp-Source: AA0mqf4gsyIqdJFg2P3qrEuLdinfQ4FKQumy9dms27zk/g3GK6s7YvGUf5xrhYGtz719noC4839N8g== X-Received: by 2002:a17:906:9518:b0:7ad:b152:6bd1 with SMTP id u24-20020a170906951800b007adb1526bd1mr827134ejx.30.1668863269634; Sat, 19 Nov 2022 05:07:49 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id ch28-20020a0564021bdc00b0045d74aa401fsm2923802edb.60.2022.11.19.05.07.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Nov 2022 05:07:48 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 03/11] cocci & cache.h: remove rarely used "the_index" compat macros Date: Sat, 19 Nov 2022 14:07:30 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1509.g9445af83948 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Since 4aab5b46f44 (Make read-cache.c "the_index" free., 2007-04-01) we've been undergoing a slow migration away from these macros, but haven't made much progress since f8adbec9fea (cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch, 2019-01-24). Let's move forward a bit by changing the users of those macros that are rare enough that we can convert them in one go, and then remove the compatibility shim. The only manual change to the C code here is to "cache.h", the rest is all the result of applying the new "index-compatibility.cocci". Even though it's a one-off, let's keep the coccinelle rules for now. We'll extend them in subsequent commits, and this will help anything that's in-flight or out-of-tree to migrate. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/add.c | 5 ++- builtin/am.c | 4 +- builtin/checkout.c | 4 +- builtin/clean.c | 2 +- builtin/commit.c | 2 +- builtin/merge.c | 2 +- builtin/mv.c | 4 +- builtin/pull.c | 4 +- builtin/read-tree.c | 4 +- builtin/reset.c | 4 +- builtin/update-index.c | 4 +- cache.h | 10 ----- contrib/coccinelle/index-compatibility.cocci | 45 ++++++++++++++++++++ 13 files changed, 65 insertions(+), 29 deletions(-) create mode 100644 contrib/coccinelle/index-compatibility.cocci diff --git a/builtin/add.c b/builtin/add.c index 626c71ec6aa..75be1d021ab 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -55,7 +55,7 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only) continue; if (!show_only) - err = chmod_cache_entry(ce, flip); + err = chmod_index_entry(&the_index, ce, flip); else err = S_ISREG(ce->ce_mode) ? 0 : -1; @@ -172,7 +172,8 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags) continue; /* do not touch non blobs */ if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL)) continue; - retval |= add_file_to_cache(ce->name, flags | ADD_CACHE_RENORMALIZE); + retval |= add_file_to_index(&the_index, ce->name, + flags | ADD_CACHE_RENORMALIZE); } return retval; diff --git a/builtin/am.c b/builtin/am.c index 20aea0d2487..f362a1c29fd 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1930,7 +1930,7 @@ static void am_resolve(struct am_state *state, int allow_empty) } } - if (unmerged_cache()) { + if (unmerged_index(&the_index)) { printf_ln(_("You still have unmerged paths in your index.\n" "You should 'git add' each file with resolved conflicts to mark them as such.\n" "You might run `git rm` on a file to accept \"deleted by them\" for it.")); @@ -2045,7 +2045,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem if (!remote_tree) return error(_("Could not parse object '%s'."), oid_to_hex(remote)); - read_cache_unmerged(); + repo_read_index_unmerged(the_repository); if (fast_forward_to(head_tree, head_tree, 1)) return -1; diff --git a/builtin/checkout.c b/builtin/checkout.c index 2a132392fbe..aa610b274e3 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -722,7 +722,7 @@ static void init_topts(struct unpack_trees_options *topts, int merge, setup_unpack_trees_porcelain(topts, "checkout"); - topts->initial_checkout = is_cache_unborn(); + topts->initial_checkout = is_index_unborn(&the_index); topts->update = 1; topts->merge = 1; topts->quiet = merge && old_commit; @@ -763,7 +763,7 @@ static int merge_working_tree(const struct checkout_opts *opts, refresh_cache(REFRESH_QUIET); - if (unmerged_cache()) { + if (unmerged_index(&the_index)) { error(_("you need to resolve your current index first")); return 1; } diff --git a/builtin/clean.c b/builtin/clean.c index 40ff2c578de..7084e685f6f 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -1031,7 +1031,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix) struct stat st; const char *rel; - if (!cache_name_is_other(ent->name, ent->len)) + if (!index_name_is_other(&the_index, ent->name, ent->len)) continue; if (lstat(ent->name, &st)) diff --git a/builtin/commit.c b/builtin/commit.c index e22bdf23f5f..985503d43a6 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -302,7 +302,7 @@ static void add_remove_files(struct string_list *list) continue; if (!lstat(p->string, &st)) { - if (add_to_cache(p->string, &st, 0)) + if (add_to_index(&the_index, p->string, &st, 0)) die(_("updating files failed")); } else remove_file_from_cache(p->string); diff --git a/builtin/merge.c b/builtin/merge.c index b3f75f55c8a..da11dfae19e 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -1375,7 +1375,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) goto done; } - if (read_cache_unmerged()) + if (repo_read_index_unmerged(the_repository)) die_resolve_conflict("merge"); if (file_exists(git_path_merge_head(the_repository))) { diff --git a/builtin/mv.c b/builtin/mv.c index 3413ad1c9b1..df6157fd6b5 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -343,7 +343,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) argc += last - first; goto act_on_entry; } - if (!(ce = cache_file_exists(src, length, 0))) { + if (!(ce = index_file_exists(&the_index, src, length, 0))) { bad = _("not under version control"); goto act_on_entry; } @@ -472,7 +472,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) assert(pos >= 0); if (!(mode & SPARSE) && !lstat(src, &st)) sparse_and_dirty = ce_modified(active_cache[pos], &st, 0); - rename_cache_entry_at(pos, dst); + rename_index_entry_at(&the_index, pos, dst); if (ignore_sparse && core_apply_sparse_checkout && diff --git a/builtin/pull.c b/builtin/pull.c index b21edd767aa..4a2a6db2dce 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -1030,7 +1030,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix) if (opt_rebase < 0) opt_rebase = config_get_rebase(&rebase_unspecified); - if (read_cache_unmerged()) + if (repo_read_index_unmerged(the_repository)) die_resolve_conflict("pull"); if (file_exists(git_path_merge_head(the_repository))) @@ -1043,7 +1043,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix) if (opt_autostash == -1) opt_autostash = config_autostash; - if (is_null_oid(&orig_head) && !is_cache_unborn()) + if (is_null_oid(&orig_head) && !is_index_unborn(&the_index)) die(_("Updating an unborn branch with changes added to the index.")); if (!opt_autostash) diff --git a/builtin/read-tree.c b/builtin/read-tree.c index 45c6652444b..fd708273101 100644 --- a/builtin/read-tree.c +++ b/builtin/read-tree.c @@ -188,7 +188,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix) */ if (opts.reset || opts.merge || opts.prefix) { - if (read_cache_unmerged() && (opts.prefix || opts.merge)) + if (repo_read_index_unmerged(the_repository) && (opts.prefix || opts.merge)) die(_("You need to resolve your current index first")); stage = opts.merge = 1; } @@ -232,7 +232,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix) break; case 2: opts.fn = twoway_merge; - opts.initial_checkout = is_cache_unborn(); + opts.initial_checkout = is_index_unborn(&the_index); break; case 3: default: diff --git a/builtin/reset.c b/builtin/reset.c index ab027774824..e561180e8c4 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -84,7 +84,7 @@ static int reset_index(const char *ref, const struct object_id *oid, int reset_t BUG("invalid reset_type passed to reset_index"); } - read_cache_unmerged(); + repo_read_index_unmerged(the_repository); if (reset_type == KEEP) { struct object_id head_oid; @@ -220,7 +220,7 @@ static void set_reflog_message(struct strbuf *sb, const char *action, static void die_if_unmerged_cache(int reset_type) { - if (is_merge() || unmerged_cache()) + if (is_merge() || unmerged_index(&the_index)) die(_("Cannot do a %s reset in the middle of a merge."), _(reset_type_names[reset_type])); diff --git a/builtin/update-index.c b/builtin/update-index.c index 7b0c924d7d4..e1b2bb78e72 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -445,7 +445,7 @@ static void chmod_path(char flip, const char *path) if (pos < 0) goto fail; ce = active_cache[pos]; - if (chmod_cache_entry(ce, flip) < 0) + if (chmod_index_entry(&the_index, ce, flip) < 0) goto fail; report("chmod %cx '%s'", flip, path); @@ -641,7 +641,7 @@ static int unresolve_one(const char *path) pos = cache_name_pos(path, namelen); if (0 <= pos) { /* already merged */ - pos = unmerge_cache_entry_at(pos); + pos = unmerge_index_entry_at(&the_index, pos); if (pos < active_nr) { const struct cache_entry *ce = active_cache[pos]; if (ce_stage(ce) && diff --git a/cache.h b/cache.h index 29bb0ad2b41..53dc4341717 100644 --- a/cache.h +++ b/cache.h @@ -444,25 +444,15 @@ extern struct index_state the_index; #define read_cache() repo_read_index(the_repository) #define read_cache_from(path) read_index_from(&the_index, (path), (get_git_dir())) #define read_cache_preload(pathspec) repo_read_index_preload(the_repository, (pathspec), 0) -#define is_cache_unborn() is_index_unborn(&the_index) -#define read_cache_unmerged() repo_read_index_unmerged(the_repository) #define discard_cache() discard_index(&the_index) -#define unmerged_cache() unmerged_index(&the_index) #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen)) #define add_cache_entry(ce, option) add_index_entry(&the_index, (ce), (option)) -#define rename_cache_entry_at(pos, new_name) rename_index_entry_at(&the_index, (pos), (new_name)) #define remove_file_from_cache(path) remove_file_from_index(&the_index, (path)) -#define add_to_cache(path, st, flags) add_to_index(&the_index, (path), (st), (flags)) -#define add_file_to_cache(path, flags) add_file_to_index(&the_index, (path), (flags)) -#define chmod_cache_entry(ce, flip) chmod_index_entry(&the_index, (ce), (flip)) #define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL, NULL) #define refresh_and_write_cache(refresh_flags, write_flags, gentle) repo_refresh_and_write_index(the_repository, (refresh_flags), (write_flags), (gentle), NULL, NULL, NULL) #define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options)) #define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options)) -#define cache_file_exists(name, namelen, igncase) index_file_exists(&the_index, (name), (namelen), (igncase)) -#define cache_name_is_other(name, namelen) index_name_is_other(&the_index, (name), (namelen)) #define resolve_undo_clear() resolve_undo_clear_index(&the_index) -#define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at) #define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags)) #endif diff --git a/contrib/coccinelle/index-compatibility.cocci b/contrib/coccinelle/index-compatibility.cocci new file mode 100644 index 00000000000..04207c409e1 --- /dev/null +++ b/contrib/coccinelle/index-compatibility.cocci @@ -0,0 +1,45 @@ +// "the_repository" simple cases +@@ +@@ +( +- read_cache_unmerged ++ repo_read_index_unmerged +) + ( ++ the_repository, + ...) + +// "the_index" simple cases +@@ +@@ +( +- is_cache_unborn ++ is_index_unborn +| +- unmerged_cache ++ unmerged_index +| +- rename_cache_entry_at ++ rename_index_entry_at +| +- chmod_cache_entry ++ chmod_index_entry +| +- cache_file_exists ++ index_file_exists +| +- cache_name_is_other ++ index_name_is_other +| +- unmerge_cache_entry_at ++ unmerge_index_entry_at +| +- add_to_cache ++ add_to_index +| +- add_file_to_cache ++ add_file_to_index +) + ( ++ &the_index, + ...) From patchwork Sat Nov 19 13:07:31 2022 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: 13049735 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 4A9A6C433FE for ; Sat, 19 Nov 2022 13:08:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233817AbiKSNH7 (ORCPT ); Sat, 19 Nov 2022 08:07:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233576AbiKSNHy (ORCPT ); Sat, 19 Nov 2022 08:07:54 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9979B8FF8B for ; Sat, 19 Nov 2022 05:07:52 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id l11so10604762edb.4 for ; Sat, 19 Nov 2022 05:07: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=gdLtHAMPlY1D5GoKUQBaTZvYHsE1AWCSANryp5WaWCc=; b=HYpltvmztDRmPw7svRoZmTfsPl0D1FZkIeZcBXuAPnf/R6AaJyROeIL4MJKxirdNr2 3XDiKuvfHT68m595qniIC+XyeiRHdZ+mZ6hErWY/iwV06sJtChZ+zDjP3LHWJLlPTqGs nVeLG0cuC3GCQixp4GXcqm7uAWCGrNnwCOJFGJFHZUp0HtA816ZhxrerU7nyoV8rba7P GVQw2V9AD8KI0rUMDybFaPsxZmw67X8G83BIGOjLS8/wU7pEfLLepNuN42YPj/5rHUSW cEYjH668uFAAQl/4QvwXgUR0j2vkIGLzpcmdF6Qwl/6g4wsw+rhVx+/myioTTUlQidzY zWrw== 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=gdLtHAMPlY1D5GoKUQBaTZvYHsE1AWCSANryp5WaWCc=; b=A8nbFi0+sUgMg8Oe6evHjVHfcB97glkZJ0HngWzOwZwJtNSsc8hGRJ5kbiIOk0eUe1 +AnUh2FfsfCc9eVnULD6Qxw4KnuF6f8yuxzKSyd/mcQ92xzszx97d8RKWNW6QMvzcLPc 4nOnTwiadlXlSAWASK9cPl1tTJ/GoEvoDxxylH3O7+66v0OXRFgGmg9nCPj3pKV8ZsMN 0/K80SII9gW4fARDdmudgBXHBxKAVMpjxc4DL/mLs2sk+IdTivqH9hImfelefDhsO95x z0AVS7XAvLE05KfozVEYTPdExiQ0lC6hPk/kRg1S2bPOSaND36orOfWcZQxXeHhBRVdq sxKQ== X-Gm-Message-State: ANoB5pndna8NW2jRSj//eG95Z74PU9/aKZf06XCzyTwdMnFQrRceIMqW OATnvqqLFbNfReiJ/PdNfQmfXX5VzRmC8w== X-Google-Smtp-Source: AA0mqf7BnYJQwcVha4zhun/z/lZ2xTHOFXc6Rl/QAfNIPz81ED3SoFvOI5F4d27CNiXJ4+IYzjxZTg== X-Received: by 2002:a05:6402:3203:b0:467:b8c9:a7fa with SMTP id g3-20020a056402320300b00467b8c9a7famr10003141eda.25.1668863270802; Sat, 19 Nov 2022 05:07:50 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id ch28-20020a0564021bdc00b0045d74aa401fsm2923802edb.60.2022.11.19.05.07.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Nov 2022 05:07:49 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 04/11] read-cache API & users: make discard_index() return void Date: Sat, 19 Nov 2022 14:07:31 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1509.g9445af83948 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The discard_index() function has not returned non-zero since 7a51ed66f65 (Make on-disk index representation separate from in-core one, 2008-01-14), but we've had various code in-tree still acting as though that might be the case. Signed-off-by: Ævar Arnfjörð Bjarmason --- add-interactive.c | 8 ++++---- add-patch.c | 3 ++- builtin/merge.c | 3 ++- cache.h | 2 +- read-cache.c | 4 +--- sequencer.c | 15 +++++++++------ 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/add-interactive.c b/add-interactive.c index ecc5ae1b249..ae1839c04a7 100644 --- a/add-interactive.c +++ b/add-interactive.c @@ -530,8 +530,8 @@ static int get_modified_files(struct repository *r, struct collection_status s = { 0 }; int i; - if (discard_index(r->index) < 0 || - repo_read_index_preload(r, ps, 0) < 0) + discard_index(r->index); + if (repo_read_index_preload(r, ps, 0) < 0) return error(_("could not read index")); prefix_item_list_clear(files); @@ -1156,8 +1156,8 @@ int run_add_i(struct repository *r, const struct pathspec *ps) _("staged"), _("unstaged"), _("path")); opts.list_opts.header = header.buf; - if (discard_index(r->index) < 0 || - repo_read_index(r) < 0 || + discard_index(r->index); + if (repo_read_index(r) < 0 || repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1, NULL, NULL, NULL) < 0) warning(_("could not refresh index")); diff --git a/add-patch.c b/add-patch.c index 33ecd8398a1..a86a92e1646 100644 --- a/add-patch.c +++ b/add-patch.c @@ -1750,7 +1750,8 @@ int run_add_p(struct repository *r, enum add_p_mode mode, s.mode = &patch_mode_add; s.revision = revision; - if (discard_index(r->index) < 0 || repo_read_index(r) < 0 || + discard_index(r->index); + if (repo_read_index(r) < 0 || (!s.mode->index_only && repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1, NULL, NULL, NULL) < 0) || diff --git a/builtin/merge.c b/builtin/merge.c index da11dfae19e..89fdac24e40 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -390,7 +390,8 @@ static void restore_state(const struct object_id *head, run_command(&cmd); refresh_cache: - if (discard_cache() < 0 || read_cache() < 0) + discard_cache(); + if (read_cache() < 0) die(_("could not read index")); } diff --git a/cache.h b/cache.h index 53dc4341717..489e9e1925b 100644 --- a/cache.h +++ b/cache.h @@ -774,7 +774,7 @@ void ensure_full_index(struct index_state *istate); */ int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags); -int discard_index(struct index_state *); +void discard_index(struct index_state *); void move_index_extensions(struct index_state *dst, struct index_state *src); int unmerged_index(const struct index_state *); diff --git a/read-cache.c b/read-cache.c index 32024029274..46f5e497b14 100644 --- a/read-cache.c +++ b/read-cache.c @@ -2531,7 +2531,7 @@ int is_index_unborn(struct index_state *istate) return (!istate->cache_nr && !istate->timestamp.sec); } -int discard_index(struct index_state *istate) +void discard_index(struct index_state *istate) { /* * Cache entries in istate->cache[] should have been allocated @@ -2562,8 +2562,6 @@ int discard_index(struct index_state *istate) mem_pool_discard(istate->ce_mem_pool, should_validate_cache_entries()); FREE_AND_NULL(istate->ce_mem_pool); } - - return 0; } /* diff --git a/sequencer.c b/sequencer.c index a46f3ad2e33..746a71cdc92 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3564,7 +3564,8 @@ static int do_exec(struct repository *r, const char *command_line) status = run_command(&cmd); /* force re-reading of the cache */ - if (discard_index(r->index) < 0 || repo_read_index(r) < 0) + discard_index(r->index); + if (repo_read_index(r) < 0) return error(_("could not read index")); dirty = require_clean_work_tree(r, "rebase", NULL, 1, 1); @@ -4029,9 +4030,11 @@ static int do_merge(struct repository *r, ret = run_command(&cmd); /* force re-reading of the cache */ - if (!ret && (discard_index(r->index) < 0 || - repo_read_index(r) < 0)) - ret = error(_("could not read index")); + if (!ret) { + discard_index(r->index); + if (repo_read_index(r) < 0) + ret = error(_("could not read index")); + } goto leave_merge; } @@ -4404,8 +4407,8 @@ void create_autostash(struct repository *r, const char *path) printf(_("Created autostash: %s\n"), buf.buf); if (reset_head(r, &ropts) < 0) die(_("could not reset --hard")); - if (discard_index(r->index) < 0 || - repo_read_index(r) < 0) + discard_index(r->index); + if (repo_read_index(r) < 0) die(_("could not read index")); } strbuf_release(&buf); From patchwork Sat Nov 19 13:07:32 2022 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: 13049737 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 4A521C4332F for ; Sat, 19 Nov 2022 13:08:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233862AbiKSNIA (ORCPT ); Sat, 19 Nov 2022 08:08:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232923AbiKSNHy (ORCPT ); Sat, 19 Nov 2022 08:07:54 -0500 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 991C79150F for ; Sat, 19 Nov 2022 05:07:53 -0800 (PST) Received: by mail-ej1-x634.google.com with SMTP id f27so19219303eje.1 for ; Sat, 19 Nov 2022 05:07: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=/LTZurM52svLb6DffW0f3XwhUa3KTR3d9c5iYxl60wY=; b=okvhGAU96Eq8a+ypffVK+8lVPuKKaYVF8TbyjAz7XYt+4Uo6ki1stHuVFqpHDY5gUQ 735t97nwaZTZ72LR0PjqZhKMyNeTi0N8qx6uGzDzcy/IvmX6KXkJt1BecwmeiRtJj2L5 pdMldbq5Ma1bDhyDNHZeXmeVRqtBc/lycu79IRhilOmw8vY1SD7jmjMsv3zWGTA8EWbS GBWIWH0Hbk9A8dMCPSccym6IaSzAUkRy6CCbehEj8pS9rRCBf/YGWdekaAa32HPd6EAj 0ZCHbb+F1unaAPsziVcW2LzFh2qM8xR9chAYwdKBoSHHuJQqW5Q+zgdxFdgP2eTpDCXh ENmQ== 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=/LTZurM52svLb6DffW0f3XwhUa3KTR3d9c5iYxl60wY=; b=1YNuQ/vZQTLXxtxQI7VgMby9DT6KUXUZLOk742moVqywbKxpgBZDU3WKypPeYE3o1b cv0NmewRadmcnmFnHi3PcdYn20l3/eKNSTV8IqJKtTIiImRBsfKBekP3s/j5cscSiuMR x/Ro03PtvdPP/Z9bpHCz/h9lFV8GYzC94BU3TuMkjae62XVB6iej/FQnOE6NOBNM+d2X bKGInBW+V2wAe06po2U3JUmH9htIn4AF5qlL5DyYMR6eCLXgysFCfBYEiHrYFeWTGpm3 Ur36FJwTbfDzadWH3jbfxOtcqzBnd82QhRCRiQnZHG1+kL413H8EXB/l0fUsUxHU3hyz u/8g== X-Gm-Message-State: ANoB5pk1LwO73iEbz/+JCHLGNNwIk/N64TVhaV/Of/lp5svdPi1PwODr j6+yi43bfhmJkxthamTzjXHh5Vjr8q/EEw== X-Google-Smtp-Source: AA0mqf5VB2lP/rM/4Xr5RPqGEvWDq7fU6IqPuQUjzoqbEPOmaRVJsEn7L8qT0wbgETmeXYE7uRz/1A== X-Received: by 2002:a17:906:2693:b0:7aa:57c3:3f26 with SMTP id t19-20020a170906269300b007aa57c33f26mr9452304ejc.195.1668863271678; Sat, 19 Nov 2022 05:07:51 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id ch28-20020a0564021bdc00b0045d74aa401fsm2923802edb.60.2022.11.19.05.07.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Nov 2022 05:07:51 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 05/11] cocci: add a index-compatibility.pending.cocci Date: Sat, 19 Nov 2022 14:07:32 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1509.g9445af83948 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a coccinelle rule which covers the rest of the macros guarded by "USE_THE_INDEX_COMPATIBILITY_MACROS" cache.h. If the result of this were applied it can be reduced down to just: #ifdef USE_THE_INDEX_COMPATIBILITY_MACROS extern struct index_state the_index; #endif But that patch is just under 2000 lines, so let's first add this as a "pending", and then incrementally pick changes from it in subsequent commits. In doing that we'll migrate rules from this "index-compatibility.pending.cocci" to the "index-compatibility.cocci" created in a preceding commit. Signed-off-by: Ævar Arnfjörð Bjarmason --- .../index-compatibility.pending.cocci | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 contrib/coccinelle/index-compatibility.pending.cocci diff --git a/contrib/coccinelle/index-compatibility.pending.cocci b/contrib/coccinelle/index-compatibility.pending.cocci new file mode 100644 index 00000000000..6e96de0f638 --- /dev/null +++ b/contrib/coccinelle/index-compatibility.pending.cocci @@ -0,0 +1,110 @@ +// the_index.* variables +@@ +@@ +( +- active_cache ++ the_index.cache +| +- active_nr ++ the_index.cache_nr +| +- active_cache_changed ++ the_index.cache_changed +| +- active_cache_tree ++ the_index.cache_tree +) + +// "the_repository" simple cases +@@ +@@ +( +- read_cache ++ repo_read_index +| +- hold_locked_index ++ repo_hold_locked_index +) + ( ++ the_repository, + ...) + +// "the_index" simple cases +@@ +@@ +( +- discard_cache ++ discard_index +| +- cache_name_pos ++ index_name_pos +| +- add_cache_entry ++ add_index_entry +| +- remove_file_from_cache ++ remove_file_from_index +| +- ce_match_stat ++ ie_match_stat +| +- ce_modified ++ ie_modified +| +- resolve_undo_clear ++ resolve_undo_clear_index +) + ( ++ &the_index, + ...) + +// "the_repository" special-cases +@@ +@@ +( +- read_cache_preload ++ repo_read_index_preload +) + ( ++ the_repository, + ... ++ , 0 + ) + +@@ +@@ +( +- refresh_and_write_cache ++ repo_refresh_and_write_index +) + ( ++ the_repository, + ... ++ , NULL, NULL, NULL + ) + + +// "the_index" special-cases +@@ +@@ +( +- read_cache_from ++ read_index_from +) + ( ++ &the_index, + ... ++ , get_git_dir() + ) + +@@ +@@ +( +- refresh_cache ++ refresh_index +) + ( ++ &the_index, + ... ++ , NULL, NULL, NULL + ) From patchwork Sat Nov 19 13:07:33 2022 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: 13049738 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 847D0C43217 for ; Sat, 19 Nov 2022 13:08:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233903AbiKSNIC (ORCPT ); Sat, 19 Nov 2022 08:08:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233670AbiKSNH4 (ORCPT ); Sat, 19 Nov 2022 08:07:56 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70C2990596 for ; Sat, 19 Nov 2022 05:07:54 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id s5so10557790edc.12 for ; Sat, 19 Nov 2022 05:07:54 -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=7vMPKAIJbk5wrO+LupTb1Mf59IgCyh6iqeI8EX4ox8U=; b=A3/qZp2KxWTBLw9C2g/4h0k78dKlHXJ16IZgqu1gt+dOsu4lfR9eUj6crlhFln/nUo PMEyhy0Ti/fuwKzGVSAVchw+4kxwnymHmyW6GC3fIeeGj0WhR3cQKXGI+Ztu1zt4MaHQ NIOd4oHnZASIzUr639ECkP1/ClZIe6Zuv3PJIGLjGZC7Ho0cAvurwmOIvXnxpnBG5ebf 93KEgvqPwvh+dYpIAXa92Xb3w2Cg6UL/+W6zD59oMbanE9Rjndf7ouYBBVXlp5K6AYgk EpCyPXbToBSz9ga6vDdHf1Jr8jLN0gByGW9X70M5JA7q3Au+KEZ1e+ZtRckwXtbFS9so Qodw== 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=7vMPKAIJbk5wrO+LupTb1Mf59IgCyh6iqeI8EX4ox8U=; b=rMF812y1Dfsg5kwNOnb7ysenFIw69ShPb40wa4X/aV+3OXF/ObOtR1j1jyQLyegd4n 1YSFH5JaAO+92Wvd6G6vNkcmaveQH78gEyAZXDO9ayhryqxUvt4YR0uxLdVwuYHzUnr3 I80CrXlkBpkbS1Nb5Ej9XFde7Zo0vL1jtREixgLrE8Iri/Kk1op/QIrRQtI0c5HcPsWV Gasf7N+ednK19iHBQCpxdtjMVkC5W79by14EBeB6WsKl0Ht1vTtdj/2IrAVq0rPTWzij /rdbTpLXAtCro9vUMD0siiNptyLRbkF/Av4LL/QUErzu949NdAUc/z9UapyNPAScs9Qr jT7Q== X-Gm-Message-State: ANoB5pnBSQj/I2Pd5RRUYwNVElp7sKL2M3OCXjZCMpTikhtmmKeXvSAW 83t5ba+JYaCnz/Go/09fgahsvfQvzHSCiQ== X-Google-Smtp-Source: AA0mqf5XZI7uZUWfb4cSYo0ubsN7AHu1fhMXpFynB2f7i7wy0ttYZSQUFrXgxZ83Egd4HoWDkhKwnw== X-Received: by 2002:aa7:d7d3:0:b0:469:906:2ece with SMTP id e19-20020aa7d7d3000000b0046909062ecemr6504256eds.342.1668863272519; Sat, 19 Nov 2022 05:07:52 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id ch28-20020a0564021bdc00b0045d74aa401fsm2923802edb.60.2022.11.19.05.07.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Nov 2022 05:07:51 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 06/11] cocci & cache.h: apply a selection of "pending" index-compatibility Date: Sat, 19 Nov 2022 14:07:33 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1509.g9445af83948 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Apply a selection of rules in "index-compatibility.pending.cocci" tree-wide, and in doing so migrate them to "index-compatibility.cocci". As in preceding commits the only manual changes here are the macro removals in "cache.h", and the update to the '*.cocci" rules. The rest of the C code changes are the result of applying those updated rules. Move rules for some rarely used cache compatibility macros from "index-compatibility.pending.cocci" to "index-compatibility.cocci" and apply them. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/checkout.c | 5 +++-- builtin/commit.c | 2 +- builtin/merge.c | 2 +- builtin/mv.c | 4 +++- builtin/read-tree.c | 2 +- builtin/reset.c | 5 +++-- builtin/rm.c | 4 ++-- builtin/update-index.c | 22 +++++++++---------- cache.h | 5 ----- contrib/coccinelle/index-compatibility.cocci | 15 +++++++++++++ .../index-compatibility.pending.cocci | 15 ------------- 11 files changed, 40 insertions(+), 41 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index aa610b274e3..afbd71764a3 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -160,7 +160,8 @@ static int update_some(const struct object_id *oid, struct strbuf *base, } } - add_cache_entry(ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE); + add_index_entry(&the_index, ce, + ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE); return 0; } @@ -744,7 +745,7 @@ static int merge_working_tree(const struct checkout_opts *opts, if (read_cache_preload(NULL) < 0) return error(_("index file corrupt")); - resolve_undo_clear(); + resolve_undo_clear_index(&the_index); if (opts->new_orphan_branch && opts->orphan_from_empty_tree) { if (new_branch_info->commit) BUG("'switch --orphan' should never accept a commit as starting point"); diff --git a/builtin/commit.c b/builtin/commit.c index 985503d43a6..10a827b1f4a 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -305,7 +305,7 @@ static void add_remove_files(struct string_list *list) if (add_to_index(&the_index, p->string, &st, 0)) die(_("updating files failed")); } else - remove_file_from_cache(p->string); + remove_file_from_index(&the_index, p->string); } } diff --git a/builtin/merge.c b/builtin/merge.c index 89fdac24e40..2046992d75a 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -1397,7 +1397,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) else die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).")); } - resolve_undo_clear(); + resolve_undo_clear_index(&the_index); if (option_edit < 0) option_edit = default_edit_option(); diff --git a/builtin/mv.c b/builtin/mv.c index df6157fd6b5..6f94c3b9238 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -471,7 +471,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix) pos = cache_name_pos(src, strlen(src)); assert(pos >= 0); if (!(mode & SPARSE) && !lstat(src, &st)) - sparse_and_dirty = ce_modified(active_cache[pos], &st, 0); + sparse_and_dirty = ie_modified(&the_index, + active_cache[pos], &st, + 0); rename_index_entry_at(&the_index, pos, dst); if (ignore_sparse && diff --git a/builtin/read-tree.c b/builtin/read-tree.c index fd708273101..9ced755a6db 100644 --- a/builtin/read-tree.c +++ b/builtin/read-tree.c @@ -192,7 +192,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix) die(_("You need to resolve your current index first")); stage = opts.merge = 1; } - resolve_undo_clear(); + resolve_undo_clear_index(&the_index); for (i = 0; i < argc; i++) { const char *arg = argv[i]; diff --git a/builtin/reset.c b/builtin/reset.c index e561180e8c4..59f777a1da4 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -145,7 +145,7 @@ static void update_index_from_diff(struct diff_queue_struct *q, struct cache_entry *ce; if (!is_in_reset_tree && !intent_to_add) { - remove_file_from_cache(one->path); + remove_file_from_index(&the_index, one->path); continue; } @@ -172,7 +172,8 @@ static void update_index_from_diff(struct diff_queue_struct *q, ce->ce_flags |= CE_INTENT_TO_ADD; set_object_name_for_intent_to_add_entry(ce); } - add_cache_entry(ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE); + add_index_entry(&the_index, ce, + ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE); } } diff --git a/builtin/rm.c b/builtin/rm.c index f0d025a4e23..c717cdc97f5 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -168,7 +168,7 @@ static int check_local_mod(struct object_id *head, int index_only) * Is the index different from the file in the work tree? * If it's a submodule, is its work tree modified? */ - if (ce_match_stat(ce, &st, 0) || + if (ie_match_stat(&the_index, ce, &st, 0) || (S_ISGITLINK(ce->ce_mode) && bad_to_remove_submodule(ce->name, SUBMODULE_REMOVAL_DIE_ON_ERROR | @@ -386,7 +386,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix) if (!quiet) printf("rm '%s'\n", path); - if (remove_file_from_cache(path)) + if (remove_file_from_index(&the_index, path)) die(_("git rm: unable to remove %s"), path); } diff --git a/builtin/update-index.c b/builtin/update-index.c index e1b2bb78e72..533ba66df05 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -256,7 +256,7 @@ static int remove_one_path(const char *path) { if (!allow_remove) return error("%s: does not exist and --remove not passed", path); - if (remove_file_from_cache(path)) + if (remove_file_from_index(&the_index, path)) return error("%s: cannot remove from the index", path); return 0; } @@ -281,7 +281,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len struct cache_entry *ce; /* Was the old index entry already up-to-date? */ - if (old && !ce_stage(old) && !ce_match_stat(old, st, 0)) + if (old && !ce_stage(old) && !ie_match_stat(&the_index, old, st, 0)) return 0; ce = make_empty_cache_entry(&the_index, len); @@ -298,7 +298,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len } option = allow_add ? ADD_CACHE_OK_TO_ADD : 0; option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0; - if (add_cache_entry(ce, option)) { + if (add_index_entry(&the_index, ce, option)) { discard_cache_entry(ce); return error("%s: cannot add to the index - missing --add option?", path); } @@ -390,7 +390,7 @@ static int process_path(const char *path, struct stat *st, int stat_errno) * On the other hand, removing it from index should work */ if (!ignore_skip_worktree_entries && allow_remove && - remove_file_from_cache(path)) + remove_file_from_index(&the_index, path)) return error("%s: cannot remove from the index", path); return 0; } @@ -429,7 +429,7 @@ static int add_cacheinfo(unsigned int mode, const struct object_id *oid, ce->ce_flags |= CE_VALID; option = allow_add ? ADD_CACHE_OK_TO_ADD : 0; option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0; - if (add_cache_entry(ce, option)) + if (add_index_entry(&the_index, ce, option)) return error("%s: cannot add to the index - missing --add option?", path); report("add '%s'", path); @@ -488,7 +488,7 @@ static void update_one(const char *path) } if (force_remove) { - if (remove_file_from_cache(path)) + if (remove_file_from_index(&the_index, path)) die("git update-index: unable to remove %s", path); report("remove '%s'", path); return; @@ -571,7 +571,7 @@ static void read_index_info(int nul_term_line) if (!mode) { /* mode == 0 means there is no such path -- remove */ - if (remove_file_from_cache(path_name)) + if (remove_file_from_index(&the_index, path_name)) die("git update-index: unable to remove %s", ptr); } @@ -686,13 +686,13 @@ static int unresolve_one(const char *path) goto free_return; } - remove_file_from_cache(path); - if (add_cache_entry(ce_2, ADD_CACHE_OK_TO_ADD)) { + remove_file_from_index(&the_index, path); + if (add_index_entry(&the_index, ce_2, ADD_CACHE_OK_TO_ADD)) { error("%s: cannot add our version to the index.", path); ret = -1; goto free_return; } - if (!add_cache_entry(ce_3, ADD_CACHE_OK_TO_ADD)) + if (!add_index_entry(&the_index, ce_3, ADD_CACHE_OK_TO_ADD)) return 0; error("%s: cannot add their version to the index.", path); ret = -1; @@ -850,7 +850,7 @@ static int resolve_undo_clear_callback(const struct option *opt, { BUG_ON_OPT_NEG(unset); BUG_ON_OPT_ARG(arg); - resolve_undo_clear(); + resolve_undo_clear_index(&the_index); return 0; } diff --git a/cache.h b/cache.h index 489e9e1925b..79b8d479710 100644 --- a/cache.h +++ b/cache.h @@ -446,13 +446,8 @@ extern struct index_state the_index; #define read_cache_preload(pathspec) repo_read_index_preload(the_repository, (pathspec), 0) #define discard_cache() discard_index(&the_index) #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen)) -#define add_cache_entry(ce, option) add_index_entry(&the_index, (ce), (option)) -#define remove_file_from_cache(path) remove_file_from_index(&the_index, (path)) #define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL, NULL) #define refresh_and_write_cache(refresh_flags, write_flags, gentle) repo_refresh_and_write_index(the_repository, (refresh_flags), (write_flags), (gentle), NULL, NULL, NULL) -#define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options)) -#define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options)) -#define resolve_undo_clear() resolve_undo_clear_index(&the_index) #define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags)) #endif diff --git a/contrib/coccinelle/index-compatibility.cocci b/contrib/coccinelle/index-compatibility.cocci index 04207c409e1..89c18986160 100644 --- a/contrib/coccinelle/index-compatibility.cocci +++ b/contrib/coccinelle/index-compatibility.cocci @@ -39,6 +39,21 @@ | - add_file_to_cache + add_file_to_index +| +- add_cache_entry ++ add_index_entry +| +- remove_file_from_cache ++ remove_file_from_index +| +- ce_match_stat ++ ie_match_stat +| +- ce_modified ++ ie_modified +| +- resolve_undo_clear ++ resolve_undo_clear_index ) ( + &the_index, diff --git a/contrib/coccinelle/index-compatibility.pending.cocci b/contrib/coccinelle/index-compatibility.pending.cocci index 6e96de0f638..cf1ea57d700 100644 --- a/contrib/coccinelle/index-compatibility.pending.cocci +++ b/contrib/coccinelle/index-compatibility.pending.cocci @@ -38,21 +38,6 @@ | - cache_name_pos + index_name_pos -| -- add_cache_entry -+ add_index_entry -| -- remove_file_from_cache -+ remove_file_from_index -| -- ce_match_stat -+ ie_match_stat -| -- ce_modified -+ ie_modified -| -- resolve_undo_clear -+ resolve_undo_clear_index ) ( + &the_index, From patchwork Sat Nov 19 13:07:34 2022 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: 13049740 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 0C6DCC433FE for ; Sat, 19 Nov 2022 13:08:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234014AbiKSNIT (ORCPT ); Sat, 19 Nov 2022 08:08:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233571AbiKSNH6 (ORCPT ); Sat, 19 Nov 2022 08:07:58 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF9278FE4E for ; Sat, 19 Nov 2022 05:07:55 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id n21so19102682ejb.9 for ; Sat, 19 Nov 2022 05:07: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=as5su2VCT4z+Hg6/C9laaK25IcyAiJP4JdHcObLJSEU=; b=Umd2TlgwGop92AuCQLMsIgIXyTakmZklEbfrjDWukNcTeuxi8oyUJlsAGAFEcFHWnj apiwsjBI8nxFrtrwu9DXvVjVEf2H8bfC0Q/SQeIqJjitP6l5z2XWz6xtFMhJ0QuucG3+ tPXi1bMNgWYNdl3M75cjn268vHISlFHbPmhgsijSFkBP0wJf5EE1+pF+NDiAnt8MKW6E POldRXj2MxnAMlpvAXD4st4Yfb3evrGiFlYM1evD3FLzaxGTwP2c51lkDmiVo7iqAl4P 5ZbogYwwBXzFy8alsxQ1A7Aoyp7M8Ig7naXzuD5lgyZombdsPpAKOK7w8XYz2IthLe7i xKGA== 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=as5su2VCT4z+Hg6/C9laaK25IcyAiJP4JdHcObLJSEU=; b=dM5Am98puXJrprM9C9QgW5tJODB5wQUlUXYCHGnwLyqNmt4HmM/bhxE+7Ninn+tswa NRQfNnykACkmJ8BJjYYeRUVYasguf2lmvx/+oQgJ6ZmXdnobNCV4sy0VK5kB9tXxrKrW QOERB1q2LDKOMhAGLH2TSDVrq848IW34g+4fJ2WK4N+r6YPO3A5ZviIrRkBX4wSwjwGD jMkgaJKFZS094fhdir4G8x0Dqxc/D2Z3Fevbi/hZd3iUPGZ2iws2QNSUyStVcDiVJQPv SVj0uEjyJjC71HvtuU/pbZigtLDSvjfCJ4mDPeHVVCHNd3FwdMmV9s3jMUnnUeWxjlK7 diPA== X-Gm-Message-State: ANoB5pmMqrY4ephPz0k/ll0vjmWj1Psu/qY1mCXJI6b1HIwbFHPhgpgR dqounwUMapyYzoD3ffKsqgUeUOMSzWKOOg== X-Google-Smtp-Source: AA0mqf628oMlYxJR1/C+4pjwQSbZj96NVbqWHfVwpX04rXy+l3IqLx+wfr4WfzWzRzkEJn1OeDJZ1A== X-Received: by 2002:a17:906:2552:b0:7ad:917b:61ec with SMTP id j18-20020a170906255200b007ad917b61ecmr1083401ejb.513.1668863273552; Sat, 19 Nov 2022 05:07:53 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id ch28-20020a0564021bdc00b0045d74aa401fsm2923802edb.60.2022.11.19.05.07.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Nov 2022 05:07:52 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 07/11] cocci & cache.h: apply variable section of "pending" index-compatibility Date: Sat, 19 Nov 2022 14:07:34 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1509.g9445af83948 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Mostly apply the part of "index-compatibility.pending.cocci" that renames the global variables like "active_nr", which are a shorthand to referencing (in that case) a struct member as "the_index.cache_nr". In doing so move more of "index-compatibility.pending.cocci" to "index-compatibility.cocci". In the case of "active_nr" we'd have a textual conflict with "ab/various-leak-fixes" in "next"[1]. Let's exclude that specific case while moving the rule over from "pending". 1. 407b94280f8 (commit: discard partial cache before (re-)reading it, 2022-11-08) Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/add.c | 8 ++-- builtin/checkout-index.c | 10 ++-- builtin/checkout.c | 46 +++++++++---------- builtin/commit.c | 16 +++---- builtin/fsck.c | 12 ++--- builtin/merge-index.c | 10 ++-- builtin/merge.c | 6 +-- builtin/mv.c | 19 ++++---- builtin/read-tree.c | 2 +- builtin/reset.c | 2 +- builtin/rm.c | 14 +++--- builtin/stash.c | 8 ++-- builtin/submodule--helper.c | 14 +++--- builtin/update-index.c | 46 +++++++++---------- cache.h | 3 -- contrib/coccinelle/index-compatibility.cocci | 22 +++++++++ .../index-compatibility.pending.cocci | 17 ------- t/helper/test-dump-cache-tree.c | 2 +- t/helper/test-scrap-cache-tree.c | 4 +- 19 files changed, 132 insertions(+), 129 deletions(-) diff --git a/builtin/add.c b/builtin/add.c index 75be1d021ab..23f9f0e08bb 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -42,8 +42,8 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only) { int i, ret = 0; - for (i = 0; i < active_nr; i++) { - struct cache_entry *ce = active_cache[i]; + for (i = 0; i < the_index.cache_nr; i++) { + struct cache_entry *ce = the_index.cache[i]; int err; if (!include_sparse && @@ -159,8 +159,8 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags) { int i, retval = 0; - for (i = 0; i < active_nr; i++) { - struct cache_entry *ce = active_cache[i]; + for (i = 0; i < the_index.cache_nr; i++) { + struct cache_entry *ce = the_index.cache[i]; if (!include_sparse && (ce_skip_worktree(ce) || diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c index 97e06e8c52c..c2aee450c40 100644 --- a/builtin/checkout-index.c +++ b/builtin/checkout-index.c @@ -75,8 +75,8 @@ static int checkout_file(const char *name, const char *prefix) if (pos < 0) pos = -pos - 1; - while (pos < active_nr) { - struct cache_entry *ce = active_cache[pos]; + while (pos < the_index.cache_nr) { + struct cache_entry *ce = the_index.cache[pos]; if (ce_namelen(ce) != namelen || memcmp(ce->name, name, namelen)) break; @@ -136,8 +136,8 @@ static int checkout_all(const char *prefix, int prefix_length) int i, errs = 0; struct cache_entry *last_ce = NULL; - for (i = 0; i < active_nr ; i++) { - struct cache_entry *ce = active_cache[i]; + for (i = 0; i < the_index.cache_nr ; i++) { + struct cache_entry *ce = the_index.cache[i]; if (S_ISSPARSEDIR(ce->ce_mode)) { if (!ce_skip_worktree(ce)) @@ -151,7 +151,7 @@ static int checkout_all(const char *prefix, int prefix_length) */ if (ignore_skip_worktree) { ensure_full_index(&the_index); - ce = active_cache[i]; + ce = the_index.cache[i]; } } diff --git a/builtin/checkout.c b/builtin/checkout.c index afbd71764a3..3fd303f5604 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -150,7 +150,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base, */ pos = cache_name_pos(ce->name, ce->ce_namelen); if (pos >= 0) { - struct cache_entry *old = active_cache[pos]; + struct cache_entry *old = the_index.cache[pos]; if (ce->ce_mode == old->ce_mode && !ce_intent_to_add(old) && oideq(&ce->oid, &old->oid)) { @@ -179,8 +179,8 @@ static int read_tree_some(struct tree *tree, const struct pathspec *pathspec) static int skip_same_name(const struct cache_entry *ce, int pos) { - while (++pos < active_nr && - !strcmp(active_cache[pos]->name, ce->name)) + while (++pos < the_index.cache_nr && + !strcmp(the_index.cache[pos]->name, ce->name)) ; /* skip */ return pos; } @@ -188,9 +188,9 @@ static int skip_same_name(const struct cache_entry *ce, int pos) static int check_stage(int stage, const struct cache_entry *ce, int pos, int overlay_mode) { - while (pos < active_nr && - !strcmp(active_cache[pos]->name, ce->name)) { - if (ce_stage(active_cache[pos]) == stage) + while (pos < the_index.cache_nr && + !strcmp(the_index.cache[pos]->name, ce->name)) { + if (ce_stage(the_index.cache[pos]) == stage) return 0; pos++; } @@ -207,8 +207,8 @@ static int check_stages(unsigned stages, const struct cache_entry *ce, int pos) unsigned seen = 0; const char *name = ce->name; - while (pos < active_nr) { - ce = active_cache[pos]; + while (pos < the_index.cache_nr) { + ce = the_index.cache[pos]; if (strcmp(name, ce->name)) break; seen |= (1 << ce_stage(ce)); @@ -224,10 +224,10 @@ static int checkout_stage(int stage, const struct cache_entry *ce, int pos, const struct checkout *state, int *nr_checkouts, int overlay_mode) { - while (pos < active_nr && - !strcmp(active_cache[pos]->name, ce->name)) { - if (ce_stage(active_cache[pos]) == stage) - return checkout_entry(active_cache[pos], state, + while (pos < the_index.cache_nr && + !strcmp(the_index.cache[pos]->name, ce->name)) { + if (ce_stage(the_index.cache[pos]) == stage) + return checkout_entry(the_index.cache[pos], state, NULL, nr_checkouts); pos++; } @@ -244,7 +244,7 @@ static int checkout_stage(int stage, const struct cache_entry *ce, int pos, static int checkout_merged(int pos, const struct checkout *state, int *nr_checkouts, struct mem_pool *ce_mem_pool) { - struct cache_entry *ce = active_cache[pos]; + struct cache_entry *ce = the_index.cache[pos]; const char *path = ce->name; mmfile_t ancestor, ours, theirs; enum ll_merge_result merge_status; @@ -257,7 +257,7 @@ static int checkout_merged(int pos, const struct checkout *state, int renormalize = 0; memset(threeway, 0, sizeof(threeway)); - while (pos < active_nr) { + while (pos < the_index.cache_nr) { int stage; stage = ce_stage(ce); if (!stage || strcmp(path, ce->name)) @@ -266,7 +266,7 @@ static int checkout_merged(int pos, const struct checkout *state, if (stage == 2) mode = create_ce_mode(ce->ce_mode); pos++; - ce = active_cache[pos]; + ce = the_index.cache[pos]; } if (is_null_oid(&threeway[1]) || is_null_oid(&threeway[2])) return error(_("path '%s' does not have necessary versions"), path); @@ -392,8 +392,8 @@ static int checkout_worktree(const struct checkout_opts *opts, if (pc_workers > 1) init_parallel_checkout(); - for (pos = 0; pos < active_nr; pos++) { - struct cache_entry *ce = active_cache[pos]; + for (pos = 0; pos < the_index.cache_nr; pos++) { + struct cache_entry *ce = the_index.cache[pos]; if (ce->ce_flags & CE_MATCHED) { if (!ce_stage(ce)) { errs |= checkout_entry(ce, &state, @@ -541,13 +541,13 @@ static int checkout_paths(const struct checkout_opts *opts, * Make sure all pathspecs participated in locating the paths * to be checked out. */ - for (pos = 0; pos < active_nr; pos++) + for (pos = 0; pos < the_index.cache_nr; pos++) if (opts->overlay_mode) - mark_ce_for_checkout_overlay(active_cache[pos], + mark_ce_for_checkout_overlay(the_index.cache[pos], ps_matched, opts); else - mark_ce_for_checkout_no_overlay(active_cache[pos], + mark_ce_for_checkout_no_overlay(the_index.cache[pos], ps_matched, opts); @@ -562,8 +562,8 @@ static int checkout_paths(const struct checkout_opts *opts, unmerge_marked_index(&the_index); /* Any unmerged paths? */ - for (pos = 0; pos < active_nr; pos++) { - const struct cache_entry *ce = active_cache[pos]; + for (pos = 0; pos < the_index.cache_nr; pos++) { + const struct cache_entry *ce = the_index.cache[pos]; if (ce->ce_flags & CE_MATCHED) { if (!ce_stage(ce)) continue; @@ -868,7 +868,7 @@ static int merge_working_tree(const struct checkout_opts *opts, } } - if (!cache_tree_fully_valid(active_cache_tree)) + if (!cache_tree_fully_valid(the_index.cache_tree)) cache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR); if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK)) diff --git a/builtin/commit.c b/builtin/commit.c index 10a827b1f4a..abbed750276 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -272,8 +272,8 @@ static int list_paths(struct string_list *list, const char *with_tree, /* TODO: audit for interaction with sparse-index. */ ensure_full_index(&the_index); - for (i = 0; i < active_nr; i++) { - const struct cache_entry *ce = active_cache[i]; + for (i = 0; i < the_index.cache_nr; i++) { + const struct cache_entry *ce = the_index.cache[i]; struct string_list_item *item; if (ce->ce_flags & CE_UPDATE) @@ -461,8 +461,8 @@ static const char *prepare_index(const char **argv, const char *prefix, if (!only && !pathspec.nr) { hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR); refresh_cache_or_die(refresh_flags); - if (active_cache_changed - || !cache_tree_fully_valid(active_cache_tree)) + if (the_index.cache_changed + || !cache_tree_fully_valid(the_index.cache_tree)) update_main_cache_tree(WRITE_TREE_SILENT); if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK | SKIP_IF_UNCHANGED)) @@ -998,10 +998,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix, /* TODO: audit for interaction with sparse-index. */ ensure_full_index(&the_index); - for (i = 0; i < active_nr; i++) - if (ce_intent_to_add(active_cache[i])) + for (i = 0; i < the_index.cache_nr; i++) + if (ce_intent_to_add(the_index.cache[i])) ita_nr++; - committable = active_nr - ita_nr > 0; + committable = the_index.cache_nr - ita_nr > 0; } else { /* * Unless the user did explicitly request a submodule @@ -1823,7 +1823,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) append_merge_tag_headers(parents, &tail); } - if (commit_tree_extended(sb.buf, sb.len, &active_cache_tree->oid, + if (commit_tree_extended(sb.buf, sb.len, &the_index.cache_tree->oid, parents, &oid, author_ident.buf, NULL, sign_commit, extra)) { rollback_index_files(); diff --git a/builtin/fsck.c b/builtin/fsck.c index 7436e1a68ef..cd47675e371 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -961,26 +961,26 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) read_cache(); /* TODO: audit for interaction with sparse-index. */ ensure_full_index(&the_index); - for (i = 0; i < active_nr; i++) { + for (i = 0; i < the_index.cache_nr; i++) { unsigned int mode; struct blob *blob; struct object *obj; - mode = active_cache[i]->ce_mode; + mode = the_index.cache[i]->ce_mode; if (S_ISGITLINK(mode)) continue; blob = lookup_blob(the_repository, - &active_cache[i]->oid); + &the_index.cache[i]->oid); if (!blob) continue; obj = &blob->object; obj->flags |= USED; fsck_put_object_name(&fsck_walk_options, &obj->oid, - ":%s", active_cache[i]->name); + ":%s", the_index.cache[i]->name); mark_object_reachable(obj); } - if (active_cache_tree) - fsck_cache_tree(active_cache_tree); + if (the_index.cache_tree) + fsck_cache_tree(the_index.cache_tree); fsck_resolve_undo(&the_index); } diff --git a/builtin/merge-index.c b/builtin/merge-index.c index 012f52bd007..a334c513c9d 100644 --- a/builtin/merge-index.c +++ b/builtin/merge-index.c @@ -14,11 +14,11 @@ static int merge_entry(int pos, const char *path) char ownbuf[4][60]; struct child_process cmd = CHILD_PROCESS_INIT; - if (pos >= active_nr) + if (pos >= the_index.cache_nr) die("git merge-index: %s not in the cache", path); found = 0; do { - const struct cache_entry *ce = active_cache[pos]; + const struct cache_entry *ce = the_index.cache[pos]; int stage = ce_stage(ce); if (strcmp(ce->name, path)) @@ -28,7 +28,7 @@ static int merge_entry(int pos, const char *path) xsnprintf(ownbuf[stage], sizeof(ownbuf[stage]), "%o", ce->ce_mode); arguments[stage] = hexbuf[stage]; arguments[stage + 4] = ownbuf[stage]; - } while (++pos < active_nr); + } while (++pos < the_index.cache_nr); if (!found) die("git merge-index: %s not in the cache", path); @@ -62,8 +62,8 @@ static void merge_all(void) int i; /* TODO: audit for interaction with sparse-index. */ ensure_full_index(&the_index); - for (i = 0; i < active_nr; i++) { - const struct cache_entry *ce = active_cache[i]; + for (i = 0; i < the_index.cache_nr; i++) { + const struct cache_entry *ce = the_index.cache[i]; if (!ce_stage(ce)) continue; i += merge_entry(i, ce->name)-1; diff --git a/builtin/merge.c b/builtin/merge.c index 2046992d75a..27218ee93c9 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -694,7 +694,7 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head, if (!trees[nr_trees++]) return -1; opts.fn = threeway_merge; - cache_tree_free(&active_cache_tree); + cache_tree_free(&the_index.cache_tree); for (i = 0; i < nr_trees; i++) { parse_tree(trees[i]); init_tree_desc(t+i, trees[i]->buffer, trees[i]->size); @@ -784,8 +784,8 @@ static int count_unmerged_entries(void) { int i, ret = 0; - for (i = 0; i < active_nr; i++) - if (ce_stage(active_cache[i])) + for (i = 0; i < the_index.cache_nr; i++) + if (ce_stage(the_index.cache[i])) ret++; return ret; diff --git a/builtin/mv.c b/builtin/mv.c index 6f94c3b9238..883cf3ff12b 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -87,7 +87,7 @@ static void prepare_move_submodule(const char *src, int first, const char **submodule_gitfile) { struct strbuf submodule_dotgit = STRBUF_INIT; - if (!S_ISGITLINK(active_cache[first]->ce_mode)) + if (!S_ISGITLINK(the_index.cache[first]->ce_mode)) die(_("Directory %s is in index and no submodule?"), src); if (!is_staging_gitmodules_ok(&the_index)) die(_("Please stage your changes to .gitmodules or stash them to proceed")); @@ -111,8 +111,8 @@ static int index_range_of_same_dir(const char *src, int length, die(_("%.*s is in index"), len_w_slash, src_w_slash); first = -1 - first; - for (last = first; last < active_nr; last++) { - const char *path = active_cache[last]->name; + for (last = first; last < the_index.cache_nr; last++) { + const char *path = the_index.cache[last]->name; if (strncmp(path, src_w_slash, len_w_slash)) break; } @@ -143,7 +143,7 @@ static int empty_dir_has_sparse_contents(const char *name) pos = -pos - 1; if (pos >= the_index.cache_nr) goto free_return; - ce = active_cache[pos]; + ce = the_index.cache[pos]; if (strncmp(with_slash, ce->name, length)) goto free_return; if (ce_skip_worktree(ce)) @@ -268,7 +268,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) bad = _("bad source"); goto act_on_entry; } - ce = active_cache[pos]; + ce = the_index.cache[pos]; if (!ce_skip_worktree(ce)) { bad = _("bad source"); goto act_on_entry; @@ -331,7 +331,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) dst_len = strlen(dst); for (j = 0; j < last - first; j++) { - const struct cache_entry *ce = active_cache[first + j]; + const struct cache_entry *ce = the_index.cache[first + j]; const char *path = ce->name; source[argc + j] = path; destination[argc + j] = @@ -472,7 +472,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix) assert(pos >= 0); if (!(mode & SPARSE) && !lstat(src, &st)) sparse_and_dirty = ie_modified(&the_index, - active_cache[pos], &st, + the_index.cache[pos], + &st, 0); rename_index_entry_at(&the_index, pos, dst); @@ -489,7 +490,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) path_in_sparse_checkout(dst, &the_index)) { /* from out-of-cone to in-cone */ int dst_pos = cache_name_pos(dst, strlen(dst)); - struct cache_entry *dst_ce = active_cache[dst_pos]; + struct cache_entry *dst_ce = the_index.cache[dst_pos]; dst_ce->ce_flags &= ~CE_SKIP_WORKTREE; @@ -500,7 +501,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) !path_in_sparse_checkout(dst, &the_index)) { /* from in-cone to out-of-cone */ int dst_pos = cache_name_pos(dst, strlen(dst)); - struct cache_entry *dst_ce = active_cache[dst_pos]; + struct cache_entry *dst_ce = the_index.cache[dst_pos]; /* * if src is clean, it will suffice to remove it diff --git a/builtin/read-tree.c b/builtin/read-tree.c index 9ced755a6db..c50b563e2be 100644 --- a/builtin/read-tree.c +++ b/builtin/read-tree.c @@ -253,7 +253,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix) if (nr_trees == 1 && !opts.prefix) opts.skip_cache_tree_update = 1; - cache_tree_free(&active_cache_tree); + cache_tree_free(&the_index.cache_tree); for (i = 0; i < nr_trees; i++) { struct tree *tree = trees[i]; parse_tree(tree); diff --git a/builtin/reset.c b/builtin/reset.c index 59f777a1da4..75e061f5dcf 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -161,7 +161,7 @@ static void update_index_from_diff(struct diff_queue_struct *q, * to properly construct the reset sparse directory. */ pos = cache_name_pos(one->path, strlen(one->path)); - if ((pos >= 0 && ce_skip_worktree(active_cache[pos])) || + if ((pos >= 0 && ce_skip_worktree(the_index.cache[pos])) || (pos < 0 && !path_in_sparse_checkout(one->path, &the_index))) ce->ce_flags |= CE_SKIP_WORKTREE; diff --git a/builtin/rm.c b/builtin/rm.c index c717cdc97f5..2b23eb25438 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -35,8 +35,8 @@ static int get_ours_cache_pos(const char *path, int pos) { int i = -pos - 1; - while ((i < active_nr) && !strcmp(active_cache[i]->name, path)) { - if (ce_stage(active_cache[i]) == 2) + while ((i < the_index.cache_nr) && !strcmp(the_index.cache[i]->name, path)) { + if (ce_stage(the_index.cache[i]) == 2) return i; i++; } @@ -78,7 +78,7 @@ static void submodules_absorb_gitdir_if_needed(void) if (pos < 0) continue; } - ce = active_cache[pos]; + ce = the_index.cache[pos]; if (!S_ISGITLINK(ce->ce_mode) || !file_exists(ce->name) || @@ -127,11 +127,11 @@ static int check_local_mod(struct object_id *head, int index_only) if (pos < 0) continue; - if (!S_ISGITLINK(active_cache[pos]->ce_mode) || + if (!S_ISGITLINK(the_index.cache[pos]->ce_mode) || is_empty_dir(name)) continue; } - ce = active_cache[pos]; + ce = the_index.cache[pos]; if (lstat(ce->name, &st) < 0) { if (!is_missing_file_error(errno)) @@ -303,8 +303,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix) if (pathspec_needs_expanded_index(&the_index, &pathspec)) ensure_full_index(&the_index); - for (i = 0; i < active_nr; i++) { - const struct cache_entry *ce = active_cache[i]; + for (i = 0; i < the_index.cache_nr; i++) { + const struct cache_entry *ce = the_index.cache[i]; if (!include_sparse && (ce_skip_worktree(ce) || diff --git a/builtin/stash.c b/builtin/stash.c index bb5485b4095..c251419af7c 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -454,10 +454,10 @@ static void unstage_changes_unless_new(struct object_id *orig_tree) * path, but left it out of the working tree, then clear the * SKIP_WORKTREE bit and write it to the working tree. */ - if (pos >= 0 && ce_skip_worktree(active_cache[pos])) { + if (pos >= 0 && ce_skip_worktree(the_index.cache[pos])) { struct stat st; - ce = active_cache[pos]; + ce = the_index.cache[pos]; if (!lstat(ce->name, &st)) { /* Conflicting path present; relocate it */ struct strbuf new_path = STRBUF_INIT; @@ -1520,8 +1520,8 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q /* TODO: audit for interaction with sparse-index. */ ensure_full_index(&the_index); - for (i = 0; i < active_nr; i++) - ce_path_match(&the_index, active_cache[i], ps, + for (i = 0; i < the_index.cache_nr; i++) + ce_path_match(&the_index, the_index.cache[i], ps, ps_matched); if (report_path_error(ps_matched, ps)) { diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index a7683d35299..808865a5e31 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -199,8 +199,8 @@ static int module_list_compute(const char **argv, if (read_cache() < 0) die(_("index file corrupt")); - for (i = 0; i < active_nr; i++) { - const struct cache_entry *ce = active_cache[i]; + for (i = 0; i < the_index.cache_nr; i++) { + const struct cache_entry *ce = the_index.cache[i]; if (!match_pathspec(&the_index, pathspec, ce->name, ce_namelen(ce), 0, ps_matched, 1) || @@ -209,8 +209,8 @@ static int module_list_compute(const char **argv, ALLOC_GROW(list->entries, list->nr + 1, list->alloc); list->entries[list->nr++] = ce; - while (i + 1 < active_nr && - !strcmp(ce->name, active_cache[i + 1]->name)) + while (i + 1 < the_index.cache_nr && + !strcmp(ce->name, the_index.cache[i + 1]->name)) /* * Skip entries with the same name in different stages * to make sure an entry is returned only once. @@ -3255,15 +3255,15 @@ static void die_on_index_match(const char *path, int force) * need to check ps_matched[0] to know if a cache * entry matched. */ - for (i = 0; i < active_nr; i++) { - ce_path_match(&the_index, active_cache[i], &ps, + for (i = 0; i < the_index.cache_nr; i++) { + ce_path_match(&the_index, the_index.cache[i], &ps, ps_matched); if (ps_matched[0]) { if (!force) die(_("'%s' already exists in the index"), path); - if (!S_ISGITLINK(active_cache[i]->ce_mode)) + if (!S_ISGITLINK(the_index.cache[i]->ce_mode)) die(_("'%s' already exists in the index " "and is not a submodule"), path); break; diff --git a/builtin/update-index.c b/builtin/update-index.c index 533ba66df05..fec3da05abb 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -239,14 +239,14 @@ static int mark_ce_flags(const char *path, int flag, int mark) int namelen = strlen(path); int pos = cache_name_pos(path, namelen); if (0 <= pos) { - mark_fsmonitor_invalid(&the_index, active_cache[pos]); + mark_fsmonitor_invalid(&the_index, the_index.cache[pos]); if (mark) - active_cache[pos]->ce_flags |= flag; + the_index.cache[pos]->ce_flags |= flag; else - active_cache[pos]->ce_flags &= ~flag; - active_cache[pos]->ce_flags |= CE_UPDATE_IN_BASE; + the_index.cache[pos]->ce_flags &= ~flag; + the_index.cache[pos]->ce_flags |= CE_UPDATE_IN_BASE; cache_tree_invalidate_path(&the_index, path); - active_cache_changed |= CE_ENTRY_CHANGED; + the_index.cache_changed |= CE_ENTRY_CHANGED; return 0; } return -1; @@ -335,7 +335,7 @@ static int process_directory(const char *path, int len, struct stat *st) /* Exact match: file or existing gitlink */ if (pos >= 0) { - const struct cache_entry *ce = active_cache[pos]; + const struct cache_entry *ce = the_index.cache[pos]; if (S_ISGITLINK(ce->ce_mode)) { /* Do nothing to the index if there is no HEAD! */ @@ -350,8 +350,8 @@ static int process_directory(const char *path, int len, struct stat *st) /* Inexact match: is there perhaps a subdirectory match? */ pos = -pos-1; - while (pos < active_nr) { - const struct cache_entry *ce = active_cache[pos++]; + while (pos < the_index.cache_nr) { + const struct cache_entry *ce = the_index.cache[pos++]; if (strncmp(ce->name, path, len)) break; @@ -382,7 +382,7 @@ static int process_path(const char *path, struct stat *st, int stat_errno) return error("'%s' is beyond a symbolic link", path); pos = cache_name_pos(path, len); - ce = pos < 0 ? NULL : active_cache[pos]; + ce = pos < 0 ? NULL : the_index.cache[pos]; if (ce && ce_skip_worktree(ce)) { /* * working directory version is assumed "good" @@ -444,7 +444,7 @@ static void chmod_path(char flip, const char *path) pos = cache_name_pos(path, strlen(path)); if (pos < 0) goto fail; - ce = active_cache[pos]; + ce = the_index.cache[pos]; if (chmod_index_entry(&the_index, ce, flip) < 0) goto fail; @@ -642,8 +642,8 @@ static int unresolve_one(const char *path) if (0 <= pos) { /* already merged */ pos = unmerge_index_entry_at(&the_index, pos); - if (pos < active_nr) { - const struct cache_entry *ce = active_cache[pos]; + if (pos < the_index.cache_nr) { + const struct cache_entry *ce = the_index.cache[pos]; if (ce_stage(ce) && ce_namelen(ce) == namelen && !memcmp(ce->name, path, namelen)) @@ -656,8 +656,8 @@ static int unresolve_one(const char *path) * want to do anything in the former case. */ pos = -pos-1; - if (pos < active_nr) { - const struct cache_entry *ce = active_cache[pos]; + if (pos < the_index.cache_nr) { + const struct cache_entry *ce = the_index.cache[pos]; if (ce_namelen(ce) == namelen && !memcmp(ce->name, path, namelen)) { fprintf(stderr, @@ -752,8 +752,8 @@ static int do_reupdate(const char **paths, */ has_head = 0; redo: - for (pos = 0; pos < active_nr; pos++) { - const struct cache_entry *ce = active_cache[pos]; + for (pos = 0; pos < the_index.cache_nr; pos++) { + const struct cache_entry *ce = the_index.cache[pos]; struct cache_entry *old = NULL; int save_nr; char *path; @@ -782,12 +782,12 @@ static int do_reupdate(const char **paths, * path anymore, in which case, under 'allow_remove', * or worse yet 'allow_replace', active_nr may decrease. */ - save_nr = active_nr; + save_nr = the_index.cache_nr; path = xstrdup(ce->name); update_one(path); free(path); discard_cache_entry(old); - if (save_nr != active_nr) + if (save_nr != the_index.cache_nr) goto redo; } clear_pathspec(&pathspec); @@ -813,7 +813,7 @@ static int refresh(struct refresh_params *o, unsigned int flag) * refresh_cache() as these are no actual errors. * cmd_status() does the same. */ - active_cache_changed |= SOMETHING_CHANGED; + the_index.cache_changed |= SOMETHING_CHANGED; } return 0; } @@ -951,7 +951,7 @@ static enum parse_opt_result unresolve_callback( *has_errors = do_unresolve(ctx->argc, ctx->argv, prefix, prefix ? strlen(prefix) : 0); if (*has_errors) - active_cache_changed = 0; + the_index.cache_changed = 0; ctx->argv += ctx->argc - 1; ctx->argc = 1; @@ -972,7 +972,7 @@ static enum parse_opt_result reupdate_callback( setup_work_tree(); *has_errors = do_reupdate(ctx->argv + 1, prefix); if (*has_errors) - active_cache_changed = 0; + the_index.cache_changed = 0; ctx->argv += ctx->argc - 1; ctx->argc = 1; @@ -1178,7 +1178,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) INDEX_FORMAT_LB, INDEX_FORMAT_UB); if (the_index.version != preferred_index_format) - active_cache_changed |= SOMETHING_CHANGED; + the_index.cache_changed |= SOMETHING_CHANGED; the_index.version = preferred_index_format; } @@ -1290,7 +1290,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) report(_("fsmonitor disabled")); } - if (active_cache_changed || force_write) { + if (the_index.cache_changed || force_write) { if (newfd < 0) { if (refresh_args.flags & REFRESH_QUIET) exit(128); diff --git a/cache.h b/cache.h index 79b8d479710..805e25f9a67 100644 --- a/cache.h +++ b/cache.h @@ -436,10 +436,7 @@ void prefetch_cache_entries(const struct index_state *istate, #ifdef USE_THE_INDEX_COMPATIBILITY_MACROS extern struct index_state the_index; -#define active_cache (the_index.cache) #define active_nr (the_index.cache_nr) -#define active_cache_changed (the_index.cache_changed) -#define active_cache_tree (the_index.cache_tree) #define read_cache() repo_read_index(the_repository) #define read_cache_from(path) read_index_from(&the_index, (path), (get_git_dir())) diff --git a/contrib/coccinelle/index-compatibility.cocci b/contrib/coccinelle/index-compatibility.cocci index 89c18986160..8b1ed65e7b0 100644 --- a/contrib/coccinelle/index-compatibility.cocci +++ b/contrib/coccinelle/index-compatibility.cocci @@ -1,3 +1,25 @@ +// the_index.* variables +@@ +@@ +( +- active_cache ++ the_index.cache +| +- active_cache_changed ++ the_index.cache_changed +| +- active_cache_tree ++ the_index.cache_tree +) + +@@ +identifier f != prepare_to_commit; +@@ + f(...) {<... +- active_nr ++ the_index.cache_nr + ...>} + // "the_repository" simple cases @@ @@ diff --git a/contrib/coccinelle/index-compatibility.pending.cocci b/contrib/coccinelle/index-compatibility.pending.cocci index cf1ea57d700..8207aee62c3 100644 --- a/contrib/coccinelle/index-compatibility.pending.cocci +++ b/contrib/coccinelle/index-compatibility.pending.cocci @@ -1,20 +1,3 @@ -// the_index.* variables -@@ -@@ -( -- active_cache -+ the_index.cache -| -- active_nr -+ the_index.cache_nr -| -- active_cache_changed -+ the_index.cache_changed -| -- active_cache_tree -+ the_index.cache_tree -) - // "the_repository" simple cases @@ @@ diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c index 0d6d7f1ecbf..8d88111b357 100644 --- a/t/helper/test-dump-cache-tree.c +++ b/t/helper/test-dump-cache-tree.c @@ -67,7 +67,7 @@ int cmd__dump_cache_tree(int ac, const char **av) istate = the_index; istate.cache_tree = another; cache_tree_update(&istate, WRITE_TREE_DRY_RUN); - ret = dump_cache_tree(active_cache_tree, another, ""); + ret = dump_cache_tree(the_index.cache_tree, another, ""); cache_tree_free(&another); return ret; diff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c index 026c802479d..20e2e31f9e2 100644 --- a/t/helper/test-scrap-cache-tree.c +++ b/t/helper/test-scrap-cache-tree.c @@ -12,8 +12,8 @@ int cmd__scrap_cache_tree(int ac, const char **av) hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR); if (read_cache() < 0) die("unable to read index file"); - cache_tree_free(&active_cache_tree); - active_cache_tree = NULL; + cache_tree_free(&the_index.cache_tree); + the_index.cache_tree = NULL; if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK)) die("unable to write index file"); return 0; From patchwork Sat Nov 19 13:07:35 2022 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: 13049739 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 45103C4332F for ; Sat, 19 Nov 2022 13:08:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233930AbiKSNIF (ORCPT ); Sat, 19 Nov 2022 08:08:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233631AbiKSNH5 (ORCPT ); Sat, 19 Nov 2022 08:07:57 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25A2692B53 for ; Sat, 19 Nov 2022 05:07:56 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id i10so19137365ejg.6 for ; Sat, 19 Nov 2022 05:07: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=uQlaos3rneUa9QDwETVQPfjWt7Upj4N6f5RRZ0D8brE=; b=ASO9evO5fN1x6JULdU4/mgbfuKN005xu0NfcmE4Z577pJV/zDx4skOzFN4pM5glY30 DkFnU/zG4psuWRMOMszXb90Ttq6d3XzsGGXOA5+MCdVx1Ghvp+PVi659mdjTJ3Y52FzZ LTE+1D+hpE1uIPtHEDippvewbdgRS9X1K9X8HdpQpCCTyL3RAnFKn63hPpI85Y+tJKTC P5F8rz8BaNfjUprQbcR0ka2uiG2eh7oSKl9dB2IQCwZOKh7K8DnNuefbQRDjrLCuHDSr d3AjDHLsj8BJ+lRx2WTBQBbZp2wUKTOvqpf6EpPT9CyWcPHfXm34FQ5ablHPDwkKG4xV ZQXg== 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=uQlaos3rneUa9QDwETVQPfjWt7Upj4N6f5RRZ0D8brE=; b=k4cN47R+xyXdYIMoE2Ejq9PxVeHCt+PuYUPGDeiwy/BZUbm9yjPfKex6uKYwL9KfyI LzjlxBV9yCwhOEp90u1BPr5zBbBEmET4KIZaiOZZqdzTkvNTqrDJXuZN/qGItl6icWI7 rP12sTSKumC2JnRcTJFD+98LHofbIapMOPsfSzh4ijZ31cIvjSPRZ4HNd8qwG424ODsR mPuDc8kmNvKDqC7s8PEiQIoAAzb+m5+PIRYTklcpiJx8nbGQWRubyE+WAV/UvYkZ8/u+ 8sw9xyuofszc0VhE7dF5q3GNWFBsB66mMQR8ziO0q9ESz9O9sv0gPVZ1UWv43LN7Of6S BeSA== X-Gm-Message-State: ANoB5plSXJtbQxWRix+XrjKnHrO0Q6Ttg5kmFV+7VYR9H8PrXWqLX/gX hJEVRfygg2hFfTJe3+vNI0rnaHiFjfYrhw== X-Google-Smtp-Source: AA0mqf4z79xZpcXICwSo0ZDHPyA7HCF9at7Hnmq9IC9ya5CXBoAtKwttonttU3IdsmXU6jdlUTet3A== X-Received: by 2002:a17:906:1146:b0:78d:9f02:5458 with SMTP id i6-20020a170906114600b0078d9f025458mr9573695eja.753.1668863274297; Sat, 19 Nov 2022 05:07:54 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id ch28-20020a0564021bdc00b0045d74aa401fsm2923802edb.60.2022.11.19.05.07.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Nov 2022 05:07:53 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 08/11] cocci: apply "pending" index-compatibility to "t/helper/*.c" Date: Sat, 19 Nov 2022 14:07:35 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1509.g9445af83948 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Apply the "index-compatibility.pending.cocci" rule to the "t/helper/*" directory, a subsequent commit will extend cache.h to further narrow down the use of "USE_THE_INDEX_COMPATIBILITY_MACROS" in this area. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/helper/test-cache-tree.c | 2 +- t/helper/test-dump-cache-tree.c | 2 +- t/helper/test-dump-untracked-cache.c | 2 +- t/helper/test-fast-rebase.c | 2 +- t/helper/test-lazy-init-name-hash.c | 20 ++++++++++---------- t/helper/test-read-cache.c | 4 ++-- t/helper/test-scrap-cache-tree.c | 4 ++-- t/helper/test-write-cache.c | 5 +++-- 8 files changed, 21 insertions(+), 20 deletions(-) diff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c index 93051b25f56..5514afdfe7a 100644 --- a/t/helper/test-cache-tree.c +++ b/t/helper/test-cache-tree.c @@ -30,7 +30,7 @@ int cmd__cache_tree(int argc, const char **argv) argc = parse_options(argc, argv, NULL, options, test_cache_tree_usage, 0); - if (read_cache() < 0) + if (repo_read_index(the_repository) < 0) die(_("unable to read index file")); oidcpy(&oid, &the_index.cache_tree->oid); diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c index 8d88111b357..4bf8bc3df6e 100644 --- a/t/helper/test-dump-cache-tree.c +++ b/t/helper/test-dump-cache-tree.c @@ -62,7 +62,7 @@ int cmd__dump_cache_tree(int ac, const char **av) int ret; setup_git_directory(); - if (read_cache() < 0) + if (repo_read_index(the_repository) < 0) die("unable to read index file"); istate = the_index; istate.cache_tree = another; diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c index 99010614f6d..ffe34736e53 100644 --- a/t/helper/test-dump-untracked-cache.c +++ b/t/helper/test-dump-untracked-cache.c @@ -51,7 +51,7 @@ int cmd__dump_untracked_cache(int ac, const char **av) xsetenv("GIT_CONFIG_VALUE_0", "keep", 1); setup_git_directory(); - if (read_cache() < 0) + if (repo_read_index(the_repository) < 0) die("unable to read index file"); uc = the_index.untracked; if (!uc) { diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c index 45665ec19a5..9def2ba6889 100644 --- a/t/helper/test-fast-rebase.c +++ b/t/helper/test-fast-rebase.c @@ -123,7 +123,7 @@ int cmd__fast_rebase(int argc, const char **argv) die(_("Cannot read HEAD")); assert(oideq(&onto->object.oid, &head)); - hold_locked_index(&lock, LOCK_DIE_ON_ERROR); + repo_hold_locked_index(the_repository, &lock, LOCK_DIE_ON_ERROR); if (repo_read_index(the_repository) < 0) BUG("Could not read index"); diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c index cd1b4c9736e..7e8723a1900 100644 --- a/t/helper/test-lazy-init-name-hash.c +++ b/t/helper/test-lazy-init-name-hash.c @@ -32,7 +32,7 @@ static void dump_run(void) struct dir_entry *dir; struct cache_entry *ce; - read_cache(); + repo_read_index(the_repository); if (single) { test_lazy_init_name_hash(&the_index, 0); } else { @@ -49,7 +49,7 @@ static void dump_run(void) ent /* member name */) printf("name %08x %s\n", ce->ent.hash, ce->name); - discard_cache(); + discard_index(&the_index); } /* @@ -66,7 +66,7 @@ static uint64_t time_runs(int try_threaded) for (i = 0; i < count; i++) { t0 = getnanotime(); - read_cache(); + repo_read_index(the_repository); t1 = getnanotime(); nr_threads_used = test_lazy_init_name_hash(&the_index, try_threaded); t2 = getnanotime(); @@ -89,7 +89,7 @@ static uint64_t time_runs(int try_threaded) the_index.cache_nr); fflush(stdout); - discard_cache(); + discard_index(&the_index); } avg = sum / count; @@ -113,9 +113,9 @@ static void analyze_run(void) int i; int nr; - read_cache(); + repo_read_index(the_repository); cache_nr_limit = the_index.cache_nr; - discard_cache(); + discard_index(&the_index); nr = analyze; while (1) { @@ -128,23 +128,23 @@ static void analyze_run(void) nr = cache_nr_limit; for (i = 0; i < count; i++) { - read_cache(); + repo_read_index(the_repository); the_index.cache_nr = nr; /* cheap truncate of index */ t1s = getnanotime(); test_lazy_init_name_hash(&the_index, 0); t2s = getnanotime(); sum_single += (t2s - t1s); the_index.cache_nr = cache_nr_limit; - discard_cache(); + discard_index(&the_index); - read_cache(); + repo_read_index(the_repository); the_index.cache_nr = nr; /* cheap truncate of index */ t1m = getnanotime(); nr_threads_used = test_lazy_init_name_hash(&the_index, 1); t2m = getnanotime(); sum_multi += (t2m - t1m); the_index.cache_nr = cache_nr_limit; - discard_cache(); + discard_index(&the_index); if (!nr_threads_used) printf(" [size %8d] [single %f] non-threaded code path used\n", diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c index b736ef16421..a089be9104c 100644 --- a/t/helper/test-read-cache.c +++ b/t/helper/test-read-cache.c @@ -20,7 +20,7 @@ int cmd__read_cache(int argc, const char **argv) git_config(git_default_config, NULL); for (i = 0; i < cnt; i++) { - read_cache(); + repo_read_index(the_repository); if (name) { int pos; @@ -33,7 +33,7 @@ int cmd__read_cache(int argc, const char **argv) ce_uptodate(the_index.cache[pos]) ? "" : " not"); write_file(name, "%d\n", i); } - discard_cache(); + discard_index(&the_index); } return 0; } diff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c index 20e2e31f9e2..9206dee1fd2 100644 --- a/t/helper/test-scrap-cache-tree.c +++ b/t/helper/test-scrap-cache-tree.c @@ -9,8 +9,8 @@ int cmd__scrap_cache_tree(int ac, const char **av) struct lock_file index_lock = LOCK_INIT; setup_git_directory(); - hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR); - if (read_cache() < 0) + repo_hold_locked_index(the_repository, &index_lock, LOCK_DIE_ON_ERROR); + if (repo_read_index(the_repository) < 0) die("unable to read index file"); cache_tree_free(&the_index.cache_tree); the_index.cache_tree = NULL; diff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c index 8837717d36a..66287d6d47d 100644 --- a/t/helper/test-write-cache.c +++ b/t/helper/test-write-cache.c @@ -9,9 +9,10 @@ int cmd__write_cache(int argc, const char **argv) if (argc == 2) cnt = strtol(argv[1], NULL, 0); setup_git_directory(); - read_cache(); + repo_read_index(the_repository); for (i = 0; i < cnt; i++) { - hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR); + repo_hold_locked_index(the_repository, &index_lock, + LOCK_DIE_ON_ERROR); if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK)) die("unable to write index file"); } From patchwork Sat Nov 19 13:07:36 2022 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: 13049741 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 2D5C4C433FE for ; Sat, 19 Nov 2022 13:08:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233591AbiKSNIW (ORCPT ); Sat, 19 Nov 2022 08:08:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233572AbiKSNH6 (ORCPT ); Sat, 19 Nov 2022 08:07:58 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44BA592B52 for ; Sat, 19 Nov 2022 05:07:57 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id vv4so9851035ejc.2 for ; Sat, 19 Nov 2022 05:07:57 -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=xSrSF+ZjUQhMVcUVGUUOQ4Sf/4LCZa0L3/c0+tNxobU=; b=kb0cZ/lLbKelxK3cdYryAnIyEj9VxXMGY/LKbkPaBC5AmrqgG6JBBUyImShDVz3P2t xVoi8xgUDVhNPPg7jHA+wu/kIQmB6zaTJ/a1flT4enRQUqxDwmhAU4/NbzgJfRbsjM11 AdFs/WBi/P05+sBtEVJIFvq8xmnjId2QOohJqy2+ac5vkzdIwArjJ+L5NpbWTNbT3wgH zsk5cG0BbtB8A/qR7ykO3JfwEfjYStT2Mjv/ou0Og+jCtxWLceqXKt6l7wIOoArX7gJO 2kElDPwokUmulpbIO+V/ZbFfXR7CFfnkZ/fiZkLiwwgMdJH88KfLNlRvIhDAUvJgUe+C gKnA== 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=xSrSF+ZjUQhMVcUVGUUOQ4Sf/4LCZa0L3/c0+tNxobU=; b=G6CVreMTA7Sic2U6RvlltIIEvoPc3XpF9/gs8gv9ynZXQsBzOd/P/1V8WsNdcfVth5 3loOAMWZzYKyi3SGMGPEGfwaG8M0uk9Q8dyQDPJaRB+g1D5t7ldtvdCPq9SeomxLeZsq 8fGv0yze5rjnkcPn4YLLzXpFxOqsJ0ACtQg6VzdLPe6lXo25bNf4W1KMCba5uNdS+KaB +awxQhZzEZMiwuVsFWB7nDoVicf9apHj0k80v5Ot+XS3NCyPTc0uyDR995/tq4aoe/dk vai7/qtSlWxOngZQQNS1+2fUWl/Ebeo0XPghYOwSriTtYxuGsy0iWc+gY6onHIMbkXsj pFYg== X-Gm-Message-State: ANoB5pmV+OuxknS4rxU9JQqzX6IgTgS+Nyekdlee2O0ui4yN7//Bsiru iRrdsK2N5QvQfm14zeWixCWKWBxhCrVsIw== X-Google-Smtp-Source: AA0mqf6HUMhLKB0MhazkU4rvXWGYUeggP5S28+rIoJMSMuTgLeTaRKxyAiGpUz18o1k2Hm9cnQaVoA== X-Received: by 2002:a17:906:2e82:b0:7ae:44b2:cb7f with SMTP id o2-20020a1709062e8200b007ae44b2cb7fmr9152253eji.437.1668863275261; Sat, 19 Nov 2022 05:07:55 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id ch28-20020a0564021bdc00b0045d74aa401fsm2923802edb.60.2022.11.19.05.07.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Nov 2022 05:07:54 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 09/11] {builtin/*,repository}.c: add & use "USE_THE_INDEX_VARIABLE" Date: Sat, 19 Nov 2022 14:07:36 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1509.g9445af83948 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Split up the "USE_THE_INDEX_COMPATIBILITY_MACROS" into that setting and a more narrow "USE_THE_INDEX_VARIABLE". In the case of these built-ins we only need "the_index" variable, but not the compatibility wrapper for functions we're not using. Let's then have some users of "USE_THE_INDEX_COMPATIBILITY_MACROS" use this more narrow and descriptive define. For context: The USE_THE_INDEX_COMPATIBILITY_MACROS macro was added to test-tool.h in f8adbec9fea (cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch, 2019-01-24). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/cat-file.c | 2 +- builtin/difftool.c | 2 +- builtin/merge-tree.c | 2 +- builtin/pull.c | 2 +- cache.h | 6 +++++- repository.c | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index fa7bd891692..b3be58b1fb0 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.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 "config.h" #include "builtin.h" diff --git a/builtin/difftool.c b/builtin/difftool.c index d7f08c8a7fa..d9b76226f6a 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -11,7 +11,7 @@ * * Copyright (C) 2016 Johannes Schindelin */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "cache.h" #include "config.h" #include "builtin.h" diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index fe853aa8f91..e3767087bbf 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -1,4 +1,4 @@ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "tree-walk.h" #include "xdiff-interface.h" diff --git a/builtin/pull.c b/builtin/pull.c index 4a2a6db2dce..1ab4de0005d 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -5,7 +5,7 @@ * * Fetch one or more remote refs and merge it/them into the current HEAD. */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "cache.h" #include "config.h" #include "builtin.h" diff --git a/cache.h b/cache.h index 805e25f9a67..707806d2125 100644 --- a/cache.h +++ b/cache.h @@ -433,9 +433,11 @@ typedef int (*must_prefetch_predicate)(const struct cache_entry *); void prefetch_cache_entries(const struct index_state *istate, must_prefetch_predicate must_prefetch); -#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS +#if defined(USE_THE_INDEX_COMPATIBILITY_MACROS) || defined(USE_THE_INDEX_VARIABLE) 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) @@ -447,6 +449,8 @@ extern struct index_state the_index; #define refresh_and_write_cache(refresh_flags, write_flags, gentle) repo_refresh_and_write_index(the_repository, (refresh_flags), (write_flags), (gentle), NULL, NULL, NULL) #define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags)) #endif +#endif +#endif #define TYPE_BITS 3 diff --git a/repository.c b/repository.c index 5d166b692c8..3427085fd6d 100644 --- a/repository.c +++ b/repository.c @@ -2,7 +2,7 @@ * not really _using_ the compat macros, just make sure the_index * declaration matches the definition in this file. */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "cache.h" #include "repository.h" #include "object-store.h" From patchwork Sat Nov 19 13:07:37 2022 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: 13049742 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 9F55FC4332F for ; Sat, 19 Nov 2022 13:08:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234050AbiKSNI0 (ORCPT ); Sat, 19 Nov 2022 08:08:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233825AbiKSNH7 (ORCPT ); Sat, 19 Nov 2022 08:07:59 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1ED69153A for ; Sat, 19 Nov 2022 05:07:57 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id ft34so19058749ejc.12 for ; Sat, 19 Nov 2022 05:07:57 -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=MtvP4qPfs8r+Zht5icBsvyXCpJqLFu6gS7Cjmz0n1yM=; b=DMpm1xU6FAgUdsDB4IF+0y9r1EqHA+X9S9Nj6wTiwkRAunrPo34WcKfYj7JPQa2Pxt upX6mF37iTideVDbLPWBzZ4SteZl7iGcEbOTUdAJ7KVjZY/J2lfkJMBVLqSi7S0j9trc b7SqgUW1ef03whNIkQteEt2zlY7xuyHAUa8gfdV6pNPwzvYJ7LJA87NJpiX02YUo1pY9 hRBD5+//b/F2fY8U0XPIfwl8v8UObsaPPBKTX6Y50omEblxDO9b15esgNXQzUlgUiChg oywbfCdxJYAQDyZPOpojCBaMZov3qluOHs+WbohwX2X0Xqc+VTfS+DYxTpVy9nMCvXeL dRwQ== 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=MtvP4qPfs8r+Zht5icBsvyXCpJqLFu6gS7Cjmz0n1yM=; b=cBRp82lvd9ik0FCwEeprKmbmZ6Hf6i1V9/MizX/tjn7b+T7m9fa6txRAgrTAjEptW+ IxmK7q2OmRw8u8/3JuDPmv7Rbs/XSjwtKVa4yV9XaMCyIhAxiEeu8xilxZHi6Qs/8kG/ JPYbMn6ISJu5deM/S1Dxn6jhlnmsqcd5/f2q3Kc4s5ddIHe4PMEA9fyuroj0JpY3pQk2 37Qfe9cvIxGGez1UqWfV82JstElkzn08P1mCN0LWRnyISdfbjeRdUZwc5VXgHq+VZirh O7+YPln0Jl7NSPBVFraXgspNKflYwTBQOvraKxbFIEC5/88VvlT3zEsfX/u9MnCYVNyM jG1A== X-Gm-Message-State: ANoB5pn8X4yQKIK+Tmv3wJTG1QA2vbQYYX14/2IZcIt/SsaDexcfhVua 1zTj5q2h481EavNCedSzA5HX/oWVYrrhzQ== X-Google-Smtp-Source: AA0mqf4WH+e5me/uMRzMV94SZRC0p8zse5m3m1kzQHXWNnZpGYOn5+ZRLY99gyOykZF6QHI96b9WyA== X-Received: by 2002:a17:906:b794:b0:7ae:6450:c620 with SMTP id dt20-20020a170906b79400b007ae6450c620mr9387260ejb.270.1668863276202; Sat, 19 Nov 2022 05:07:56 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id ch28-20020a0564021bdc00b0045d74aa401fsm2923802edb.60.2022.11.19.05.07.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Nov 2022 05:07:55 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 10/11] cache.h & test-tool.h: add & use "USE_THE_INDEX_VARIABLE" Date: Sat, 19 Nov 2022 14:07:37 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1509.g9445af83948 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In a preceding commit we fully applied the "index-compatibility.pending.cocci" rule to "t/helper/*". Let's now stop defining "USE_THE_INDEX_COMPATIBILITY_MACROS" in test-tool.h itself, and instead instead define "USE_THE_INDEX_VARIABLE" in the individual test helpers that need it. This mirrors how we do the same thing in the "builtin/" directory. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/helper/test-cache-tree.c | 1 + t/helper/test-dump-cache-tree.c | 1 + t/helper/test-dump-split-index.c | 1 + t/helper/test-dump-untracked-cache.c | 2 +- t/helper/test-fast-rebase.c | 2 +- t/helper/test-lazy-init-name-hash.c | 1 + t/helper/test-read-cache.c | 1 + t/helper/test-scrap-cache-tree.c | 1 + t/helper/test-tool.h | 1 - t/helper/test-write-cache.c | 1 + 10 files changed, 9 insertions(+), 3 deletions(-) diff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c index 5514afdfe7a..9159a173015 100644 --- a/t/helper/test-cache-tree.c +++ b/t/helper/test-cache-tree.c @@ -1,3 +1,4 @@ +#define USE_THE_INDEX_VARIABLE #include "test-tool.h" #include "cache.h" #include "tree.h" diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c index 4bf8bc3df6e..454f17b1a0c 100644 --- a/t/helper/test-dump-cache-tree.c +++ b/t/helper/test-dump-cache-tree.c @@ -1,3 +1,4 @@ +#define USE_THE_INDEX_VARIABLE #include "test-tool.h" #include "cache.h" #include "tree.h" diff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c index a209880eb37..0ea97b84072 100644 --- a/t/helper/test-dump-split-index.c +++ b/t/helper/test-dump-split-index.c @@ -1,3 +1,4 @@ +#define USE_THE_INDEX_VARIABLE #include "test-tool.h" #include "cache.h" #include "split-index.h" diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c index ffe34736e53..6d53683f13b 100644 --- a/t/helper/test-dump-untracked-cache.c +++ b/t/helper/test-dump-untracked-cache.c @@ -1,4 +1,4 @@ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "test-tool.h" #include "cache.h" #include "dir.h" diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c index 9def2ba6889..efc82dd80c5 100644 --- a/t/helper/test-fast-rebase.c +++ b/t/helper/test-fast-rebase.c @@ -10,7 +10,7 @@ * refactoring is the better route). */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "test-tool.h" #include "cache-tree.h" diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c index 7e8723a1900..ab86c14c8ba 100644 --- a/t/helper/test-lazy-init-name-hash.c +++ b/t/helper/test-lazy-init-name-hash.c @@ -1,3 +1,4 @@ +#define USE_THE_INDEX_VARIABLE #include "test-tool.h" #include "cache.h" #include "parse-options.h" diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c index a089be9104c..23e9e27109f 100644 --- a/t/helper/test-read-cache.c +++ b/t/helper/test-read-cache.c @@ -1,3 +1,4 @@ +#define USE_THE_INDEX_VARIABLE #include "test-tool.h" #include "cache.h" #include "config.h" diff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c index 9206dee1fd2..a26107ed70a 100644 --- a/t/helper/test-scrap-cache-tree.c +++ b/t/helper/test-scrap-cache-tree.c @@ -1,3 +1,4 @@ +#define USE_THE_INDEX_VARIABLE #include "test-tool.h" #include "cache.h" #include "lockfile.h" diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h index da7cd6351a6..2e20a16eb82 100644 --- a/t/helper/test-tool.h +++ b/t/helper/test-tool.h @@ -1,7 +1,6 @@ #ifndef TEST_TOOL_H #define TEST_TOOL_H -#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "git-compat-util.h" int cmd__advise_if_enabled(int argc, const char **argv); diff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c index 66287d6d47d..7d45cd61e82 100644 --- a/t/helper/test-write-cache.c +++ b/t/helper/test-write-cache.c @@ -1,3 +1,4 @@ +#define USE_THE_INDEX_VARIABLE #include "test-tool.h" #include "cache.h" #include "lockfile.h" From patchwork Sat Nov 19 13:07:38 2022 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: 13049743 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 1D3D0C433FE for ; Sat, 19 Nov 2022 13:08:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233543AbiKSNI3 (ORCPT ); Sat, 19 Nov 2022 08:08:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233631AbiKSNI0 (ORCPT ); Sat, 19 Nov 2022 08:08:26 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8593D93CE1 for ; Sat, 19 Nov 2022 05:07:58 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id l11so10605008edb.4 for ; Sat, 19 Nov 2022 05:07:58 -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=Xur1b1eNofBFc/W+qb7oxP6Hk1pCrKX6vnecY4HOhEQ=; b=j18T7mQ+2CjBnRy0Himl10WHgYJTY/kTyocFZY9mstHA9HGwEsfG4qH4VA+mK83F1E XG8vS9ggvv3m4iUSZO1UuOBwi71cTP+NH3wvTNzMaof/WVml5LQtauKlk3s+ZEKg0VP/ VOdEsvlg+OVONxCOgm3p4gh0Ic09Qjd7qjiuKF89UScYvjqAquIEEeWhb1bwfXxkXh+8 Ei9poOWhu/eRhh2tnDDJbogkTcDsx3f86sXGHIVE5ixlIFm1FeXC6zutw5U0GgsL4LGa c7rEowjexv+aYUcK4NpDBJN8V4L6FdiKMVeETbo+xaEGDi0DTJm2SnMAhela/NAUJr1u OEjQ== 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=Xur1b1eNofBFc/W+qb7oxP6Hk1pCrKX6vnecY4HOhEQ=; b=TOtT9uSR1FVmpXy0neSSYy6fZIYBQfT+qiUKxrE0K1n7u8jRmg5rHJMLGKT84ZeKEf ZcMJ8D+5AcHDcFO9oH9k68BjWuK20POcr8w7oQ+Dm9w2FZL0rGlJjptDu6EgqBaoj8v3 nV4YwyjLEFmA/R9ENGxve8E9yTlwjZ4d5S8LkXeUScIFksc5myDz0GrshpIQjVqReXJf P/oIwLfGWtuBSVI9Tw7xpjtRepswz/Vm9CpznrA92TaBZH1QJ2bV9KJVpnV5TZZ2/6Ys fvVp+i5lLsnBpx5jsTiMoHPwI3MQnENBbNj0oJE6ETPLsrdNueq7GrywNlYy+bEk3sa8 tOzA== X-Gm-Message-State: ANoB5pl+dCnAbtFP3qEbtLpdY0q7uIgwe1JyzPzA0KQmjBRi33YB2qcR GxL4870xL/12C7g9jS2HcOy6yrQN6v0mpg== X-Google-Smtp-Source: AA0mqf44Z1zz+8y1NYwkb5Z9unfCqFDvQ6PVzcFbj9JevocxdTz5JXWxDPewral/rTdpZK+G0Z4CXg== X-Received: by 2002:a05:6402:915:b0:467:d741:f359 with SMTP id g21-20020a056402091500b00467d741f359mr9861691edz.100.1668863277112; Sat, 19 Nov 2022 05:07:57 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id ch28-20020a0564021bdc00b0045d74aa401fsm2923802edb.60.2022.11.19.05.07.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Nov 2022 05:07:56 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 11/11] cocci: apply "pending" index-compatibility to some "builtin/*.c" Date: Sat, 19 Nov 2022 14:07:38 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1509.g9445af83948 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Apply "index-compatibility.pending.cocci" rule to "builtin/*", but exclude those where we conflict with in-flight changes. As a result some of them end up using only "the_index", so let's have them use the more narrow "USE_THE_INDEX_VARIABLE" rather than "USE_THE_INDEX_COMPATIBILITY_MACROS". Manual changes not made by coccinelle, that were squashed in: * Whitespace-wrap argument lists for repo_hold_locked_index(), repo_read_index_preload() and repo_refresh_and_write_index(), in cases where the line became too long after the transformation. * Change "refresh_cache()" to "refresh_index()" in a comment in "builtin/update-index.c". * For those whose call was followed by perror(""), change it to perror(""), referring to the new function. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/add.c | 8 +-- builtin/am.c | 21 ++++---- builtin/check-attr.c | 4 +- builtin/check-ignore.c | 4 +- builtin/checkout-index.c | 9 ++-- builtin/checkout.c | 12 ++--- builtin/clean.c | 4 +- builtin/clone.c | 4 +- builtin/commit.c | 40 +++++++------- builtin/describe.c | 7 +-- builtin/diff-files.c | 5 +- builtin/diff-index.c | 9 ++-- builtin/diff-tree.c | 4 +- builtin/diff.c | 25 +++++---- builtin/fsck.c | 4 +- builtin/merge-index.c | 6 +-- builtin/merge-ours.c | 3 +- builtin/merge.c | 19 ++++--- builtin/mv.c | 16 +++--- builtin/read-tree.c | 4 +- builtin/rebase.c | 6 +-- builtin/reset.c | 9 ++-- builtin/rev-parse.c | 4 +- builtin/rm.c | 8 +-- builtin/stash.c | 35 ++++++------ builtin/submodule--helper.c | 14 ++--- builtin/update-index.c | 19 +++---- cache.h | 5 -- contrib/coccinelle/index-compatibility.cocci | 53 ++++++++++++++++++ .../index-compatibility.pending.cocci | 54 ------------------- 30 files changed, 213 insertions(+), 202 deletions(-) diff --git a/builtin/add.c b/builtin/add.c index 23f9f0e08bb..76277df326b 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -3,7 +3,7 @@ * * Copyright (C) 2006 Linus Torvalds */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "cache.h" #include "config.h" #include "builtin.h" @@ -312,7 +312,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix) git_config(git_diff_basic_config, NULL); /* no "diff" UI options */ - if (read_cache() < 0) + if (repo_read_index(the_repository) < 0) die(_("Could not read the index")); repo_init_revisions(the_repository, &rev, prefix); @@ -544,7 +544,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) prepare_repo_settings(the_repository); the_repository->settings.command_requires_full_index = 0; - hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); + repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR); /* * Check the "pathspec '%s' did not match any files" block @@ -587,7 +587,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) (!(addremove || take_worktree_changes) ? ADD_CACHE_IGNORE_REMOVAL : 0)); - if (read_cache_preload(&pathspec) < 0) + if (repo_read_index_preload(the_repository, &pathspec, 0) < 0) die(_("index file corrupt")); die_in_unpopulated_submodule(&the_index, prefix); diff --git a/builtin/am.c b/builtin/am.c index f362a1c29fd..30c9b3a9cd7 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1519,8 +1519,8 @@ static int run_apply(const struct am_state *state, const char *index_file) if (index_file) { /* Reload index as apply_all_patches() will have modified it. */ - discard_cache(); - read_cache_from(index_file); + discard_index(&the_index); + read_index_from(&the_index, index_file, get_git_dir()); } return 0; @@ -1562,8 +1562,8 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa if (build_fake_ancestor(state, index_path)) return error("could not build fake ancestor"); - discard_cache(); - read_cache_from(index_path); + discard_index(&the_index); + read_index_from(&the_index, index_path, get_git_dir()); if (write_index_as_tree(&orig_tree, &the_index, index_path, 0, NULL)) return error(_("Repository lacks necessary blobs to fall back on 3-way merge.")); @@ -1596,8 +1596,8 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa say(state, stdout, _("Falling back to patching base and 3-way merge...")); - discard_cache(); - read_cache(); + discard_index(&the_index); + repo_read_index(the_repository); /* * This is not so wrong. Depending on which base we picked, orig_tree @@ -1781,7 +1781,8 @@ static void am_run(struct am_state *state, int resume) unlink(am_path(state, "dirtyindex")); - if (refresh_and_write_cache(REFRESH_QUIET, 0, 0) < 0) + if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0, + NULL, NULL, NULL) < 0) die(_("unable to write index file")); if (repo_index_has_changes(the_repository, NULL, &sb)) { @@ -1967,9 +1968,9 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset) if (parse_tree(head) || parse_tree(remote)) return -1; - hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); + repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR); - refresh_cache(REFRESH_QUIET); + refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL); memset(&opts, 0, sizeof(opts)); opts.head_idx = 1; @@ -2007,7 +2008,7 @@ static int merge_tree(struct tree *tree) if (parse_tree(tree)) return -1; - hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); + repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR); memset(&opts, 0, sizeof(opts)); opts.head_idx = 1; diff --git a/builtin/check-attr.c b/builtin/check-attr.c index dd833977864..0fef10eb6bc 100644 --- a/builtin/check-attr.c +++ b/builtin/check-attr.c @@ -1,4 +1,4 @@ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "cache.h" #include "config.h" @@ -115,7 +115,7 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, check_attr_options, check_attr_usage, PARSE_OPT_KEEP_DASHDASH); - if (read_cache() < 0) { + if (repo_read_index(the_repository) < 0) { die("invalid cache"); } diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c index 21912569650..ab776061c7c 100644 --- a/builtin/check-ignore.c +++ b/builtin/check-ignore.c @@ -1,4 +1,4 @@ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "cache.h" #include "config.h" @@ -179,7 +179,7 @@ int cmd_check_ignore(int argc, const char **argv, const char *prefix) die(_("--non-matching is only valid with --verbose")); /* read_cache() is only necessary so we can watch out for submodules. */ - if (!no_index && read_cache() < 0) + if (!no_index && repo_read_index(the_repository) < 0) die(_("index file corrupt")); setup_standard_excludes(&dir); diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c index c2aee450c40..cf6fba97ba7 100644 --- a/builtin/checkout-index.c +++ b/builtin/checkout-index.c @@ -4,7 +4,7 @@ * Copyright (C) 2005 Linus Torvalds * */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "config.h" #include "dir.h" @@ -65,7 +65,7 @@ static void write_tempfile_record(const char *name, const char *prefix) static int checkout_file(const char *name, const char *prefix) { int namelen = strlen(name); - int pos = cache_name_pos(name, namelen); + int pos = index_name_pos(&the_index, name, namelen); int has_same_name = 0; int is_file = 0; int is_skipped = 1; @@ -249,7 +249,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix) prepare_repo_settings(the_repository); the_repository->settings.command_requires_full_index = 0; - if (read_cache() < 0) { + if (repo_read_index(the_repository) < 0) { die("invalid cache"); } @@ -270,7 +270,8 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix) if (index_opt && !state.base_dir_len && !to_tempfile) { state.refresh_cache = 1; state.istate = &the_index; - hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); + repo_hold_locked_index(the_repository, &lock_file, + LOCK_DIE_ON_ERROR); } get_parallel_checkout_configs(&pc_workers, &pc_threshold); diff --git a/builtin/checkout.c b/builtin/checkout.c index 3fd303f5604..3fa29a08eea 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -1,4 +1,4 @@ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "advice.h" #include "blob.h" @@ -148,7 +148,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base, * entry in place. Whether it is UPTODATE or not, checkout_entry will * do the right thing. */ - pos = cache_name_pos(ce->name, ce->ce_namelen); + pos = index_name_pos(&the_index, ce->name, ce->ce_namelen); if (pos >= 0) { struct cache_entry *old = the_index.cache[pos]; if (ce->ce_mode == old->ce_mode && @@ -529,7 +529,7 @@ static int checkout_paths(const struct checkout_opts *opts, } repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR); - if (read_cache_preload(&opts->pathspec) < 0) + if (repo_read_index_preload(the_repository, &opts->pathspec, 0) < 0) return error(_("index file corrupt")); if (opts->source_tree) @@ -741,8 +741,8 @@ static int merge_working_tree(const struct checkout_opts *opts, struct lock_file lock_file = LOCK_INIT; struct tree *new_tree; - hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); - if (read_cache_preload(NULL) < 0) + repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR); + if (repo_read_index_preload(the_repository, NULL, 0) < 0) return error(_("index file corrupt")); resolve_undo_clear_index(&the_index); @@ -762,7 +762,7 @@ static int merge_working_tree(const struct checkout_opts *opts, struct unpack_trees_options topts; const struct object_id *old_commit_oid; - refresh_cache(REFRESH_QUIET); + refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL); if (unmerged_index(&the_index)) { error(_("you need to resolve your current index first")); diff --git a/builtin/clean.c b/builtin/clean.c index 7084e685f6f..b2701a28158 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -6,7 +6,7 @@ * Based on git-clean.sh by Pavel Roskin */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "cache.h" #include "config.h" @@ -1012,7 +1012,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix) prepare_repo_settings(the_repository); the_repository->settings.command_requires_full_index = 0; - if (read_cache() < 0) + if (repo_read_index(the_repository) < 0) die(_("index file corrupt")); pl = add_pattern_list(&dir, EXC_CMDL, "--exclude option"); diff --git a/builtin/clone.c b/builtin/clone.c index 0e4348686b6..f518bb2dc1f 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -8,7 +8,7 @@ * Clone a repository into a different directory that does not yet exist. */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "config.h" #include "lockfile.h" @@ -703,7 +703,7 @@ static int checkout(int submodule_progress, int filter_submodules) /* We need to be in the new work tree for the checkout */ setup_work_tree(); - hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); + repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR); memset(&opts, 0, sizeof opts); opts.update = 1; diff --git a/builtin/commit.c b/builtin/commit.c index abbed750276..06b1330346f 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -316,7 +316,7 @@ static void create_base_index(const struct commit *current_head) struct tree_desc t; if (!current_head) { - discard_cache(); + discard_index(&the_index); return; } @@ -343,7 +343,7 @@ static void refresh_cache_or_die(int refresh_flags) * refresh_flags contains REFRESH_QUIET, so the only errors * are for unmerged entries. */ - if (refresh_cache(refresh_flags | REFRESH_IN_PORCELAIN)) + if (refresh_index(&the_index, refresh_flags | REFRESH_IN_PORCELAIN, NULL, NULL, NULL)) die_resolve_conflict("commit"); } @@ -382,12 +382,13 @@ static const char *prepare_index(const char **argv, const char *prefix, (!amend || (fixup_message && strcmp(fixup_prefix, "amend")))))) die(_("No paths with --include/--only does not make sense.")); - if (read_cache_preload(&pathspec) < 0) + if (repo_read_index_preload(the_repository, &pathspec, 0) < 0) die(_("index file corrupt")); if (interactive) { char *old_index_env = NULL, *old_repo_index_file; - hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR); + repo_hold_locked_index(the_repository, &index_lock, + LOCK_DIE_ON_ERROR); refresh_cache_or_die(refresh_flags); @@ -410,8 +411,9 @@ static const char *prepare_index(const char **argv, const char *prefix, unsetenv(INDEX_ENVIRONMENT); FREE_AND_NULL(old_index_env); - discard_cache(); - read_cache_from(get_lock_file_path(&index_lock)); + 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 (reopen_lock_file(&index_lock) < 0) die(_("unable to write index file")); @@ -438,7 +440,8 @@ static const char *prepare_index(const char **argv, const char *prefix, * (B) on failure, rollback the real index. */ if (all || (also && pathspec.nr)) { - hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR); + repo_hold_locked_index(the_repository, &index_lock, + 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); @@ -459,7 +462,8 @@ static const char *prepare_index(const char **argv, const char *prefix, * We still need to refresh the index here. */ if (!only && !pathspec.nr) { - hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR); + repo_hold_locked_index(the_repository, &index_lock, + LOCK_DIE_ON_ERROR); refresh_cache_or_die(refresh_flags); if (the_index.cache_changed || !cache_tree_fully_valid(the_index.cache_tree)) @@ -505,13 +509,13 @@ static const char *prepare_index(const char **argv, const char *prefix, if (list_paths(&partial, !current_head ? NULL : "HEAD", &pathspec)) exit(1); - discard_cache(); - if (read_cache() < 0) + discard_index(&the_index); + if (repo_read_index(the_repository) < 0) die(_("cannot read the index")); - hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR); + repo_hold_locked_index(the_repository, &index_lock, LOCK_DIE_ON_ERROR); add_remove_files(&partial); - refresh_cache(REFRESH_QUIET); + refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL); update_main_cache_tree(WRITE_TREE_SILENT); if (write_locked_index(&the_index, &index_lock, 0)) die(_("unable to write new_index file")); @@ -523,14 +527,14 @@ static const char *prepare_index(const char **argv, const char *prefix, create_base_index(current_head); add_remove_files(&partial); - refresh_cache(REFRESH_QUIET); + refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL); if (write_locked_index(&the_index, &false_lock, 0)) die(_("unable to write temporary index file")); - discard_cache(); + discard_index(&the_index); ret = get_lock_file_path(&false_lock); - read_cache_from(ret); + read_index_from(&the_index, ret, get_git_dir()); out: string_list_clear(&partial, 0); clear_pathspec(&pathspec); @@ -1068,9 +1072,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix, * and could have updated it. We must do this before we invoke * the editor and after we invoke run_status above. */ - discard_cache(); + discard_index(&the_index); } - read_cache_from(index_file); + read_index_from(&the_index, index_file, get_git_dir()); if (update_main_cache_tree(0)) { error(_("Error building trees")); @@ -1556,7 +1560,7 @@ int cmd_status(int argc, const char **argv, const char *prefix) &s.pathspec, NULL, NULL); if (use_optional_locks()) - fd = hold_locked_index(&index_lock, 0); + fd = repo_hold_locked_index(the_repository, &index_lock, 0); else fd = -1; diff --git a/builtin/describe.c b/builtin/describe.c index 23e3f05fb10..eea1e330c00 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -1,4 +1,4 @@ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "cache.h" #include "config.h" #include "lockfile.h" @@ -653,10 +653,11 @@ int cmd_describe(int argc, const char **argv, const char *prefix) int fd, result; setup_work_tree(); - read_cache(); + repo_read_index(the_repository); refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL); - fd = hold_locked_index(&index_lock, 0); + fd = repo_hold_locked_index(the_repository, + &index_lock, 0); if (0 <= fd) repo_update_index_if_able(the_repository, &index_lock); diff --git a/builtin/diff-files.c b/builtin/diff-files.c index 096ea2fedbc..dc991f753bb 100644 --- a/builtin/diff-files.c +++ b/builtin/diff-files.c @@ -3,7 +3,6 @@ * * Copyright (C) Linus Torvalds, 2005 */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "diff.h" @@ -76,8 +75,8 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix) (rev.diffopt.output_format & DIFF_FORMAT_PATCH)) diff_merges_set_dense_combined_if_unset(&rev); - if (read_cache_preload(&rev.diffopt.pathspec) < 0) { - perror("read_cache_preload"); + if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) { + perror("repo_read_index_preload"); result = -1; goto cleanup; } diff --git a/builtin/diff-index.c b/builtin/diff-index.c index aea139b9d8f..35dc9b23eef 100644 --- a/builtin/diff-index.c +++ b/builtin/diff-index.c @@ -1,4 +1,3 @@ -#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "diff.h" @@ -62,12 +61,12 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix) usage(diff_cache_usage); if (!(option & DIFF_INDEX_CACHED)) { setup_work_tree(); - if (read_cache_preload(&rev.diffopt.pathspec) < 0) { - perror("read_cache_preload"); + if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) { + perror("repo_read_index_preload"); return -1; } - } else if (read_cache() < 0) { - perror("read_cache"); + } else if (repo_read_index(the_repository) < 0) { + perror("repo_read_index"); return -1; } result = run_diff_index(&rev, option); diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c index 85e8c81e594..25b853b85ca 100644 --- a/builtin/diff-tree.c +++ b/builtin/diff-tree.c @@ -1,4 +1,4 @@ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "cache.h" #include "config.h" #include "diff.h" @@ -120,7 +120,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix) git_config(git_diff_basic_config, NULL); /* no "diff" UI options */ repo_init_revisions(the_repository, opt, prefix); - if (read_cache() < 0) + if (repo_read_index(the_repository) < 0) die(_("index file corrupt")); opt->abbrev = 0; opt->diff = 1; diff --git a/builtin/diff.c b/builtin/diff.c index 854d2c5a5c4..163f2c6a874 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -3,7 +3,7 @@ * * Copyright (c) 2006 Junio C Hamano */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "cache.h" #include "config.h" #include "ewah/ewok.h" @@ -157,12 +157,13 @@ static int builtin_diff_index(struct rev_info *revs, usage(builtin_diff_usage); if (!(option & DIFF_INDEX_CACHED)) { setup_work_tree(); - if (read_cache_preload(&revs->diffopt.pathspec) < 0) { - perror("read_cache_preload"); + if (repo_read_index_preload(the_repository, + &revs->diffopt.pathspec, 0) < 0) { + perror("repo_read_index_preload"); return -1; } - } else if (read_cache() < 0) { - perror("read_cache"); + } else if (repo_read_index(the_repository) < 0) { + perror("repo_read_cache"); return -1; } return run_diff_index(revs, option); @@ -239,12 +240,13 @@ static void refresh_index_quietly(void) struct lock_file lock_file = LOCK_INIT; int fd; - fd = hold_locked_index(&lock_file, 0); + fd = repo_hold_locked_index(the_repository, &lock_file, 0); if (fd < 0) return; - discard_cache(); - read_cache(); - refresh_cache(REFRESH_QUIET|REFRESH_UNMERGED); + discard_index(&the_index); + repo_read_index(the_repository); + refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, + NULL); repo_update_index_if_able(the_repository, &lock_file); } @@ -279,8 +281,9 @@ static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv diff_merges_set_dense_combined_if_unset(revs); setup_work_tree(); - if (read_cache_preload(&revs->diffopt.pathspec) < 0) { - perror("read_cache_preload"); + if (repo_read_index_preload(the_repository, &revs->diffopt.pathspec, + 0) < 0) { + perror("repo_read_index_preload"); return -1; } return run_diff_files(revs, options); diff --git a/builtin/fsck.c b/builtin/fsck.c index cd47675e371..d207bd909b4 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -1,4 +1,4 @@ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "cache.h" #include "repository.h" @@ -958,7 +958,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) if (keep_cache_objects) { verify_index_checksum = 1; verify_ce_order = 1; - read_cache(); + repo_read_index(the_repository); /* TODO: audit for interaction with sparse-index. */ ensure_full_index(&the_index); for (i = 0; i < the_index.cache_nr; i++) { diff --git a/builtin/merge-index.c b/builtin/merge-index.c index a334c513c9d..452f833ac46 100644 --- a/builtin/merge-index.c +++ b/builtin/merge-index.c @@ -1,4 +1,4 @@ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "run-command.h" @@ -47,7 +47,7 @@ static int merge_entry(int pos, const char *path) static void merge_one_path(const char *path) { - int pos = cache_name_pos(path, strlen(path)); + int pos = index_name_pos(&the_index, path, strlen(path)); /* * If it already exists in the cache as stage0, it's @@ -82,7 +82,7 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix) if (argc < 3) usage("git merge-index [-o] [-q] (-a | [--] [...])"); - read_cache(); + repo_read_index(the_repository); /* TODO: audit for interaction with sparse-index. */ ensure_full_index(&the_index); diff --git a/builtin/merge-ours.c b/builtin/merge-ours.c index 3583cff71c7..284eb486098 100644 --- a/builtin/merge-ours.c +++ b/builtin/merge-ours.c @@ -7,7 +7,6 @@ * * Pretend we resolved the heads, but declare our tree trumps everybody else. */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "git-compat-util.h" #include "builtin.h" #include "diff.h" @@ -25,7 +24,7 @@ int cmd_merge_ours(int argc, const char **argv, const char *prefix) * commit. The index must match HEAD, or this merge cannot go * through. */ - if (read_cache() < 0) + if (repo_read_index(the_repository) < 0) die_errno("read_cache failed"); if (index_differs_from(the_repository, "HEAD", NULL, 0)) return 2; diff --git a/builtin/merge.c b/builtin/merge.c index 27218ee93c9..dd474371a25 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -318,7 +318,7 @@ static int save_state(struct object_id *stash) int rc = -1; fd = repo_hold_locked_index(the_repository, &lock_file, 0); - refresh_cache(REFRESH_QUIET); + refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL); if (0 <= fd) repo_update_index_if_able(the_repository, &lock_file); rollback_lock_file(&lock_file); @@ -716,7 +716,9 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common, { const char *head_arg = "HEAD"; - if (refresh_and_write_cache(REFRESH_QUIET, SKIP_IF_UNCHANGED, 0) < 0) + if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, + SKIP_IF_UNCHANGED, 0, NULL, NULL, + NULL) < 0) return error(_("Unable to write index.")); if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree") || @@ -750,7 +752,8 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common, for (j = common; j; j = j->next) commit_list_insert(j->item, &reversed); - hold_locked_index(&lock, LOCK_DIE_ON_ERROR); + repo_hold_locked_index(the_repository, &lock, + LOCK_DIE_ON_ERROR); if (!strcmp(strategy, "ort")) clean = merge_ort_recursive(&o, head, remoteheads->item, reversed, &result); @@ -859,9 +862,9 @@ static void prepare_to_commit(struct commit_list *remoteheads) * the editor and after we invoke run_status above. */ if (invoked_hook) - discard_cache(); + discard_index(&the_index); } - read_cache_from(index_file); + read_index_from(&the_index, index_file, get_git_dir()); strbuf_addbuf(&msg, &merge_msg); if (squash) BUG("the control must not reach here under --squash"); @@ -910,7 +913,9 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads) struct object_id result_tree, result_commit; struct commit_list *parents, **pptr = &parents; - if (refresh_and_write_cache(REFRESH_QUIET, SKIP_IF_UNCHANGED, 0) < 0) + if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, + SKIP_IF_UNCHANGED, 0, NULL, NULL, + NULL) < 0) return error(_("Unable to write index.")); write_tree_trivial(&result_tree); @@ -1602,7 +1607,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) * We are not doing octopus, not fast-forward, and have * only one common. */ - refresh_cache(REFRESH_QUIET); + refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL); if (allow_trivial && fast_forward != FF_ONLY) { /* * Must first ensure that index matches HEAD before diff --git a/builtin/mv.c b/builtin/mv.c index 883cf3ff12b..19790ce38fa 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -106,7 +106,7 @@ static int index_range_of_same_dir(const char *src, int length, const char *src_w_slash = add_slash(src); int first, last, len_w_slash = length + 1; - first = cache_name_pos(src_w_slash, len_w_slash); + first = index_name_pos(&the_index, src_w_slash, len_w_slash); if (first >= 0) die(_("%.*s is in index"), len_w_slash, src_w_slash); @@ -136,7 +136,7 @@ static int empty_dir_has_sparse_contents(const char *name) const char *with_slash = add_slash(name); int length = strlen(with_slash); - int pos = cache_name_pos(with_slash, length); + int pos = index_name_pos(&the_index, with_slash, length); const struct cache_entry *ce; if (pos < 0) { @@ -189,8 +189,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix) if (--argc < 1) usage_with_options(builtin_mv_usage, builtin_mv_options); - hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); - if (read_cache() < 0) + repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR); + if (repo_read_index(the_repository) < 0) die(_("index file corrupt")); source = internal_prefix_pathspec(prefix, argv, argc, 0); @@ -255,7 +255,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) int pos; const struct cache_entry *ce; - pos = cache_name_pos(src, length); + pos = index_name_pos(&the_index, src, length); if (pos < 0) { const char *src_w_slash = add_slash(src); if (!path_in_sparse_checkout(src_w_slash, &the_index) && @@ -278,7 +278,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) goto act_on_entry; } /* Check if dst exists in index */ - if (cache_name_pos(dst, strlen(dst)) < 0) { + if (index_name_pos(&the_index, dst, strlen(dst)) < 0) { modes[i] |= SPARSE; goto act_on_entry; } @@ -303,7 +303,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) dir_check: if (S_ISDIR(st.st_mode)) { int j, dst_len, n; - int first = cache_name_pos(src, length), last; + int first = index_name_pos(&the_index, src, length), last; if (first >= 0) { prepare_move_submodule(src, first, @@ -468,7 +468,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) if (mode & (WORKING_DIRECTORY | SKIP_WORKTREE_DIR)) continue; - pos = cache_name_pos(src, strlen(src)); + pos = index_name_pos(&the_index, src, strlen(src)); assert(pos >= 0); if (!(mode & SPARSE) && !lstat(src, &st)) sparse_and_dirty = ie_modified(&the_index, diff --git a/builtin/read-tree.c b/builtin/read-tree.c index c50b563e2be..f702f9d47bb 100644 --- a/builtin/read-tree.c +++ b/builtin/read-tree.c @@ -4,7 +4,7 @@ * Copyright (C) Linus Torvalds, 2005 */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "cache.h" #include "config.h" #include "lockfile.h" @@ -176,7 +176,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix) prepare_repo_settings(the_repository); the_repository->settings.command_requires_full_index = 0; - hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); + repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR); /* * NEEDSWORK diff --git a/builtin/rebase.c b/builtin/rebase.c index 5d855fd8f51..1384008fe09 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -4,7 +4,7 @@ * Copyright (c) 2018 Pratik Karki */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "run-command.h" #include "exec-cmd.h" @@ -292,7 +292,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags) if (ret) error(_("could not generate todo list")); else { - discard_cache(); + discard_index(&the_index); if (todo_list_parse_insn_buffer(the_repository, todo_list.buf.buf, &todo_list)) BUG("unusable todo list"); @@ -1268,7 +1268,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) if (get_oid("HEAD", &head)) die(_("Cannot read HEAD")); - fd = hold_locked_index(&lock_file, 0); + fd = repo_hold_locked_index(the_repository, &lock_file, 0); if (repo_read_index(the_repository) < 0) die(_("could not read index")); refresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL, diff --git a/builtin/reset.c b/builtin/reset.c index 75e061f5dcf..1fa86edb4c9 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -7,7 +7,7 @@ * * Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "config.h" #include "lockfile.h" @@ -160,7 +160,7 @@ static void update_index_from_diff(struct diff_queue_struct *q, * if this entry is outside the sparse cone - this is necessary * to properly construct the reset sparse directory. */ - pos = cache_name_pos(one->path, strlen(one->path)); + pos = index_name_pos(&the_index, one->path, strlen(one->path)); if ((pos >= 0 && ce_skip_worktree(the_index.cache[pos])) || (pos < 0 && !path_in_sparse_checkout(one->path, &the_index))) ce->ce_flags |= CE_SKIP_WORKTREE; @@ -423,7 +423,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix) prepare_repo_settings(the_repository); the_repository->settings.command_requires_full_index = 0; - if (read_cache() < 0) + if (repo_read_index(the_repository) < 0) die(_("index file corrupt")); /* Soft reset does not touch the index file nor the working tree @@ -434,7 +434,8 @@ int cmd_reset(int argc, const char **argv, const char *prefix) if (reset_type != SOFT) { struct lock_file lock = LOCK_INIT; - hold_locked_index(&lock, LOCK_DIE_ON_ERROR); + repo_hold_locked_index(the_repository, &lock, + LOCK_DIE_ON_ERROR); if (reset_type == MIXED) { int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN; if (read_from_tree(&pathspec, &oid, intent_to_add)) diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 8f61050bde8..d4c81352a65 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.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 "config.h" #include "commit.h" @@ -997,7 +997,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) continue; } if (!strcmp(arg, "--shared-index-path")) { - if (read_cache() < 0) + if (repo_read_index(the_repository) < 0) die(_("Could not read the index")); if (the_index.split_index) { const struct object_id *oid = &the_index.split_index->base_oid; diff --git a/builtin/rm.c b/builtin/rm.c index 2b23eb25438..40b7990de11 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -72,7 +72,7 @@ static void submodules_absorb_gitdir_if_needed(void) int pos; const struct cache_entry *ce; - pos = cache_name_pos(name, strlen(name)); + pos = index_name_pos(&the_index, name, strlen(name)); if (pos < 0) { pos = get_ours_cache_pos(name, pos); if (pos < 0) @@ -117,7 +117,7 @@ static int check_local_mod(struct object_id *head, int index_only) int local_changes = 0; int staged_changes = 0; - pos = cache_name_pos(name, strlen(name)); + pos = index_name_pos(&the_index, name, strlen(name)); if (pos < 0) { /* * Skip unmerged entries except for populated submodules @@ -291,9 +291,9 @@ int cmd_rm(int argc, const char **argv, const char *prefix) prepare_repo_settings(the_repository); the_repository->settings.command_requires_full_index = 0; - hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); + repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR); - if (read_cache() < 0) + if (repo_read_index(the_repository) < 0) die(_("index file corrupt")); refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &pathspec, NULL, NULL); diff --git a/builtin/stash.c b/builtin/stash.c index c251419af7c..62e36718d38 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -261,11 +261,11 @@ static int reset_tree(struct object_id *i_tree, int update, int reset) struct tree *tree; struct lock_file lock_file = LOCK_INIT; - read_cache_preload(NULL); - if (refresh_cache(REFRESH_QUIET)) + repo_read_index_preload(the_repository, NULL, 0); + if (refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL)) return -1; - hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); + repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR); memset(&opts, 0, sizeof(opts)); @@ -523,8 +523,9 @@ static int do_apply_stash(const char *prefix, struct stash_info *info, struct tree *head, *merge, *merge_base; struct lock_file lock = LOCK_INIT; - read_cache_preload(NULL); - if (refresh_and_write_cache(REFRESH_QUIET, 0, 0)) + repo_read_index_preload(the_repository, NULL, 0); + if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0, + NULL, NULL, NULL)) return -1; if (write_cache_as_tree(&c_tree, 0, NULL)) @@ -549,14 +550,14 @@ static int do_apply_stash(const char *prefix, struct stash_info *info, return error(_("conflicts in index. " "Try without --index.")); - discard_cache(); - read_cache(); + discard_index(&the_index); + repo_read_index(the_repository); if (write_cache_as_tree(&index_tree, 0, NULL)) return error(_("could not save index tree")); reset_head(); - discard_cache(); - read_cache(); + discard_index(&the_index); + repo_read_index(the_repository); } } @@ -1082,7 +1083,7 @@ static int check_changes_tracked_files(const struct pathspec *ps) if (get_oid("HEAD", &dummy)) return -1; - if (read_cache() < 0) + if (repo_read_index(the_repository) < 0) return -1; init_revisions(&rev, NULL); @@ -1286,7 +1287,7 @@ static int stash_working_tree(struct stash_info *info, const struct pathspec *ps rev.diffopt.format_callback = add_diff_to_buf; rev.diffopt.format_callback_data = &diff_output; - if (read_cache_preload(&rev.diffopt.pathspec) < 0) { + if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) { ret = -1; goto done; } @@ -1344,8 +1345,9 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b prepare_fallback_ident("git stash", "git@stash"); - read_cache_preload(NULL); - if (refresh_and_write_cache(REFRESH_QUIET, 0, 0) < 0) { + repo_read_index_preload(the_repository, NULL, 0); + if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0, + NULL, NULL, NULL) < 0) { ret = -1; goto done; } @@ -1513,7 +1515,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q goto done; } - read_cache_preload(NULL); + repo_read_index_preload(the_repository, NULL, 0); if (!include_untracked && ps->nr) { int i; char *ps_matched = xcalloc(ps->nr, 1); @@ -1533,7 +1535,8 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q free(ps_matched); } - if (refresh_and_write_cache(REFRESH_QUIET, 0, 0)) { + if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0, + NULL, NULL, NULL)) { ret = -1; goto done; } @@ -1590,7 +1593,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q goto done; } } - discard_cache(); + discard_index(&the_index); if (ps->nr) { struct child_process cp_add = CHILD_PROCESS_INIT; struct child_process cp_diff = CHILD_PROCESS_INIT; diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 808865a5e31..ebe86e68176 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1,4 +1,4 @@ -#define USE_THE_INDEX_COMPATIBILITY_MACROS +#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "repository.h" #include "cache.h" @@ -196,7 +196,7 @@ static int module_list_compute(const char **argv, if (pathspec->nr) ps_matched = xcalloc(pathspec->nr, 1); - if (read_cache() < 0) + if (repo_read_index(the_repository) < 0) die(_("index file corrupt")); for (i = 0; i < the_index.cache_nr; i++) { @@ -1109,13 +1109,13 @@ static int compute_summary_module_list(struct object_id *head_oid, if (!info->cached) { if (diff_cmd == DIFF_INDEX) setup_work_tree(); - if (read_cache_preload(&rev.diffopt.pathspec) < 0) { - perror("read_cache_preload"); + if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) { + perror("repo_read_index_preload"); ret = -1; goto cleanup; } - } else if (read_cache() < 0) { - perror("read_cache"); + } else if (repo_read_index(the_repository) < 0) { + perror("repo_read_cache"); ret = -1; goto cleanup; } @@ -3240,7 +3240,7 @@ static void die_on_index_match(const char *path, int force) const char *args[] = { path, NULL }; parse_pathspec(&ps, 0, PATHSPEC_PREFER_CWD, NULL, args); - if (read_cache_preload(NULL) < 0) + if (repo_read_index_preload(the_repository, NULL, 0) < 0) die(_("index file corrupt")); if (ps.nr) { diff --git a/builtin/update-index.c b/builtin/update-index.c index fec3da05abb..82d5902cc8b 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -237,7 +237,7 @@ static int test_if_untracked_cache_is_supported(void) static int mark_ce_flags(const char *path, int flag, int mark) { int namelen = strlen(path); - int pos = cache_name_pos(path, namelen); + int pos = index_name_pos(&the_index, path, namelen); if (0 <= pos) { mark_fsmonitor_invalid(&the_index, the_index.cache[pos]); if (mark) @@ -331,7 +331,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len static int process_directory(const char *path, int len, struct stat *st) { struct object_id oid; - int pos = cache_name_pos(path, len); + int pos = index_name_pos(&the_index, path, len); /* Exact match: file or existing gitlink */ if (pos >= 0) { @@ -441,7 +441,7 @@ static void chmod_path(char flip, const char *path) int pos; struct cache_entry *ce; - pos = cache_name_pos(path, strlen(path)); + pos = index_name_pos(&the_index, path, strlen(path)); if (pos < 0) goto fail; ce = the_index.cache[pos]; @@ -638,7 +638,7 @@ static int unresolve_one(const char *path) struct cache_entry *ce_2 = NULL, *ce_3 = NULL; /* See if there is such entry in the index. */ - pos = cache_name_pos(path, namelen); + pos = index_name_pos(&the_index, path, namelen); if (0 <= pos) { /* already merged */ pos = unmerge_index_entry_at(&the_index, pos); @@ -802,15 +802,16 @@ struct refresh_params { static int refresh(struct refresh_params *o, unsigned int flag) { setup_work_tree(); - read_cache(); - *o->has_errors |= refresh_cache(o->flags | flag); + repo_read_index(the_repository); + *o->has_errors |= refresh_index(&the_index, o->flags | flag, NULL, + NULL, NULL); if (has_racy_timestamp(&the_index)) { /* * Even if nothing else has changed, updating the file * increases the chance that racy timestamps become * non-racy, helping future run-time performance. * We do that even in case of "errors" returned by - * refresh_cache() as these are no actual errors. + * refresh_index() as these are no actual errors. * cmd_status() does the same. */ the_index.cache_changed |= SOMETHING_CHANGED; @@ -1109,11 +1110,11 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) the_repository->settings.command_requires_full_index = 0; /* we will diagnose later if it turns out that we need to update it */ - newfd = hold_locked_index(&lock_file, 0); + newfd = repo_hold_locked_index(the_repository, &lock_file, 0); if (newfd < 0) lock_error = errno; - entries = read_cache(); + entries = repo_read_index(the_repository); if (entries < 0) die("cache corrupted"); diff --git a/cache.h b/cache.h index 707806d2125..07d40b0964b 100644 --- a/cache.h +++ b/cache.h @@ -441,13 +441,8 @@ extern struct index_state the_index; #define active_nr (the_index.cache_nr) #define read_cache() repo_read_index(the_repository) -#define read_cache_from(path) read_index_from(&the_index, (path), (get_git_dir())) -#define read_cache_preload(pathspec) repo_read_index_preload(the_repository, (pathspec), 0) #define discard_cache() discard_index(&the_index) #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen)) -#define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL, NULL) -#define refresh_and_write_cache(refresh_flags, write_flags, gentle) repo_refresh_and_write_index(the_repository, (refresh_flags), (write_flags), (gentle), NULL, NULL, NULL) -#define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags)) #endif #endif #endif diff --git a/contrib/coccinelle/index-compatibility.cocci b/contrib/coccinelle/index-compatibility.cocci index 8b1ed65e7b0..4c1b890c3ef 100644 --- a/contrib/coccinelle/index-compatibility.cocci +++ b/contrib/coccinelle/index-compatibility.cocci @@ -26,11 +26,27 @@ identifier f != prepare_to_commit; ( - read_cache_unmerged + repo_read_index_unmerged +| +- hold_locked_index ++ repo_hold_locked_index ) ( + the_repository, ...) +// "the_repository" special-cases +@@ +@@ +( +- read_cache_preload ++ repo_read_index_preload +) + ( ++ the_repository, + ... ++ , 0 + ) + // "the_index" simple cases @@ @@ @@ -80,3 +96,40 @@ identifier f != prepare_to_commit; ( + &the_index, ...) + +@@ +@@ +( +- refresh_and_write_cache ++ repo_refresh_and_write_index +) + ( ++ the_repository, + ... ++ , NULL, NULL, NULL + ) + +// "the_index" special-cases +@@ +@@ +( +- read_cache_from ++ read_index_from +) + ( ++ &the_index, + ... ++ , get_git_dir() + ) + +@@ +@@ +( +- refresh_cache ++ refresh_index +) + ( ++ &the_index, + ... ++ , NULL, NULL, NULL + ) diff --git a/contrib/coccinelle/index-compatibility.pending.cocci b/contrib/coccinelle/index-compatibility.pending.cocci index 8207aee62c3..01f875d0060 100644 --- a/contrib/coccinelle/index-compatibility.pending.cocci +++ b/contrib/coccinelle/index-compatibility.pending.cocci @@ -4,9 +4,6 @@ ( - read_cache + repo_read_index -| -- hold_locked_index -+ repo_hold_locked_index ) ( + the_repository, @@ -25,54 +22,3 @@ ( + &the_index, ...) - -// "the_repository" special-cases -@@ -@@ -( -- read_cache_preload -+ repo_read_index_preload -) - ( -+ the_repository, - ... -+ , 0 - ) - -@@ -@@ -( -- refresh_and_write_cache -+ repo_refresh_and_write_index -) - ( -+ the_repository, - ... -+ , NULL, NULL, NULL - ) - - -// "the_index" special-cases -@@ -@@ -( -- read_cache_from -+ read_index_from -) - ( -+ &the_index, - ... -+ , get_git_dir() - ) - -@@ -@@ -( -- refresh_cache -+ refresh_index -) - ( -+ &the_index, - ... -+ , NULL, NULL, NULL - )