From patchwork Fri Jan 8 20:02:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12007407 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 64898C433E6 for ; Fri, 8 Jan 2021 20:03:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 319E923ABA for ; Fri, 8 Jan 2021 20:03:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729007AbhAHUDn (ORCPT ); Fri, 8 Jan 2021 15:03:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728929AbhAHUDl (ORCPT ); Fri, 8 Jan 2021 15:03:41 -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 64D5EC0612FD for ; Fri, 8 Jan 2021 12:03:01 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id n16so7341704wmc.0 for ; Fri, 08 Jan 2021 12:03:01 -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=qvvuC/ZH7zFw+fPwNQG2/+MFpZ/Hx73u7ux4o0zirfEfg4M8pa7g6cZU9wyeqFtl87 T1pD4aBPXYC6WJbuynvr0j5YM+eX9/LW7Pqq3rb2U8iuLBitdJQIzIfOBknujvZCO3pt iHdlpjBfVtFvfia2jfKuuam5sT7cLgLdADvRcG4aF+q/9XNwKysTHC9dzRMTM8KlPFJa wpes8iaZGitzAUgW2MIJA5OKxc+P/m14H+uf1JLAVmOTZTK7gPU4tW/7vAaT0CmOXF8a GXB9gNW9Z9akBUABMZL4GlXq6llUjkLXAsymZXco0M+wlTn0Bf6aQSfowEXl6ulp8raJ ta6w== 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=bfrRa1/5a6/uGKKY8ANqU4RY0M/4nPRqiDzBjANPrESq5Ph9FM5uq1kPS5WGM16oCi 6Lmr2ewtthqpGHgezL4uf1RXUEyukaLZHW0AxEfr3iGvwnf8+hGzRX+GrDXiRwVeq9/P cZYjWyNV/6xW0efjAi7/neAxSzMt0TUJ6meBgAn//gCDMMT45F2khmFc44+ZTUTOnPGu dHmXOPpfHfh/Ewwf8mGDKWyFD2XvLDkyEpiRMvQDOrCBm1GVwan6A4FmywhISFJwy75/ cuouOW0NfeX3YpdImOic8SP5ALkVsF9jKV6T+8Jdo/j7+U0KkPbOUsAwyZrzu8jPaUQ0 2wmQ== X-Gm-Message-State: AOAM530cYgug6v1l2IVox4I40/rLIM9oQlsuQRIArrlDA3IlZj/6/x9d w1c4EzzFCUxzQzLTeX43oblsd+WtTTo= X-Google-Smtp-Source: ABdhPJxBloawJapOBgteUtKilsRyX36S4x3v1VMeJcjKxYfGsUnxQDqbi6WA5j+1un/b/NH8TWwSrg== X-Received: by 2002:a1c:68d6:: with SMTP id d205mr4527463wmc.154.1610136179822; Fri, 08 Jan 2021 12:02:59 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v1sm12950909wmj.31.2021.01.08.12.02.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 12:02:59 -0800 (PST) Message-Id: <5ccc464cf268476932197c790693e1ecea9e778c.1610136177.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 08 Jan 2021 20:02:44 +0000 Subject: [PATCH v3 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 Fri Jan 8 20:02:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12007409 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,URIBL_BLOCKED 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 A37D7C433E9 for ; Fri, 8 Jan 2021 20:03:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 798C123ABA for ; Fri, 8 Jan 2021 20:03:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729016AbhAHUDp (ORCPT ); Fri, 8 Jan 2021 15:03:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728940AbhAHUDm (ORCPT ); Fri, 8 Jan 2021 15:03:42 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F367C0612FE for ; Fri, 8 Jan 2021 12:03:02 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id k10so8726828wmi.3 for ; Fri, 08 Jan 2021 12:03:02 -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=J+XxQG+XP94VCSQQnLLN1myWSFh8tEVaBEvCpQVguuK0NsRpaLJvp7BuipqjTbySM4 0/3yQdg3trvvWeM7E7P6L+oLt6mCQg0D0iihW6ncdrCJUdoOtHWwl3+PqK/5+mOKqjLJ MFLJSjqyXU7OVuRd3Fri3hyv1VftcSVSF8zSIUw1TljxdXhwzoBjv7jlGuXYthqPNQhR H7A57wR1IVjHkN01bPsslmcd65xFziAhKhqGCOVJYTpMHhmrJnXI/d+0rztb7lwHqaTg LvxBB2qCVxlu14cV8QhhJJ30h8ZOJNNNi/zTyBDC2ZhLKvsc21wZgTluCEaKBsXZvblU GeAw== 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=R97e7J9QXOPMvsp9njkS90IP0mT89yUW7gOJ7U9dn3wJmmLyprAgDg141dOCm8JYLO jxiWp/YeChZ3XOaQZrRhyKQYlXv4eCTLz8oHHx+JWroL7BYwNVly2m9t019K0G9TJTA/ hkxeDtZv5+ek0ZqB1d/7nNE8oVYi0P5NfbM1UBoj24RW+IqNgpzPAwlVyuxK2XLrC2Xw 182ZDdh5hVCXtpG86sHxa2ODqBbRsH3o8PwIxk1ZILZeiKz4G2gcF5oXAdVusp4fXuKx ffvdHnGTj+SlD5SVzB7WaYPdpvm1sloOSuK7pP/K4zhfr8VTomJAQwGRfnFFA/DrmPRS gShw== X-Gm-Message-State: AOAM53161PVuJP3P/EoX9ctG9sYTefOzVIoLWe/yOyjo7SxuYD9I+Izc qpWVwn4JirUAm4m0FIUDzScjL7AS3y4= X-Google-Smtp-Source: ABdhPJwwEBMDci69IAy7gQTHkeX2jDyeyfx6aF5bn4JV3AsmVEE7G+9sqkxafDCX+3EGC+eDASg0Gw== X-Received: by 2002:a1c:98cc:: with SMTP id a195mr4519787wme.150.1610136180736; Fri, 08 Jan 2021 12:03:00 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c81sm13493311wmd.6.2021.01.08.12.03.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 12:03:00 -0800 (PST) Message-Id: In-Reply-To: References: Date: Fri, 08 Jan 2021 20:02:45 +0000 Subject: [PATCH v3 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 Fri Jan 8 20:02:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12007415 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 CB7B3C433DB for ; Fri, 8 Jan 2021 20:04:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8123923AC2 for ; Fri, 8 Jan 2021 20:04:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729020AbhAHUD7 (ORCPT ); Fri, 8 Jan 2021 15:03:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728853AbhAHUD6 (ORCPT ); Fri, 8 Jan 2021 15:03:58 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A905C0612FF for ; Fri, 8 Jan 2021 12:03:03 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id c133so8722622wme.4 for ; Fri, 08 Jan 2021 12:03:03 -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=sYrG+Tmjs3a0QRrDXQB7FAfyXPu2y77OsT88XEQh6vk=; b=ph7t2RFFL9u+htDkCXQ53KD2lA5LvCcsO1tnVTFgQhyknMZQXRyBRSQdqGI7cYvoRW Mz9MGIEAQBVSgcSDjvV9h7hjWVthMjAyghf2A+Z1XWhVkZtPvIXfx/tpOG5v3z0ZFKya 8A5znplnMllHlJjRIU50lliQlGak4yJcBI+/zbe4YOmMVSjuNib/o0znXgRGrAoeyZXE RUXuTtxtCkrpUq2xzBgoDDTFvGY83I0B5pNcmq1ySzT+1snmNmBXV4Trj6BLfKuKfO8W INGK7Au/d2nGQuXTzZxK284iFNE4yx7b+RL6VXtyX3ql5gLG0h+XcmWPIjtur8Q2VWK7 /TWA== 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=sYrG+Tmjs3a0QRrDXQB7FAfyXPu2y77OsT88XEQh6vk=; b=ncYd/jTIRPAgnCEQW6Egyh3mYsuJzDR91cMhjp28JZvSUhdbZ8HYpeXbFsYaeCrjfY uKIrteOYSGh8m8f6Kpzust8AJsZ1iUYiahkIfZLhArAgnvFPzBlcP2B8PGe+Aq3eLchp LcpEwDxfx/go7g77humIhSWT2qhb1fFO3GS37xtv4s1ipQGa6mdmuiYOCtgizIsTAgll 4B2eJFJHjMTGTY1pf98wWrpXRkneBgKgBFqTah1YssseX25/GVVTk2av2m4iZYFwK2Ej eM4frk4+pkCcXG2eEuX1Q8nGfzm/sBAJsW4B51h9A1ONDEldbPsaZqmJJAbwWuUvLhoW EP6A== X-Gm-Message-State: AOAM532v8PpyjE2y2blaKJewp0hWJBG666GHFCpkxSFJoyp1MCOfTnLQ 9gaFnvEXExFtjL6br2Vlei3zIcajuFE= X-Google-Smtp-Source: ABdhPJxnOeBEyez7P0G4JXR1lvPhISZ/qHX4uXhli6Z21S0XVR6Hy6sgOrLzDABBFKuIw3NthY/s1Q== X-Received: by 2002:a1c:2c4:: with SMTP id 187mr4551164wmc.187.1610136181833; Fri, 08 Jan 2021 12:03:01 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u9sm13560640wmb.32.2021.01.08.12.03.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 12:03:01 -0800 (PST) Message-Id: In-Reply-To: References: Date: Fri, 08 Jan 2021 20:02:46 +0000 Subject: [PATCH v3 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. We will be careful to use "repo->index" over "istate" whenever repo is needed by a method. 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..22284f301dc 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -227,18 +227,20 @@ static int test_if_untracked_cache_is_supported(void) return ret; } +static struct index_state *istate; + 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 +279,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 +408,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; @@ -583,6 +585,7 @@ 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 cache_entry *read_one_ent(const char *which, struct object_id *ent, const char *path, @@ -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(repo->index, 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(repo->index, 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; + repo->index->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 (repo->index->version != preferred_index_format) active_cache_changed |= SOMETHING_CHANGED; - the_index.version = preferred_index_format; + repo->index->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 (repo->index->split_index) + repo->index->cache_changed |= SPLIT_INDEX_ORDERED; else - add_split_index(&the_index); + add_split_index(repo->index); } 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(repo->index); } - 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(repo->index); 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(repo->index); 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(repo->index); 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(repo->index); 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(repo->index, &lock_file, COMMIT_LOCK)) die("Unable to write new index file"); } From patchwork Fri Jan 8 20:02:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12007413 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 8FB45C433E6 for ; Fri, 8 Jan 2021 20:04:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4C7E123ABA for ; Fri, 8 Jan 2021 20:04:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729030AbhAHUD7 (ORCPT ); Fri, 8 Jan 2021 15:03:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728940AbhAHUD6 (ORCPT ); Fri, 8 Jan 2021 15:03:58 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D5B7C06129C for ; Fri, 8 Jan 2021 12:03:04 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id m5so10107770wrx.9 for ; Fri, 08 Jan 2021 12:03:04 -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=4ogiS5dB7FcwEbFzUilxWg7l0FMJl93G7xV7dDQotmg=; b=RlJ6/ZnewnLuqgVkvAORcHSSojN978bDTRkr4ss8weYeQYpX/cCMwEfpfnL1xcai0Q sob0jaA3ramS6sdMEmy2fW4lNRXhR6lnuKCkQDZI0OgcXMs3OP5mG2pwYR128NryA4t8 WXK9c6l/cGOn2FnpIs6LJijVxSryzlau/tYpwrDprsrhVTb1+8uk8UH5+hxit41EpIB0 pVoUXqGywdalXChXiFGcrPXSWFNCeQQgDykTN/V7b/rKrS9HwKoOaKJqU6Vk2I7xiZwN NDyno34Vk4V+ap96uHsbLahixgBfrZpLTr8BLTqH2VzeFdZZCrWMO27a5bzwGfAIo34U qwXQ== 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=4ogiS5dB7FcwEbFzUilxWg7l0FMJl93G7xV7dDQotmg=; b=Z778Vfh4s0bgZsCqVg4JfP7Pfnh9xvs9IihVMbUa3HU2sSVEpUh6qspeUzAZ2+7IQm Ij77MaxtM1gqAOyBPTvG1zKQRzVS4KLIGD9CEseQOYj2tULyHdGrnIsC+TjBdBvP/AAE m73gxO75NEm94JJ0fXEXpHjdnb8ANcV56XYKg87esOjPcQInXbKlqNMxnfDgs2BEjpZN JvXTYhhuvXAmoWkkgFAiXR7BvTT+0XNeTSa4x87tpBd3AkVHQREt0E9VQ+eedv7xsM2s F/3l0j7LANk8YE4fbzwAKaZYE3GzDQNgdbfN1/5MKkMI3LvII3q6zqM51txIFQM9nRqQ 0V7w== X-Gm-Message-State: AOAM533Bfg4UrwWtG7dyBmFMFboONWva/JTPGvqnBdbKRO1jKQEXO+9/ Eu2A3vKcSAeOR1DLfYCVJEtDpi9nRIU= X-Google-Smtp-Source: ABdhPJzoeFL+c1KxBvu9pId6dS8hmbD1oBk0mqeNWLxWYNDQFPBZiurJgXLRqpHXmaq4ofew2nlxBQ== X-Received: by 2002:adf:e406:: with SMTP id g6mr5187850wrm.255.1610136182754; Fri, 08 Jan 2021 12:03:02 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l1sm14833161wrq.64.2021.01.08.12.03.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 12:03:02 -0800 (PST) Message-Id: In-Reply-To: References: Date: Fri, 08 Jan 2021 20:02:47 +0000 Subject: [PATCH v3 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 Also use repo->index over istate, when possible. 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 22284f301dc..0c5a10f5dba 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -234,12 +234,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; @@ -330,7 +330,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! */ @@ -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) { - const struct cache_entry *ce = active_cache[pos++]; + const struct cache_entry *ce = istate->cache[pos++]; if (strncmp(ce->name, path, len)) break; @@ -377,7 +377,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" @@ -428,7 +428,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 = repo->index->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 = repo->index->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 = repo->index->cache[pos]; struct cache_entry *old = NULL; int save_nr; char *path; From patchwork Fri Jan 8 20:02:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12007419 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 30EAEC433DB for ; Fri, 8 Jan 2021 20:04:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 02C5B23AC0 for ; Fri, 8 Jan 2021 20:04:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729050AbhAHUEV (ORCPT ); Fri, 8 Jan 2021 15:04:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727130AbhAHUEU (ORCPT ); Fri, 8 Jan 2021 15:04:20 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 504ABC06129D for ; Fri, 8 Jan 2021 12:03:05 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id n16so7341792wmc.0 for ; Fri, 08 Jan 2021 12:03:05 -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=xMtarFkCXXf3v10b7WLr59mTF67kLoe+kFVV2c39wR4=; b=nTpeTRX6nG63PjMNzj5vGMcYqsG1HQce/OEVG/mozIy8hSJ5/kBnV611qwfThVZeBv jB7w3NAvecFpcg+jlMy/u3AEzfidn8FicWDvwGrzKyL7HluyNAPZs5v+cnMpRgMih6i8 BkPDNNPcAFjhhDeY49eHA/n2eWLftQdhx2gOBV6C9rRHXtkpdLWDgz6SVKjDyhEglCh1 xUT713v5kLJaQmTzjUogLrb5CIQHvjbdqaDJ+JX3hr3znGx6VJ6RLLv/xxxsqQhYLahN 3SlNSyTfqfUFMjqZpaaNPd3mY8G6O5sh+awHpLRrVZip3lpdesfyRuBYKEnEs4ztRHuP knpQ== 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=xMtarFkCXXf3v10b7WLr59mTF67kLoe+kFVV2c39wR4=; b=k61TKiC//tKUceh8uSRoEnEdaGwr0MDyK4Tg1K915v5srfyX+OvA63GqbZ2K0EmKm6 omX4YOMsMhxpVjbw4XITtsk2432pmJp3UTWXunDIfjyB7VWbJWkgjahvkFQ5t4cIn7Up hb4Vdt2P5GcmYM2SY9SbNdLKbD8CMVSLvtVdffbM0782Ip4wjPBb4shtA/qtLIPlvx3/ 2HPTN0YnZO1yggQcDh2YEoa/k1LZ2+N0LQRoZhpY82GoNTRneyUifbck2hNjZCIe5Zzc PCoHgYRZdcNaW5ipJ1R16J748BeZXGAyQYVdCCQrSOnaBfTtrR44Tg4tmZf4nTtrQw8g Ssgg== X-Gm-Message-State: AOAM5328Sa6WWdyGWGZZyn1wN0SQCcYwTJZIkD3PfmREC3vfB+N/4ezm UtJCkdWEf5mC9TkxuX1q2nnPJquBmU8= X-Google-Smtp-Source: ABdhPJwK2yavMHMzD7Jelf84d0QHQUtQ0295GbL9+iO3Pkmaxg7i7HXEs/CR+VirmVTXoxegHCkhCg== X-Received: by 2002:a1c:c204:: with SMTP id s4mr4369110wmf.73.1610136183696; Fri, 08 Jan 2021 12:03:03 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s3sm12428162wmc.44.2021.01.08.12.03.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 12:03:03 -0800 (PST) Message-Id: <586371ee769f61cc42957bd53bd6a257eacec211.1610136177.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 08 Jan 2021 20:02:48 +0000 Subject: [PATCH v3 05/14] update-index: use istate->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 Also use "repo->index" over "istate" when possible. 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 0c5a10f5dba..2b03b29261b 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -345,7 +345,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 < repo->index->cache_nr) { const struct cache_entry *ce = repo->index->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 < repo->index->cache_nr) { const struct cache_entry *ce = repo->index->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 < repo->index->cache_nr; pos++) { const struct cache_entry *ce = repo->index->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', repo->index->cache_nr may decrease. */ - save_nr = active_nr; + save_nr = repo->index->cache_nr; path = xstrdup(ce->name); update_one(path); free(path); discard_cache_entry(old); - if (save_nr != active_nr) + if (save_nr != repo->index->cache_nr) goto redo; } clear_pathspec(&pathspec); From patchwork Fri Jan 8 20:02:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12007427 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 D1945C433E6 for ; Fri, 8 Jan 2021 20:04:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A06A723A01 for ; Fri, 8 Jan 2021 20:04:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729070AbhAHUEX (ORCPT ); Fri, 8 Jan 2021 15:04:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727130AbhAHUEW (ORCPT ); Fri, 8 Jan 2021 15:04:22 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38519C06129F for ; Fri, 8 Jan 2021 12:03:06 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id y23so9419012wmi.1 for ; Fri, 08 Jan 2021 12:03:06 -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=jO10ZIWybl1T7dDcsv1BvC3cxOd3MoOlPtprl9OSFoE=; b=AOCq7RElOa46POxXyK64f9ccC/c0K8/iAb8nvVNOvFEcBXNa1KyH2SJ8LflpcZG+kf hJIj3oq2SSMwW7DLOKU2xYtzzZC1r9BJ9Iyzhw4iDR+BuFwQxirZf3p/9pRw3K4YyypF KaLagjxm2BC6pro7q4m2f2anFCdgUtpaFxuB15tMPyGj+eNlsOcn7xGbpGVAp946l8ep bMyX0XjY8qkGC5eIqXUuyv2OOieX/G9vwyyNJH9s2t2BbHG4N2k2/HVEoXsF8tCn9GTk mFKDvCp1S7k+L9d9BVd5VQdHDc4OtmCpKopiHuBNcBFTYhvFAsPOjifK8K2/N4cyHwxf RSJw== 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=jO10ZIWybl1T7dDcsv1BvC3cxOd3MoOlPtprl9OSFoE=; b=N8NxJGXxvfWYy/SZOBtGv7vbOj9RhCyyaOk+Q4moa+KAeHPTYhGCS7PWSRyD0inyxx 8e+IkfFbKOiutlnyYRRnjOAzCvcoW+vj9MNNCZoo/Ekl6eK7sk/hvxocregN7JB11POk ocqJeJIpqvISxvyRuEcxZryx5UWdINyQ8Es/7maLsIquS1gX7wT0HSpqdt9kbgUnogVh Gl7VyLbqeRYJ3Nq2pbW2WnFGZDxQ3sZhIAw8mDa355wOUvoBcTUtjg9VBcSNiBNanefJ XD8oR2G5gWuEIYfBAi39ULI9aZWw1w83XpT8rHfOHFTqjOF+6qKaZzDYmRsO0heVVF39 HWSw== X-Gm-Message-State: AOAM530gHbLZG9moClqmcMmaxGYNgW7qucLf6TIuiR6dByHVjri5AhZg 5SrqpbFigtoKvwkY5KUjUfWb5ioeNAk= X-Google-Smtp-Source: ABdhPJzd4vMXl/WnyFEUXhHadquQiJS6dkC4rXkF9d2FfxiuUW2rPJNSKj4+7JoOsG3PYbBnaSSV5g== X-Received: by 2002:a7b:ce14:: with SMTP id m20mr4496430wmc.149.1610136184765; Fri, 08 Jan 2021 12:03:04 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u205sm13901116wme.42.2021.01.08.12.03.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 12:03:04 -0800 (PST) Message-Id: In-Reply-To: References: Date: Fri, 08 Jan 2021 20:02:49 +0000 Subject: [PATCH v3 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 2b03b29261b..70ca47e712c 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -241,7 +241,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; + repo->index->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; + repo->index->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 (repo->index->version != preferred_index_format) - active_cache_changed |= SOMETHING_CHANGED; + repo->index->cache_changed |= SOMETHING_CHANGED; repo->index->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 (repo->index->cache_changed || force_write) { if (newfd < 0) { if (refresh_args.flags & REFRESH_QUIET) exit(128); From patchwork Fri Jan 8 20:02: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: 12007421 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 A20A2C433E0 for ; Fri, 8 Jan 2021 20:04:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7BBE823AC0 for ; Fri, 8 Jan 2021 20:04:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729081AbhAHUEX (ORCPT ); Fri, 8 Jan 2021 15:04:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728694AbhAHUEW (ORCPT ); Fri, 8 Jan 2021 15:04:22 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26D91C0612A3 for ; Fri, 8 Jan 2021 12:03:07 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id n16so7341834wmc.0 for ; Fri, 08 Jan 2021 12:03:07 -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=PFxyY3CjN99QIFwMQAf6TXXsTDJK41SUyzIXVoFNe/Y=; b=n+Ru3JpCifiSBQkXrkxANrsfZ//GYoUlx+I0Wc4i5sjwIq9OEPrTYtzP9ruB3/ArCA Bsx04gQ4gejJ3qpRzMH5fpikgTZFfBkdAJ5qMEiJ7uYvcDvbYSaKclpEVi0923jjf3Zu uVO2Kx98CB3B2wVGItlJfbos3KGT8ZntsPQAI0p66FA7vGpsSUsrAVQ1+fr6SugmyYLH xflHqX3yfkm8CwhCg5QOYW4l/tJ7iiChtq0Ene1WOSL7WBnt/1tY633IIOqubwZxoJWu KHOzju8mwKoTVTWS8KJ0rLs37jLphQ1C5WpesY4xF/TJWnkmdQRhaIlyoyywaO4ZPAwi pPtg== 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=PFxyY3CjN99QIFwMQAf6TXXsTDJK41SUyzIXVoFNe/Y=; b=sZzQlCbna3h8gXVc1kvWf9F12mFXzxxHFjH6zZXdOWwjmIDtE23ww3Mlh+q00HMfMu pGQge0Kow7tkPGfkpz0hISARa+WyINgih4Z5iUrjvpixFLRdsA+g88JnwIi45Id4TqPV 8IdegFaEH3QEW+PuXeiozJI0MZJ2GDGa3g8jQ3537xyBUmuOz7br2wCX5BozkG2PR79d m4B0yYXDAGOan/BuQ+fFXYWD2EWUfaHm6zA8ejr6pUfjmsQvYZHCo8sBYsh5ebS2OG1w TyW6feyeGcfbYR67Ih//oiJb1l80HSQ39IqZriDniOR2438pQtxn5zjcxzt1YNwXG9IG 1rpA== X-Gm-Message-State: AOAM533VZDi1ee+HScD9kGftKj6v7wEdoRIv3yBzIqItkg/KLz7eqF4y R+XbT3GTrWvbL9X4Fh2jSduVNxG4IiI= X-Google-Smtp-Source: ABdhPJyMTwqwTAinBREFJrJ1R6uRIg17jWBMDSKa/gkrF0aQC43uxzLRCw5KHWbQtI2HqvBaJcopWw== X-Received: by 2002:a05:600c:2106:: with SMTP id u6mr4550271wml.4.1610136185693; Fri, 08 Jan 2021 12:03:05 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f7sm19570888wmc.1.2021.01.08.12.03.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 12:03:05 -0800 (PST) Message-Id: In-Reply-To: References: Date: Fri, 08 Jan 2021 20:02:50 +0000 Subject: [PATCH v3 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 70ca47e712c..a24b1fc90e4 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -232,7 +232,7 @@ static struct index_state *istate; 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) @@ -326,7 +326,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) { @@ -376,7 +376,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)) { /* @@ -425,7 +425,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(repo->index, path, namelen); if (0 <= pos) { /* already merged */ pos = unmerge_cache_entry_at(pos); From patchwork Fri Jan 8 20:02: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: 12007431 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 C493BC433DB for ; Fri, 8 Jan 2021 20:04:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9AF4F23AAC for ; Fri, 8 Jan 2021 20:04:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729096AbhAHUE2 (ORCPT ); Fri, 8 Jan 2021 15:04:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729057AbhAHUEW (ORCPT ); Fri, 8 Jan 2021 15:04:22 -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 15A25C0612A4 for ; Fri, 8 Jan 2021 12:03:08 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id v14so8728818wml.1 for ; Fri, 08 Jan 2021 12:03: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=ErszZlGN3ltMcK2sPORBKYvHBVvmshBvJvPsKViGnLY=; b=cGc52n5VMTpYMGiifyWv4LCnXcHfFCHJMKDUqNr7aLOOrtLRSceHSHsFHiWLf0fkVB NMPzGZ9ubpV0SvaJwuVIPemwieQXJFcseKM4BfHPZCN6q5WEDr694niK/EkflFofQvxy QbNNn6+G6pSWXcWDI/WwxN2eGup1HjGRAz0cPy0s/sJO9WCosMZUrvufXh6b6riqjQlR otp6eMf2eFDbxcHq9VeNmS5OAHhhGnfJP7FYPF67nPycBiQbWmDZ8jQ++1fb6KYQ8HFa 4GDwnKB6hCPNOVaLqM6pvO3aI1gSzRUgsJFI98zsdF1l+n4BXeCdl0p0D7huT1x6HAPm GGKg== 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=ErszZlGN3ltMcK2sPORBKYvHBVvmshBvJvPsKViGnLY=; b=lmhMthJ0LlB9zo5srMBZus8yLwUWMQhCuaWFnrDNdySUOTc6ACEVDBiLnOY9ezHXbJ luWGsgEgcnYWliNx22Mi03NZFRerTGUk+lwTL/T7i1J56uat7SRkT7DrhJylCJr8Bjc0 1s2ukeyxYy07gDC55EB1iePKdSxufoAaDA5SWvzQVHQ9gVVdwgfVt9siYqtnaQfFQyfI YE3QJ6sHt7GiO03y01uU4WmhJzO2EChxGUemO2x1ZD/FDqScccKgHNeM3zEYFONImmQj YHkPBeguGyNmOXve50BcAH4JjGdHStfHi5V0aZuVD6nNeDRN6WZLvmSF7MgffaRNRTKh 2LsA== X-Gm-Message-State: AOAM5316h5ueXyTbYmEUm8QVdo7nLg/bbSpzwH/o6Py8N+uiZJqYdQ4S v9kwNmLUr5BrRI2RW0Xlz6E178f9wrw= X-Google-Smtp-Source: ABdhPJwQFso1xXj6XhUO1/6bOR7flp8SrRRb3crtLZZAsi4hW8yf23EK994zY9vZ4jvblTgQEyTk8Q== X-Received: by 2002:a1c:8f:: with SMTP id 137mr4593241wma.4.1610136186694; Fri, 08 Jan 2021 12:03:06 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 189sm13654743wma.22.2021.01.08.12.03.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 12:03:06 -0800 (PST) Message-Id: <2eead833fbafdc3cb408532cdcb7e7bd0909d03a.1610136177.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 08 Jan 2021 20:02:51 +0000 Subject: [PATCH v3 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 a24b1fc90e4..87fbc580032 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -251,7 +251,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; } @@ -385,7 +385,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; } @@ -472,7 +472,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; @@ -555,7 +555,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(repo->index, 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 Fri Jan 8 20:02: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: 12007423 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 4EFF9C433DB for ; Fri, 8 Jan 2021 20:04:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 28A5D23A01 for ; Fri, 8 Jan 2021 20:04:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729085AbhAHUEY (ORCPT ); Fri, 8 Jan 2021 15:04:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729061AbhAHUEX (ORCPT ); Fri, 8 Jan 2021 15:04:23 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09C26C0612A5 for ; Fri, 8 Jan 2021 12:03:09 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id c124so8690177wma.5 for ; Fri, 08 Jan 2021 12:03: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=7ozUhWR+6ZY3BKwSXupnxTyk689IQLRDfnfUHNVtnhk=; b=oLu6q0BG7vCtqohM4yZPVepzNQM8b3Snb+T9tNvlBhNmrkCX9dFGnRx9CXeZ+leMB0 dkBvGWkB6T9NtG+Href+Qv5sIyrQMzwwImf8UfjFL8p8pHimzBYyoQIF8qzFJgS++j/n w0chjDVi+tSNzfXg25CGa6kdvgMNCWejlT6sVHDJ8B44iub04XhEj2RI1qScruOyptXt fDzAaLn36byYnRJpcrASV/qZkYY59N4Y2yxEYuHx9UA0i0L1nNiN+HG+sq3uE43JDjU+ FbpDXVHtHWn0fPlx/rZs07TeX7r5k96M25uCCf9KOU73VCDZBgzgEO6+n78MJtXr4Csj 6ddw== 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=7ozUhWR+6ZY3BKwSXupnxTyk689IQLRDfnfUHNVtnhk=; b=W/BE+gtv0WeU7Fh3i3Au6g8ld4d9ryICmpfUIB8iAEbw/SKlUlmIddnoMptBZx8OA5 WBzP+Eo5ArLjM/HXHq3h24024PjCHhlieTLjooAG9DfVasuWiSq70uno72vZgV1IGETl sVB1HFIo/GHuZtyRPym7gZMUML2nDCFziOMgqFQmoItoOACAvizkrrKmVzHQga+MJ5Ts 5u/4E9/LJIY3YFFiCcQjiORWrZquSlrO9pk92Jkivjdfhyo/OLsvMrq50vHQpUZkXaPu ZYZcIyl269KXAHMOCl6emzlVuowv9QMB0x2zGjEbuIsI/H3jxM65c8cOp3kq3h/mxZWm 5NNg== X-Gm-Message-State: AOAM532+iqYDT8FBRb2lRCmNZUxA5EsZ9gSlxRjZFJec+HXNMcW/lnLc FezNgZY9znfxXE+fn/wHGHAgEXDSZsk= X-Google-Smtp-Source: ABdhPJyA/zeNjUIVlqDxnO9/zX+FL58Lca1tmqVfqVDc6go43/u9c1EB/zgcaUgI8s3F5UXwHeQygA== X-Received: by 2002:a1c:2394:: with SMTP id j142mr4548928wmj.42.1610136187586; Fri, 08 Jan 2021 12:03:07 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e17sm14680772wrw.84.2021.01.08.12.03.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 12:03:07 -0800 (PST) Message-Id: <8016b089556c7ae3633480a4e11c0b2ef055cd42.1610136177.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 08 Jan 2021 20:02:52 +0000 Subject: [PATCH v3 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 87fbc580032..a1e4ee89056 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -293,7 +293,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(repo->index, path); - if (add_cache_entry(ce_2, ADD_CACHE_OK_TO_ADD)) { + if (add_index_entry(repo->index, ce_2, ADD_CACHE_OK_TO_ADD)) { error("%s: cannot add our version to the index.", path); ret = -1; goto free_return; } - if (!add_cache_entry(ce_3, ADD_CACHE_OK_TO_ADD)) + if (!add_index_entry(repo->index, ce_3, ADD_CACHE_OK_TO_ADD)) return 0; error("%s: cannot add their version to the index.", path); ret = -1; From patchwork Fri Jan 8 20:02: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: 12007429 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 22987C433E0 for ; Fri, 8 Jan 2021 20:04:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB2DC23AAA for ; Fri, 8 Jan 2021 20:04:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729093AbhAHUE0 (ORCPT ); Fri, 8 Jan 2021 15:04:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727130AbhAHUEX (ORCPT ); Fri, 8 Jan 2021 15:04:23 -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 E60ABC0612A6 for ; Fri, 8 Jan 2021 12:03:09 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id 190so8745123wmz.0 for ; Fri, 08 Jan 2021 12:03: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=+37K2Cpfk5xUV/APXn1+LZ0XFNT5/nJxATiZzmdqwwA=; b=KbOcdrOkeBc9iiklD66EMYLDvecmI6HH/Eo+TjSe+IHBIywGmj8zLVBuw9NsGnPIW+ 8yHOa+IDQQRVIP6Gqum0ni32+dBRnNc+54VJQo+XvA1AchLMkQTyZAB0SnToVdj8ySjr n7WB5DUnX53ec3y+6XTJ+Iclatg7wPgFI4C5Kzouz/mjo2PvD2bUL46vCwpRlHNUktB5 Dx9/q3ge03uk4Icw5ZBbY0i/ctgPTEB7sCNZuB8cGEthqanJsKRn69kFkQac9Mv1/ZbV gcFCRsTnZAbXJ8faNsxOgsz4EH0ZCuSAiTOKLoHDB2cvOjCdDq4rkUhZ0kD3R6v7gLo3 cJgg== 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=+37K2Cpfk5xUV/APXn1+LZ0XFNT5/nJxATiZzmdqwwA=; b=ML/Fx6LdTC9wVq6/fQprqEyUQbTYb1tqhxThbRwaa2/MlwUiVXbe8RU/K226YWH/S6 yixrO9vbPZimjUKQ7IzJ7OKafvLLI38sdYbY6k9KZAvCZeXvoy5CYPbe5mYmjdsG0DZ1 1Ku6lrkuVzL7nevZ0sT9SstR4UttJdemCxpK4YzFYCCXlOSvzUh7sr6yrD6JAbnX4Okm ug99YC1U7UsBdKn48pO3RgeK6a4kILwRsjr+FXS6ZQvheV/F8El8zDfooRrQmqxAFz7W eEQ6NbwIapXyOrMSDODwGvYV6luhLRUCVcUst7yU1O6twWUrvqyl6KHfsgy1lM6lwIiL FVhA== X-Gm-Message-State: AOAM533IuDKHL9c47wNbyycVit09IL5+gBCMcp2L4t7I55njWG89yFAD 3Fy6fqii43dpY/obj9BzZOJQcJBdANU= X-Google-Smtp-Source: ABdhPJwhwxdLitNqWGxiJhnO7U6y5LSn5QjP4lE8O+wJ4tvF/8QQguheBt7APrftjTB+EI3pbeNA2A== X-Received: by 2002:a1c:e342:: with SMTP id a63mr4606471wmh.64.1610136188541; Fri, 08 Jan 2021 12:03:08 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h9sm14475033wre.24.2021.01.08.12.03.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 12:03:08 -0800 (PST) Message-Id: In-Reply-To: References: Date: Fri, 08 Jan 2021 20:02:53 +0000 Subject: [PATCH v3 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 a1e4ee89056..64feb47c97f 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -429,7 +429,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(repo->index, path, namelen); if (0 <= pos) { /* already merged */ - pos = unmerge_cache_entry_at(pos); + pos = unmerge_index_entry_at(repo->index, pos); if (pos < repo->index->cache_nr) { const struct cache_entry *ce = repo->index->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(repo->index, 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(repo->index); 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 Fri Jan 8 20:02: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: 12007425 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 F3221C433E9 for ; Fri, 8 Jan 2021 20:04:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C9C9023A80 for ; Fri, 8 Jan 2021 20:04:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729090AbhAHUEZ (ORCPT ); Fri, 8 Jan 2021 15:04:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729073AbhAHUEX (ORCPT ); Fri, 8 Jan 2021 15:04:23 -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 D2FE7C0612A7 for ; Fri, 8 Jan 2021 12:03:10 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id t30so10157011wrb.0 for ; Fri, 08 Jan 2021 12:03: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=tfHl/JvvFkcclxfk74hs+6J1R6G8s7cxlIqUHRLIFj4=; b=CyAPkxP061z2CASw6dZSCp+vGIZzPUOmXCBs8Ki11k4Sz8u/1QVSJXbrX85mOioU08 c2bKThFPx/2R3g7gGwrSy5giqgfyzv0Wgpqlj5u5ARvMFYmNf/VLWXK2UBcceXp5Hn0W 5zjcoXyftSSMi/z5HVWX6eTujDvkGbXsg/FqUJNGqywo2woFulmjW76FsN/RuCZk82zw RDybD+RYcBin3gw+XLRz1sSNDosQzUrPw50tr9KOO7Pj0eDLPVhoS4eEMx9e5zXHNHMl uRel25GqJc76iGFX9z68WKeEwsg9JPyGxVeU52ea4nLRxCHeuQLmZEezJt13qlyukHfQ 2JyA== 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=tfHl/JvvFkcclxfk74hs+6J1R6G8s7cxlIqUHRLIFj4=; b=Ff9fZYOixsmIM6ScpwyIVMCn7c9/0W+iabYVjvZyWMgaQXXJeqLbMrwR7/H0lH/L1v 0szqROPJ80AyI1fAYzqwvbRXmqAhvi5RsM/oGb7Ieu9CyjO58TU1qHAJLwUGWN40QzFj fTP/dR1fBTHYBb8ycJkMNSL/xQstye9vbaHsEv5p/fdDQ2Q017NCCB3TbGT2HGWWmoET bkeT/aXHN0b2nm6SHzXN8u3BSoONwNDJBiSpKXl+Fozp8SiVsMVRfSdEVI4/EWp1J0Nm vF2j8LsZeGi++hqlODcqwr9TY3V/S4F35hhzU6AaQcHfj/Pb16oNyZVxsjYtTu89mQDa TJCQ== X-Gm-Message-State: AOAM530KnYDLihmvWT2AiMbUwCVOtn8jYMDRfvWR7CplUt2FrAw++jYH x/o4M+wr6bKaBnrDe+Jw9BL8mynau3E= X-Google-Smtp-Source: ABdhPJwtnlqsc+lLWTOc9Glg0cPE/hcuujvb+IhMIVpwE6gTWJWI0LnJnrCaWWX6PVw6c5OZ6co6UA== X-Received: by 2002:adf:aad3:: with SMTP id i19mr5119101wrc.119.1610136189411; Fri, 08 Jan 2021 12:03:09 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q1sm14492677wrj.8.2021.01.08.12.03.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 12:03:08 -0800 (PST) Message-Id: In-Reply-To: References: Date: Fri, 08 Jan 2021 20:02:54 +0000 Subject: [PATCH v3 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 64feb47c97f..1c1cb8f8d4a 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" @@ -276,7 +275,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 Fri Jan 8 20:02: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: 12007417 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 5A9A3C433E0 for ; Fri, 8 Jan 2021 20:04:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3417923AC0 for ; Fri, 8 Jan 2021 20:04:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729035AbhAHUEO (ORCPT ); Fri, 8 Jan 2021 15:04:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727130AbhAHUEN (ORCPT ); Fri, 8 Jan 2021 15:04:13 -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 143AAC0612A8 for ; Fri, 8 Jan 2021 12:03:12 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id q18so10162021wrn.1 for ; Fri, 08 Jan 2021 12:03: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=fX/H5VOu/FRbxYrdaW1abnN3Wn3tasBSLM26Gwzwr5g=; b=UI1qfwHkS1wtHMgzCMA7+yNdTFF5yg9ylpI1A/ykk7TxJlcKrzXXdr22HGMxcM2Gll uLpf2d+U0b838qXe5IJcrLhhkKyoo2TNsDm4fpH1lOdQuBgk5yBRNktWUFlWEOSAbABW I2SIUh0z99RmllHOTexBPGrI1wRGSs0WsB77ZxSlDmguqpjgcqJ+vJkakkF1FCkSqQE6 pdCYMWInMtMcy5ezGtu6YAoYaiR7nqCXxa5DZdmYpSUmGel7BLh/xXBJF2Bk7bAL2TQX Aqzhf7knJ+EykC6splTDcFhKSBH6g6W8lVoNFWGY2RB1djb9FPlgHqbxSN8WUpUzUTI7 Ls9Q== 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=fX/H5VOu/FRbxYrdaW1abnN3Wn3tasBSLM26Gwzwr5g=; b=EY5r1u4txY9DfFFAyHnCjL/ROUtRU+Cxlx+vwBcA0QjQzoYEDcQdo72z2u07kt/uQ2 oJn02eDDy49hN2Ly1MAPSBHljBsN4c9s49YpaNTf//X7rohH2j1fCNdS1lzr86wsg0sa H69UepA7QLMtI9hxGxRz7wPc+u8IMJT6fIY9Y0JvZI8CB+VNJakVkWpiBv5sFBBZTfd+ Fp5s0Nq2dP/eo4QBjP2/1AgHvwLJk+Rly13lpvhIr6QYgjzdVbOmuL9GLrm3yTBP1Bwp /f3Eeyx15C7gYIY7a0b8tbRzMW3TOhfvpQ4ZAHtGVjwQs5Lu6KyBIev7yevsqK4yZhQr dOUw== X-Gm-Message-State: AOAM530KnY3/bpAghp7bYv7oJlzJIZOkXmjq76PtLwdLspGLwdDIzhfn aqWfPC44aCwmEHdd7vAPwKkdH1PIchk= X-Google-Smtp-Source: ABdhPJxTF2P5w4miAKAy9xriPxyyYctipw/LDi7Y0JwRPC+3vPB01ubdt0aFqAhUhoAtv3AityHOPA== X-Received: by 2002:adf:a34d:: with SMTP id d13mr5271089wrb.194.1610136190411; Fri, 08 Jan 2021 12:03:10 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v11sm14433682wrt.25.2021.01.08.12.03.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 12:03:09 -0800 (PST) Message-Id: <4754a9214ee9900302fc01501c4b15083ed2c2db.1610136177.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 08 Jan 2021 20:02:55 +0000 Subject: [PATCH v3 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. Remove the 'istate' static global in favor of method parameters. This adjusts some callers, which either use their own 'istate' parameter or 'repo->index'. Signed-off-by: Derrick Stolee --- builtin/update-index.c | 74 +++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/builtin/update-index.c b/builtin/update-index.c index 1c1cb8f8d4a..9a83603c0db 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -226,9 +226,8 @@ static int test_if_untracked_cache_is_supported(void) return ret; } -static struct index_state *istate; - -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); @@ -246,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); @@ -262,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; @@ -322,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); @@ -336,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? */ @@ -360,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; @@ -394,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; @@ -419,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; @@ -437,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; @@ -455,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; } @@ -476,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; @@ -564,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); } @@ -758,7 +767,7 @@ static int do_reupdate(int ac, const char **av, */ save_nr = repo->index->cache_nr; path = xstrdup(ce->name); - update_one(path); + update_one(repo->index, path); free(path); discard_cache_entry(old); if (save_nr != repo->index->cache_nr) @@ -854,7 +863,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(repo->index, mode, &oid, path, 0)) die("git update-index: --cacheinfo cannot add %s", path); ctx->argv++; ctx->argc--; @@ -864,7 +873,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(repo->index, mode, &oid, *++ctx->argv, 0)) die("git update-index: --cacheinfo cannot add %s", *ctx->argv); ctx->argc -= 3; return 0; @@ -882,7 +891,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(repo->index, *nul_term_line); return 0; } @@ -1079,7 +1088,6 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) if (entries < 0) die("cache corrupted"); - istate = repo->index; repo->index->updated_skipworktree = 1; /* @@ -1108,9 +1116,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(repo->index, p); if (set_executable_bit) - chmod_path(set_executable_bit, p); + chmod_path(repo->index, set_executable_bit, p); free(p); ctx.argc--; ctx.argv++; @@ -1153,9 +1161,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(repo->index, p); if (set_executable_bit) - chmod_path(set_executable_bit, p); + chmod_path(repo->index, set_executable_bit, p); free(p); } strbuf_release(&unquoted); From patchwork Fri Jan 8 20:02: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: 12007433 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 52651C433E0 for ; Fri, 8 Jan 2021 20:04:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 06F7F23AAC for ; Fri, 8 Jan 2021 20:04:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729110AbhAHUEj (ORCPT ); Fri, 8 Jan 2021 15:04:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729057AbhAHUEj (ORCPT ); Fri, 8 Jan 2021 15:04:39 -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 D64CCC0612A9 for ; Fri, 8 Jan 2021 12:03:12 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id d13so10071316wrc.13 for ; Fri, 08 Jan 2021 12:03: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=AKrjmO1/ZFbpcKjWQvaQLMrhMhS47QmP9byd4n49/9E=; b=YNmNOyIw98AJ7tqr9QHXc47mNYU6hjsuAMX+aATkvvxoF3RkSL73DCplM7nzWZumTV MdHMK1G4zxmW8BM5TLIt+By30R1S7ergSgP8lqgLHoZ+useippeOHTrwukuo3bICDPhy YhAdmyl391ufwEDBHZlRMD0C7CP8FRXwC95DKrMAasDjkIaHIDR5Z5a8pLwZutnvt39z YQcyqv7ZMg1aCdjqvPR/+6/XIM1QOfmVG7oM84pxfwJ8On9WwraCd9CD7rY0eOl/XiVm kfvVc24SR9mXGvn4CR/CVgvzxGkiECtdy3fKQdNOFGL64Kx4ablI5/OYbVQgOLA1lvM3 BauA== 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=AKrjmO1/ZFbpcKjWQvaQLMrhMhS47QmP9byd4n49/9E=; b=hZu9wFC+uw1uDNq0DCjsu1AaEffPgTv7ldu9YVdYQzQTgBhlIM9A0nu00HHVLp2ou6 R7lI4waqe063odtQ8CthgX4IytWSsrSlTCt3YeBknykVEk34AX13GwTqamGPcy5tn+ST CnhYQKDu/6Lb70YqCyqUnz+vpT2dKMqfCaXcLk++7tk59iyIZ8jChUfv/BB6WzZRh2Vz 87xIcXdoVujx6dWuTvY6jpv4IqbbUYPpsHUwNc/ibzvjVQnVrRdgxz++lkHHMc8cATaN 1Y1jpZcRufMk/38zk85Ir+BGmUg+uWQ9BjSLtnkhszskrDHoaYroGq+fPDQvU5W7YpNI nQFg== X-Gm-Message-State: AOAM530LthkSC79cJHyycnkk3yWwXMstjS7Y3mt6JGaICDYikeZud/hk 3zi5ObxYbOLuSiHekjmjP+IkzqGkgdE= X-Google-Smtp-Source: ABdhPJw4kdHJZKFyMF7Wokr311EWrJOrmCFIqcP1MEbrsYXSk/CHnIVZU/SdRebmP7OV2vWyjK3MCw== X-Received: by 2002:adf:c18d:: with SMTP id x13mr5129482wre.128.1610136191430; Fri, 08 Jan 2021 12:03:11 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c10sm14942505wrb.92.2021.01.08.12.03.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 12:03:10 -0800 (PST) Message-Id: In-Reply-To: References: Date: Fri, 08 Jan 2021 20:02:56 +0000 Subject: [PATCH v3 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 the remaining 'struct repository *repo' further down the file and use method parameters to pass it around instead. The only remaining change is to remove the static global entirely, but that requires updating the parse-opt callbacks, which need a different solution. Signed-off-by: Derrick Stolee --- builtin/update-index.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/builtin/update-index.c b/builtin/update-index.c index 9a83603c0db..3e01d62865f 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -593,9 +593,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 cache_entry *read_one_ent(const char *which, +static struct cache_entry *read_one_ent(struct repository *repo, + const char *which, struct object_id *ent, const char *path, int namelen, int stage) { @@ -623,7 +623,8 @@ 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, + const char *path) { int namelen = strlen(path); int pos; @@ -665,8 +666,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, "our", &head_oid, path, namelen, 2); + ce_3 = read_one_ent(repo, "their", &merge_head_oid, path, namelen, 3); if (!ce_2 || !ce_3) { ret = -1; @@ -705,7 +706,8 @@ static void read_head_pointers(void) } } -static int do_unresolve(int ac, const char **av, +static int do_unresolve(struct repository *repo, + int ac, const char **av, const char *prefix, int prefix_length) { int i; @@ -719,13 +721,14 @@ 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, p); free(p); } return err; } -static int do_reupdate(int ac, const char **av, +static int do_reupdate(struct repository *repo, + int ac, const char **av, const char *prefix) { /* Read HEAD and run update-index on paths that are @@ -754,7 +757,7 @@ static int do_reupdate(int ac, const char **av, if (ce_stage(ce) || !ce_path_match(repo->index, ce, &pathspec, NULL)) continue; if (has_head) - old = read_one_ent(NULL, &head_oid, + old = read_one_ent(repo, NULL, &head_oid, ce->name, ce_namelen(ce), 0); if (old && ce->ce_mode == old->ce_mode && oideq(&ce->oid, &old->oid)) { @@ -782,6 +785,8 @@ struct refresh_params { int *has_errors; }; +static struct repository *repo; + static int refresh(struct refresh_params *o, unsigned int flag) { setup_work_tree(); @@ -921,8 +926,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, ctx->argc, ctx->argv, + prefix, prefix ? strlen(prefix) : 0); if (*has_errors) repo->index->cache_changed = 0; @@ -943,7 +948,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, ctx->argc, ctx->argv, prefix); if (*has_errors) repo->index->cache_changed = 0; From patchwork Fri Jan 8 20:02: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: 12007435 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 3CA83C433DB for ; Fri, 8 Jan 2021 20:05:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB2C723AAC for ; Fri, 8 Jan 2021 20:05:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729118AbhAHUEy (ORCPT ); Fri, 8 Jan 2021 15:04:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728591AbhAHUEy (ORCPT ); Fri, 8 Jan 2021 15:04:54 -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 13B9FC0612AF for ; Fri, 8 Jan 2021 12:03:14 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id 91so10127751wrj.7 for ; Fri, 08 Jan 2021 12:03: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=jr9QSNZH0hJrEkZSU/fGXnrjyJtEjvE16udnwVcQxKA=; b=vWxvH/KQJh0gHLdEOCHns7Fd3q3WRiuuJXmjpmMsvYfphas/7ztHaS6P0KznlbTg4X UdFnOqKWaEiIAYS5+m/qhLgCJFr49pdIXyY++9pv2fWakjY7QlIaquyv0w140ifEwDGu fz4TP7Njwk/ApGZLGNyU1yeNILkkMTUY4JvcosGxo996RIyN2DOiGjRiO6Dh6fnxxMJJ sAsYkjuXrkkmigZYYfPHV9Ymqfa9go+vvyM1zZiAEF+GqOqezc7KIH7nC9zhIkQ48g/u Q+2aeVs8NEH0rWJPso7BxnLPZte86y3RglGDKLHBa7lTDS8Gooy5hmmFjURN9JO0M8kO kjhw== 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=jr9QSNZH0hJrEkZSU/fGXnrjyJtEjvE16udnwVcQxKA=; b=Khew5SWaGXOwrm6tc2h9gzFUKASTvQtn3/jCTWowQN+8gz4twgkPoXaAlMQ72GuXqu 65+EkGxfyrLA84MZjJFTkN8PzVwdy66A03WwsLRFTgsQ1e4tAcrWnC8UcJKtOOMM/76K CgiBQuuUdpXmiU5BMeHGhCLSayId81KaGIN2dTZAl0t2rrvKEi4GkafLFu2lGsw4tIzW 46oqetKhq5smFLKIg6eojG4SbuRQmaJD1og1E8KSFl4v8iNTxRxfmXCBTkaEPq8UXA1e wwNADqEaaSkZESVIRsbh7NDc2qZwvuc+jfo3CjRxoJbsgREkU4JcA1+3b3wy2Cb9VtE1 u0JQ== X-Gm-Message-State: AOAM532Qoazkk/dJHzvFFpnIawKCW13NDdZhLBhbf2IOcT25z547rxNJ vc9WSkgrOSgrwm/m83nEtYcgSZZYwfg= X-Google-Smtp-Source: ABdhPJxL1q/C2cPODntO+IdCOSh0DVJiCy9IXyWtDIeDFNmN78/Bbx3fkeCS9UEvx5+YxOcDeSMPQQ== X-Received: by 2002:adf:f60b:: with SMTP id t11mr5266365wrp.401.1610136192417; Fri, 08 Jan 2021 12:03:12 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o125sm13090315wmo.30.2021.01.08.12.03.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 12:03:11 -0800 (PST) Message-Id: <414ef816845b6e08dd0e3d9316f8ba3b9ae7d996.1610136177.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 08 Jan 2021 20:02:57 +0000 Subject: [PATCH v3 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 a 'repo' member, 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 | 104 ++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 48 deletions(-) diff --git a/builtin/update-index.c b/builtin/update-index.c index 3e01d62865f..2c67a870cdc 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -780,18 +780,20 @@ static int do_reupdate(struct repository *repo, return 0; } -struct refresh_params { +struct callback_data { + struct repository *repo; + unsigned int flags; - int *has_errors; + unsigned int has_errors; + unsigned nul_term_line; + unsigned read_from_stdin; }; -static struct repository *repo; - -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(repo->index, o->flags | flag, + repo_read_index(cd->repo); + cd->has_errors |= refresh_index(cd->repo->index, cd->flags | flag, NULL, NULL, NULL); return 0; } @@ -813,7 +815,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); @@ -824,11 +826,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(repo->index); + resolve_undo_clear_index(cd->repo->index); return 0; } @@ -863,12 +866,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(repo->index, mode, &oid, path, 0)) + if (add_cacheinfo(cd->repo->index, mode, &oid, path, 0)) die("git update-index: --cacheinfo cannot add %s", path); ctx->argv++; ctx->argc--; @@ -878,7 +882,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(repo->index, mode, &oid, *++ctx->argv, 0)) + add_cacheinfo(cd->repo->index, mode, &oid, *++ctx->argv, 0)) die("git update-index: --cacheinfo cannot add %s", *ctx->argv); ctx->argc -= 3; return 0; @@ -888,7 +892,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); @@ -896,7 +900,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(repo->index, *nul_term_line); + read_index_info(cd->repo->index, cd->nul_term_line); return 0; } @@ -904,14 +908,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; } @@ -919,17 +923,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, ctx->argc, ctx->argv, - prefix, prefix ? strlen(prefix) : 0); - if (*has_errors) - repo->index->cache_changed = 0; + cd->has_errors = do_unresolve(cd->repo, ctx->argc, ctx->argv, + prefix, prefix ? strlen(prefix) : 0); + if (cd->has_errors) + cd->repo->index->cache_changed = 0; ctx->argv += ctx->argc - 1; ctx->argc = 1; @@ -940,17 +944,17 @@ 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, ctx->argc, ctx->argv, prefix); - if (*has_errors) - repo->index->cache_changed = 0; + cd->has_errors = do_reupdate(cd->repo, ctx->argc, ctx->argv, prefix); + if (cd->has_errors) + cd->repo->index->cache_changed = 0; ctx->argv += ctx->argc - 1; ctx->argc = 1; @@ -959,13 +963,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; @@ -974,11 +978,12 @@ 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 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, @@ -987,18 +992,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 */ @@ -1027,30 +1032,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), @@ -1082,8 +1087,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) @@ -1094,6 +1097,11 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) die("cache corrupted"); repo->index->updated_skipworktree = 1; + cd.repo = repo; + 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 @@ -1139,7 +1147,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) @@ -1152,14 +1160,14 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) repo->index->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"); @@ -1238,7 +1246,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) if (repo->index->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); } @@ -1248,5 +1256,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; }