From patchwork Tue Jan 5 04:42:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11998101 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BBB8C433E6 for ; Tue, 5 Jan 2021 04:44:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6498E22515 for ; Tue, 5 Jan 2021 04:44:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727285AbhAEEnu (ORCPT ); Mon, 4 Jan 2021 23:43:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726749AbhAEEnt (ORCPT ); Mon, 4 Jan 2021 23:43:49 -0500 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA519C061574 for ; Mon, 4 Jan 2021 20:43:08 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id c133so1857690wme.4 for ; Mon, 04 Jan 2021 20:43:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=46EBxVR106mVIDbq6Lo6I4pbDbN3mZe9YLzzhfxnxgk=; b=qQSXSg32GGwbuOJFBtkK7Md25mqaphhXfb06LrVzzx9rYAAI8C/U2zpXaZNaYbC0Pq yrnL+8RLbni9LH0Aw6B7sj0QnD+nBvHxpSh2iqkrHl8RHgpUc6l5qhnNzfaO2iiOg/0V 6xbIOg5JIZh0gpcbq3lL63Yc0Jq8dqRIQbLIuNBJsbns+xeZ2oQKOvfteAQXodQDBF7d 2fxMFW/efByDA3fgxMJrfYLXLdr/TrQ6qniDg/qfHrvPICER6BThA1UwLvzOegzh+F4p JwO8rcqNjkQGg3Q5B1LHU1SIqDBy5R9fWN0j8pmyNPBU5hHjvUEeY7Ks7S8FzGHG2/mX 1szQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=46EBxVR106mVIDbq6Lo6I4pbDbN3mZe9YLzzhfxnxgk=; b=I0JgFcUCxqh9hOiN3DChrpMKlCrr0NJOKLLO7dtf5kD/TESOdeWgLFvi+alGmkQMc4 +1twBCsBC25sVP3EDIIO0Ecglb6iHkjtgl8QPHeQUdyXbV9d2jUYyVm3HjjP7B7bm9dx j7QamxWeFSMXZVS9fJ5Hg1Yt0EEiD8QrmjR4X6dbwE+AeX3jtYfXDFuY5R15SbL2IYrN FuUfr3fAV2/TlVF7qTgu5/PKGWiZiMnhW82YbKMf/UB5sfXu1IknjOMClCdQMYnGu9P2 uDEr7An/svU/LUkanQn6GHd7p1gR0hjsUm3idR3FWj9JYvWyqnoIffJC5Y6VoEpIcmc6 8jow== X-Gm-Message-State: AOAM531nncONzihVaO2jxoLVnDsiWzTSdojHF23TL9+1Lhk2m7Yh31tG KaV2q3u/1Smi7fJ7dqrLjWLmvQBCgmI= X-Google-Smtp-Source: ABdhPJxySCxhSDubYycbaMEZA0i+VeLMqZBOdM/H45OLP2/pi/Gnq7iYIVmoYBqUokKhb2Z0VNTa7A== X-Received: by 2002:a7b:ca47:: with SMTP id m7mr1664528wml.33.1609821785740; Mon, 04 Jan 2021 20:43:05 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b200sm2324396wmb.10.2021.01.04.20.43.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 20:43:04 -0800 (PST) Message-Id: <5ccc464cf268476932197c790693e1ecea9e778c.1609821783.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 05 Jan 2021 04:42:50 +0000 Subject: [PATCH v2 01/14] mv: remove index compatibility macros Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: pclouds@gmail.com, gitster@pobox.com, Elijah Newren , Eric Sunshine , Alban Gruin , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The mv builtin uses the compatibility macros to interact with the index. Update these to use modern methods referring to a 'struct index_state' pointer. Several helper methods need to be updated to consider such a pointer, but the modifications are rudimentary. Two macros can be deleted from cache.h because these are the last uses. Signed-off-by: Derrick Stolee --- builtin/mv.c | 42 +++++++++++++++++++++++------------------- cache.h | 2 -- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/builtin/mv.c b/builtin/mv.c index 7dac714af90..0055d49a8a7 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -3,7 +3,6 @@ * * Copyright (C) 2006 Johannes Schindelin */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "config.h" #include "pathspec.h" @@ -75,13 +74,14 @@ static const char *add_slash(const char *path) #define SUBMODULE_WITH_GITDIR ((const char *)1) -static void prepare_move_submodule(const char *src, int first, +static void prepare_move_submodule(struct index_state *istate, + 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(istate->cache[first]->ce_mode)) die(_("Directory %s is in index and no submodule?"), src); - if (!is_staging_gitmodules_ok(&the_index)) + if (!is_staging_gitmodules_ok(istate)) die(_("Please stage your changes to .gitmodules or stash them to proceed")); strbuf_addf(&submodule_dotgit, "%s/.git", src); *submodule_gitfile = read_gitfile(submodule_dotgit.buf); @@ -92,19 +92,20 @@ static void prepare_move_submodule(const char *src, int first, strbuf_release(&submodule_dotgit); } -static int index_range_of_same_dir(const char *src, int length, +static int index_range_of_same_dir(struct index_state *istate, + const char *src, int length, int *first_p, int *last_p) { 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(istate, src_w_slash, len_w_slash); if (first >= 0) 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 < istate->cache_nr; last++) { + const char *path = istate->cache[last]->name; if (strncmp(path, src_w_slash, len_w_slash)) break; } @@ -133,6 +134,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) struct string_list src_for_dst = STRING_LIST_INIT_NODUP; struct lock_file lock_file = LOCK_INIT; struct cache_entry *ce; + struct index_state *istate; git_config(git_default_config, NULL); @@ -141,9 +143,10 @@ 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")); + istate = the_repository->index; source = internal_prefix_pathspec(prefix, argv, argc, 0); modes = xcalloc(argc, sizeof(enum update_mode)); @@ -190,12 +193,13 @@ int cmd_mv(int argc, const char **argv, const char *prefix) && lstat(dst, &st) == 0) bad = _("cannot move directory over file"); else if (src_is_dir) { - int first = cache_name_pos(src, length), last; + int first = index_name_pos(istate, src, length); + int last; if (first >= 0) - prepare_move_submodule(src, first, + prepare_move_submodule(istate, src, first, submodule_gitfile + i); - else if (index_range_of_same_dir(src, length, + else if (index_range_of_same_dir(istate, src, length, &first, &last) < 1) bad = _("source directory is empty"); else { /* last - first >= 1 */ @@ -212,7 +216,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) dst_len = strlen(dst); for (j = 0; j < last - first; j++) { - const char *path = active_cache[first + j]->name; + const char *path = istate->cache[first + j]->name; source[argc + j] = path; destination[argc + j] = prefix_path(dst, dst_len, path + length + 1); @@ -221,7 +225,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) } argc += last - first; } - } else if (!(ce = cache_file_exists(src, length, ignore_case))) { + } else if (!(ce = index_file_exists(istate, src, length, ignore_case))) { bad = _("not under version control"); } else if (ce_stage(ce)) { bad = _("conflicted"); @@ -291,15 +295,15 @@ int cmd_mv(int argc, const char **argv, const char *prefix) if (mode == WORKING_DIRECTORY) continue; - pos = cache_name_pos(src, strlen(src)); + pos = index_name_pos(istate, src, strlen(src)); assert(pos >= 0); - rename_cache_entry_at(pos, dst); + rename_index_entry_at(istate, pos, dst); } if (gitmodules_modified) - stage_updated_gitmodules(&the_index); + stage_updated_gitmodules(istate); - if (write_locked_index(&the_index, &lock_file, + if (write_locked_index(istate, &lock_file, COMMIT_LOCK | SKIP_IF_UNCHANGED)) die(_("Unable to write new index file")); diff --git a/cache.h b/cache.h index 2d844576ead..fdf061cac56 100644 --- a/cache.h +++ b/cache.h @@ -409,7 +409,6 @@ extern struct index_state 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_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)) @@ -420,7 +419,6 @@ extern struct index_state the_index; #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) From patchwork Tue Jan 5 04:42:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11998099 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 812A1C433E9 for ; Tue, 5 Jan 2021 04:44:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4484F22955 for ; Tue, 5 Jan 2021 04:44:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727783AbhAEEnu (ORCPT ); Mon, 4 Jan 2021 23:43:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726834AbhAEEnt (ORCPT ); Mon, 4 Jan 2021 23:43:49 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8AF3C061794 for ; Mon, 4 Jan 2021 20:43:08 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id c5so34866482wrp.6 for ; Mon, 04 Jan 2021 20:43:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=0TeogiNJ7ipGmFDWNnuJH30APRPsqSsAei8/MLisySQ=; b=G351nDPPkKg0/JS9mQyXrzKsmZ2dCguZfk90xANHpMvG8dAHoNOAC61Z3CrVOP4jCR IueXgtXpP1h6YWdYjmgDUTsu8ILN8be+w3Ki/wHkc5eVD2BUBGep+dhoa36vBoZqQVBy II8q2pK6ZPa8VF5MC7WKPo2AvX2tFXv6RdTzSHz2YlxC/vePAhQHHqxD21iSrJIymknx otiu+xZq/K44RzLFuHU9Me92mVd8F4OUdR52NqIacStXVdGZNc4rC2Ykd+Rc7mEsJ/0M FtIFM0Mlg2JdYt30QlGXPKN4U5XKM3f/VJEX0yRPQ8X/QM8jp00Vl671QkjT5wCbMFgh 1OIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=0TeogiNJ7ipGmFDWNnuJH30APRPsqSsAei8/MLisySQ=; b=UkEcnGZq4fZQZP2g2vSC0u7QsnGlkdXtsE3iO1wzWBc187AicPNoDhAATkkMKxlO7C A5/7Q4FfU1jpDqm/pSUaAnzchtFEH/vn54MdvpCmo6irx9+IkX0GCkJtLdbIAHZToz1h rlBeN2dVpWvNTIsUk8GKEVFdNIGDeiyBvkl/AJhh1uPkUntQAs5uk/j9kha7BJHTSKkz JNt4FU3D8vo8eJOaDjJ/sJIzq9Hz/X4Vs3fpkg+UJvbjDDq/i9Mc64BQkgan+NEZSpb8 rHiJHQB6p5qrAIkWtB55kSMsrjn4TxNOxMFczmnlPaF7Bb3YpV5RduCSIIVSyHvQASW6 +meQ== X-Gm-Message-State: AOAM530s4SmDwRbZEGiRNd3vEbe+Gzmxgqx8CtQRoCxAFTbAjSwRrdWD MOv24q2608s056QcR8aOjVmJ9ffrozk= X-Google-Smtp-Source: ABdhPJwL63sTxUpRZ5NcBep0E0bX6EK6hblSrwW4JQcNTkqX+IT4/SBD8jyUXoDhzC1CWAuSH1qjyg== X-Received: by 2002:a5d:5049:: with SMTP id h9mr85661112wrt.404.1609821786655; Mon, 04 Jan 2021 20:43:06 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h184sm2474554wmh.23.2021.01.04.20.43.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 20:43:06 -0800 (PST) Message-Id: In-Reply-To: References: Date: Tue, 05 Jan 2021 04:42:51 +0000 Subject: [PATCH v2 02/14] rm: remove compatilibity macros Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: pclouds@gmail.com, gitster@pobox.com, Elijah Newren , Eric Sunshine , Alban Gruin , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The rm builtin still uses the antiquated compatibility macros for interacting with the index. Update these to the more modern uses by passing around a 'struct index_state' pointer. Signed-off-by: Derrick Stolee --- builtin/rm.c | 56 ++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/builtin/rm.c b/builtin/rm.c index 4858631e0f0..767df8d6b25 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -3,7 +3,6 @@ * * Copyright (C) Linus Torvalds 2006 */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "config.h" #include "lockfile.h" @@ -28,12 +27,14 @@ static struct { } *entry; } list; -static int get_ours_cache_pos(const char *path, int pos) +static int get_ours_cache_pos(struct index_state *istate, + 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 < istate->cache_nr) && + !strcmp(istate->cache[i]->name, path)) { + if (ce_stage(istate->cache[i]) == 2) return i; i++; } @@ -61,7 +62,7 @@ static void print_error_files(struct string_list *files_list, } } -static void submodules_absorb_gitdir_if_needed(void) +static void submodules_absorb_gitdir_if_needed(struct index_state *istate) { int i; for (i = 0; i < list.nr; i++) { @@ -69,13 +70,13 @@ 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(istate, name, strlen(name)); if (pos < 0) { - pos = get_ours_cache_pos(name, pos); + pos = get_ours_cache_pos(istate, name, pos); if (pos < 0) continue; } - ce = active_cache[pos]; + ce = istate->cache[pos]; if (!S_ISGITLINK(ce->ce_mode) || !file_exists(ce->name) || @@ -88,7 +89,8 @@ static void submodules_absorb_gitdir_if_needed(void) } } -static int check_local_mod(struct object_id *head, int index_only) +static int check_local_mod(struct index_state *istate, + struct object_id *head, int index_only) { /* * Items in list are already sorted in the cache order, @@ -114,21 +116,21 @@ 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(istate, name, strlen(name)); if (pos < 0) { /* * Skip unmerged entries except for populated submodules * that could lose history when removed. */ - pos = get_ours_cache_pos(name, pos); + pos = get_ours_cache_pos(istate, name, pos); if (pos < 0) continue; - if (!S_ISGITLINK(active_cache[pos]->ce_mode) || + if (!S_ISGITLINK(istate->cache[pos]->ce_mode) || is_empty_dir(name)) continue; } - ce = active_cache[pos]; + ce = istate->cache[pos]; if (lstat(ce->name, &st) < 0) { if (!is_missing_file_error(errno)) @@ -165,7 +167,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(istate, ce, &st, 0) || (S_ISGITLINK(ce->ce_mode) && bad_to_remove_submodule(ce->name, SUBMODULE_REMOVAL_DIE_ON_ERROR | @@ -257,6 +259,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix) int i; struct pathspec pathspec; char *seen; + struct index_state *istate; git_config(git_default_config, NULL); @@ -284,24 +287,25 @@ int cmd_rm(int argc, const char **argv, const char *prefix) if (!index_only) setup_work_tree(); - 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); + istate = the_repository->index; + refresh_index(istate, REFRESH_QUIET|REFRESH_UNMERGED, &pathspec, NULL, NULL); seen = xcalloc(pathspec.nr, 1); - for (i = 0; i < active_nr; i++) { - const struct cache_entry *ce = active_cache[i]; - if (!ce_path_match(&the_index, ce, &pathspec, seen)) + for (i = 0; i < istate->cache_nr; i++) { + const struct cache_entry *ce = istate->cache[i]; + if (!ce_path_match(istate, ce, &pathspec, seen)) continue; ALLOC_GROW(list.entry, list.nr + 1, list.alloc); list.entry[list.nr].name = xstrdup(ce->name); list.entry[list.nr].is_submodule = S_ISGITLINK(ce->ce_mode); if (list.entry[list.nr++].is_submodule && - !is_staging_gitmodules_ok(&the_index)) + !is_staging_gitmodules_ok(istate)) die(_("please stage your changes to .gitmodules or stash them to proceed")); } @@ -329,7 +333,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix) } if (!index_only) - submodules_absorb_gitdir_if_needed(); + submodules_absorb_gitdir_if_needed(istate); /* * If not forced, the file, the index and the HEAD (if exists) @@ -345,7 +349,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix) struct object_id oid; if (get_oid("HEAD", &oid)) oidclr(&oid); - if (check_local_mod(&oid, index_only)) + if (check_local_mod(istate, &oid, index_only)) exit(1); } @@ -358,7 +362,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(istate, path)) die(_("git rm: unable to remove %s"), path); } @@ -398,10 +402,10 @@ int cmd_rm(int argc, const char **argv, const char *prefix) } strbuf_release(&buf); if (gitmodules_modified) - stage_updated_gitmodules(&the_index); + stage_updated_gitmodules(istate); } - if (write_locked_index(&the_index, &lock_file, + if (write_locked_index(istate, &lock_file, COMMIT_LOCK | SKIP_IF_UNCHANGED)) die(_("Unable to write new index file")); From patchwork Tue Jan 5 04:42:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11998095 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D1B9C433DB for ; Tue, 5 Jan 2021 04:44:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2C41F227C3 for ; Tue, 5 Jan 2021 04:44:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727816AbhAEEnw (ORCPT ); Mon, 4 Jan 2021 23:43:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726934AbhAEEnt (ORCPT ); Mon, 4 Jan 2021 23:43:49 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17FE8C061795 for ; Mon, 4 Jan 2021 20:43:09 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id d13so34850194wrc.13 for ; Mon, 04 Jan 2021 20:43:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=eEjodH6fftcpEWknf6S050nVN2RpjZkqA8QrqjvJ9js=; b=j+jGg7/F2J743Yi7jK4LUA6qEUNbwH0RMr3kkpQUMXMC6BDaLE9/Dh3/GpUPny62nj xpXrKWhXms62BjgKYwBg/OynKBdvDeBlreaxQGgQ9wQiCyZDuHUz66/SBI8CHUNUI0DD 8G1fqfNVO6KglK2PLGMxUsdMXiPIvdUqfdEqYEY7aBcHcqrSP++S3EOqV2GwdJs9qGHg GTfLEDlGZ6xOa1zvyPFKV2hjIoIKo3s0IYqpP7EJjqwhVXntRiqVav2FkmPRh9T7xumC Pfgx/GwASHt6+G9UUfzdrk5zMNW/8mcB0juA1FU5VUcJoUAvBF8cRmdUmyg8/IcTAvaV wncw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=eEjodH6fftcpEWknf6S050nVN2RpjZkqA8QrqjvJ9js=; b=LZM+O5mKKHuh/pYcHSARL5ZLYYIVi/qr0COhmu90GMehKEtMqN0qT9Vkf6GuoCgFjQ rFvQc13kvb/FlF+tq+JRkxhlHQg4xj3p+eEGCu5ZPEU0vndIsmR956Iv574pwbpjOpkp QvblLQIs8KmVTI+R3sT/SrMFjTkDIAdR1h9BfDhmUkmS87TCjb2oHEM+iXUu1beWw9WO vx0cHrX2rETvlTEjemc7A1ubcg1F1GyhsfJNRFhUXHt/QIqARqDKwWtYnkg9KLlPcf+A gAYHRAgJh4KRvqTMUKajGPLyINAMm4g49AqAEyfZGkBNhSH1pOA+cu11Pj6Phe/NZ0aP JnlQ== X-Gm-Message-State: AOAM531QPEnm9RO2UrjqmvpfdnZmxHCqLFfFAQu0nKxcfyU0AdYM8SFv P7dhGmZz9GW25N8nJVJt+PmNWd3HfZw= X-Google-Smtp-Source: ABdhPJwpnMIWLM1/3ZI0S8f2YKQBWFIJE6p3qrAPJTe++hD+L+/r3Z9uVJotxOv/jswtkHUtPuwGbw== X-Received: by 2002:adf:f6cc:: with SMTP id y12mr82317296wrp.35.1609821787537; Mon, 04 Jan 2021 20:43:07 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w4sm2316943wmc.13.2021.01.04.20.43.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 20:43:07 -0800 (PST) Message-Id: <4bf3c582f9d211769333939f5adfb176c3e42a90.1609821783.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 05 Jan 2021 04:42:52 +0000 Subject: [PATCH v2 03/14] update-index: drop the_index, the_repository Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: pclouds@gmail.com, gitster@pobox.com, Elijah Newren , Eric Sunshine , Alban Gruin , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee To reduce the need for the index compatibility macros, we will replace their uses in update-index mechanically. This is the most interesting change, which creates global "repo" and "istate" pointers. The macros that expand to use the_index can then be mechanically replaced by references to the istate pointer. Signed-off-by: Derrick Stolee --- builtin/update-index.c | 59 +++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/builtin/update-index.c b/builtin/update-index.c index 44862f5e1de..dde5b01a949 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -40,6 +40,9 @@ static int ignore_skip_worktree_entries; #define UNMARK_FLAG 2 static struct strbuf mtime_dir = STRBUF_INIT; +static struct repository *repo; +static struct index_state *istate; + /* Untracked cache mode */ enum uc_mode { UC_UNSPECIFIED = -1, @@ -232,13 +235,13 @@ 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(istate, active_cache[pos]); if (mark) active_cache[pos]->ce_flags |= flag; else active_cache[pos]->ce_flags &= ~flag; active_cache[pos]->ce_flags |= CE_UPDATE_IN_BASE; - cache_tree_invalidate_path(&the_index, path); + cache_tree_invalidate_path(istate, path); active_cache_changed |= CE_ENTRY_CHANGED; return 0; } @@ -277,14 +280,14 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len if (old && !ce_stage(old) && !ce_match_stat(old, st, 0)) return 0; - ce = make_empty_cache_entry(&the_index, len); + ce = make_empty_cache_entry(istate, len); memcpy(ce->name, path, len); ce->ce_flags = create_ce_flags(0); ce->ce_namelen = len; - fill_stat_cache_info(&the_index, ce, st); + fill_stat_cache_info(istate, ce, st); ce->ce_mode = ce_mode_from_stat(old, st->st_mode); - if (index_path(&the_index, &ce->oid, path, st, + if (index_path(istate, &ce->oid, path, st, info_only ? 0 : HASH_WRITE_OBJECT)) { discard_cache_entry(ce); return -1; @@ -406,7 +409,7 @@ static int add_cacheinfo(unsigned int mode, const struct object_id *oid, { int res; - res = add_to_index_cacheinfo(&the_index, mode, oid, path, stage, + res = add_to_index_cacheinfo(istate, mode, oid, path, stage, allow_add, allow_replace, NULL); if (res == -1) return res; @@ -592,7 +595,7 @@ static struct cache_entry *read_one_ent(const char *which, struct object_id oid; struct cache_entry *ce; - if (get_tree_entry(the_repository, ent, path, &oid, &mode)) { + if (get_tree_entry(repo, ent, path, &oid, &mode)) { if (which) error("%s: not in %s branch.", path, which); return NULL; @@ -602,7 +605,7 @@ static struct cache_entry *read_one_ent(const char *which, error("%s: not a blob in %s branch.", path, which); return NULL; } - ce = make_empty_cache_entry(&the_index, namelen); + ce = make_empty_cache_entry(istate, namelen); oidcpy(&ce->oid, &oid); memcpy(ce->name, path, namelen); @@ -740,7 +743,7 @@ static int do_reupdate(int ac, const char **av, int save_nr; char *path; - if (ce_stage(ce) || !ce_path_match(&the_index, ce, &pathspec, NULL)) + if (ce_stage(ce) || !ce_path_match(istate, ce, &pathspec, NULL)) continue; if (has_head) old = read_one_ent(NULL, &head_oid, @@ -957,7 +960,6 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) struct parse_opt_ctx_t ctx; strbuf_getline_fn getline_fn; int parseopt_state = PARSE_OPT_UNKNOWN; - struct repository *r = the_repository; struct option options[] = { OPT_BIT('q', NULL, &refresh_args.flags, N_("continue refresh even when index needs update"), @@ -1066,16 +1068,19 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) git_config(git_default_config, NULL); + repo = the_repository; + /* 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(repo, &lock_file, 0); if (newfd < 0) lock_error = errno; - entries = read_cache(); + entries = repo_read_index(repo); if (entries < 0) die("cache corrupted"); - the_index.updated_skipworktree = 1; + istate = repo->index; + istate->updated_skipworktree = 1; /* * Custom copy of parse_options() because we want to handle @@ -1129,9 +1134,9 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) preferred_index_format, INDEX_FORMAT_LB, INDEX_FORMAT_UB); - if (the_index.version != preferred_index_format) + if (istate->version != preferred_index_format) active_cache_changed |= SOMETHING_CHANGED; - the_index.version = preferred_index_format; + istate->version = preferred_index_format; } if (read_from_stdin) { @@ -1162,28 +1167,28 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) warning(_("core.splitIndex is set to false; " "remove or change it, if you really want to " "enable split index")); - if (the_index.split_index) - the_index.cache_changed |= SPLIT_INDEX_ORDERED; + if (istate->split_index) + istate->cache_changed |= SPLIT_INDEX_ORDERED; else - add_split_index(&the_index); + add_split_index(istate); } else if (!split_index) { if (git_config_get_split_index() == 1) warning(_("core.splitIndex is set to true; " "remove or change it, if you really want to " "disable split index")); - remove_split_index(&the_index); + remove_split_index(istate); } - prepare_repo_settings(r); + prepare_repo_settings(repo); switch (untracked_cache) { case UC_UNSPECIFIED: break; case UC_DISABLE: - if (r->settings.core_untracked_cache == UNTRACKED_CACHE_WRITE) + if (repo->settings.core_untracked_cache == UNTRACKED_CACHE_WRITE) warning(_("core.untrackedCache is set to true; " "remove or change it, if you really want to " "disable the untracked cache")); - remove_untracked_cache(&the_index); + remove_untracked_cache(istate); report(_("Untracked cache disabled")); break; case UC_TEST: @@ -1191,11 +1196,11 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) return !test_if_untracked_cache_is_supported(); case UC_ENABLE: case UC_FORCE: - if (r->settings.core_untracked_cache == UNTRACKED_CACHE_REMOVE) + if (repo->settings.core_untracked_cache == UNTRACKED_CACHE_REMOVE) warning(_("core.untrackedCache is set to false; " "remove or change it, if you really want to " "enable the untracked cache")); - add_untracked_cache(&the_index); + add_untracked_cache(istate); report(_("Untracked cache enabled for '%s'"), get_git_work_tree()); break; default: @@ -1207,14 +1212,14 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) warning(_("core.fsmonitor is unset; " "set it if you really want to " "enable fsmonitor")); - add_fsmonitor(&the_index); + add_fsmonitor(istate); report(_("fsmonitor enabled")); } else if (!fsmonitor) { if (git_config_get_fsmonitor() == 1) warning(_("core.fsmonitor is set; " "remove it if you really want to " "disable fsmonitor")); - remove_fsmonitor(&the_index); + remove_fsmonitor(istate); report(_("fsmonitor disabled")); } @@ -1224,7 +1229,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) exit(128); unable_to_lock_die(get_index_file(), lock_error); } - if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK)) + if (write_locked_index(istate, &lock_file, COMMIT_LOCK)) die("Unable to write new index file"); } From patchwork Tue Jan 5 04:42:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11998103 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2ED87C433E0 for ; Tue, 5 Jan 2021 04:44:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F0D50227BF for ; Tue, 5 Jan 2021 04:44:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728013AbhAEEoQ (ORCPT ); Mon, 4 Jan 2021 23:44:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726934AbhAEEoP (ORCPT ); Mon, 4 Jan 2021 23:44:15 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D501DC061798 for ; Mon, 4 Jan 2021 20:43:09 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id r3so34908301wrt.2 for ; Mon, 04 Jan 2021 20:43:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=4NDrbhT170uFBvoekGGO1YbXK+r7+BGK9A0+ou0b/YM=; b=vJLIgw2NcIrCbzHqvQ9xZA34qrQuKdBEK4u0GeAcbUQ6sdH5DOLV+mLB28LMDFmwu4 cLKpoaY0vVFLPuKYIkpk2SJLJSiyrbUyncY05gQWTlXWsCpYlL0v2BXrXCM4hoGnbwyh hSYU/t7CgjncpKFCOK7ChtlRrWByAd7MmNTrrDhrOrQGX2ecs9uVuDe98Lk7MVTO5cRf l1qxA7jeTJP+x9Q/sovS0Ng+tWCKPDRE6jii+FyjRCN4AwU53wfQsOfeHBvzarkjrKo3 70yuOFXvw3CyBF1Aq9ihMKDE7942rCDPKuR+Epjkh4MkzTEj/mo9yCe+QhVWI3OT0AYg SnIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=4NDrbhT170uFBvoekGGO1YbXK+r7+BGK9A0+ou0b/YM=; b=hnz7xfu6HhOVoqofjjh58qE9EcM7ZFfQDOnSg3awxQeIpcU/bljWbwjawdphc8lGqv FUCZgx7VoZqhsW9rBiSLWzQUwEEPkGfePuNLnzsbJsAzK8MgAlLgNlxIx1ArUfmXK4Fn gRppycN+hnYIYNn97/LqUe+W82mCgA+HL2LjYDiwMnzPWcxITs612+m6X+ilhXR412uf u+J0SyCLvn/3JEsLfMOiAXNIqTebaNkmpn6dQszckGd+vUMIhvy9sP5ERUaiMEDS+JAl XQNh7LiMf++olPPESN20nlE32aM+ewx5V6WvfFhuCXFmC6Q06S7nI2DUVRtWqPGDz1ri 4CBA== X-Gm-Message-State: AOAM5331ughB4LU61T9qwtMz0p1FGwCuzab7gM/BoeDWNMkHePOy+HX2 JmwTBVdZf3uAFURu8JMD6ERLs/TQLHc= X-Google-Smtp-Source: ABdhPJzN9we/uHX56uaSVJJciTuvfX94LQRWN0A/kB04fGJs+Vb6rPKhczofydLEWXp43TFW/uM1lw== X-Received: by 2002:adf:8145:: with SMTP id 63mr80059084wrm.8.1609821788440; Mon, 04 Jan 2021 20:43:08 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s3sm2265013wmc.44.2021.01.04.20.43.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 20:43:07 -0800 (PST) Message-Id: <4b509ba5fa283d29c320e39a9225fadf966e53a8.1609821783.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 05 Jan 2021 04:42:53 +0000 Subject: [PATCH v2 04/14] update-index: use istate->cache over active_cache Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: pclouds@gmail.com, gitster@pobox.com, Elijah Newren , Eric Sunshine , Alban Gruin , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee Signed-off-by: Derrick Stolee --- builtin/update-index.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/builtin/update-index.c b/builtin/update-index.c index dde5b01a949..3e459d2b9de 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -235,12 +235,12 @@ 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(istate, active_cache[pos]); + mark_fsmonitor_invalid(istate, istate->cache[pos]); if (mark) - active_cache[pos]->ce_flags |= flag; + istate->cache[pos]->ce_flags |= flag; else - active_cache[pos]->ce_flags &= ~flag; - active_cache[pos]->ce_flags |= CE_UPDATE_IN_BASE; + istate->cache[pos]->ce_flags &= ~flag; + istate->cache[pos]->ce_flags |= CE_UPDATE_IN_BASE; cache_tree_invalidate_path(istate, path); active_cache_changed |= CE_ENTRY_CHANGED; return 0; @@ -331,7 +331,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 = istate->cache[pos]; if (S_ISGITLINK(ce->ce_mode)) { /* Do nothing to the index if there is no HEAD! */ @@ -347,7 +347,7 @@ 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++]; + const struct cache_entry *ce = istate->cache[pos++]; if (strncmp(ce->name, path, len)) break; @@ -378,7 +378,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 : istate->cache[pos]; if (ce && ce_skip_worktree(ce)) { /* * working directory version is assumed "good" @@ -429,7 +429,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 = istate->cache[pos]; if (chmod_cache_entry(ce, flip) < 0) goto fail; @@ -628,7 +628,7 @@ static int unresolve_one(const char *path) /* already merged */ pos = unmerge_cache_entry_at(pos); if (pos < active_nr) { - const struct cache_entry *ce = active_cache[pos]; + const struct cache_entry *ce = istate->cache[pos]; if (ce_stage(ce) && ce_namelen(ce) == namelen && !memcmp(ce->name, path, namelen)) @@ -642,7 +642,7 @@ static int unresolve_one(const char *path) */ pos = -pos-1; if (pos < active_nr) { - const struct cache_entry *ce = active_cache[pos]; + const struct cache_entry *ce = istate->cache[pos]; if (ce_namelen(ce) == namelen && !memcmp(ce->name, path, namelen)) { fprintf(stderr, @@ -738,7 +738,7 @@ static int do_reupdate(int ac, const char **av, has_head = 0; redo: for (pos = 0; pos < active_nr; pos++) { - const struct cache_entry *ce = active_cache[pos]; + const struct cache_entry *ce = istate->cache[pos]; struct cache_entry *old = NULL; int save_nr; char *path; From patchwork Tue Jan 5 04:42:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11998105 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DECF9C433E6 for ; Tue, 5 Jan 2021 04:44:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B5029227BF for ; Tue, 5 Jan 2021 04:44:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727922AbhAEEoQ (ORCPT ); Mon, 4 Jan 2021 23:44:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727701AbhAEEoP (ORCPT ); Mon, 4 Jan 2021 23:44:15 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB654C06179A for ; Mon, 4 Jan 2021 20:43:10 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id c5so34866595wrp.6 for ; Mon, 04 Jan 2021 20:43:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=1hoL6dpakMgJMT9kbSjsU1Q+dHl9b5qV0/mlWtinvuQ=; b=h1xEHvYOmWgX2QlaGFg+VlmTcg/y4DgyVGWNgGaQCGBWHqdA0+M6pLGmH50D9e2BsO PcYuNOjNGxXDEr9l3rdEHeqh52KOV18JR3L+Oc+onlfN20KUb7snTUnwlhyX4nwEnYfy M/hzmQzuhXC1IQx2XmtGndgQeRPrqvjPTUqlwXC8nQAyfyqcRzHGhuwGKl+vYmepFbLU sVwHghEay4gRXaHsupFyVs8lqps+sFTVict4fWFYSGEzkzmtEMIBGI0MgeKX08OQZgww IcFEmJ74cl1hQV9zDU3gMwLOfuwA8k8zZcVonP8TJBNRHUFh/ZqY0SzCM6ltnyMhy+4/ vESw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=1hoL6dpakMgJMT9kbSjsU1Q+dHl9b5qV0/mlWtinvuQ=; b=aK+jzreMGg6W9f11fh1xJ1P2Co1RPjYWvThxHuj+Bpdy7hAgAz9wEDQX+je8r2gKFl enB+DYcuEaYt45Uwuo+rZRQnlv69FN8BAXDeannpGU/tcSPzsYQQDAbVLKi9j3hizvXD H26rGw87+Q3Cf6gL57esGkcLxoobUvt2NXzI/QPBYLwK/8ypl1SciGtxUBtp9bRwmNSX OmClA4GmaKTEj2IaKk1UjsE/K8McccopZQ91JwlmKHtrgvlAAb8biA5nhfDgAvXwKAeo qij0mGqH8iPJhZVxJnnf8o5UPlOVePVkMRKvOF18n46AGq/t7kA4pgrFcHkMmEGhxxhd XiVA== X-Gm-Message-State: AOAM5339BtLExMLLUQk4bUwMUdOFRQv3SXOgMeCd7wIC4NwbFXg1xPgW ZPqrVJ+8QslJSJwlqzs1/hzfdstBBO8= X-Google-Smtp-Source: ABdhPJyD1MbHei7pOTuKNn+aXAe0HVRxsscFZQk6/2dQb37MUjFFomUHOAU4JEiaFGifvTlZvNqOAw== X-Received: by 2002:a5d:678c:: with SMTP id v12mr85654065wru.115.1609821789279; Mon, 04 Jan 2021 20:43:09 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c10sm99570401wrb.92.2021.01.04.20.43.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 20:43:08 -0800 (PST) Message-Id: <6c0e019f91ce50bef8a98ac60072a61c77710080.1609821783.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 05 Jan 2021 04:42:54 +0000 Subject: [PATCH v2 05/14] update-index: use index->cache_nr over active_nr Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: pclouds@gmail.com, gitster@pobox.com, Elijah Newren , Eric Sunshine , Alban Gruin , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee Signed-off-by: Derrick Stolee --- builtin/update-index.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/builtin/update-index.c b/builtin/update-index.c index 3e459d2b9de..106bfdab78e 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -346,7 +346,7 @@ 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) { + while (pos < istate->cache_nr) { const struct cache_entry *ce = istate->cache[pos++]; if (strncmp(ce->name, path, len)) @@ -627,7 +627,7 @@ static int unresolve_one(const char *path) if (0 <= pos) { /* already merged */ pos = unmerge_cache_entry_at(pos); - if (pos < active_nr) { + if (pos < istate->cache_nr) { const struct cache_entry *ce = istate->cache[pos]; if (ce_stage(ce) && ce_namelen(ce) == namelen && @@ -641,7 +641,7 @@ static int unresolve_one(const char *path) * want to do anything in the former case. */ pos = -pos-1; - if (pos < active_nr) { + if (pos < istate->cache_nr) { const struct cache_entry *ce = istate->cache[pos]; if (ce_namelen(ce) == namelen && !memcmp(ce->name, path, namelen)) { @@ -737,7 +737,7 @@ static int do_reupdate(int ac, const char **av, */ has_head = 0; redo: - for (pos = 0; pos < active_nr; pos++) { + for (pos = 0; pos < istate->cache_nr; pos++) { const struct cache_entry *ce = istate->cache[pos]; struct cache_entry *old = NULL; int save_nr; @@ -755,14 +755,14 @@ static int do_reupdate(int ac, const char **av, } /* Be careful. The working tree may not have the * path anymore, in which case, under 'allow_remove', - * or worse yet 'allow_replace', active_nr may decrease. + * or worse yet 'allow_replace', istate->cache_nr may decrease. */ - save_nr = active_nr; + save_nr = istate->cache_nr; path = xstrdup(ce->name); update_one(path); free(path); discard_cache_entry(old); - if (save_nr != active_nr) + if (save_nr != istate->cache_nr) goto redo; } clear_pathspec(&pathspec); From patchwork Tue Jan 5 04:42:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11998119 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66BF1C433DB for ; Tue, 5 Jan 2021 04:44:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3A23C227BF for ; Tue, 5 Jan 2021 04:44:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728094AbhAEEoa (ORCPT ); Mon, 4 Jan 2021 23:44:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726064AbhAEEoa (ORCPT ); Mon, 4 Jan 2021 23:44:30 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 811C3C06179E for ; Mon, 4 Jan 2021 20:43:11 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id y17so34879718wrr.10 for ; Mon, 04 Jan 2021 20:43:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=HjKFPw9an+6lpJcV7qb9eYBOfFSo/2RlHH7d+jhmTdk=; b=bk1EYf0K+973BtYxA0fMUaHlwyH2i9fQWcTn3eeHmTViOSBFaW7qtfYKHHHE9KxzDP ziBmJ20pHuavGKbiMYuqKB3Q3xOAL5r4S7GpC1AtsQ6a1mKq2mFGH2fSvtcx5kzCyAel HJMZ4veNhOwuKmJ7QhP252ZiiZgQz+a97bwR96Czk8HFR+cUjoj0cOrhbxSOqya8zBt0 h+HzPhBvK+3pVq/4nFyYy7RQOiUZ7fiGup6o1Q8Dvyubvps6JcUacCwNL4J5DnA1Upuo yBc/DwhkVqzGRe03iux8R+Awple56+SNELQHqn0fidRmIxaqRKjFC5yfGi9EO2luNBa6 PlZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=HjKFPw9an+6lpJcV7qb9eYBOfFSo/2RlHH7d+jhmTdk=; b=N5Pjs0mtzmAxPygm1kKEcgTcs7z2eSYamSfdYmdJyZoVYD3GI+K5uPsG9B1PWjRc4T pXWefcxrHxyeOxMWwPI8gSwKySeHLXd+Sdks54ftUcMzx/zZ9qJYAiouFFH69c0h/qCJ 1ozqqsI2aHMkBWUB4YPSuaVuAl17shnOlNNoMFQ4pLPFmAWpzdEeJK5K94/A8MYoY0XN KaFDZXEMllTZLsaEWV3O0CGHWrFAXUK9Vv1WlgbejumpvWf8PzG+d+X2/S40ZF6fU0UO ecDFj//zCfasqfWkKIYIKe8t7129KS+oQm78bEqCk4Z3ei9YE5BJcnK80Rd9pgYWeOgv iYnw== X-Gm-Message-State: AOAM533K6z2y2uGFDIFWS1KyCFNoLcDYjUrq2hwpgJz5xj5ecibP+ZDz 8nE0TRgfpuJEYq7X77We40f9ePvw7lA= X-Google-Smtp-Source: ABdhPJyk8DFahNmF8FG4D9NrSO5oLADKEb4yx40aityHLIpbBqwkvmk35lp+QjGqIBtbJvtTu3ltHw== X-Received: by 2002:a5d:56c3:: with SMTP id m3mr83173505wrw.419.1609821790111; Mon, 04 Jan 2021 20:43:10 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g184sm2475665wma.16.2021.01.04.20.43.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 20:43:09 -0800 (PST) Message-Id: <5091e2661d1a38a24883a8e366a07d92be95c9e6.1609821783.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 05 Jan 2021 04:42:55 +0000 Subject: [PATCH v2 06/14] update-index: use istate->cache_changed Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: pclouds@gmail.com, gitster@pobox.com, Elijah Newren , Eric Sunshine , Alban Gruin , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee This is a mechanical replacement of active_cache_changed. Signed-off-by: Derrick Stolee --- builtin/update-index.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/builtin/update-index.c b/builtin/update-index.c index 106bfdab78e..346d798c60b 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -242,7 +242,7 @@ static int mark_ce_flags(const char *path, int flag, int mark) istate->cache[pos]->ce_flags &= ~flag; istate->cache[pos]->ce_flags |= CE_UPDATE_IN_BASE; cache_tree_invalidate_path(istate, path); - active_cache_changed |= CE_ENTRY_CHANGED; + istate->cache_changed |= CE_ENTRY_CHANGED; return 0; } return -1; @@ -915,7 +915,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; + istate->cache_changed = 0; ctx->argv += ctx->argc - 1; ctx->argc = 1; @@ -936,7 +936,7 @@ static enum parse_opt_result reupdate_callback( setup_work_tree(); *has_errors = do_reupdate(ctx->argc, ctx->argv, prefix); if (*has_errors) - active_cache_changed = 0; + istate->cache_changed = 0; ctx->argv += ctx->argc - 1; ctx->argc = 1; @@ -1135,7 +1135,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) INDEX_FORMAT_LB, INDEX_FORMAT_UB); if (istate->version != preferred_index_format) - active_cache_changed |= SOMETHING_CHANGED; + istate->cache_changed |= SOMETHING_CHANGED; istate->version = preferred_index_format; } @@ -1223,7 +1223,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) report(_("fsmonitor disabled")); } - if (active_cache_changed || force_write) { + if (istate->cache_changed || force_write) { if (newfd < 0) { if (refresh_args.flags & REFRESH_QUIET) exit(128); From patchwork Tue Jan 5 04:42:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11998107 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 593C2C433DB for ; Tue, 5 Jan 2021 04:44:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2EFAB227BF for ; Tue, 5 Jan 2021 04:44:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728137AbhAEEoa (ORCPT ); Mon, 4 Jan 2021 23:44:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726408AbhAEEoa (ORCPT ); Mon, 4 Jan 2021 23:44:30 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58300C06179F for ; Mon, 4 Jan 2021 20:43:12 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id a6so1869813wmc.2 for ; Mon, 04 Jan 2021 20:43:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=N0hmkF+LncZsfqN5AU5+oGPwMIQ48eBXCRGzFvacOos=; b=QWal3aRbyTJdseFX4V5FI46fGMizNW49/OpJkWXnJsvmDhZo43CVEHCWeJmRuzxdsU v6g+7DiyLQba4g/pGPz5e3B/P3/0GwDspdjZhxRtpGCbhlg3j9YfZxG38nzWXzuEBfLQ 0ohWZcDLsTFhmuFSNcsXLJnWCUf+K/hqBXLCxtGaQi80R0hhGIqrwM0SF19JrYgd32FK Q9Q/5JjN5JJpMDvq7wAPexpix9Bdj4+1GaidNkRGS7941cY5bB+1kdmOvVzOK+1nHTuA KcK5sq1NGdDLKvyXY5EP99tHZyeJc0/Z2zGJXQIMfIMJqh+Pcl6iEHYlO2wi3VFUZwYn 0ieA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=N0hmkF+LncZsfqN5AU5+oGPwMIQ48eBXCRGzFvacOos=; b=rY2m3eExfJXrnzLaD7mFoJ7FDoTUEoyVzydoTbFpluOsKoYbFo7TKXMNUvSpHMVrRk KtTvC1SeoDW1ZOr68bDNq43X40um6Iwx8Ht2YIZ5Ac6xrSFfgpoboGR9ldXpfJI8L6N2 QxNuaZ8LMk3S3ucZGA6NXy0ycIdqZSompypyRq6L/G0FjWBTE/NJ+E0sPi4R50ByQEUM gc+IS/RfdXp2yR0soMCpUiuJ4XWA/ITq/bQr6nbYQGcawXSt/01tJzMB0rwV1zU8FW6h kXilm69cGVs+1cWPvmQqs+0Pjuy3YfjUMu5tyWzBHXynn/HtPkaXrzJpvtO5s/QzL3Rm MYQw== X-Gm-Message-State: AOAM530g5fLunqvcTlLfhABFkY7mfjCJIekuLQdtz60ixdIV5UzkP5/J ZjmpzJtjmKIRUdg1TD6Lw5hyfxNgO5I= X-Google-Smtp-Source: ABdhPJyhIUJB74OQuOBJK0SJWV15qfnwqBpo/g+dGDa6W2yE0qmNNpzJH50mtAqFByrj+OHV7SgIMA== X-Received: by 2002:a7b:c212:: with SMTP id x18mr1685800wmi.113.1609821790980; Mon, 04 Jan 2021 20:43:10 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t1sm98128917wro.27.2021.01.04.20.43.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 20:43:10 -0800 (PST) Message-Id: <5b14fa10a4bec330bb31e9c7cb2c4375ce914ca9.1609821783.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 05 Jan 2021 04:42:56 +0000 Subject: [PATCH v2 07/14] update-index: use index_name_pos() over cache_name_pos() Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: pclouds@gmail.com, gitster@pobox.com, Elijah Newren , Eric Sunshine , Alban Gruin , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee Signed-off-by: Derrick Stolee --- builtin/update-index.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/builtin/update-index.c b/builtin/update-index.c index 346d798c60b..096cbdfa8ac 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -233,7 +233,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(istate, path, namelen); if (0 <= pos) { mark_fsmonitor_invalid(istate, istate->cache[pos]); if (mark) @@ -327,7 +327,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(istate, path, len); /* Exact match: file or existing gitlink */ if (pos >= 0) { @@ -377,7 +377,7 @@ static int process_path(const char *path, struct stat *st, int stat_errno) if (has_symlink_leading_path(path, len)) return error("'%s' is beyond a symbolic link", path); - pos = cache_name_pos(path, len); + pos = index_name_pos(istate, path, len); ce = pos < 0 ? NULL : istate->cache[pos]; if (ce && ce_skip_worktree(ce)) { /* @@ -426,7 +426,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(istate, path, strlen(path)); if (pos < 0) goto fail; ce = istate->cache[pos]; @@ -623,7 +623,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(istate, path, namelen); if (0 <= pos) { /* already merged */ pos = unmerge_cache_entry_at(pos); From patchwork Tue Jan 5 04:42:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11998117 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3465C433E9 for ; Tue, 5 Jan 2021 04:44:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C0DEA227BF for ; Tue, 5 Jan 2021 04:44:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728179AbhAEEob (ORCPT ); Mon, 4 Jan 2021 23:44:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726518AbhAEEoa (ORCPT ); Mon, 4 Jan 2021 23:44:30 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AE6EC0617A0 for ; Mon, 4 Jan 2021 20:43:13 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id m5so34833241wrx.9 for ; Mon, 04 Jan 2021 20:43:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=YdKJNJU+VGWKXDxEbhTBS+DhIooYcT8eg3fpuPnwn/Y=; b=cHP6HzfSLEer1PCitQ1GbpqZwg3l/kNojCEnAW4+9JRZPNRlBmhuZGRbMDgchdTzwJ /SU2uIlG0ZZ/3DqNgUotrLG+B3jK+BKs+H64jDXwltfEPbe5uiyQ1iyNLgf8Corjx2FM tLh/NI8Hyq2HDD0sZKz/NdI77qOeZW+jQj9/gKrb4bPXxXSV0vDAi/cvUhNSYYkshTD6 Nb63KvLGmNGAiFDzslaief/QVwq9udxS1RfeR8TGHwwMuzM/dseXGye4SNqDGX64yIeM CdNPGQYdN0Fh8LPU2aS1DGWE0rrU859oTK9+FTljmCK2IfDfE/z3q8beIqkOTt9OKypo XSIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=YdKJNJU+VGWKXDxEbhTBS+DhIooYcT8eg3fpuPnwn/Y=; b=FCQYPmgex5AfQ0ouluI3VFCZFJA97pE8+4PG3V/ajnGcLKhjkHQW6/WMBdVFpvqXO/ K0uwFKpDEWdJLY2YapzROzQ3yjQs2wO6uDYvgK12/GtSYIeShGrnCtH0mwlwkPBstjWo FYlLRbxNnDRMkYTVwPMa2w5VYXoRynMvkr8bw1WXmU8YcNT1ZggsxMs4wWMM30eJoyRO BdfGHwN/5FaAMnwVexNg3ayAwTXb69e4GWwJDwtU1bR5s0PCgG8TFbBkOnnme7W37lmP G0wlzHKjj8Dh1i2pWQzgV+qrJz3onlTuh2ouNP46iT2FRAxp7AbqwM9/uInfvl2rIkQ9 sYcw== X-Gm-Message-State: AOAM533qNFz7SxTGIEpEsM8BrZQ5p2ChtO3YLhOoxisifckE8Zp770tC anUgz4L5QxtzojNeqxE57sS6Vjsv+rU= X-Google-Smtp-Source: ABdhPJzAaxU4k8fLbIToDo435g76RFDfDlP/vdpL9N07vMcpJiUTr6D/lxMpICw48Lbp3UhBZ0LeWw== X-Received: by 2002:adf:fdcc:: with SMTP id i12mr82221806wrs.317.1609821791800; Mon, 04 Jan 2021 20:43:11 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e15sm94710176wrx.86.2021.01.04.20.43.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 20:43:11 -0800 (PST) Message-Id: In-Reply-To: References: Date: Tue, 05 Jan 2021 04:42:57 +0000 Subject: [PATCH v2 08/14] update-index: use remove_file_from_index() Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: pclouds@gmail.com, gitster@pobox.com, Elijah Newren , Eric Sunshine , Alban Gruin , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee This is a mechanical replacement of remove_file_from_cache(). Signed-off-by: Derrick Stolee --- builtin/update-index.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/builtin/update-index.c b/builtin/update-index.c index 096cbdfa8ac..aa859c4e018 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -252,7 +252,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(istate, path)) return error("%s: cannot remove from the index", path); return 0; } @@ -386,7 +386,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(istate, path)) return error("%s: cannot remove from the index", path); return 0; } @@ -473,7 +473,7 @@ static void update_one(const char *path) } if (force_remove) { - if (remove_file_from_cache(path)) + if (remove_file_from_index(istate, path)) die("git update-index: unable to remove %s", path); report("remove '%s'", path); return; @@ -556,7 +556,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(istate, path_name)) die("git update-index: unable to remove %s", ptr); } @@ -671,7 +671,7 @@ static int unresolve_one(const char *path) goto free_return; } - remove_file_from_cache(path); + remove_file_from_index(istate, path); if (add_cache_entry(ce_2, ADD_CACHE_OK_TO_ADD)) { error("%s: cannot add our version to the index.", path); ret = -1; From patchwork Tue Jan 5 04:42:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11998109 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10A95C433E0 for ; Tue, 5 Jan 2021 04:44:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D0D26227BF for ; Tue, 5 Jan 2021 04:44:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728207AbhAEEob (ORCPT ); Mon, 4 Jan 2021 23:44:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726477AbhAEEoa (ORCPT ); Mon, 4 Jan 2021 23:44:30 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19553C0617A2 for ; Mon, 4 Jan 2021 20:43:14 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id v14so1871138wml.1 for ; Mon, 04 Jan 2021 20:43:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=7wxpQwD2S7ImoZHKLssEJqa72kQrG0DmjRoz4MATBCU=; b=qczC+UgK30uGMTEnLc6H/vnFY10KEyLdOVKr1PufazN4nNhRTmnjtc58hFk22qlTAP amdvKPv2EUWMTQIxi3wa4WQP6xrc5iZQ0ui0WzKm9qpNE6GcdyNKeLrinfttpwhdsZBE 2SiAieFgUZMTPNkUT/Ao9rSXM8LSou6OFFcKlm0Lme/PVq+XADFrGmyAtO4hkdKAIDdc 5iSkan5MQQ7kYIyYQfTQmqp4ENh+1W94PurUjz+undVxH/5+kTxR0PLKMgQwqsoyU03d 81m7d/J73QxBztke61fSeUbEyRbMoKObz5Q694N637tPN1DIbHKfOxMjmUQKPVXvbgFw Ycpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=7wxpQwD2S7ImoZHKLssEJqa72kQrG0DmjRoz4MATBCU=; b=qYb0l2eYZi+w2gyY7ln9/SQZhM8qa+L/RlL00y06+k7atxYhsELfYZZl5BpA2B6Qxr KInN2MCKvsV9boZaNurl+2sGrslsU3Uq3ttcF715fv+QzNIJ63CcDJ/5Q98gs5I0457q Pn/IAVFICImjPMBQu7ZvxSiITjiNXou8UGd/mR25kYCSjKeRY6kkPnqqDZvgbJdFqIQK M6rr5cmrOeJFn7FNnoTdsxDh1NH1eaxbSasZNy/6Q10P05kgSUnFkMxOGPlcnHTYmK75 vKzOuMmWg0/wnh2GsAfjwCKOXBjRVAaL8R9G9coPDL6/M/YcZ+IKyd8y+5uMqc0HfLqU bh+w== X-Gm-Message-State: AOAM53281jUs0V8d+v8eLmED7+LOBirLcRuwzZrsSLhhJ8Okv84W68If hqUkpInQAQB41rzu17zsn2gr1j/sIfo= X-Google-Smtp-Source: ABdhPJzOnzb2cACx31uu9PaLdkJERpATSU2yiE4fimNu4XM9SdruQ6J0AetoqQmnJg6EggcJa3K/kQ== X-Received: by 2002:a1c:287:: with SMTP id 129mr1694051wmc.133.1609821792650; Mon, 04 Jan 2021 20:43:12 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z63sm2586774wme.8.2021.01.04.20.43.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 20:43:12 -0800 (PST) Message-Id: <620e300ad6b346af6b73feec625a3e125afaa53f.1609821783.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 05 Jan 2021 04:42:58 +0000 Subject: [PATCH v2 09/14] update-index: use add_index_entry() Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: pclouds@gmail.com, gitster@pobox.com, Elijah Newren , Eric Sunshine , Alban Gruin , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee This is a mechanical replacement of add_cache_entry(). Signed-off-by: Derrick Stolee --- builtin/update-index.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/update-index.c b/builtin/update-index.c index aa859c4e018..ffa42813370 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -294,7 +294,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(istate, ce, option)) { discard_cache_entry(ce); return error("%s: cannot add to the index - missing --add option?", path); } @@ -672,12 +672,12 @@ static int unresolve_one(const char *path) } remove_file_from_index(istate, path); - if (add_cache_entry(ce_2, ADD_CACHE_OK_TO_ADD)) { + if (add_index_entry(istate, 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(istate, ce_3, ADD_CACHE_OK_TO_ADD)) return 0; error("%s: cannot add their version to the index.", path); ret = -1; From patchwork Tue Jan 5 04:42:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11998115 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC3C0C433DB for ; Tue, 5 Jan 2021 04:44:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B5CD227BF for ; Tue, 5 Jan 2021 04:44:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728226AbhAEEob (ORCPT ); Mon, 4 Jan 2021 23:44:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726528AbhAEEoa (ORCPT ); Mon, 4 Jan 2021 23:44:30 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F181AC0617A3 for ; Mon, 4 Jan 2021 20:43:14 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id t16so34886764wra.3 for ; Mon, 04 Jan 2021 20:43:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=mqPr3/fTsc9D2oFthYhDZfW9JiRllFSqavVMmAN0O0I=; b=gyfry2w8YuutpiWXLC9U+k9sAGcRKJV45IKJRB6t678T73HSYLRHQxnd19rBiMMxKI oEDjA2blL4zgOsEl/q0G6FRhRbssS80lhV0MInJiQ7bjitfqj8Ql9hZcQREmS7m9N1Ja Vssx/j7Yh0JeaMbIuvwRcWBol3IMv15SvJUKM316M74HlSj3y8jH7519MwZ9eXufZ/+/ KKfXc1kHvhuvSRVlk00ioY39nSgc+QukyYsdjQQx+InZt/0yHNVT/kcsHPop7XovmfMi f9Bw99sy/WiUz5/3WUZWFsdifYBEPAnoRuA+ca4iw4SlT/fFk5e32UxUzKVuojenmDTe m6IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=mqPr3/fTsc9D2oFthYhDZfW9JiRllFSqavVMmAN0O0I=; b=cGIsB65dWG6pryNOiJ5zNlbvB9WwX4tvQebLQUD1ycB9yVHAUk7i6t642Rd18G3zXZ RhOyj26f2b9UsCgHj8luNEM9k6mCU5g8U7wZpYjJa7CRThWVEFnlc03u0haHX0FDgMlo WZsVQciqMDBU3tNOy4+vStXD6rETWwRESuTuQp5Z/SBB0Qo/uw7RmZSoB5ta0NqoTTox ZjTtc1J5poX3vzj9hBfXwehb44EZMDxIF3/E5V8/DdBzs+6hb0npczMkdCdBilvuAuAN tKLq75tTtBuBvUy+zCxlSRRGO8EClCjZLhWUYKIcDYtTJm+4ZDwTQPOXbK26w2AzmX8b LqHw== X-Gm-Message-State: AOAM533f0JcdZ9xNQkKpAOl8k7ZTF21qSzz45Zodx5zt+iJfD/jUxzLs vHramkTZ7BgEFyoDPkl/rRKXvDyQTwQ= X-Google-Smtp-Source: ABdhPJxNvNq8CHwCk8PKZvguI6Vyfnb2JURfo1wWUzUjZlSBVeviF1MSNxb3BmyjTuj3QT8FGW6XSQ== X-Received: by 2002:adf:dd09:: with SMTP id a9mr82061887wrm.90.1609821793589; Mon, 04 Jan 2021 20:43:13 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h83sm2443498wmf.9.2021.01.04.20.43.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 20:43:13 -0800 (PST) Message-Id: <68b26a11d779e225566f8581f4afcd514ef1cd70.1609821783.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 05 Jan 2021 04:42:59 +0000 Subject: [PATCH v2 10/14] update-index: replace several compatibility macros Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: pclouds@gmail.com, gitster@pobox.com, Elijah Newren , Eric Sunshine , Alban Gruin , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee This is also the last usage of unmerge_cache_entry_at(), so it can be removed from cache.h. Signed-off-by: Derrick Stolee --- builtin/update-index.c | 11 ++++++----- cache.h | 1 - 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/builtin/update-index.c b/builtin/update-index.c index ffa42813370..dd8e0acc52e 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -430,7 +430,7 @@ static void chmod_path(char flip, const char *path) if (pos < 0) goto fail; ce = istate->cache[pos]; - if (chmod_cache_entry(ce, flip) < 0) + if (chmod_index_entry(istate, ce, flip) < 0) goto fail; report("chmod %cx '%s'", flip, path); @@ -626,7 +626,7 @@ static int unresolve_one(const char *path) pos = index_name_pos(istate, path, namelen); if (0 <= pos) { /* already merged */ - pos = unmerge_cache_entry_at(pos); + pos = unmerge_index_entry_at(istate, pos); if (pos < istate->cache_nr) { const struct cache_entry *ce = istate->cache[pos]; if (ce_stage(ce) && @@ -777,8 +777,9 @@ 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(repo); + *o->has_errors |= refresh_index(istate, o->flags | flag, + NULL, NULL, NULL); return 0; } @@ -814,7 +815,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(istate); return 0; } diff --git a/cache.h b/cache.h index fdf061cac56..8c091be6256 100644 --- a/cache.h +++ b/cache.h @@ -421,7 +421,6 @@ extern struct index_state the_index; #define cache_dir_exists(name, namelen) index_dir_exists(&the_index, (name), (namelen)) #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)) From patchwork Tue Jan 5 04:43:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11998123 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62C73C433E6 for ; Tue, 5 Jan 2021 04:44:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3A8C122838 for ; Tue, 5 Jan 2021 04:44:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728285AbhAEEoh (ORCPT ); Mon, 4 Jan 2021 23:44:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726545AbhAEEoa (ORCPT ); Mon, 4 Jan 2021 23:44:30 -0500 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E50B8C0617A4 for ; Mon, 4 Jan 2021 20:43:15 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id i9so34887030wrc.4 for ; Mon, 04 Jan 2021 20:43:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=gKsL1Z5Y55+Y1PL5GuxJoS7EBIhj0OmqHFfz9/ukPzQ=; b=mmJKaDY07livWdrY/kQPxy4g4jj9fjc6G7VoG0e23bQv8h1VIBaR4ju9n9o+ITiBdH i8S2MJfIzpnV2MrGiwfwv1xDDxztzDzxBUQ9GbzJMr28nKsiURywC56H4oyrAZd2qJc3 4zvNA2d8gGaSVDy4tu9q9fXx/d9gApieknlfv54KBLwTLP3Ps6NgzjA/aDLx2qACXq38 o0JNGUdrrFy/CEpGOUVQXAndxYDYHhENeJigsa8zVDKB05WB7pndZdGsu/nJPaG7HB81 pcvIQCvHPPO68+S6ijDEKpE3NRmM/oFKcBxqqcOltwDdEOehXxlDyxgkT3cEzJ/OacFl 9Gbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=gKsL1Z5Y55+Y1PL5GuxJoS7EBIhj0OmqHFfz9/ukPzQ=; b=umxqbHHE3tK1y002N9vDuHu7Jy/WT9UQcb89dXTqHSjfjpfIgW27B0y1bdfYkLuTRb sALz01ryzAoik5Ct0o+//d97TSAnQme8Du9WVhHV9kpdAXc/O5ah7pXUzl7pbMi9enPt W3Ntw5VlbAlbY5O1MS0/eG7zaTL6roE8LKdfETcsOH0MwGONkcEZE6FndBXbNYwXMJPe IOVIQVq+xJvNBankb7T0QaooycO/F9HZQwfRNnNf0ehhkZgzlt0h1L2tkSKMjBpZfoFY ufdXJvQNXdUWR/umbyDMi+dE1qUYBZhBQ6fahHYhKpo/co2r1tfGwP/Gky0Ms+dbjcGC Bosg== X-Gm-Message-State: AOAM5316GZaEMBb/cPgqNerkxSk+NdP8ropV2/53dQUDNobZ14DRBtPz JifJltlipkKG8pBuUIoF7zKtgxG9yvk= X-Google-Smtp-Source: ABdhPJw8pEv1LI7t15FZCnFUbm6BMiXRve/9jZ8CTqEgeBDz0cpfA5Pn0PsZpMyNv6TvZrVZbHwQnA== X-Received: by 2002:adf:fb05:: with SMTP id c5mr81484684wrr.69.1609821794482; Mon, 04 Jan 2021 20:43:14 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t188sm2101167wmf.9.2021.01.04.20.43.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 20:43:13 -0800 (PST) Message-Id: In-Reply-To: References: Date: Tue, 05 Jan 2021 04:43:00 +0000 Subject: [PATCH v2 11/14] update-index: remove ce_match_stat(), all macros Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: pclouds@gmail.com, gitster@pobox.com, Elijah Newren , Eric Sunshine , Alban Gruin , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The final index compatibility macro to remove from the update-index builtin is ce_match_stat(). Further, this is the last use of that macro anywhere, so it should be removed. There are some remaining references in the racy-git.txt technical document that are updated to ie_match_stat(). Signed-off-by: Derrick Stolee --- Documentation/technical/racy-git.txt | 6 +++--- builtin/update-index.c | 3 +-- cache.h | 1 - 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Documentation/technical/racy-git.txt b/Documentation/technical/racy-git.txt index ceda4bbfda4..65188e04559 100644 --- a/Documentation/technical/racy-git.txt +++ b/Documentation/technical/racy-git.txt @@ -26,7 +26,7 @@ information obtained from the filesystem via `lstat(2)` system call when they were last updated. When checking if they differ, Git first runs `lstat(2)` on the files and compares the result with this information (this is what was originally done by the -`ce_match_stat()` function, but the current code does it in +`ie_match_stat()` function, but the current code does it in `ce_match_stat_basic()` function). If some of these "cached stat information" fields do not match, Git can tell that the files are modified without even looking at their contents. @@ -102,7 +102,7 @@ timestamp as the index file itself. The callers that want to check if an index entry matches the corresponding file in the working tree continue to call -`ce_match_stat()`, but with this change, `ce_match_stat()` uses +`ie_match_stat()`, but with this change, `ie_match_stat()` uses `ce_modified_check_fs()` to see if racily clean ones are actually clean after comparing the cached stat information using `ce_match_stat_basic()`. @@ -128,7 +128,7 @@ Runtime penalty --------------- The runtime penalty of falling back to `ce_modified_check_fs()` -from `ce_match_stat()` can be very expensive when there are many +from `ie_match_stat()` can be very expensive when there are many racily clean entries. An obvious way to artificially create this situation is to give the same timestamp to all the files in the working tree in a large project, run `git update-index` on diff --git a/builtin/update-index.c b/builtin/update-index.c index dd8e0acc52e..8fc680090be 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -3,7 +3,6 @@ * * Copyright (C) Linus Torvalds, 2005 */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "lockfile.h" @@ -277,7 +276,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(istate, old, st, 0)) return 0; ce = make_empty_cache_entry(istate, len); diff --git a/cache.h b/cache.h index 8c091be6256..740bd0aa1dd 100644 --- a/cache.h +++ b/cache.h @@ -416,7 +416,6 @@ extern struct index_state the_index; #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_dir_exists(name, namelen) index_dir_exists(&the_index, (name), (namelen)) #define cache_name_is_other(name, namelen) index_name_is_other(&the_index, (name), (namelen)) From patchwork Tue Jan 5 04:43:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11998111 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB5AFC433E9 for ; Tue, 5 Jan 2021 04:44:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8596B227BF for ; Tue, 5 Jan 2021 04:44:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728240AbhAEEoc (ORCPT ); Mon, 4 Jan 2021 23:44:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726546AbhAEEoa (ORCPT ); Mon, 4 Jan 2021 23:44:30 -0500 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9EC6C0617A5 for ; Mon, 4 Jan 2021 20:43:16 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id c133so1858128wme.4 for ; Mon, 04 Jan 2021 20:43:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=grX1ZI10qrCaKi+H6erN9/35HPk41gfsbba08KfVeyI=; b=iFZ1iaq+zj7rQdAB2xj/6M9rIz4bZAGETxPKRG86gIKQcpcZkXgtTQC6LtoK3avvS6 dHtUOxJDpdydRDMJgv/QYhU7rqPwvhYeOAJcpD+XR5G/BVOTdfg1EyeUGEpmRf4fcCPk a7LnoDUiDw+lHVIawK8EOPczTRNrRpImpjQYUHpFribGO0wGIf3I3k2IT0ka2eMeLWsc irV/eD54bW12XbFCAf7A+E7flgWhlsMCJGQee0y18xKT/+aTUOhIg6dnobMBGTqq6ajl vKajgSjtS8Jr1lVZBX+YVp43IABxeztZMpiU0pqth+UT/LQ6Zqyty5BhUmesVPEQ92MI NxDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=grX1ZI10qrCaKi+H6erN9/35HPk41gfsbba08KfVeyI=; b=GjPk0xMSYq2pBJgmKRaKcflJfcAwENg7BInMmhKYYpQU7IjShV8K55SfjOyj9OO627 2fZ9Q9p1KJonHN58nC/DqoRfh7cLuFiizepHzjO9wcUbjaA2aS26n6bUt9Gma+CAKo7W 3l1giti5WBGzj0LjxqLTJmWqYuXyIVvKAEImNyhXynnMXZkao3hMVHBJxjAtSYjHRLjm OqqEAd5OG3pXK8WKuNcKqly/ukcOZBkz+eOf34DsDCXfL0hCRLQ2k9w4ig940VkF815b OiA0/eU8UlO8Il8Wgs56birLI11sd2n4mRoxuT+3vsQeWVf2bv8d4FiSbxrvGomC/FV4 gK0Q== X-Gm-Message-State: AOAM532tM62r9sqhbkh5yyPN5oBh1KgUd7Q9izT1FsNVQOoP5nwP9Lun ChgezZK35QSrgFeVeY8bXs+lqRZf24U= X-Google-Smtp-Source: ABdhPJxJzW1miF7zMLEUkra11oyZux26Kdm2Pu3TTJtOr/sMN1YwEPMAotnCXYXE00ztYvY9Z6Ilhg== X-Received: by 2002:a7b:cf30:: with SMTP id m16mr1641855wmg.145.1609821795400; Mon, 04 Jan 2021 20:43:15 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s1sm96346245wrv.97.2021.01.04.20.43.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 20:43:14 -0800 (PST) Message-Id: <79e267f39ec764e03788ba1ddfe1051156a625fa.1609821783.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 05 Jan 2021 04:43:01 +0000 Subject: [PATCH v2 12/14] update-index: reduce static globals, part 1 Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: pclouds@gmail.com, gitster@pobox.com, Elijah Newren , Eric Sunshine , Alban Gruin , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee In order to remove index compatibility macros cleanly, we relied upon static globals 'repo' and 'istate' to be pointers to the_repository and the_index, respectively. We can now start reducing the need for these static globals by modifying method prototypes to use them when necessary. Move these static globals further down in the file so we can identify which method only need to add a 'struct index_state *istate' parameter. The only changes included here adjust method prototypes and their call locations. Signed-off-by: Derrick Stolee --- builtin/update-index.c | 77 ++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/builtin/update-index.c b/builtin/update-index.c index 8fc680090be..6b585fb8ede 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -39,9 +39,6 @@ static int ignore_skip_worktree_entries; #define UNMARK_FLAG 2 static struct strbuf mtime_dir = STRBUF_INIT; -static struct repository *repo; -static struct index_state *istate; - /* Untracked cache mode */ enum uc_mode { UC_UNSPECIFIED = -1, @@ -229,7 +226,8 @@ static int test_if_untracked_cache_is_supported(void) return ret; } -static int mark_ce_flags(const char *path, int flag, int mark) +static int mark_ce_flags(struct index_state *istate, + const char *path, int flag, int mark) { int namelen = strlen(path); int pos = index_name_pos(istate, path, namelen); @@ -247,7 +245,7 @@ static int mark_ce_flags(const char *path, int flag, int mark) return -1; } -static int remove_one_path(const char *path) +static int remove_one_path(struct index_state *istate, const char *path) { if (!allow_remove) return error("%s: does not exist and --remove not passed", path); @@ -263,14 +261,17 @@ static int remove_one_path(const char *path) * succeeds. * - permission error. That's never ok. */ -static int process_lstat_error(const char *path, int err) +static int process_lstat_error(struct index_state *istate, + const char *path, int err) { if (is_missing_file_error(err)) - return remove_one_path(path); + return remove_one_path(istate, path); return error("lstat(\"%s\"): %s", path, strerror(err)); } -static int add_one_path(const struct cache_entry *old, const char *path, int len, struct stat *st) +static int add_one_path(struct index_state *istate, + const struct cache_entry *old, + const char *path, int len, struct stat *st) { int option; struct cache_entry *ce; @@ -323,7 +324,8 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len * - it doesn't exist at all in the index, but it is a valid * git directory, and it should be *added* as a gitlink. */ -static int process_directory(const char *path, int len, struct stat *st) +static int process_directory(struct index_state *istate, + const char *path, int len, struct stat *st) { struct object_id oid; int pos = index_name_pos(istate, path, len); @@ -337,10 +339,10 @@ static int process_directory(const char *path, int len, struct stat *st) if (resolve_gitlink_ref(path, "HEAD", &oid) < 0) return 0; - return add_one_path(ce, path, len, st); + return add_one_path(istate, ce, path, len, st); } /* Should this be an unconditional error? */ - return remove_one_path(path); + return remove_one_path(istate, path); } /* Inexact match: is there perhaps a subdirectory match? */ @@ -361,13 +363,14 @@ static int process_directory(const char *path, int len, struct stat *st) /* No match - should we add it as a gitlink? */ if (!resolve_gitlink_ref(path, "HEAD", &oid)) - return add_one_path(NULL, path, len, st); + return add_one_path(istate, NULL, path, len, st); /* Error out. */ return error("%s: is a directory - add files inside instead", path); } -static int process_path(const char *path, struct stat *st, int stat_errno) +static int process_path(struct index_state *istate, + const char *path, struct stat *st, int stat_errno) { int pos, len; const struct cache_entry *ce; @@ -395,15 +398,16 @@ static int process_path(const char *path, struct stat *st, int stat_errno) * what to do about the pathname! */ if (stat_errno) - return process_lstat_error(path, stat_errno); + return process_lstat_error(istate, path, stat_errno); if (S_ISDIR(st->st_mode)) - return process_directory(path, len, st); + return process_directory(istate, path, len, st); - return add_one_path(ce, path, len, st); + return add_one_path(istate, ce, path, len, st); } -static int add_cacheinfo(unsigned int mode, const struct object_id *oid, +static int add_cacheinfo(struct index_state *istate, + unsigned int mode, const struct object_id *oid, const char *path, int stage) { int res; @@ -420,7 +424,8 @@ static int add_cacheinfo(unsigned int mode, const struct object_id *oid, return 0; } -static void chmod_path(char flip, const char *path) +static void chmod_path(struct index_state *istate, + char flip, const char *path) { int pos; struct cache_entry *ce; @@ -438,7 +443,7 @@ static void chmod_path(char flip, const char *path) die("git update-index: cannot chmod %cx '%s'", flip, path); } -static void update_one(const char *path) +static void update_one(struct index_state *istate, const char *path) { int stat_errno = 0; struct stat st; @@ -456,17 +461,20 @@ static void update_one(const char *path) return; } if (mark_valid_only) { - if (mark_ce_flags(path, CE_VALID, mark_valid_only == MARK_FLAG)) + if (mark_ce_flags(istate, path, CE_VALID, + mark_valid_only == MARK_FLAG)) die("Unable to mark file %s", path); return; } if (mark_skip_worktree_only) { - if (mark_ce_flags(path, CE_SKIP_WORKTREE, mark_skip_worktree_only == MARK_FLAG)) + if (mark_ce_flags(istate, path, CE_SKIP_WORKTREE, + mark_skip_worktree_only == MARK_FLAG)) die("Unable to mark file %s", path); return; } if (mark_fsmonitor_only) { - if (mark_ce_flags(path, CE_FSMONITOR_VALID, mark_fsmonitor_only == MARK_FLAG)) + if (mark_ce_flags(istate, path, CE_FSMONITOR_VALID, + mark_fsmonitor_only == MARK_FLAG)) die("Unable to mark file %s", path); return; } @@ -477,12 +485,12 @@ static void update_one(const char *path) report("remove '%s'", path); return; } - if (process_path(path, &st, stat_errno)) + if (process_path(istate, path, &st, stat_errno)) die("Unable to process path %s", path); report("add '%s'", path); } -static void read_index_info(int nul_term_line) +static void read_index_info(struct index_state *istate, int nul_term_line) { const int hexsz = the_hash_algo->hexsz; struct strbuf buf = STRBUF_INIT; @@ -565,7 +573,7 @@ static void read_index_info(int nul_term_line) * ptr[-41] is at the beginning of sha1 */ ptr[-(hexsz + 2)] = ptr[-1] = 0; - if (add_cacheinfo(mode, &oid, path_name, stage)) + if (add_cacheinfo(istate, mode, &oid, path_name, stage)) die("git update-index: unable to update %s", path_name); } @@ -586,6 +594,9 @@ static const char * const update_index_usage[] = { static struct object_id head_oid; static struct object_id merge_head_oid; +static struct repository *repo; +static struct index_state *istate; + static struct cache_entry *read_one_ent(const char *which, struct object_id *ent, const char *path, int namelen, int stage) @@ -758,7 +769,7 @@ static int do_reupdate(int ac, const char **av, */ save_nr = istate->cache_nr; path = xstrdup(ce->name); - update_one(path); + update_one(istate, path); free(path); discard_cache_entry(old); if (save_nr != istate->cache_nr) @@ -854,7 +865,7 @@ static enum parse_opt_result cacheinfo_callback( BUG_ON_OPT_ARG(arg); if (!parse_new_style_cacheinfo(ctx->argv[1], &mode, &oid, &path)) { - if (add_cacheinfo(mode, &oid, path, 0)) + if (add_cacheinfo(istate, mode, &oid, path, 0)) die("git update-index: --cacheinfo cannot add %s", path); ctx->argv++; ctx->argc--; @@ -864,7 +875,7 @@ static enum parse_opt_result cacheinfo_callback( return error("option 'cacheinfo' expects ,,"); if (strtoul_ui(*++ctx->argv, 8, &mode) || get_oid_hex(*++ctx->argv, &oid) || - add_cacheinfo(mode, &oid, *++ctx->argv, 0)) + add_cacheinfo(istate, mode, &oid, *++ctx->argv, 0)) die("git update-index: --cacheinfo cannot add %s", *ctx->argv); ctx->argc -= 3; return 0; @@ -882,7 +893,7 @@ static enum parse_opt_result stdin_cacheinfo_callback( if (ctx->argc != 1) return error("option '%s' must be the last argument", opt->long_name); allow_add = allow_replace = allow_remove = 1; - read_index_info(*nul_term_line); + read_index_info(istate, *nul_term_line); return 0; } @@ -1108,9 +1119,9 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) setup_work_tree(); p = prefix_path(prefix, prefix_length, path); - update_one(p); + update_one(istate, p); if (set_executable_bit) - chmod_path(set_executable_bit, p); + chmod_path(istate, set_executable_bit, p); free(p); ctx.argc--; ctx.argv++; @@ -1153,9 +1164,9 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) strbuf_swap(&buf, &unquoted); } p = prefix_path(prefix, prefix_length, buf.buf); - update_one(p); + update_one(istate, p); if (set_executable_bit) - chmod_path(set_executable_bit, p); + chmod_path(istate, set_executable_bit, p); free(p); } strbuf_release(&unquoted); From patchwork Tue Jan 5 04:43:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11998121 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3AC5CC433DB for ; Tue, 5 Jan 2021 04:44:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 14AB82251F for ; Tue, 5 Jan 2021 04:44:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728302AbhAEEoi (ORCPT ); Mon, 4 Jan 2021 23:44:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726589AbhAEEoa (ORCPT ); Mon, 4 Jan 2021 23:44:30 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AECC4C0617A6 for ; Mon, 4 Jan 2021 20:43:17 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id t30so34910294wrb.0 for ; Mon, 04 Jan 2021 20:43:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=y8LiKrnf+O++nvf7DjK19abFAOnRB5WPkCBFP+JWfRg=; b=V0nKyCsTOIzCQRYJp3d9rOWm93uTA0MC8bMZHPACgoaWAYqmkYG7G/G94pLMR7SZdg XdrmvMuqP3zWAeYTzyODgiI6qVWA9oZHAPvYwVX+tkSShSGxlIdoYloOJKJJF09LteEt LCcDZ0+boA0nOaBoJDy9Ksy4aaDgl1WAG3vh3YiupSxQEQPqrkMLWKSu69ET6weccKPi m2mcrxGPnx9VbdezVg7R6qf5/wfJFC8wI8pkRF3Rc2h6mv6z09T7SxZl/MNdFywto9SN kvHTfiR53NomCYE2NMc8wFaaSQrZkiJB6MKULa9QJesB5YZk+wEEfpbNdDHsKFLFwKKM tpAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=y8LiKrnf+O++nvf7DjK19abFAOnRB5WPkCBFP+JWfRg=; b=ndHkvrns1AaMxPkJBF87Tpy3WinCV9qASZp1m95RWj9nrJCsr9PfqnS80DkuRkYgcS BGstZdTdC9PmPbA2wROjkyeF9Dsebw74FWSU+e+vrdNohylNHHgJ7r4X73lu1sBBjGAP XoO6/AC5GPKW2lsyVR+jX4wkM/I4/HYYpM+u6pzICR3imCUF2WgGQOOjF0TypAAeAPhr /TPpIosJjxT3rxuA4IJfIwc7Lempb7ZF24rwiYtt2cWUs33Gs/hThbCVaXU4mU+050ma V5RDILSnd9h/ajamgRq9iiUIdoKQhJI7esyYYFekslOO/qkJK7gxjRQJxvywnvfdJc+l BYxg== X-Gm-Message-State: AOAM532bKQVfcmIpZ9xuqv7MXagZPAcAX1ldplpjZ5D4ky4N67sXCmif XoiTbeIKP74LN626wXOY14KlrS5372s= X-Google-Smtp-Source: ABdhPJyDFZJlj3ZuDXbX6whNB5kYcSTV8foivSc6jditHVTMiqYb9xDN0SE/8wKP9UcPlvkCIURmAw== X-Received: by 2002:a5d:6209:: with SMTP id y9mr82254063wru.197.1609821796278; Mon, 04 Jan 2021 20:43:16 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m11sm2271596wmi.16.2021.01.04.20.43.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 20:43:15 -0800 (PST) Message-Id: <457402b4fdcab4b2d390733d1d5cc9174a318e89.1609821783.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 05 Jan 2021 04:43:02 +0000 Subject: [PATCH v2 13/14] update-index: reduce static globals, part 2 Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: pclouds@gmail.com, gitster@pobox.com, Elijah Newren , Eric Sunshine , Alban Gruin , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee In order to remove index compatibility macros cleanly, we relied upon static globals 'repo' and 'istate' to be pointers to the_repository and the_index, respectively. We can continue reducing the need for these static globals by modifying method prototypes to use them when necessary. Move these static globals further down the file so we can identify which methods need both 'struct repository *repo' and 'struct index_state *istate' parameters. The only changes included here adjust method prototypes and their call locations. The only remaining change is to remove the static globals entirely, but that requires updating the parse-opt callbacks, which need a different solution. Signed-off-by: Derrick Stolee --- builtin/update-index.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/builtin/update-index.c b/builtin/update-index.c index 6b585fb8ede..fb8d7879783 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -594,10 +594,9 @@ static const char * const update_index_usage[] = { static struct object_id head_oid; static struct object_id merge_head_oid; -static struct repository *repo; -static struct index_state *istate; - -static struct cache_entry *read_one_ent(const char *which, +static struct cache_entry *read_one_ent(struct repository *repo, + struct index_state *istate, + const char *which, struct object_id *ent, const char *path, int namelen, int stage) { @@ -625,7 +624,9 @@ static struct cache_entry *read_one_ent(const char *which, return ce; } -static int unresolve_one(const char *path) +static int unresolve_one(struct repository *repo, + struct index_state *istate, + const char *path) { int namelen = strlen(path); int pos; @@ -667,8 +668,8 @@ static int unresolve_one(const char *path) * stuff HEAD version in stage #2, * stuff MERGE_HEAD version in stage #3. */ - ce_2 = read_one_ent("our", &head_oid, path, namelen, 2); - ce_3 = read_one_ent("their", &merge_head_oid, path, namelen, 3); + ce_2 = read_one_ent(repo, istate, "our", &head_oid, path, namelen, 2); + ce_3 = read_one_ent(repo, istate, "their", &merge_head_oid, path, namelen, 3); if (!ce_2 || !ce_3) { ret = -1; @@ -707,7 +708,9 @@ static void read_head_pointers(void) } } -static int do_unresolve(int ac, const char **av, +static int do_unresolve(struct repository *repo, + struct index_state *istate, + int ac, const char **av, const char *prefix, int prefix_length) { int i; @@ -721,13 +724,15 @@ static int do_unresolve(int ac, const char **av, for (i = 1; i < ac; i++) { const char *arg = av[i]; char *p = prefix_path(prefix, prefix_length, arg); - err |= unresolve_one(p); + err |= unresolve_one(repo, istate, p); free(p); } return err; } -static int do_reupdate(int ac, const char **av, +static int do_reupdate(struct repository *repo, + struct index_state *istate, + int ac, const char **av, const char *prefix) { /* Read HEAD and run update-index on paths that are @@ -756,7 +761,7 @@ static int do_reupdate(int ac, const char **av, if (ce_stage(ce) || !ce_path_match(istate, ce, &pathspec, NULL)) continue; if (has_head) - old = read_one_ent(NULL, &head_oid, + old = read_one_ent(repo, istate, NULL, &head_oid, ce->name, ce_namelen(ce), 0); if (old && ce->ce_mode == old->ce_mode && oideq(&ce->oid, &old->oid)) { @@ -784,6 +789,9 @@ struct refresh_params { int *has_errors; }; +static struct repository *repo; +static struct index_state *istate; + static int refresh(struct refresh_params *o, unsigned int flag) { setup_work_tree(); @@ -923,8 +931,8 @@ static enum parse_opt_result unresolve_callback( BUG_ON_OPT_ARG(arg); /* consume remaining arguments. */ - *has_errors = do_unresolve(ctx->argc, ctx->argv, - prefix, prefix ? strlen(prefix) : 0); + *has_errors = do_unresolve(repo, istate, ctx->argc, ctx->argv, + prefix, prefix ? strlen(prefix) : 0); if (*has_errors) istate->cache_changed = 0; @@ -945,7 +953,7 @@ static enum parse_opt_result reupdate_callback( /* consume remaining arguments. */ setup_work_tree(); - *has_errors = do_reupdate(ctx->argc, ctx->argv, prefix); + *has_errors = do_reupdate(repo, istate, ctx->argc, ctx->argv, prefix); if (*has_errors) istate->cache_changed = 0; From patchwork Tue Jan 5 04:43:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11998113 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35A8CC433E0 for ; Tue, 5 Jan 2021 04:44:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF466227BF for ; Tue, 5 Jan 2021 04:44:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728268AbhAEEod (ORCPT ); Mon, 4 Jan 2021 23:44:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726408AbhAEEob (ORCPT ); Mon, 4 Jan 2021 23:44:31 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB506C0617A7 for ; Mon, 4 Jan 2021 20:43:18 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id i9so34887139wrc.4 for ; Mon, 04 Jan 2021 20:43:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=TJlNRVfvQznY4xMUrb4h1llVXgrBaGfvjLTUs5lP0LI=; b=coayqL2hLJ06+1oaMnU3pZbR07B4n0kZwhih7J2Fu3OA7boqrVF3xpnGpVFdaU2AV2 f7rF0Jau1CRR7qHfAjSk12atDkCpCJCEc+X7IgvnuTYNsix5exsqX861ugYqUnfWZ0vI CWXtJJZPp9CE6setFlx1L1PPizf9ME+wtL5CkSegfFmRJMe50fwKSuR1JuR23MWtWWn8 kGvWyEMR2JLp2KxshMTSLJ4DvQxWmCi62cFliM/MPpr1/ViJAFo67IlHJ6sKru1TAP58 v9wV2C8PI2yBehZlC2eDaXxRmtSOCs7LKZfDHKv9x1cNC4tgyh+CVbcETQ80UZcioKY3 Ki/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=TJlNRVfvQznY4xMUrb4h1llVXgrBaGfvjLTUs5lP0LI=; b=XinN4QP+tzUJ+VcWZqxTImzNGsAbQ+XkyjikWVwOdhPuHLazGSK3rMIJWi4rj/6qVk YR7irBZZOpFLtumorqO5e/bTByXbsOnCCyRyKJDyGly9gVCvKGIFnWo0JYnAXDBYY/Kr Fc2AFZjdFS5uBpk7bXOTq03uA7M8dMcjPjmEi+eiWqSiaWqhLUV4Ke9EAclcCNSEZR/h nFDsUZe0pn7DBGVOl9II8UgdmsbWPIqK3Ypr6JebNF7PeW+p5ISoWVrED1H5p0IGImDh LqQDNMDCpEQx/q5W69EhA5lUT2mijamOh3KhNuu1GdhvsNwcdGVsZsCg8PDEck9gCwH7 HEcA== X-Gm-Message-State: AOAM530UREuK+xRVTsPTLltr1eUrH72F0JCigx2jIwuu5qEgmwR9yBe8 47jFxtuysJQGwamQuLXlytszXKi51RU= X-Google-Smtp-Source: ABdhPJyYkQNW8Sa6uS9wxlZNOCtqsGWn03veD1SM/IDJDar82o+TUDOiNsw4MdBrJg3DPWgn+qmKMw== X-Received: by 2002:a5d:58d3:: with SMTP id o19mr31679983wrf.250.1609821797171; Mon, 04 Jan 2021 20:43:17 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b19sm2348561wmj.37.2021.01.04.20.43.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 20:43:16 -0800 (PST) Message-Id: <2b171a142b36b114d5ff526073fe3fd9517a4d32.1609821783.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 05 Jan 2021 04:43:03 +0000 Subject: [PATCH v2 14/14] update-index: remove static globals from callbacks Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: pclouds@gmail.com, gitster@pobox.com, Elijah Newren , Eric Sunshine , Alban Gruin , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee In order to remove index compatibility macros cleanly, we relied upon static globals 'repo' and 'istate' to be pointers to the_repository and the_index, respectively. We remove these static globals inside the option parsing callbacks, which are the final uses in update-index. The callbacks cannot change their method signature, so we must use the value member of 'struct option', assigned in the array of option macros. There are several callback methods that require at least one of 'repo' and 'istate', but they use a variety of different data types for the callback value. Unify these callback methods to use a consistent 'struct callback_data' that contains 'repo' and 'istate', ready to use. This takes the place of the previous 'struct refresh_params' which served only to group the 'flags' and 'has_errors' ints. We also collect other one-off settings, but only those that require access to the index or repository in their operation. Signed-off-by: Derrick Stolee --- builtin/update-index.c | 110 ++++++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 50 deletions(-) diff --git a/builtin/update-index.c b/builtin/update-index.c index fb8d7879783..258db619a40 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -784,19 +784,21 @@ static int do_reupdate(struct repository *repo, return 0; } -struct refresh_params { +struct callback_data { + struct repository *repo; + struct index_state *istate; + unsigned int flags; - int *has_errors; + unsigned int has_errors; + unsigned nul_term_line; + unsigned read_from_stdin; }; -static struct repository *repo; -static struct index_state *istate; - -static int refresh(struct refresh_params *o, unsigned int flag) +static int refresh(struct callback_data *cd, unsigned int flag) { setup_work_tree(); - repo_read_index(repo); - *o->has_errors |= refresh_index(istate, o->flags | flag, + repo_read_index(cd->repo); + cd->has_errors |= refresh_index(cd->istate, cd->flags | flag, NULL, NULL, NULL); return 0; } @@ -818,7 +820,7 @@ static int really_refresh_callback(const struct option *opt, } static int chmod_callback(const struct option *opt, - const char *arg, int unset) + const char *arg, int unset) { char *flip = opt->value; BUG_ON_OPT_NEG(unset); @@ -829,11 +831,12 @@ static int chmod_callback(const struct option *opt, } static int resolve_undo_clear_callback(const struct option *opt, - const char *arg, int unset) + const char *arg, int unset) { + struct callback_data *cd = opt->value; BUG_ON_OPT_NEG(unset); BUG_ON_OPT_ARG(arg); - resolve_undo_clear_index(istate); + resolve_undo_clear_index(cd->istate); return 0; } @@ -868,12 +871,13 @@ static enum parse_opt_result cacheinfo_callback( struct object_id oid; unsigned int mode; const char *path; + struct callback_data *cd = opt->value; BUG_ON_OPT_NEG(unset); BUG_ON_OPT_ARG(arg); if (!parse_new_style_cacheinfo(ctx->argv[1], &mode, &oid, &path)) { - if (add_cacheinfo(istate, mode, &oid, path, 0)) + if (add_cacheinfo(cd->istate, mode, &oid, path, 0)) die("git update-index: --cacheinfo cannot add %s", path); ctx->argv++; ctx->argc--; @@ -883,7 +887,7 @@ static enum parse_opt_result cacheinfo_callback( return error("option 'cacheinfo' expects ,,"); if (strtoul_ui(*++ctx->argv, 8, &mode) || get_oid_hex(*++ctx->argv, &oid) || - add_cacheinfo(istate, mode, &oid, *++ctx->argv, 0)) + add_cacheinfo(cd->istate, mode, &oid, *++ctx->argv, 0)) die("git update-index: --cacheinfo cannot add %s", *ctx->argv); ctx->argc -= 3; return 0; @@ -893,7 +897,7 @@ static enum parse_opt_result stdin_cacheinfo_callback( struct parse_opt_ctx_t *ctx, const struct option *opt, const char *arg, int unset) { - int *nul_term_line = opt->value; + struct callback_data *cd = opt->value; BUG_ON_OPT_NEG(unset); BUG_ON_OPT_ARG(arg); @@ -901,7 +905,7 @@ static enum parse_opt_result stdin_cacheinfo_callback( if (ctx->argc != 1) return error("option '%s' must be the last argument", opt->long_name); allow_add = allow_replace = allow_remove = 1; - read_index_info(istate, *nul_term_line); + read_index_info(cd->istate, cd->nul_term_line); return 0; } @@ -909,14 +913,14 @@ static enum parse_opt_result stdin_callback( struct parse_opt_ctx_t *ctx, const struct option *opt, const char *arg, int unset) { - int *read_from_stdin = opt->value; + struct callback_data *cd = opt->value; BUG_ON_OPT_NEG(unset); BUG_ON_OPT_ARG(arg); if (ctx->argc != 1) return error("option '%s' must be the last argument", opt->long_name); - *read_from_stdin = 1; + cd->read_from_stdin = 1; return 0; } @@ -924,17 +928,17 @@ static enum parse_opt_result unresolve_callback( struct parse_opt_ctx_t *ctx, const struct option *opt, const char *arg, int unset) { - int *has_errors = opt->value; const char *prefix = startup_info->prefix; + struct callback_data *cd = opt->value; BUG_ON_OPT_NEG(unset); BUG_ON_OPT_ARG(arg); /* consume remaining arguments. */ - *has_errors = do_unresolve(repo, istate, ctx->argc, ctx->argv, - prefix, prefix ? strlen(prefix) : 0); - if (*has_errors) - istate->cache_changed = 0; + cd->has_errors = do_unresolve(cd->repo, cd->istate, ctx->argc, ctx->argv, + prefix, prefix ? strlen(prefix) : 0); + if (cd->has_errors) + cd->istate->cache_changed = 0; ctx->argv += ctx->argc - 1; ctx->argc = 1; @@ -945,17 +949,18 @@ static enum parse_opt_result reupdate_callback( struct parse_opt_ctx_t *ctx, const struct option *opt, const char *arg, int unset) { - int *has_errors = opt->value; const char *prefix = startup_info->prefix; + struct callback_data *cd = opt->value; BUG_ON_OPT_NEG(unset); BUG_ON_OPT_ARG(arg); /* consume remaining arguments. */ setup_work_tree(); - *has_errors = do_reupdate(repo, istate, ctx->argc, ctx->argv, prefix); - if (*has_errors) - istate->cache_changed = 0; + cd->has_errors = do_reupdate(cd->repo, cd->istate, + ctx->argc, ctx->argv, prefix); + if (cd->has_errors) + cd->istate->cache_changed = 0; ctx->argv += ctx->argc - 1; ctx->argc = 1; @@ -964,13 +969,13 @@ static enum parse_opt_result reupdate_callback( int cmd_update_index(int argc, const char **argv, const char *prefix) { - int newfd, entries, has_errors = 0, nul_term_line = 0; + struct repository *repo = the_repository; + struct callback_data cd; + int newfd, entries; enum uc_mode untracked_cache = UC_UNSPECIFIED; - int read_from_stdin = 0; int prefix_length = prefix ? strlen(prefix) : 0; int preferred_index_format = 0; char set_executable_bit = 0; - struct refresh_params refresh_args = {0, &has_errors}; int lock_error = 0; int split_index = -1; int force_write = 0; @@ -979,11 +984,13 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) struct parse_opt_ctx_t ctx; strbuf_getline_fn getline_fn; int parseopt_state = PARSE_OPT_UNKNOWN; + struct index_state *istate; + struct option options[] = { - OPT_BIT('q', NULL, &refresh_args.flags, + OPT_BIT('q', NULL, &cd.flags, N_("continue refresh even when index needs update"), REFRESH_QUIET), - OPT_BIT(0, "ignore-submodules", &refresh_args.flags, + OPT_BIT(0, "ignore-submodules", &cd.flags, N_("refresh: ignore submodules"), REFRESH_IGNORE_SUBMODULES), OPT_SET_INT(0, "add", &allow_add, @@ -992,18 +999,18 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) N_("let files replace directories and vice-versa"), 1), OPT_SET_INT(0, "remove", &allow_remove, N_("notice files missing from worktree"), 1), - OPT_BIT(0, "unmerged", &refresh_args.flags, + OPT_BIT(0, "unmerged", &cd.flags, N_("refresh even if index contains unmerged entries"), REFRESH_UNMERGED), - OPT_CALLBACK_F(0, "refresh", &refresh_args, NULL, + OPT_CALLBACK_F(0, "refresh", &cd, NULL, N_("refresh stat information"), PARSE_OPT_NOARG | PARSE_OPT_NONEG, refresh_callback), - OPT_CALLBACK_F(0, "really-refresh", &refresh_args, NULL, + OPT_CALLBACK_F(0, "really-refresh", &cd, NULL, N_("like --refresh, but ignore assume-unchanged setting"), PARSE_OPT_NOARG | PARSE_OPT_NONEG, really_refresh_callback), - {OPTION_LOWLEVEL_CALLBACK, 0, "cacheinfo", NULL, + {OPTION_LOWLEVEL_CALLBACK, 0, "cacheinfo", &cd, N_(",,"), N_("add the specified entry to the index"), PARSE_OPT_NOARG | /* disallow --cacheinfo= form */ @@ -1032,30 +1039,30 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) N_("add to index only; do not add content to object database"), 1), OPT_SET_INT(0, "force-remove", &force_remove, N_("remove named paths even if present in worktree"), 1), - OPT_BOOL('z', NULL, &nul_term_line, + OPT_BOOL('z', NULL, &cd.nul_term_line, N_("with --stdin: input lines are terminated by null bytes")), - {OPTION_LOWLEVEL_CALLBACK, 0, "stdin", &read_from_stdin, NULL, + {OPTION_LOWLEVEL_CALLBACK, 0, "stdin", &cd, NULL, N_("read list of paths to be updated from standard input"), PARSE_OPT_NONEG | PARSE_OPT_NOARG, NULL, 0, stdin_callback}, - {OPTION_LOWLEVEL_CALLBACK, 0, "index-info", &nul_term_line, NULL, + {OPTION_LOWLEVEL_CALLBACK, 0, "index-info", &cd, NULL, N_("add entries from standard input to the index"), PARSE_OPT_NONEG | PARSE_OPT_NOARG, NULL, 0, stdin_cacheinfo_callback}, - {OPTION_LOWLEVEL_CALLBACK, 0, "unresolve", &has_errors, NULL, + {OPTION_LOWLEVEL_CALLBACK, 0, "unresolve", &cd, NULL, N_("repopulate stages #2 and #3 for the listed paths"), PARSE_OPT_NONEG | PARSE_OPT_NOARG, NULL, 0, unresolve_callback}, - {OPTION_LOWLEVEL_CALLBACK, 'g', "again", &has_errors, NULL, + {OPTION_LOWLEVEL_CALLBACK, 'g', "again", &cd, NULL, N_("only update entries that differ from HEAD"), PARSE_OPT_NONEG | PARSE_OPT_NOARG, NULL, 0, reupdate_callback}, - OPT_BIT(0, "ignore-missing", &refresh_args.flags, + OPT_BIT(0, "ignore-missing", &cd.flags, N_("ignore files missing from worktree"), REFRESH_IGNORE_MISSING), OPT_SET_INT(0, "verbose", &verbose, N_("report actions to standard output"), 1), - OPT_CALLBACK_F(0, "clear-resolve-undo", NULL, NULL, + OPT_CALLBACK_F(0, "clear-resolve-undo", &cd, NULL, N_("(for porcelains) forget saved unresolved conflicts"), PARSE_OPT_NOARG | PARSE_OPT_NONEG, resolve_undo_clear_callback), @@ -1087,8 +1094,6 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) git_config(git_default_config, NULL); - repo = the_repository; - /* we will diagnose later if it turns out that we need to update it */ newfd = repo_hold_locked_index(repo, &lock_file, 0); if (newfd < 0) @@ -1098,8 +1103,13 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) if (entries < 0) die("cache corrupted"); - istate = repo->index; + cd.repo = repo; + cd.istate = istate = repo->index; istate->updated_skipworktree = 1; + cd.flags = 0; + cd.has_errors = 0; + cd.nul_term_line = 0; + cd.read_from_stdin = 0; /* * Custom copy of parse_options() because we want to handle @@ -1145,7 +1155,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) } argc = parse_options_end(&ctx); - getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf; + getline_fn = cd.nul_term_line ? strbuf_getline_nul : strbuf_getline_lf; if (preferred_index_format) { if (preferred_index_format < INDEX_FORMAT_LB || INDEX_FORMAT_UB < preferred_index_format) @@ -1158,14 +1168,14 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) istate->version = preferred_index_format; } - if (read_from_stdin) { + if (cd.read_from_stdin) { struct strbuf buf = STRBUF_INIT; struct strbuf unquoted = STRBUF_INIT; setup_work_tree(); while (getline_fn(&buf, stdin) != EOF) { char *p; - if (!nul_term_line && buf.buf[0] == '"') { + if (!cd.nul_term_line && buf.buf[0] == '"') { strbuf_reset(&unquoted); if (unquote_c_style(&unquoted, buf.buf, NULL)) die("line is badly quoted"); @@ -1244,7 +1254,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) if (istate->cache_changed || force_write) { if (newfd < 0) { - if (refresh_args.flags & REFRESH_QUIET) + if (cd.flags & REFRESH_QUIET) exit(128); unable_to_lock_die(get_index_file(), lock_error); } @@ -1254,5 +1264,5 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) rollback_lock_file(&lock_file); - return has_errors ? 1 : 0; + return cd.has_errors ? 1 : 0; }