From patchwork Fri Oct 19 14:52:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10649583 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3AF8B17DE for ; Fri, 19 Oct 2018 14:52:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2AA692094F for ; Fri, 19 Oct 2018 14:52:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E9CB20950; Fri, 19 Oct 2018 14:52:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F34B920856 for ; Fri, 19 Oct 2018 14:52:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727602AbeJSW7N (ORCPT ); Fri, 19 Oct 2018 18:59:13 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:34777 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727492AbeJSW7N (ORCPT ); Fri, 19 Oct 2018 18:59:13 -0400 Received: by mail-lf1-f67.google.com with SMTP id n26-v6so6771972lfl.1 for ; Fri, 19 Oct 2018 07:52:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rt5ztErVSs1pVakzzWpWQ4IcbThJojPdHVybg6/ILdw=; b=uzGtSAZyxQfbpUKTgzRXAZeP11gi29psPX8NNFxySd/BShQqjMKCGWV0dQH7+AuIDG rB3h5eqcSbvu+CT37WctuRAP26oe7WCl7mwAunbRZi9wPn3RX2kzsDo1G0GuggekwxyC kAEZOt2c2LuZ1k2ilcg3gLyOW9V7/qBwdNOAHoGb3zBFiYy24o3rPLz0V3247PeVziZK TQnVYUIYdw9RMptTkDLAcIMUoEVLq4U4RPm8QkUFc18J3QBPnG4JZZEKIyGQ3Diw5chv tPCWRsye+lYN9Tk8cuYqhrqGJNZRiSBY7M1chHhsvRreTGyxQXFpxS6Itge++cHqxc5X itWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rt5ztErVSs1pVakzzWpWQ4IcbThJojPdHVybg6/ILdw=; b=d3kAJQO8n+RkVAW94GFjW9y9bjzVwmLhYgVzgTFKh+OhIXOQE9pmgp7TyRCYhbOltn 4XkU/2plhawUbLicGsR5lZCCNPCb3wbhzZqLXQPKgk0BPMLJldV9rpV0vUAb0MjxO1VA NZFF19oE5rq7E34RIZzTilbDbfSSZdseHfWbv3r+t1O6MZguy19lFavc5jkJksJs8pFW BP2AhBrNwMmVCBztklJh84nyAagh+Ja5acjtkDi1zq0OTo+m2576av9ml4vMD9TcDK4g fwCSna/4SAj+68M/mW8Ucp8F2kd0RY6a//nM6GbVdAVMwAjzUzulCSXJBKc2cBfjq66u b9BA== X-Gm-Message-State: ABuFfog2b1rL/5BgzVRwA2jLBm18gdUtEH5NHn2MhjVGE75+H9AgQqiZ HnmTb1c+LDU04ANrplmQ6QCJa83F X-Google-Smtp-Source: ACcGV63GA0ZwQ6bDR7Z9Dy1paKjJDzi5NqgeF88atxDG+w1vkvlvCA3k7KWEsEgSPeNMQhLtPjbc1Q== X-Received: by 2002:a19:d8d1:: with SMTP id r78-v6mr3395824lfi.146.1539960762714; Fri, 19 Oct 2018 07:52:42 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g64-v6sm4002414lfe.87.2018.10.19.07.52.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 07:52:42 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= Subject: [PATCH 01/19] wt-status.c: remove implicit dependency on the_index Date: Fri, 19 Oct 2018 16:52:19 +0200 Message-Id: <20181019145237.16079-2-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181019145237.16079-1-pclouds@gmail.com> References: <20181019145237.16079-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/commit.c | 2 +- builtin/pull.c | 3 +- sequencer.c | 6 ++-- wt-status.c | 77 +++++++++++++++++++++++++++--------------------- wt-status.h | 17 +++++++---- 5 files changed, 62 insertions(+), 43 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 074bd9a551..379d8c5cdf 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -185,7 +185,7 @@ static void determine_whence(struct wt_status *s) static void status_init_config(struct wt_status *s, config_fn_t fn) { - wt_status_prepare(s); + wt_status_prepare(s, the_repository); init_diff_ui_defaults(); git_config(fn, s); determine_whence(s); diff --git a/builtin/pull.c b/builtin/pull.c index 798ecf7faf..9b0fce07ca 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -888,7 +888,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix) die(_("Updating an unborn branch with changes added to the index.")); if (!autostash) - require_clean_work_tree(N_("pull with rebase"), + require_clean_work_tree(the_repository, + N_("pull with rebase"), _("please commit or stash them."), 1, 0); if (get_rebase_fork_point(&rebase_fork_point, repo, *refspecs)) diff --git a/sequencer.c b/sequencer.c index 0c164d5f98..90435593a4 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2712,7 +2712,7 @@ static int do_exec(const char *command_line) if (discard_cache() < 0 || read_cache() < 0) return error(_("could not read index")); - dirty = require_clean_work_tree("rebase", NULL, 1, 1); + dirty = require_clean_work_tree(the_repository, "rebase", NULL, 1, 1); if (status) { warning(_("execution failed: %s\n%s" @@ -3583,10 +3583,10 @@ static int commit_staged_changes(struct replay_opts *opts, unsigned int flags = ALLOW_EMPTY | EDIT_MSG; unsigned int final_fixup = 0, is_clean; - if (has_unstaged_changes(1)) + if (has_unstaged_changes(the_repository, 1)) return error(_("cannot rebase: You have unstaged changes.")); - is_clean = !has_uncommitted_changes(0); + is_clean = !has_uncommitted_changes(the_repository, 0); if (file_exists(rebase_path_amend())) { struct strbuf rev = STRBUF_INIT; diff --git a/wt-status.c b/wt-status.c index 187568a112..0378bc2a48 100644 --- a/wt-status.c +++ b/wt-status.c @@ -119,9 +119,11 @@ static void status_printf_more(struct wt_status *s, const char *color, va_end(ap); } -void wt_status_prepare(struct wt_status *s) +void wt_status_prepare(struct wt_status *s, + struct repository *repo) { memset(s, 0, sizeof(*s)); + s->repo = repo; memcpy(s->color_palette, default_wt_status_colors, sizeof(default_wt_status_colors)); s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES; @@ -494,19 +496,19 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q, } } -static int unmerged_mask(const char *path) +static int unmerged_mask(struct index_state *istate, const char *path) { int pos, mask; const struct cache_entry *ce; - pos = cache_name_pos(path, strlen(path)); + pos = index_name_pos(istate, path, strlen(path)); if (0 <= pos) return 0; mask = 0; pos = -pos-1; - while (pos < active_nr) { - ce = active_cache[pos++]; + while (pos < istate->cache_nr) { + ce = istate->cache[pos++]; if (strcmp(ce->name, path) || !ce_stage(ce)) break; mask |= (1 << (ce_stage(ce) - 1)); @@ -566,7 +568,8 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q, s->committable = 1; break; case DIFF_STATUS_UNMERGED: - d->stagemask = unmerged_mask(p->two->path); + d->stagemask = unmerged_mask(s->repo->index, + p->two->path); /* * Don't bother setting {mode,oid}_{head,index} since the print * code will output the stage values directly and not use the @@ -585,7 +588,7 @@ static void wt_status_collect_changes_worktree(struct wt_status *s) { struct rev_info rev; - repo_init_revisions(the_repository, &rev, NULL); + repo_init_revisions(s->repo, &rev, NULL); setup_revisions(0, NULL, &rev, NULL); rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK; rev.diffopt.flags.dirty_submodules = 1; @@ -610,7 +613,7 @@ static void wt_status_collect_changes_index(struct wt_status *s) struct rev_info rev; struct setup_revision_opt opt; - repo_init_revisions(the_repository, &rev, NULL); + repo_init_revisions(s->repo, &rev, NULL); memset(&opt, 0, sizeof(opt)); opt.def = s->is_initial ? empty_tree_oid_hex() : s->reference; setup_revisions(0, NULL, &rev, &opt); @@ -643,14 +646,15 @@ static void wt_status_collect_changes_index(struct wt_status *s) static void wt_status_collect_changes_initial(struct wt_status *s) { + struct index_state *istate = s->repo->index; int i; - for (i = 0; i < active_nr; i++) { + for (i = 0; i < istate->cache_nr; i++) { struct string_list_item *it; struct wt_status_change_data *d; - const struct cache_entry *ce = active_cache[i]; + const struct cache_entry *ce = istate->cache[i]; - if (!ce_path_match(&the_index, ce, &s->pathspec, NULL)) + if (!ce_path_match(istate, ce, &s->pathspec, NULL)) continue; if (ce_intent_to_add(ce)) continue; @@ -684,6 +688,7 @@ static void wt_status_collect_untracked(struct wt_status *s) int i; struct dir_struct dir; uint64_t t_begin = getnanotime(); + struct index_state *istate = s->repo->index; if (!s->show_untracked_files) return; @@ -698,25 +703,25 @@ static void wt_status_collect_untracked(struct wt_status *s) if (s->show_ignored_mode == SHOW_MATCHING_IGNORED) dir.flags |= DIR_SHOW_IGNORED_TOO_MODE_MATCHING; } else { - dir.untracked = the_index.untracked; + dir.untracked = istate->untracked; } setup_standard_excludes(&dir); - fill_directory(&dir, &the_index, &s->pathspec); + fill_directory(&dir, istate, &s->pathspec); for (i = 0; i < dir.nr; i++) { struct dir_entry *ent = dir.entries[i]; - if (cache_name_is_other(ent->name, ent->len) && - dir_path_match(&the_index, ent, &s->pathspec, 0, NULL)) + if (index_name_is_other(istate, ent->name, ent->len) && + dir_path_match(istate, ent, &s->pathspec, 0, NULL)) string_list_insert(&s->untracked, ent->name); free(ent); } for (i = 0; i < dir.ignored_nr; i++) { struct dir_entry *ent = dir.ignored[i]; - if (cache_name_is_other(ent->name, ent->len) && - dir_path_match(&the_index, ent, &s->pathspec, 0, NULL)) + if (index_name_is_other(istate, ent->name, ent->len) && + dir_path_match(istate, ent, &s->pathspec, 0, NULL)) string_list_insert(&s->ignored, ent->name); free(ent); } @@ -1009,7 +1014,7 @@ static void wt_longstatus_print_verbose(struct wt_status *s) int dirty_submodules; const char *c = color(WT_STATUS_HEADER, s); - repo_init_revisions(the_repository, &rev, NULL); + repo_init_revisions(s->repo, &rev, NULL); rev.diffopt.flags.allow_textconv = 1; rev.diffopt.ita_invisible_in_index = 1; @@ -1326,7 +1331,7 @@ static void show_rebase_in_progress(struct wt_status *s, _(" (use \"git rebase --abort\" to check out the original branch)")); } } else if (s->state.rebase_in_progress || - !stat(git_path_merge_msg(the_repository), &st)) { + !stat(git_path_merge_msg(s->repo), &st)) { print_rebase_state(s, color); if (s->hints) status_printf_ln(s, color, @@ -2135,6 +2140,7 @@ static void wt_porcelain_v2_print_unmerged_entry( struct wt_status *s) { struct wt_status_change_data *d = it->util; + struct index_state *istate = s->repo->index; const struct cache_entry *ce; struct strbuf buf_index = STRBUF_INIT; const char *path_index = NULL; @@ -2173,11 +2179,11 @@ static void wt_porcelain_v2_print_unmerged_entry( */ memset(stages, 0, sizeof(stages)); sum = 0; - pos = cache_name_pos(it->string, strlen(it->string)); + pos = index_name_pos(istate, it->string, strlen(it->string)); assert(pos < 0); pos = -pos-1; - while (pos < active_nr) { - ce = active_cache[pos++]; + while (pos < istate->cache_nr) { + ce = istate->cache[pos++]; stage = ce_stage(ce); if (strcmp(ce->name, it->string) || !stage) break; @@ -2302,12 +2308,12 @@ void wt_status_print(struct wt_status *s) /** * Returns 1 if there are unstaged changes, 0 otherwise. */ -int has_unstaged_changes(int ignore_submodules) +int has_unstaged_changes(struct repository *r, int ignore_submodules) { struct rev_info rev_info; int result; - repo_init_revisions(the_repository, &rev_info, NULL); + repo_init_revisions(r, &rev_info, NULL); if (ignore_submodules) { rev_info.diffopt.flags.ignore_submodules = 1; rev_info.diffopt.flags.override_submodule_config = 1; @@ -2321,15 +2327,16 @@ int has_unstaged_changes(int ignore_submodules) /** * Returns 1 if there are uncommitted changes, 0 otherwise. */ -int has_uncommitted_changes(int ignore_submodules) +int has_uncommitted_changes(struct repository *r, + int ignore_submodules) { struct rev_info rev_info; int result; - if (is_cache_unborn()) + if (is_index_unborn(r->index)) return 0; - repo_init_revisions(the_repository, &rev_info, NULL); + repo_init_revisions(r, &rev_info, NULL); if (ignore_submodules) rev_info.diffopt.flags.ignore_submodules = 1; rev_info.diffopt.flags.quick = 1; @@ -2340,7 +2347,7 @@ int has_uncommitted_changes(int ignore_submodules) * We have no head (or it's corrupt); use the empty tree, * which will complain if the index is non-empty. */ - struct tree *tree = lookup_tree(the_repository, the_hash_algo->empty_tree); + struct tree *tree = lookup_tree(r, the_hash_algo->empty_tree); add_pending_object(&rev_info, &tree->object, ""); } @@ -2353,24 +2360,28 @@ int has_uncommitted_changes(int ignore_submodules) * If the work tree has unstaged or uncommitted changes, dies with the * appropriate message. */ -int require_clean_work_tree(const char *action, const char *hint, int ignore_submodules, int gently) +int require_clean_work_tree(struct repository *r, + const char *action, + const char *hint, + int ignore_submodules, + int gently) { struct lock_file lock_file = LOCK_INIT; int err = 0, fd; fd = hold_locked_index(&lock_file, 0); - refresh_cache(REFRESH_QUIET); + refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL); if (0 <= fd) - update_index_if_able(&the_index, &lock_file); + update_index_if_able(r->index, &lock_file); rollback_lock_file(&lock_file); - if (has_unstaged_changes(ignore_submodules)) { + if (has_unstaged_changes(r, ignore_submodules)) { /* TRANSLATORS: the action is e.g. "pull with rebase" */ error(_("cannot %s: You have unstaged changes."), _(action)); err = 1; } - if (has_uncommitted_changes(ignore_submodules)) { + if (has_uncommitted_changes(r, ignore_submodules)) { if (err) error(_("additionally, your index contains uncommitted changes.")); else diff --git a/wt-status.h b/wt-status.h index 1fcf93afbf..84653595e3 100644 --- a/wt-status.h +++ b/wt-status.h @@ -7,6 +7,7 @@ #include "pathspec.h" #include "remote.h" +struct repository; struct worktree; enum color_wt_status { @@ -83,6 +84,7 @@ struct wt_status_state { }; struct wt_status { + struct repository *repo; int is_initial; char *branch; const char *reference; @@ -128,7 +130,7 @@ struct wt_status { size_t wt_status_locate_end(const char *s, size_t len); void wt_status_add_cut_line(FILE *fp); -void wt_status_prepare(struct wt_status *s); +void wt_status_prepare(struct wt_status *s, struct repository *repo); void wt_status_print(struct wt_status *s); void wt_status_collect(struct wt_status *s); void wt_status_collect_free_buffers(struct wt_status *s); @@ -144,9 +146,14 @@ __attribute__((format (printf, 3, 4))) void status_printf(struct wt_status *s, const char *color, const char *fmt, ...); /* The following functions expect that the caller took care of reading the index. */ -int has_unstaged_changes(int ignore_submodules); -int has_uncommitted_changes(int ignore_submodules); -int require_clean_work_tree(const char *action, const char *hint, - int ignore_submodules, int gently); +int has_unstaged_changes(struct repository *repo, + int ignore_submodules); +int has_uncommitted_changes(struct repository *repo, + int ignore_submodules); +int require_clean_work_tree(struct repository *repo, + const char *action, + const char *hint, + int ignore_submodules, + int gently); #endif /* STATUS_H */ From patchwork Fri Oct 19 14:52:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10649585 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4FB50109C for ; Fri, 19 Oct 2018 14:52:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3FB7520856 for ; Fri, 19 Oct 2018 14:52:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3407C209CC; Fri, 19 Oct 2018 14:52:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6347220881 for ; Fri, 19 Oct 2018 14:52:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727610AbeJSW7O (ORCPT ); Fri, 19 Oct 2018 18:59:14 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:34778 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726664AbeJSW7O (ORCPT ); Fri, 19 Oct 2018 18:59:14 -0400 Received: by mail-lf1-f66.google.com with SMTP id n26-v6so6772024lfl.1 for ; Fri, 19 Oct 2018 07:52:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RonBt4Cqb/kDe3nboghyGp87QDXg8lcdE88q2Wn0BGc=; b=F/iknlSa06I46fDUnKbZAIYJHetlcdA1LBgMYgauTrig7V6KLQbS+mTdnABQdn1M66 UzHaQJFRYkDUcbzLbAYsCRZX50ZAbaVHPggwpqtPA+KIIH9Y/LI8fFuQQx18F7p/sL+u EL3Nu6S/pTIZn5AR1jrBXV1Ybi2l0hB3+BwqeZrnXG7+PUEsuXAV3VhLnXTh9KNpoBZv 6EebFkN3w31+476cIXStu1udBxVstylY2SJ+wh3iNwDrygMtSJxFHrnYfPwyljzW2bIv LbSoJPDMs4eWYJ1stKi7B4K3QjDo/tawT3Uk+qg01wzEEE4s65Dr1vAOvvl+3AedVHV5 fjQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RonBt4Cqb/kDe3nboghyGp87QDXg8lcdE88q2Wn0BGc=; b=GWJUyS9gt3fLjYjF2sSehOzm/PkbFLjTGwUQT3cU3QJDqvyVgO56loWDBZ3QsNRavj qRT2TIy1LUQDmIdsCchiFdYGsnUpmYhuGvA+EwabHNiW09WHZMfePxvOYrcxtXYZeopU rnM00rE2zLwYGQ/SOMUcD586P1HraD4WwDhoVzVy7BwmPGUzKaONo3P0BMpqA8CmT1Lw BQ8j9M3/V9ldl24pEsXfjmHomxjKCykz81wDoVa+/YIGCdHvND7y1CsP7vjH4Se9D7Dg QOCmMWgcqFCaQXkAi9QKfJGihvhRCXN0F9HRFtW16dYen8lTKlTe9PnrRefVUd2ZqxF+ n+hw== X-Gm-Message-State: ABuFfoi0yIM0yqspFY2fD/6lky5wwoJ/VAM+9+ytSZt1eXItzAlRkJ2L JAb5HJB71tWZDaB9AuqJVeC5QQnx X-Google-Smtp-Source: ACcGV62jV2PIYThJ12dX/Z1BRhXlAfWq4xkyNVZEHqDb9/0guVjvKiRQiH/ogvhHbXizfpZao92+bg== X-Received: by 2002:a19:2a4b:: with SMTP id f72mr1610536lfl.139.1539960764173; Fri, 19 Oct 2018 07:52:44 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g64-v6sm4002414lfe.87.2018.10.19.07.52.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 07:52:43 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= Subject: [PATCH 02/19] wt-status.c: remove implicit dependency the_repository Date: Fri, 19 Oct 2018 16:52:20 +0200 Message-Id: <20181019145237.16079-3-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181019145237.16079-1-pclouds@gmail.com> References: <20181019145237.16079-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Nguyễn Thái Ngọc Duy --- ref-filter.c | 2 +- wt-status.c | 18 ++++++++++-------- wt-status.h | 4 +++- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index 2a05619211..d6d3923eb2 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1412,7 +1412,7 @@ char *get_head_description(void) struct strbuf desc = STRBUF_INIT; struct wt_status_state state; memset(&state, 0, sizeof(state)); - wt_status_get_state(&state, 1); + wt_status_get_state(the_repository, &state, 1); if (state.rebase_in_progress || state.rebase_interactive_in_progress) { if (state.branch) diff --git a/wt-status.c b/wt-status.c index 0378bc2a48..3632276236 100644 --- a/wt-status.c +++ b/wt-status.c @@ -756,7 +756,7 @@ void wt_status_collect(struct wt_status *s) wt_status_collect_changes_index(s); wt_status_collect_untracked(s); - wt_status_get_state(&s->state, s->branch && !strcmp(s->branch, "HEAD")); + wt_status_get_state(s->repo, &s->state, s->branch && !strcmp(s->branch, "HEAD")); if (s->state.merge_in_progress && !has_unmerged(s)) s->committable = 1; } @@ -1483,7 +1483,8 @@ static int grab_1st_switch(struct object_id *ooid, struct object_id *noid, return 1; } -static void wt_status_get_detached_from(struct wt_status_state *state) +static void wt_status_get_detached_from(struct repository *r, + struct wt_status_state *state) { struct grab_1st_switch_cbdata cb; struct commit *commit; @@ -1500,7 +1501,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state) /* sha1 is a commit? match without further lookup */ (oideq(&cb.noid, &oid) || /* perhaps sha1 is a tag, try to dereference to a commit */ - ((commit = lookup_commit_reference_gently(the_repository, &oid, 1)) != NULL && + ((commit = lookup_commit_reference_gently(r, &oid, 1)) != NULL && oideq(&cb.noid, &commit->object.oid)))) { const char *from = ref; if (!skip_prefix(from, "refs/tags/", &from)) @@ -1557,30 +1558,31 @@ int wt_status_check_bisect(const struct worktree *wt, return 0; } -void wt_status_get_state(struct wt_status_state *state, +void wt_status_get_state(struct repository *r, + struct wt_status_state *state, int get_detached_from) { struct stat st; struct object_id oid; - if (!stat(git_path_merge_head(the_repository), &st)) { + if (!stat(git_path_merge_head(r), &st)) { state->merge_in_progress = 1; } else if (wt_status_check_rebase(NULL, state)) { ; /* all set */ - } else if (!stat(git_path_cherry_pick_head(the_repository), &st) && + } else if (!stat(git_path_cherry_pick_head(r), &st) && !get_oid("CHERRY_PICK_HEAD", &oid)) { state->cherry_pick_in_progress = 1; oidcpy(&state->cherry_pick_head_oid, &oid); } wt_status_check_bisect(NULL, state); - if (!stat(git_path_revert_head(the_repository), &st) && + if (!stat(git_path_revert_head(r), &st) && !get_oid("REVERT_HEAD", &oid)) { state->revert_in_progress = 1; oidcpy(&state->revert_head_oid, &oid); } if (get_detached_from) - wt_status_get_detached_from(state); + wt_status_get_detached_from(r, state); } static void wt_longstatus_print_state(struct wt_status *s) diff --git a/wt-status.h b/wt-status.h index 84653595e3..9dde7091f6 100644 --- a/wt-status.h +++ b/wt-status.h @@ -134,7 +134,9 @@ void wt_status_prepare(struct wt_status *s, struct repository *repo); void wt_status_print(struct wt_status *s); void wt_status_collect(struct wt_status *s); void wt_status_collect_free_buffers(struct wt_status *s); -void wt_status_get_state(struct wt_status_state *state, int get_detached_from); +void wt_status_get_state(struct repository *repo, + struct wt_status_state *state, + int get_detached_from); int wt_status_check_rebase(const struct worktree *wt, struct wt_status_state *state); int wt_status_check_bisect(const struct worktree *wt, From patchwork Fri Oct 19 14:52:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10649587 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7A98E3CF1 for ; Fri, 19 Oct 2018 14:52:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 66C7A205FD for ; Fri, 19 Oct 2018 14:52:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5AFFF20881; Fri, 19 Oct 2018 14:52:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D972A205FD for ; Fri, 19 Oct 2018 14:52:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727630AbeJSW7P (ORCPT ); Fri, 19 Oct 2018 18:59:15 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:35805 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727492AbeJSW7O (ORCPT ); Fri, 19 Oct 2018 18:59:14 -0400 Received: by mail-lj1-f196.google.com with SMTP id o14-v6so31121537ljj.2 for ; Fri, 19 Oct 2018 07:52:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7Vbi19/ChPsYLaFnOm7ahsyPrzFymaFSS+Cl4srI4Go=; b=GPXFVDRYO1WJNposWb0Uj7bf7gDhca9mg7CnFRTUGD2NT93JBxwPaYdJ6KyPh6rhA3 1iZ5YKfkHzZ8UgUk8LniVHLc0UYliTUJbAZyfKSUPO6DJNAcC7tsMav7pJsUko5ecQDz sUj8kdEK4amowk+AOlPYDukvcTMj8uYLrux6EHqc81uCHJSHIWMxau/cYE13vsVLBDKm i39ZMHOM3k/zbYcbNUpPd6xWUaq0z1blhpzl5NrUdmtMMtxyxkZ4Vr5yP4si8mt/e1Ha QhoQVfF5nN/wcpwPIJPMgPdlQNdYMycpw9oc0GvcSm6g8wzFllBgwQcUleJWKlR6FI/K i/4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7Vbi19/ChPsYLaFnOm7ahsyPrzFymaFSS+Cl4srI4Go=; b=uHws95utD2C+UF0QW3Dbwc8Hro6fPDiEqC+PZMDP81j79iO/tD1Kiu3vGZI2UMg7IF G0dYRXHXYnXRkir32dk3anhdacmzijn2cSpI0SGhQ+BOpEwpe56boeZ42V8m5vDD8hsS F0f0GixzWjGJdZb19YzqP98qfKVVoPIjuIItzRu6qXmMtUP+ezfufSO71z/VmXQW3BfV ZalXfEZb8gvX7VL7Y5rbv6y5QMYAd3zn+7X92vc+1XF6EMWKO8Mg8AggSXsFVs6g/qbW cQRP2z4UgxlQrDYJFVy21TVkSn/4vWuw5mU6tccTXZ2z3DefnV/Bg16kJG5ZOMGCeC1l PA6Q== X-Gm-Message-State: ABuFfohC3kNW2V8AbTv8lzXahh+Uk8JZpP4Y6pOvFyHVyIRfqLsjvKbH r93ZklxgSRdipV+mYH/VD2Dgp+XG X-Google-Smtp-Source: ACcGV62U25MrhsIL3c034z8gKwuBjF6szdP6hfNwrgIkX3zrYkWEtElqhXY320Jk/FpfFA/mNpd0+w== X-Received: by 2002:a2e:88da:: with SMTP id a26-v6mr22783775ljk.85.1539960765523; Fri, 19 Oct 2018 07:52:45 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g64-v6sm4002414lfe.87.2018.10.19.07.52.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 07:52:44 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= Subject: [PATCH 03/19] list-objects-filter.c: remove implicit dependency on the_index Date: Fri, 19 Oct 2018 16:52:21 +0200 Message-Id: <20181019145237.16079-4-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181019145237.16079-1-pclouds@gmail.com> References: <20181019145237.16079-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Nguyễn Thái Ngọc Duy --- list-objects-filter.c | 7 +++++-- list-objects-filter.h | 1 + list-objects.c | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/list-objects-filter.c b/list-objects-filter.c index a0ba78b20c..8825e2a5ab 100644 --- a/list-objects-filter.c +++ b/list-objects-filter.c @@ -38,6 +38,7 @@ static enum list_objects_filter_result filter_blobs_none( struct object *obj, const char *pathname, const char *filename, + struct index_state *istate, void *filter_data_) { struct filter_blobs_none_data *filter_data = filter_data_; @@ -94,6 +95,7 @@ static enum list_objects_filter_result filter_blobs_limit( struct object *obj, const char *pathname, const char *filename, + struct index_state *istate, void *filter_data_) { struct filter_blobs_limit_data *filter_data = filter_data_; @@ -200,6 +202,7 @@ static enum list_objects_filter_result filter_sparse( struct object *obj, const char *pathname, const char *filename, + struct index_state *istate, void *filter_data_) { struct filter_sparse_data *filter_data = filter_data_; @@ -216,7 +219,7 @@ static enum list_objects_filter_result filter_sparse( dtype = DT_DIR; val = is_excluded_from_list(pathname, strlen(pathname), filename, &dtype, &filter_data->el, - &the_index); + istate); if (val < 0) val = filter_data->array_frame[filter_data->nr].defval; @@ -279,7 +282,7 @@ static enum list_objects_filter_result filter_sparse( dtype = DT_REG; val = is_excluded_from_list(pathname, strlen(pathname), filename, &dtype, &filter_data->el, - &the_index); + istate); if (val < 0) val = frame->defval; if (val > 0) { diff --git a/list-objects-filter.h b/list-objects-filter.h index a6f6b4990b..dfa29595d1 100644 --- a/list-objects-filter.h +++ b/list-objects-filter.h @@ -58,6 +58,7 @@ typedef enum list_objects_filter_result (*filter_object_fn)( struct object *obj, const char *pathname, const char *filename, + struct index_state *istate, void *filter_data); typedef void (*filter_free_fn)(void *filter_data); diff --git a/list-objects.c b/list-objects.c index 0c2989d5ca..f9d36dabf2 100644 --- a/list-objects.c +++ b/list-objects.c @@ -51,6 +51,7 @@ static void process_blob(struct rev_info *revs, if (!(obj->flags & USER_GIVEN) && filter_fn) r = filter_fn(LOFS_BLOB, obj, path->buf, &path->buf[pathlen], + &the_index, filter_data); if (r & LOFR_MARK_SEEN) obj->flags |= SEEN; @@ -136,6 +137,7 @@ static void process_tree(struct rev_info *revs, if (!(obj->flags & USER_GIVEN) && filter_fn) r = filter_fn(LOFS_BEGIN_TREE, obj, base->buf, &base->buf[baselen], + &the_index, filter_data); if (r & LOFR_MARK_SEEN) obj->flags |= SEEN; @@ -175,6 +177,7 @@ static void process_tree(struct rev_info *revs, if (!(obj->flags & USER_GIVEN) && filter_fn) { r = filter_fn(LOFS_END_TREE, obj, base->buf, &base->buf[baselen], + &the_index, filter_data); if (r & LOFR_MARK_SEEN) obj->flags |= SEEN; From patchwork Fri Oct 19 14:52:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10649589 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B58F4109C for ; Fri, 19 Oct 2018 14:52:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4D81205FD for ; Fri, 19 Oct 2018 14:52:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9831F207A7; Fri, 19 Oct 2018 14:52:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DFAA205FD for ; Fri, 19 Oct 2018 14:52:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727635AbeJSW7R (ORCPT ); Fri, 19 Oct 2018 18:59:17 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:36301 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726664AbeJSW7Q (ORCPT ); Fri, 19 Oct 2018 18:59:16 -0400 Received: by mail-lf1-f68.google.com with SMTP id l1-v6so5674740lfc.3 for ; Fri, 19 Oct 2018 07:52:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cdunU1jiw5FYl7U1c37wJjUyjWaERejjxfqb4XYhrZE=; b=Y/t3j0UDUnOr7HbO/wxbM4im/S5AEGfCxcLHudus4puTuT9G52hHfWAlWasd6+USyy 1WECgscWRMcdYPdEeOVi007ZpVaAJOuVfsZnzLJt+6gTf02Qr0/QBIT+MjSLi942FCwl +MIGl1q5ZK4fAK2LbY2jRNQfc7/aQ0ZNp9y+02Gt4eWjgSCw8Kw3s2eJK64FALaQCTQm feAn0z/pcfc2yqQbHGC8oQbzmBc8xcZLVNUrS3jACOVHv38Iu4GXP79sapCttM7eSNDf 1Cky9xS21NGDSHJRMgU5A3hDUtxOItiOHrjpGZMvaGu0Lsh+qfoqS0aylUupP8qQJfMP tEfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cdunU1jiw5FYl7U1c37wJjUyjWaERejjxfqb4XYhrZE=; b=ftV++70zPHaS5NBFDLGh/Ns26OgwGnGECNzcGnFzmgFbX08J1H6aIfR5J3dx2MVb77 tCQKzRByf2GCqlWOEkKn116dQ5Hc70rSSAIeq5Ehb4TTk4K+ZK3+5PdQIlMJg6c5PkF2 m0alw1DVvTQaCi+DjE0OVvcdDL8ZjUoX6S55DRdj4aEVS9b9MZKXhlx2zbSUdEeP4bxW XHBPZ9I8rJuoqMLde4j2G5kpT8IL4AheYwg94Q14lOnAWhwz5Vb2phjOziqrjFfNK9jO /VBJdVCagnNaEnEhNs7+NntUl4TEMRi2TbvYk30oenl13iWoAGB3AUroN/Yd8nLyGH73 a7YQ== X-Gm-Message-State: ABuFfogUsUBsogjNKZG/KvV/NcbUymF8h8CVVgX9M8z8FIE22TojN+e7 i1feaaNFEw3M1MpD0GO5odPpxwI4 X-Google-Smtp-Source: ACcGV63CLk4Ov4qkFncn7fayjEm+PaTfy6UemRYQERfjLKMyZMR83P60MQ2JwjSmROoZ2zorTuJPig== X-Received: by 2002:a19:5a84:: with SMTP id y4mr3350755lfk.156.1539960767315; Fri, 19 Oct 2018 07:52:47 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g64-v6sm4002414lfe.87.2018.10.19.07.52.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 07:52:45 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= Subject: [PATCH 04/19] list-objects.c: remove implicit dependency on the_index Date: Fri, 19 Oct 2018 16:52:22 +0200 Message-Id: <20181019145237.16079-5-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181019145237.16079-1-pclouds@gmail.com> References: <20181019145237.16079-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Nguyễn Thái Ngọc Duy --- list-objects.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/list-objects.c b/list-objects.c index f9d36dabf2..c3a1a9b004 100644 --- a/list-objects.c +++ b/list-objects.c @@ -51,7 +51,7 @@ static void process_blob(struct rev_info *revs, if (!(obj->flags & USER_GIVEN) && filter_fn) r = filter_fn(LOFS_BLOB, obj, path->buf, &path->buf[pathlen], - &the_index, + revs->repo->index, filter_data); if (r & LOFR_MARK_SEEN) obj->flags |= SEEN; @@ -137,7 +137,7 @@ static void process_tree(struct rev_info *revs, if (!(obj->flags & USER_GIVEN) && filter_fn) r = filter_fn(LOFS_BEGIN_TREE, obj, base->buf, &base->buf[baselen], - &the_index, + revs->repo->index, filter_data); if (r & LOFR_MARK_SEEN) obj->flags |= SEEN; @@ -177,7 +177,7 @@ static void process_tree(struct rev_info *revs, if (!(obj->flags & USER_GIVEN) && filter_fn) { r = filter_fn(LOFS_END_TREE, obj, base->buf, &base->buf[baselen], - &the_index, + revs->repo->index, filter_data); if (r & LOFR_MARK_SEEN) obj->flags |= SEEN; From patchwork Fri Oct 19 14:52:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10649595 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AFC501750 for ; Fri, 19 Oct 2018 14:52:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A54B20748 for ; Fri, 19 Oct 2018 14:52:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8DF7120881; Fri, 19 Oct 2018 14:52:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5645220748 for ; Fri, 19 Oct 2018 14:52:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727656AbeJSW7V (ORCPT ); Fri, 19 Oct 2018 18:59:21 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:35811 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726664AbeJSW7U (ORCPT ); Fri, 19 Oct 2018 18:59:20 -0400 Received: by mail-lj1-f194.google.com with SMTP id o14-v6so31121755ljj.2 for ; Fri, 19 Oct 2018 07:52:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bqkpFh4S8uCn4cLGALv/GM9IHvcXVuMhVI6aR2//fHY=; b=FevEz9oQ4GFSK6ocZOQ+7VNaSgEDiyb3piXssXu0IAFDeJVy258shrXndhsjaSey9c dMEUY2Yi/AMOKCnMyqkJZPbiF5TDpJ2ql+rSDIuPg5GgCMTRv2kOU6ZkIK5JNo72Z0lm 09pkvY/RoofSBlZNN6cFu4yyQ16+/Cnvv3DATONiau4kBEsxhLvzIqvl1S5M6eenqyd5 6yL52NjuEKwWF0xg5zAXwxYiZrc1KIDamk69l8bsNu0kCUivwIju4+jVWGkbnNwJNJJu zeOlGCXs9sse+GyDI8dx065Xi+1Ies2tu/lGRUoNtVHd04Q8QXpiHJUDNyl6E65ugfw/ I2Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bqkpFh4S8uCn4cLGALv/GM9IHvcXVuMhVI6aR2//fHY=; b=A/VNCXIAN+tuLqaG4pnr9sHcjiUBHGBTwyra2xf1jtwrjj8uSXB+1I9vq53n6w5QDT WXq3rVUEFSG77zgA9eYb4gLuCC0KTTo4wtiBi5tooor9GariBhdYiOTjw40n+DdegRlR mZTihHqeTywabjHYuENumH2IzUaftHNylGg9l9NXX5Sk7JmiHbv+rNFkSAstN4/NDHjw Q0aDWIkuKCcqfKSGxMR/V9ZQ71KckKUQsZVighXTGk0WBNZaMoxtwPayc8QIOy79BPfS 8WzxS7MNT2k2gHacbwWxwMII3DR2XRbhQ9fxMjwh47fXOReO2CQcXoaDRKF4AgvkYc7B ynsg== X-Gm-Message-State: ABuFfoiqnvkO7EAwEhcfX9ZNk1QPfl0d4RzxExGmTcFluYGO8GduX3db ow5Mn3b8PA/VB26kSx4tUMs9nzuE X-Google-Smtp-Source: ACcGV63/GfKf48hXa3Bz2zuE0Jq4VOxQj/QdlsiMpo1Cmo3g6svsTLQYJspBlgBgUBwmWKTk8WIyvQ== X-Received: by 2002:a2e:1b15:: with SMTP id b21-v6mr20042871ljb.104.1539960768635; Fri, 19 Oct 2018 07:52:48 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g64-v6sm4002414lfe.87.2018.10.19.07.52.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 07:52:47 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= Subject: [PATCH 05/19] sequencer.c: remove implicit dependency on the_index Date: Fri, 19 Oct 2018 16:52:23 +0200 Message-Id: <20181019145237.16079-6-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181019145237.16079-1-pclouds@gmail.com> References: <20181019145237.16079-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since we're going to pass 'struct repository *' around most of the time instead of 'struct index_state *' because most sequencer.c operations need more than just the index, the_repository is replaced as well in the functions that now take 'struct repository *'. the_repository is still present in this file, but total clean up will be done later. It's not the main focus of this patch. Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/commit.c | 3 +- builtin/merge.c | 2 +- builtin/rebase--helper.c | 5 +- builtin/revert.c | 4 +- sequencer.c | 319 ++++++++++++++++++++++----------------- sequencer.h | 15 +- 6 files changed, 197 insertions(+), 151 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 379d8c5cdf..f7bbba944d 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1679,7 +1679,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix) flags |= SUMMARY_INITIAL_COMMIT; if (author_date_is_interesting()) flags |= SUMMARY_SHOW_AUTHOR_DATE; - print_commit_summary(prefix, &oid, flags); + print_commit_summary(the_repository, prefix, + &oid, flags); } UNLEAK(err); diff --git a/builtin/merge.c b/builtin/merge.c index 4aa6071598..db22119c93 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -896,7 +896,7 @@ static int suggest_conflicts(void) filename = git_path_merge_msg(the_repository); fp = xfopen(filename, "a"); - append_conflicts_hint(&msgbuf); + append_conflicts_hint(&the_index, &msgbuf); fputs(msgbuf.buf, fp); strbuf_release(&msgbuf); fclose(fp); diff --git a/builtin/rebase--helper.c b/builtin/rebase--helper.c index f7c2a5fdc8..b66cd8cd41 100644 --- a/builtin/rebase--helper.c +++ b/builtin/rebase--helper.c @@ -69,11 +69,12 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix) "--rebase-merges")); if (command == CONTINUE && argc == 1) - return !!sequencer_continue(&opts); + return !!sequencer_continue(the_repository, &opts); if (command == ABORT && argc == 1) return !!sequencer_remove_state(&opts); if (command == MAKE_SCRIPT && argc > 1) - return !!sequencer_make_script(stdout, argc, argv, flags); + return !!sequencer_make_script(the_repository, stdout, + argc, argv, flags); if ((command == SHORTEN_OIDS || command == EXPAND_OIDS) && argc == 1) return !!transform_todos(flags); if (command == CHECK_TODO_LIST && argc == 1) diff --git a/builtin/revert.c b/builtin/revert.c index c93393c89b..cd9f068195 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -199,10 +199,10 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) return ret; } if (cmd == 'c') - return sequencer_continue(opts); + return sequencer_continue(the_repository, opts); if (cmd == 'a') return sequencer_rollback(opts); - return sequencer_pick_revisions(opts); + return sequencer_pick_revisions(the_repository, opts); } int cmd_revert(int argc, const char **argv, const char *prefix) diff --git a/sequencer.c b/sequencer.c index 90435593a4..6b79359114 100644 --- a/sequencer.c +++ b/sequencer.c @@ -440,9 +440,9 @@ static struct tree *empty_tree(void) return lookup_tree(the_repository, the_repository->hash_algo->empty_tree); } -static int error_dirty_index(struct replay_opts *opts) +static int error_dirty_index(struct index_state *istate, struct replay_opts *opts) { - if (read_cache_unmerged()) + if (read_index_unmerged(istate)) return error_resolve_conflict(_(action_name(opts))); error(_("your local changes would be overwritten by %s."), @@ -467,15 +467,18 @@ static void update_abort_safety_file(void) write_file(git_path_abort_safety_file(), "%s", ""); } -static int fast_forward_to(const struct object_id *to, const struct object_id *from, - int unborn, struct replay_opts *opts) +static int fast_forward_to(struct repository *r, + const struct object_id *to, + const struct object_id *from, + int unborn, + struct replay_opts *opts) { struct ref_transaction *transaction; struct strbuf sb = STRBUF_INIT; struct strbuf err = STRBUF_INIT; - read_index(&the_index); - if (checkout_fast_forward(the_repository, from, to, 1)) + read_index(r->index); + if (checkout_fast_forward(r, from, to, 1)) return -1; /* the callee should have complained already */ strbuf_addf(&sb, _("%s: fast-forward"), _(action_name(opts))); @@ -501,24 +504,26 @@ static int fast_forward_to(const struct object_id *to, const struct object_id *f return 0; } -void append_conflicts_hint(struct strbuf *msgbuf) +void append_conflicts_hint(struct index_state *istate, + struct strbuf *msgbuf) { int i; strbuf_addch(msgbuf, '\n'); strbuf_commented_addf(msgbuf, "Conflicts:\n"); - for (i = 0; i < active_nr;) { - const struct cache_entry *ce = active_cache[i++]; + for (i = 0; i < istate->cache_nr;) { + const struct cache_entry *ce = istate->cache[i++]; if (ce_stage(ce)) { strbuf_commented_addf(msgbuf, "\t%s\n", ce->name); - while (i < active_nr && !strcmp(ce->name, - active_cache[i]->name)) + while (i < istate->cache_nr && + !strcmp(ce->name, istate->cache[i]->name)) i++; } } } -static int do_recursive_merge(struct commit *base, struct commit *next, +static int do_recursive_merge(struct repository *r, + struct commit *base, struct commit *next, const char *base_label, const char *next_label, struct object_id *head, struct strbuf *msgbuf, struct replay_opts *opts) @@ -532,7 +537,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next, if (hold_locked_index(&index_lock, LOCK_REPORT_ON_ERROR) < 0) return -1; - read_cache(); + read_index(r->index); init_merge_options(&o); o.ancestor = base ? base_label : "(empty tree)"; @@ -561,7 +566,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next, return clean; } - if (write_locked_index(&the_index, &index_lock, + if (write_locked_index(r->index, &index_lock, COMMIT_LOCK | SKIP_IF_UNCHANGED)) /* * TRANSLATORS: %s will be "revert", "cherry-pick" or @@ -571,26 +576,26 @@ static int do_recursive_merge(struct commit *base, struct commit *next, _(action_name(opts))); if (!clean) - append_conflicts_hint(msgbuf); + append_conflicts_hint(r->index, msgbuf); return !clean; } -static struct object_id *get_cache_tree_oid(void) +static struct object_id *get_cache_tree_oid(struct index_state *istate) { - if (!active_cache_tree) - active_cache_tree = cache_tree(); + if (!istate->cache_tree) + istate->cache_tree = cache_tree(); - if (!cache_tree_fully_valid(active_cache_tree)) - if (cache_tree_update(&the_index, 0)) { + if (!cache_tree_fully_valid(istate->cache_tree)) + if (cache_tree_update(istate, 0)) { error(_("unable to update cache tree")); return NULL; } - return &active_cache_tree->oid; + return &istate->cache_tree->oid; } -static int is_index_unchanged(void) +static int is_index_unchanged(struct index_state *istate) { struct object_id head_oid, *cache_tree_oid; struct commit *head_commit; @@ -611,7 +616,7 @@ static int is_index_unchanged(void) if (parse_commit(head_commit)) return -1; - if (!(cache_tree_oid = get_cache_tree_oid())) + if (!(cache_tree_oid = get_cache_tree_oid(istate))) return -1; return oideq(cache_tree_oid, get_commit_tree_oid(head_commit)); @@ -816,7 +821,9 @@ N_("you have staged changes in your working tree\n" * interactive rebase: in that case, we will want to retain the * author metadata. */ -static int run_git_commit(const char *defmsg, struct replay_opts *opts, +static int run_git_commit(struct repository *r, + const char *defmsg, + struct replay_opts *opts, unsigned int flags) { struct child_process cmd = CHILD_PROCESS_INIT; @@ -839,7 +846,7 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts, if (!defmsg) BUG("root commit without message"); - if (!(cache_tree_oid = get_cache_tree_oid())) + if (!(cache_tree_oid = get_cache_tree_oid(r->index))) res = -1; if (!res) @@ -1066,7 +1073,9 @@ void commit_post_rewrite(const struct commit *old_head, run_rewrite_hook(&old_head->object.oid, new_head); } -static int run_prepare_commit_msg_hook(struct strbuf *msg, const char *commit) +static int run_prepare_commit_msg_hook(struct repository *r, + struct strbuf *msg, + const char *commit) { struct argv_array hook_env = ARGV_ARRAY_INIT; int ret; @@ -1076,7 +1085,7 @@ static int run_prepare_commit_msg_hook(struct strbuf *msg, const char *commit) if (write_message(msg->buf, msg->len, name, 0)) return -1; - argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", get_index_file()); + argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", r->index_file); argv_array_push(&hook_env, "GIT_EDITOR=:"); if (commit) ret = run_hook_le(hook_env.argv, "prepare-commit-msg", name, @@ -1132,7 +1141,9 @@ static const char *implicit_ident_advice(void) } -void print_commit_summary(const char *prefix, const struct object_id *oid, +void print_commit_summary(struct repository *r, + const char *prefix, + const struct object_id *oid, unsigned int flags) { struct rev_info rev; @@ -1143,7 +1154,7 @@ void print_commit_summary(const char *prefix, const struct object_id *oid, struct strbuf author_ident = STRBUF_INIT; struct strbuf committer_ident = STRBUF_INIT; - commit = lookup_commit(the_repository, oid); + commit = lookup_commit(r, oid); if (!commit) die(_("couldn't look up newly created commit")); if (parse_commit(commit)) @@ -1176,7 +1187,7 @@ void print_commit_summary(const char *prefix, const struct object_id *oid, strbuf_release(&author_ident); strbuf_release(&committer_ident); - repo_init_revisions(the_repository, &rev, prefix); + repo_init_revisions(r, &rev, prefix); setup_revisions(0, NULL, &rev, NULL); rev.diff = 1; @@ -1242,7 +1253,8 @@ static int parse_head(struct commit **head) * 0 - success * 1 - run 'git commit' */ -static int try_to_commit(struct strbuf *msg, const char *author, +static int try_to_commit(struct repository *r, + struct strbuf *msg, const char *author, struct replay_opts *opts, unsigned int flags, struct object_id *oid) { @@ -1286,7 +1298,7 @@ static int try_to_commit(struct strbuf *msg, const char *author, commit_list_insert(current_head, &parents); } - if (write_index_as_tree(&tree, &the_index, get_index_file(), 0, NULL)) { + if (write_index_as_tree(&tree, r->index, r->index_file, 0, NULL)) { res = error(_("git write-tree failed to write a tree")); goto out; } @@ -1299,7 +1311,7 @@ static int try_to_commit(struct strbuf *msg, const char *author, } if (find_hook("prepare-commit-msg")) { - res = run_prepare_commit_msg_hook(msg, hook_commit); + res = run_prepare_commit_msg_hook(r, msg, hook_commit); if (res) goto out; if (strbuf_read_file(&commit_msg, git_path_commit_editmsg(), @@ -1348,7 +1360,8 @@ static int try_to_commit(struct strbuf *msg, const char *author, return res; } -static int do_commit(const char *msg_file, const char *author, +static int do_commit(struct repository *r, + const char *msg_file, const char *author, struct replay_opts *opts, unsigned int flags) { int res = 1; @@ -1363,20 +1376,20 @@ static int do_commit(const char *msg_file, const char *author, "from '%s'"), msg_file); - res = try_to_commit(msg_file ? &sb : NULL, author, opts, flags, - &oid); + res = try_to_commit(r, msg_file ? &sb : NULL, + author, opts, flags, &oid); strbuf_release(&sb); if (!res) { - unlink(git_path_cherry_pick_head(the_repository)); - unlink(git_path_merge_msg(the_repository)); + unlink(git_path_cherry_pick_head(r)); + unlink(git_path_merge_msg(r)); if (!is_rebase_i(opts)) - print_commit_summary(NULL, &oid, + print_commit_summary(r, NULL, &oid, SUMMARY_SHOW_AUTHOR_DATE); return res; } } if (res == 1) - return run_git_commit(msg_file, opts, flags); + return run_git_commit(r, msg_file, opts, flags); return res; } @@ -1404,7 +1417,9 @@ static int is_original_commit_empty(struct commit *commit) /* * Do we run "git commit" with "--allow-empty"? */ -static int allow_empty(struct replay_opts *opts, struct commit *commit) +static int allow_empty(struct repository *r, + struct replay_opts *opts, + struct commit *commit) { int index_unchanged, empty_commit; @@ -1421,7 +1436,7 @@ static int allow_empty(struct replay_opts *opts, struct commit *commit) if (!opts->allow_empty) return 0; /* let "git commit" barf as necessary */ - index_unchanged = is_index_unchanged(); + index_unchanged = is_index_unchanged(r->index); if (index_unchanged < 0) return index_unchanged; if (!index_unchanged) @@ -1652,11 +1667,14 @@ static void record_in_rewritten(struct object_id *oid, flush_rewritten_pending(); } -static int do_pick_commit(enum todo_command command, struct commit *commit, - struct replay_opts *opts, int final_fixup) +static int do_pick_commit(struct repository *r, + enum todo_command command, + struct commit *commit, + struct replay_opts *opts, + int final_fixup) { unsigned int flags = opts->edit ? EDIT_MSG : 0; - const char *msg_file = opts->edit ? NULL : git_path_merge_msg(the_repository); + const char *msg_file = opts->edit ? NULL : git_path_merge_msg(r); struct object_id head; struct commit *base, *next, *parent; const char *base_label, *next_label; @@ -1672,7 +1690,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit, * that represents the "current" state for merge-recursive * to work on. */ - if (write_index_as_tree(&head, &the_index, get_index_file(), 0, NULL)) + if (write_index_as_tree(&head, r->index, r->index_file, 0, NULL)) return error(_("your index file is unmerged.")); } else { unborn = get_oid("HEAD", &head); @@ -1687,9 +1705,9 @@ static int do_pick_commit(enum todo_command command, struct commit *commit, oidcpy(&head, the_hash_algo->empty_tree); if (index_differs_from(unborn ? empty_tree_oid_hex() : "HEAD", NULL, 0)) - return error_dirty_index(opts); + return error_dirty_index(r->index, opts); } - discard_cache(); + discard_index(r->index); if (!commit->parents) parent = NULL; @@ -1725,7 +1743,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit, (!parent && unborn))) { if (is_rebase_i(opts)) write_author_script(msg.message); - res = fast_forward_to(&commit->object.oid, &head, unborn, + res = fast_forward_to(r, &commit->object.oid, &head, unborn, opts); if (res || command != TODO_REWORD) goto leave; @@ -1798,12 +1816,12 @@ static int do_pick_commit(enum todo_command command, struct commit *commit, flags |= CLEANUP_MSG; msg_file = rebase_path_fixup_msg(); } else { - const char *dest = git_path_squash_msg(the_repository); + const char *dest = git_path_squash_msg(r); unlink(dest); if (copy_file(dest, rebase_path_squash_msg(), 0666)) return error(_("could not rename '%s' to '%s'"), rebase_path_squash_msg(), dest); - unlink(git_path_merge_msg(the_repository)); + unlink(git_path_merge_msg(r)); msg_file = dest; flags |= EDIT_MSG; } @@ -1815,23 +1833,23 @@ static int do_pick_commit(enum todo_command command, struct commit *commit, if (is_rebase_i(opts) && write_author_script(msg.message) < 0) res = -1; else if (!opts->strategy || !strcmp(opts->strategy, "recursive") || command == TODO_REVERT) { - res = do_recursive_merge(base, next, base_label, next_label, + res = do_recursive_merge(r, base, next, base_label, next_label, &head, &msgbuf, opts); if (res < 0) goto leave; res |= write_message(msgbuf.buf, msgbuf.len, - git_path_merge_msg(the_repository), 0); + git_path_merge_msg(r), 0); } else { struct commit_list *common = NULL; struct commit_list *remotes = NULL; res = write_message(msgbuf.buf, msgbuf.len, - git_path_merge_msg(the_repository), 0); + git_path_merge_msg(r), 0); commit_list_insert(base, &common); commit_list_insert(next, &remotes); - res |= try_merge_command(the_repository, opts->strategy, + res |= try_merge_command(r, opts->strategy, opts->xopts_nr, (const char **)opts->xopts, common, oid_to_hex(&head), remotes); free_commit_list(common); @@ -1860,11 +1878,11 @@ static int do_pick_commit(enum todo_command command, struct commit *commit, : _("could not apply %s... %s"), short_commit_name(commit), msg.subject); print_advice(res == 1, opts); - repo_rerere(the_repository, opts->allow_rerere_auto); + repo_rerere(r, opts->allow_rerere_auto); goto leave; } - allow = allow_empty(opts, commit); + allow = allow_empty(r, opts, commit); if (allow < 0) { res = allow; goto leave; @@ -1873,7 +1891,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit, if (!opts->no_commit) { fast_forward_edit: if (author || command == TODO_REVERT || (flags & AMEND_MSG)) - res = do_commit(msg_file, author, opts, flags); + res = do_commit(r, msg_file, author, opts, flags); else res = error(_("unable to parse commit author")); } @@ -1909,18 +1927,19 @@ static int prepare_revs(struct replay_opts *opts) return 0; } -static int read_and_refresh_cache(struct replay_opts *opts) +static int read_and_refresh_cache(struct repository *r, + struct replay_opts *opts) { struct lock_file index_lock = LOCK_INIT; int index_fd = hold_locked_index(&index_lock, 0); - if (read_index_preload(&the_index, NULL, 0) < 0) { + if (read_index_preload(r->index, NULL, 0) < 0) { rollback_lock_file(&index_lock); return error(_("git %s: failed to read the index"), _(action_name(opts))); } - refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL); + refresh_index(r->index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL); if (index_fd >= 0) { - if (write_locked_index(&the_index, &index_lock, + if (write_locked_index(r->index, &index_lock, COMMIT_LOCK | SKIP_IF_UNCHANGED)) { return error(_("git %s: failed to refresh the index"), _(action_name(opts))); @@ -2583,7 +2602,9 @@ static int save_opts(struct replay_opts *opts) return res; } -static int make_patch(struct commit *commit, struct replay_opts *opts) +static int make_patch(struct repository *r, + struct commit *commit, + struct replay_opts *opts) { struct strbuf buf = STRBUF_INIT; struct rev_info log_tree_opt; @@ -2599,7 +2620,7 @@ static int make_patch(struct commit *commit, struct replay_opts *opts) strbuf_addf(&buf, "%s/patch", get_dir(opts)); memset(&log_tree_opt, 0, sizeof(log_tree_opt)); - repo_init_revisions(the_repository, &log_tree_opt, NULL); + repo_init_revisions(r, &log_tree_opt, NULL); log_tree_opt.abbrev = 0; log_tree_opt.diff = 1; log_tree_opt.diffopt.output_format = DIFF_FORMAT_PATCH; @@ -2639,17 +2660,19 @@ static int intend_to_amend(void) return write_message(p, strlen(p), rebase_path_amend(), 1); } -static int error_with_patch(struct commit *commit, - const char *subject, int subject_len, - struct replay_opts *opts, int exit_code, int to_amend) +static int error_with_patch(struct repository *r, + struct commit *commit, + const char *subject, int subject_len, + struct replay_opts *opts, + int exit_code, int to_amend) { if (commit) { - if (make_patch(commit, opts)) + if (make_patch(r, commit, opts)) return -1; } else if (copy_file(rebase_path_message(), - git_path_merge_msg(the_repository), 0666)) + git_path_merge_msg(r), 0666)) return error(_("unable to copy '%s' to '%s'"), - git_path_merge_msg(the_repository), rebase_path_message()); + git_path_merge_msg(r), rebase_path_message()); if (to_amend) { if (intend_to_amend()) @@ -2680,21 +2703,24 @@ static int error_with_patch(struct commit *commit, return exit_code; } -static int error_failed_squash(struct commit *commit, - struct replay_opts *opts, int subject_len, const char *subject) +static int error_failed_squash(struct repository *r, + struct commit *commit, + struct replay_opts *opts, + int subject_len, + const char *subject) { if (copy_file(rebase_path_message(), rebase_path_squash_msg(), 0666)) return error(_("could not copy '%s' to '%s'"), rebase_path_squash_msg(), rebase_path_message()); - unlink(git_path_merge_msg(the_repository)); - if (copy_file(git_path_merge_msg(the_repository), rebase_path_message(), 0666)) + unlink(git_path_merge_msg(r)); + if (copy_file(git_path_merge_msg(r), rebase_path_message(), 0666)) return error(_("could not copy '%s' to '%s'"), rebase_path_message(), - git_path_merge_msg(the_repository)); - return error_with_patch(commit, subject, subject_len, opts, 1, 0); + git_path_merge_msg(r)); + return error_with_patch(r, commit, subject, subject_len, opts, 1, 0); } -static int do_exec(const char *command_line) +static int do_exec(struct repository *r, const char *command_line) { struct argv_array child_env = ARGV_ARRAY_INIT; const char *child_argv[] = { NULL, NULL }; @@ -2709,10 +2735,10 @@ static int do_exec(const char *command_line) child_env.argv); /* force re-reading of the cache */ - if (discard_cache() < 0 || read_cache() < 0) + if (discard_index(r->index) < 0 || read_index(r->index) < 0) return error(_("could not read index")); - dirty = require_clean_work_tree(the_repository, "rebase", NULL, 1, 1); + dirty = require_clean_work_tree(r, "rebase", NULL, 1, 1); if (status) { warning(_("execution failed: %s\n%s" @@ -2778,9 +2804,9 @@ static int safe_append(const char *filename, const char *fmt, ...) return 0; } -static int do_label(const char *name, int len) +static int do_label(struct repository *r, const char *name, int len) { - struct ref_store *refs = get_main_ref_store(the_repository); + struct ref_store *refs = get_main_ref_store(r); struct ref_transaction *transaction; struct strbuf ref_name = STRBUF_INIT, err = STRBUF_INIT; struct strbuf msg = STRBUF_INIT; @@ -2821,7 +2847,9 @@ static int do_label(const char *name, int len) static const char *reflog_message(struct replay_opts *opts, const char *sub_action, const char *fmt, ...); -static int do_reset(const char *name, int len, struct replay_opts *opts) +static int do_reset(struct repository *r, + const char *name, int len, + struct replay_opts *opts) { struct strbuf ref_name = STRBUF_INIT; struct object_id oid; @@ -2867,13 +2895,13 @@ static int do_reset(const char *name, int len, struct replay_opts *opts) memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts)); setup_unpack_trees_porcelain(&unpack_tree_opts, "reset"); unpack_tree_opts.head_idx = 1; - unpack_tree_opts.src_index = &the_index; - unpack_tree_opts.dst_index = &the_index; + unpack_tree_opts.src_index = r->index; + unpack_tree_opts.dst_index = r->index; unpack_tree_opts.fn = oneway_merge; unpack_tree_opts.merge = 1; unpack_tree_opts.update = 1; - if (read_cache_unmerged()) { + if (read_index_unmerged(r->index)) { rollback_lock_file(&lock); strbuf_release(&ref_name); return error_resolve_conflict(_(action_name(opts))); @@ -2895,9 +2923,9 @@ static int do_reset(const char *name, int len, struct replay_opts *opts) } tree = parse_tree_indirect(&oid); - prime_cache_tree(&the_index, tree); + prime_cache_tree(r->index, tree); - if (write_locked_index(&the_index, &lock, COMMIT_LOCK) < 0) + if (write_locked_index(r->index, &lock, COMMIT_LOCK) < 0) ret = error(_("could not write index")); free((void *)desc.buffer); @@ -2930,7 +2958,9 @@ static struct commit *lookup_label(const char *label, int len, return commit; } -static int do_merge(struct commit *commit, const char *arg, int arg_len, +static int do_merge(struct repository *r, + struct commit *commit, + const char *arg, int arg_len, int flags, struct replay_opts *opts) { int run_commit_flags = (flags & TODO_EDIT_MERGE_MSG) ? @@ -2997,7 +3027,7 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len, ret = error(_("octopus merge cannot be executed on " "top of a [new root]")); else - ret = fast_forward_to(&to_merge->item->object.oid, + ret = fast_forward_to(r, &to_merge->item->object.oid, &head_commit->object.oid, 0, opts); goto leave_merge; @@ -3016,11 +3046,11 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len, write_author_script(message); find_commit_subject(message, &body); len = strlen(body); - ret = write_message(body, len, git_path_merge_msg(the_repository), 0); + ret = write_message(body, len, git_path_merge_msg(r), 0); unuse_commit_buffer(commit, message); if (ret) { error_errno(_("could not write '%s'"), - git_path_merge_msg(the_repository)); + git_path_merge_msg(r)); goto leave_merge; } } else { @@ -3042,11 +3072,11 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len, len = buf.len; } - ret = write_message(p, len, git_path_merge_msg(the_repository), 0); + ret = write_message(p, len, git_path_merge_msg(r), 0); strbuf_release(&buf); if (ret) { error_errno(_("could not write '%s'"), - git_path_merge_msg(the_repository)); + git_path_merge_msg(r)); goto leave_merge; } } @@ -3082,7 +3112,7 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len, if (can_fast_forward) { rollback_lock_file(&lock); - ret = fast_forward_to(&commit->object.oid, + ret = fast_forward_to(r, &commit->object.oid, &head_commit->object.oid, 0, opts); goto leave_merge; } @@ -3107,7 +3137,7 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len, argv_array_push(&cmd.args, "--no-log"); argv_array_push(&cmd.args, "--no-stat"); argv_array_push(&cmd.args, "-F"); - argv_array_push(&cmd.args, git_path_merge_msg(the_repository)); + argv_array_push(&cmd.args, git_path_merge_msg(r)); if (opts->gpg_sign) argv_array_push(&cmd.args, opts->gpg_sign); @@ -3117,22 +3147,23 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len, oid_to_hex(&j->item->object.oid)); strbuf_release(&ref_name); - unlink(git_path_cherry_pick_head(the_repository)); + unlink(git_path_cherry_pick_head(r)); rollback_lock_file(&lock); rollback_lock_file(&lock); ret = run_command(&cmd); /* force re-reading of the cache */ - if (!ret && (discard_cache() < 0 || read_cache() < 0)) + if (!ret && (discard_index(r->index) < 0 || + read_index(r->index) < 0)) ret = error(_("could not read index")); goto leave_merge; } merge_commit = to_merge->item; write_message(oid_to_hex(&merge_commit->object.oid), GIT_SHA1_HEXSZ, - git_path_merge_head(the_repository), 0); - write_message("no-ff", 5, git_path_merge_mode(the_repository), 0); + git_path_merge_head(r), 0); + write_message("no-ff", 5, git_path_merge_mode(r), 0); bases = get_merge_bases(head_commit, merge_commit); if (bases && oideq(&merge_commit->object.oid, @@ -3146,7 +3177,7 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len, commit_list_insert(j->item, &reversed); free_commit_list(bases); - read_cache(); + read_index(r->index); init_merge_options(&o); o.branch1 = "HEAD"; o.branch2 = ref_name.buf; @@ -3171,23 +3202,23 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len, */ ret = !ret; - if (active_cache_changed && - write_locked_index(&the_index, &lock, COMMIT_LOCK)) { + if (r->index->cache_changed && + write_locked_index(r->index, &lock, COMMIT_LOCK)) { ret = error(_("merge: Unable to write new index file")); goto leave_merge; } rollback_lock_file(&lock); if (ret) - repo_rerere(the_repository, opts->allow_rerere_auto); + repo_rerere(r, opts->allow_rerere_auto); else /* * In case of problems, we now want to return a positive * value (a negative one would indicate that the `merge` * command needs to be rescheduled). */ - ret = !!run_git_commit(git_path_merge_msg(the_repository), opts, - run_commit_flags); + ret = !!run_git_commit(r, git_path_merge_msg(r), opts, + run_commit_flags); leave_merge: strbuf_release(&ref_name); @@ -3297,7 +3328,9 @@ N_("Could not execute the todo command\n" " git rebase --edit-todo\n" " git rebase --continue\n"); -static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts) +static int pick_commits(struct repository *r, + struct todo_list *todo_list, + struct replay_opts *opts) { int res = 0, reschedule = 0; @@ -3305,7 +3338,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts) if (opts->allow_ff) assert(!(opts->signoff || opts->no_commit || opts->record_origin || opts->edit)); - if (read_and_refresh_cache(opts)) + if (read_and_refresh_cache(r, opts)) return -1; while (todo_list->current < todo_list->nr) { @@ -3338,7 +3371,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts) setenv("GIT_REFLOG_ACTION", reflog_message(opts, command_to_string(item->command), NULL), 1); - res = do_pick_commit(item->command, item->commit, + res = do_pick_commit(r, item->command, item->commit, opts, is_final_fixup(todo_list)); if (is_rebase_i(opts) && res < 0) { /* Reschedule */ @@ -3358,7 +3391,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts) _("Stopped at %s... %.*s\n"), short_commit_name(commit), item->arg_len, item->arg); - return error_with_patch(commit, + return error_with_patch(r, commit, item->arg, item->arg_len, opts, res, !res); } @@ -3368,7 +3401,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts) if (res && is_fixup(item->command)) { if (res == 1) intend_to_amend(); - return error_failed_squash(item->commit, opts, + return error_failed_squash(r, item->commit, opts, item->arg_len, item->arg); } else if (res && is_rebase_i(opts) && item->commit) { int to_amend = 0; @@ -3387,7 +3420,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts) oideq(&opts->squash_onto, &oid)))) to_amend = 1; - return res | error_with_patch(item->commit, + return res | error_with_patch(r, item->commit, item->arg, item->arg_len, opts, res, to_amend); } @@ -3397,7 +3430,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts) struct stat st; *end_of_arg = '\0'; - res = do_exec(item->arg); + res = do_exec(r, item->arg); *end_of_arg = saved; /* Reread the todo file if it has changed. */ @@ -3414,13 +3447,13 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts) todo_list->current = -1; } } else if (item->command == TODO_LABEL) { - if ((res = do_label(item->arg, item->arg_len))) + if ((res = do_label(r, item->arg, item->arg_len))) reschedule = 1; } else if (item->command == TODO_RESET) { - if ((res = do_reset(item->arg, item->arg_len, opts))) + if ((res = do_reset(r, item->arg, item->arg_len, opts))) reschedule = 1; } else if (item->command == TODO_MERGE) { - if ((res = do_merge(item->commit, + if ((res = do_merge(r, item->commit, item->arg, item->arg_len, item->flags, opts)) < 0) reschedule = 1; @@ -3429,7 +3462,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts) peek_command(todo_list, 1)); if (res > 0) /* failed with merge conflicts */ - return error_with_patch(item->commit, + return error_with_patch(r, item->commit, item->arg, item->arg_len, opts, res, 0); @@ -3445,7 +3478,8 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts) if (save_todo(todo_list, opts)) return -1; if (item->commit) - return error_with_patch(item->commit, + return error_with_patch(r, + item->commit, item->arg, item->arg_len, opts, res, 0); @@ -3510,7 +3544,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts) struct object_id orig, head; memset(&log_tree_opt, 0, sizeof(log_tree_opt)); - repo_init_revisions(the_repository, &log_tree_opt, NULL); + repo_init_revisions(r, &log_tree_opt, NULL); log_tree_opt.diff = 1; log_tree_opt.diffopt.output_format = DIFF_FORMAT_DIFFSTAT; @@ -3577,16 +3611,17 @@ static int continue_single_pick(void) return run_command_v_opt(argv, RUN_GIT_CMD); } -static int commit_staged_changes(struct replay_opts *opts, +static int commit_staged_changes(struct repository *r, + struct replay_opts *opts, struct todo_list *todo_list) { unsigned int flags = ALLOW_EMPTY | EDIT_MSG; unsigned int final_fixup = 0, is_clean; - if (has_unstaged_changes(the_repository, 1)) + if (has_unstaged_changes(r, 1)) return error(_("cannot rebase: You have unstaged changes.")); - is_clean = !has_uncommitted_changes(the_repository, 0); + is_clean = !has_uncommitted_changes(r, 0); if (file_exists(rebase_path_amend())) { struct strbuf rev = STRBUF_INIT; @@ -3686,7 +3721,7 @@ static int commit_staged_changes(struct replay_opts *opts, } if (is_clean) { - const char *cherry_pick_head = git_path_cherry_pick_head(the_repository); + const char *cherry_pick_head = git_path_cherry_pick_head(r); if (file_exists(cherry_pick_head) && unlink(cherry_pick_head)) return error(_("could not remove CHERRY_PICK_HEAD")); @@ -3694,7 +3729,7 @@ static int commit_staged_changes(struct replay_opts *opts, return 0; } - if (run_git_commit(final_fixup ? NULL : rebase_path_message(), + if (run_git_commit(r, final_fixup ? NULL : rebase_path_message(), opts, flags)) return error(_("could not commit staged changes.")); unlink(rebase_path_amend()); @@ -3714,12 +3749,12 @@ static int commit_staged_changes(struct replay_opts *opts, return 0; } -int sequencer_continue(struct replay_opts *opts) +int sequencer_continue(struct repository *r, struct replay_opts *opts) { struct todo_list todo_list = TODO_LIST_INIT; int res; - if (read_and_refresh_cache(opts)) + if (read_and_refresh_cache(r, opts)) return -1; if (read_populate_opts(opts)) @@ -3727,7 +3762,7 @@ int sequencer_continue(struct replay_opts *opts) if (is_rebase_i(opts)) { if ((res = read_populate_todo(&todo_list, opts))) goto release_todo_list; - if (commit_staged_changes(opts, &todo_list)) + if (commit_staged_changes(r, opts, &todo_list)) return -1; } else if (!file_exists(get_todo_path(opts))) return continue_single_pick(); @@ -3736,14 +3771,14 @@ int sequencer_continue(struct replay_opts *opts) if (!is_rebase_i(opts)) { /* Verify that the conflict has been resolved */ - if (file_exists(git_path_cherry_pick_head(the_repository)) || - file_exists(git_path_revert_head(the_repository))) { + if (file_exists(git_path_cherry_pick_head(r)) || + file_exists(git_path_revert_head(r))) { res = continue_single_pick(); if (res) goto release_todo_list; } if (index_differs_from("HEAD", NULL, 0)) { - res = error_dirty_index(opts); + res = error_dirty_index(r->index, opts); goto release_todo_list; } todo_list.current++; @@ -3757,27 +3792,30 @@ int sequencer_continue(struct replay_opts *opts) strbuf_release(&buf); } - res = pick_commits(&todo_list, opts); + res = pick_commits(r, &todo_list, opts); release_todo_list: todo_list_release(&todo_list); return res; } -static int single_pick(struct commit *cmit, struct replay_opts *opts) +static int single_pick(struct repository *r, + struct commit *cmit, + struct replay_opts *opts) { setenv(GIT_REFLOG_ACTION, action_name(opts), 0); - return do_pick_commit(opts->action == REPLAY_PICK ? + return do_pick_commit(r, opts->action == REPLAY_PICK ? TODO_PICK : TODO_REVERT, cmit, opts, 0); } -int sequencer_pick_revisions(struct replay_opts *opts) +int sequencer_pick_revisions(struct repository *r, + struct replay_opts *opts) { struct todo_list todo_list = TODO_LIST_INIT; struct object_id oid; int i, res; assert(opts->revs); - if (read_and_refresh_cache(opts)) + if (read_and_refresh_cache(r, opts)) return -1; for (i = 0; i < opts->revs->pending.nr; i++) { @@ -3789,8 +3827,8 @@ int sequencer_pick_revisions(struct replay_opts *opts) continue; if (!get_oid(name, &oid)) { - if (!lookup_commit_reference_gently(the_repository, &oid, 1)) { - enum object_type type = oid_object_info(the_repository, + if (!lookup_commit_reference_gently(r, &oid, 1)) { + enum object_type type = oid_object_info(r, &oid, NULL); return error(_("%s: can't cherry-pick a %s"), @@ -3819,7 +3857,7 @@ int sequencer_pick_revisions(struct replay_opts *opts) return error(_("empty commit set passed")); if (get_revision(opts->revs)) BUG("unexpected extra commit from walk"); - return single_pick(cmit, opts); + return single_pick(r, cmit, opts); } /* @@ -3838,7 +3876,7 @@ int sequencer_pick_revisions(struct replay_opts *opts) if (save_opts(opts)) return -1; update_abort_safety_file(); - res = pick_commits(&todo_list, opts); + res = pick_commits(r, &todo_list, opts); todo_list_release(&todo_list); return res; } @@ -4242,7 +4280,8 @@ static int make_script_with_merges(struct pretty_print_context *pp, return 0; } -int sequencer_make_script(FILE *out, int argc, const char **argv, +int sequencer_make_script(struct repository *r, FILE *out, + int argc, const char **argv, unsigned flags) { char *format = NULL; @@ -4254,7 +4293,7 @@ int sequencer_make_script(FILE *out, int argc, const char **argv, const char *insn = flags & TODO_LIST_ABBREVIATE_CMDS ? "p" : "pick"; int rebase_merges = flags & TODO_LIST_REBASE_MERGES; - repo_init_revisions(the_repository, &revs, NULL); + repo_init_revisions(r, &revs, NULL); revs.verbose_header = 1; if (!rebase_merges) revs.max_parents = 1; diff --git a/sequencer.h b/sequencer.h index c986bc8251..ad151e95c7 100644 --- a/sequencer.h +++ b/sequencer.h @@ -5,6 +5,7 @@ #include "strbuf.h" struct commit; +struct repository; const char *git_path_commit_editmsg(void); const char *git_path_seq_dir(void); @@ -64,8 +65,9 @@ struct replay_opts { /* Call this to setup defaults before parsing command line options */ void sequencer_init_config(struct replay_opts *opts); -int sequencer_pick_revisions(struct replay_opts *opts); -int sequencer_continue(struct replay_opts *opts); +int sequencer_pick_revisions(struct repository *repo, + struct replay_opts *opts); +int sequencer_continue(struct repository *repo, struct replay_opts *opts); int sequencer_rollback(struct replay_opts *opts); int sequencer_remove_state(struct replay_opts *opts); @@ -79,7 +81,8 @@ int sequencer_remove_state(struct replay_opts *opts); * commits should be rebased onto the new base, this flag needs to be passed. */ #define TODO_LIST_REBASE_COUSINS (1U << 4) -int sequencer_make_script(FILE *out, int argc, const char **argv, +int sequencer_make_script(struct repository *repo, FILE *out, + int argc, const char **argv, unsigned flags); int sequencer_add_exec_commands(const char *command); @@ -98,7 +101,7 @@ extern const char sign_off_header[]; */ void append_signoff(struct strbuf *msgbuf, size_t ignore_footer, unsigned flag); -void append_conflicts_hint(struct strbuf *msgbuf); +void append_conflicts_hint(struct index_state *istate, struct strbuf *msgbuf); int message_is_empty(const struct strbuf *sb, enum commit_msg_cleanup_mode cleanup_mode); int template_untouched(const struct strbuf *sb, const char *template_file, @@ -112,6 +115,8 @@ void commit_post_rewrite(const struct commit *current_head, #define SUMMARY_INITIAL_COMMIT (1 << 0) #define SUMMARY_SHOW_AUTHOR_DATE (1 << 1) -void print_commit_summary(const char *prefix, const struct object_id *oid, +void print_commit_summary(struct repository *repo, + const char *prefix, + const struct object_id *oid, unsigned int flags); #endif From patchwork Fri Oct 19 14:52:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10649591 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BBACE109C for ; Fri, 19 Oct 2018 14:52:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A63EC205FD for ; Fri, 19 Oct 2018 14:52:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9743020856; Fri, 19 Oct 2018 14:52:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 702C3205FD for ; Fri, 19 Oct 2018 14:52:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727650AbeJSW7U (ORCPT ); Fri, 19 Oct 2018 18:59:20 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:34055 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727636AbeJSW7U (ORCPT ); Fri, 19 Oct 2018 18:59:20 -0400 Received: by mail-lj1-f193.google.com with SMTP id j17-v6so31124291lja.1 for ; Fri, 19 Oct 2018 07:52:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QcFlIXl5iPjK3zP1ZW2iheowNvvdVY2b/yTRdLz2OdU=; b=b8cd+uGaVYQdpx70lZmXDeYsJAPkpiIvYMZRXSes9BiVhs6+J44OdHLD1WIn+fkZjl lWv2joE2iSgY3mmv+LPOKyXe9jYuJJBZGpAlzZYUbxuQ1EKg5huRu+yBUkoxE+5Rz/qX 5NTry5HJPWrWJHAYqWMgOX+vsXKH7dEAG/NWJuIvbSx78XhWQVG/6ndMKic3vGiwlZ6r ql+1D4/KZcq9sl3+oLx106GnNteTX+nVzlPE1AT0FfWlhQx+fRMariwJ1GbuyvhAPih3 PNZdhPcOW2E8MZ4vcPqwpWgZF/Su4zNBsNUrexeHbe79sCDspjxSr1PqfasfGOOJuou1 lzng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QcFlIXl5iPjK3zP1ZW2iheowNvvdVY2b/yTRdLz2OdU=; b=RBR2GG+J239Dt3NEgRht5uHnCdCSOakWwiTtc8RQd68NH+HX4/kt3gy1h5jOHisNDn 9ZPqg0Sc0OCbl6IiBgb2nwAH+OOHZLkH9OfVGFX5AC3AYtZq+MunqdwvfeJD+FYMKKYw mQmJYb0dl5KFx9LVujxgABc3OgReAyoDVZaAaCDk2Dydu7DV23GsiCVlZoVQ7F8IXHmD 78cjmQ59A8/6mslCDjpH48l179Bi1Voq26ZNtYOWTe4iuV4aueX/ADx5OwjXUekHG0tr h/3uTbaNVgrEeYhtZw9mkp2ODGHSBweRqBVhOxywE90ggSd78NWKSYR7k5ftlKdwuzzW LyNg== X-Gm-Message-State: ABuFfogh8aRVlv+GBIXupOHcNo/2jcA7rWnVH/VAW79kDvIy5EnlbXWh bC5cJrCQYiLqRlcD4rWcyarUHhuz X-Google-Smtp-Source: ACcGV62MjrS564vID6S+13op3++KEIHZsPXwLP1jqsw3YkZIVKF2LzDld41RHm+u492LIgFEzy1UVw== X-Received: by 2002:a2e:6f0c:: with SMTP id k12-v6mr23266449ljc.66.1539960769732; Fri, 19 Oct 2018 07:52:49 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g64-v6sm4002414lfe.87.2018.10.19.07.52.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 07:52:49 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= Subject: [PATCH 06/19] sequencer.c: remove implicit dependency on the_repository Date: Fri, 19 Oct 2018 16:52:24 +0200 Message-Id: <20181019145237.16079-7-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181019145237.16079-1-pclouds@gmail.com> References: <20181019145237.16079-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Note that the_hash_algo stays, even if we can easily replace it with repo->hash_algo. My reason is I still believe tying hash_algo to a struct repository is a wrong move. But if I'm wrong, we can always go for another round of conversion. Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/rebase--helper.c | 10 ++-- builtin/revert.c | 2 +- sequencer.c | 108 +++++++++++++++++++++------------------ sequencer.h | 12 ++--- 4 files changed, 70 insertions(+), 62 deletions(-) diff --git a/builtin/rebase--helper.c b/builtin/rebase--helper.c index b66cd8cd41..605fcaa89c 100644 --- a/builtin/rebase--helper.c +++ b/builtin/rebase--helper.c @@ -76,14 +76,14 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix) return !!sequencer_make_script(the_repository, stdout, argc, argv, flags); if ((command == SHORTEN_OIDS || command == EXPAND_OIDS) && argc == 1) - return !!transform_todos(flags); + return !!transform_todos(the_repository, flags); if (command == CHECK_TODO_LIST && argc == 1) - return !!check_todo_list(); + return !!check_todo_list(the_repository); if (command == SKIP_UNNECESSARY_PICKS && argc == 1) - return !!skip_unnecessary_picks(); + return !!skip_unnecessary_picks(the_repository); if (command == REARRANGE_SQUASH && argc == 1) - return !!rearrange_squash(); + return !!rearrange_squash(the_repository); if (command == ADD_EXEC && argc == 2) - return !!sequencer_add_exec_commands(argv[1]); + return !!sequencer_add_exec_commands(the_repository, argv[1]); usage_with_options(builtin_rebase_helper_usage, options); } diff --git a/builtin/revert.c b/builtin/revert.c index cd9f068195..1fa75b2773 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -201,7 +201,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) if (cmd == 'c') return sequencer_continue(the_repository, opts); if (cmd == 'a') - return sequencer_rollback(opts); + return sequencer_rollback(the_repository, opts); return sequencer_pick_revisions(the_repository, opts); } diff --git a/sequencer.c b/sequencer.c index 6b79359114..2c2ea2b45d 100644 --- a/sequencer.c +++ b/sequencer.c @@ -351,7 +351,8 @@ static void free_message(struct commit *commit, struct commit_message *msg) unuse_commit_buffer(commit, msg->message); } -static void print_advice(int show_hint, struct replay_opts *opts) +static void print_advice(struct repository *r, int show_hint, + struct replay_opts *opts) { char *msg = getenv("GIT_CHERRY_PICK_HELP"); @@ -362,7 +363,7 @@ static void print_advice(int show_hint, struct replay_opts *opts) * (typically rebase --interactive) wants to take care * of the commit itself so remove CHERRY_PICK_HEAD */ - unlink(git_path_cherry_pick_head(the_repository)); + unlink(git_path_cherry_pick_head(r)); return; } @@ -435,9 +436,9 @@ static int read_oneliner(struct strbuf *buf, return 1; } -static struct tree *empty_tree(void) +static struct tree *empty_tree(struct repository *r) { - return lookup_tree(the_repository, the_repository->hash_algo->empty_tree); + return lookup_tree(r, the_hash_algo->empty_tree); } static int error_dirty_index(struct index_state *istate, struct replay_opts *opts) @@ -548,8 +549,8 @@ static int do_recursive_merge(struct repository *r, o.show_rename_progress = 1; head_tree = parse_tree_indirect(head); - next_tree = next ? get_commit_tree(next) : empty_tree(); - base_tree = base ? get_commit_tree(base) : empty_tree(); + next_tree = next ? get_commit_tree(next) : empty_tree(r); + base_tree = base ? get_commit_tree(base) : empty_tree(r); for (xopt = opts->xopts; xopt != opts->xopts + opts->xopts_nr; xopt++) parse_merge_opt(&o, *xopt); @@ -595,15 +596,16 @@ static struct object_id *get_cache_tree_oid(struct index_state *istate) return &istate->cache_tree->oid; } -static int is_index_unchanged(struct index_state *istate) +static int is_index_unchanged(struct repository *r) { struct object_id head_oid, *cache_tree_oid; struct commit *head_commit; + struct index_state *istate = r->index; if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL)) return error(_("could not resolve HEAD commit")); - head_commit = lookup_commit(the_repository, &head_oid); + head_commit = lookup_commit(r, &head_oid); /* * If head_commit is NULL, check_commit, called from @@ -1221,7 +1223,7 @@ void print_commit_summary(struct repository *r, strbuf_release(&format); } -static int parse_head(struct commit **head) +static int parse_head(struct repository *r, struct commit **head) { struct commit *current_head; struct object_id oid; @@ -1229,7 +1231,7 @@ static int parse_head(struct commit **head) if (get_oid("HEAD", &oid)) { current_head = NULL; } else { - current_head = lookup_commit_reference(the_repository, &oid); + current_head = lookup_commit_reference(r, &oid); if (!current_head) return error(_("could not parse HEAD")); if (!oideq(&oid, ¤t_head->object.oid)) { @@ -1269,7 +1271,7 @@ static int try_to_commit(struct repository *r, enum commit_msg_cleanup_mode cleanup; int res = 0; - if (parse_head(¤t_head)) + if (parse_head(r, ¤t_head)) return -1; if (flags & AMEND_MSG) { @@ -1436,7 +1438,7 @@ static int allow_empty(struct repository *r, if (!opts->allow_empty) return 0; /* let "git commit" barf as necessary */ - index_unchanged = is_index_unchanged(r->index); + index_unchanged = is_index_unchanged(r); if (index_unchanged < 0) return index_unchanged; if (!index_unchanged) @@ -1538,8 +1540,10 @@ static int is_pick_or_similar(enum todo_command command) } } -static int update_squash_messages(enum todo_command command, - struct commit *commit, struct replay_opts *opts) +static int update_squash_messages(struct repository *r, + enum todo_command command, + struct commit *commit, + struct replay_opts *opts) { struct strbuf buf = STRBUF_INIT; int res; @@ -1568,7 +1572,7 @@ static int update_squash_messages(enum todo_command command, if (get_oid("HEAD", &head)) return error(_("need a HEAD to fixup")); - if (!(head_commit = lookup_commit_reference(the_repository, &head))) + if (!(head_commit = lookup_commit_reference(r, &head))) return error(_("could not read HEAD")); if (!(head_message = get_commit_buffer(head_commit, NULL))) return error(_("could not read HEAD's commit message")); @@ -1807,7 +1811,7 @@ static int do_pick_commit(struct repository *r, if (command == TODO_REWORD) flags |= EDIT_MSG | VERIFY_MSG; else if (is_fixup(command)) { - if (update_squash_messages(command, commit, opts)) + if (update_squash_messages(r, command, commit, opts)) return -1; flags |= AMEND_MSG; if (!final_fixup) @@ -1877,7 +1881,7 @@ static int do_pick_commit(struct repository *r, ? _("could not revert %s... %s") : _("could not apply %s... %s"), short_commit_name(commit), msg.subject); - print_advice(res == 1, opts); + print_advice(r, res == 1, opts); repo_rerere(r, opts->allow_rerere_auto); goto leave; } @@ -1984,7 +1988,8 @@ static struct todo_item *append_new_todo(struct todo_list *todo_list) return todo_list->items + todo_list->nr++; } -static int parse_insn_line(struct todo_item *item, const char *bol, char *eol) +static int parse_insn_line(struct repository *r, struct todo_item *item, + const char *bol, char *eol) { struct object_id commit_oid; char *end_of_object_name; @@ -2068,11 +2073,12 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol) if (status < 0) return -1; - item->commit = lookup_commit_reference(the_repository, &commit_oid); + item->commit = lookup_commit_reference(r, &commit_oid); return !item->commit; } -static int parse_insn_buffer(char *buf, struct todo_list *todo_list) +static int parse_insn_buffer(struct repository *r, char *buf, + struct todo_list *todo_list) { struct todo_item *item; char *p = buf, *next_p; @@ -2088,7 +2094,7 @@ static int parse_insn_buffer(char *buf, struct todo_list *todo_list) item = append_new_todo(todo_list); item->offset_in_buf = p - todo_list->buf.buf; - if (parse_insn_line(item, p, eol)) { + if (parse_insn_line(r, item, p, eol)) { res = error(_("invalid line %d: %.*s"), i, (int)(eol - p), p); item->command = TODO_NOOP; @@ -2149,8 +2155,9 @@ static ssize_t strbuf_read_file_or_whine(struct strbuf *sb, const char *path) return len; } -static int read_populate_todo(struct todo_list *todo_list, - struct replay_opts *opts) +static int read_populate_todo(struct repository *r, + struct todo_list *todo_list, + struct replay_opts *opts) { struct stat st; const char *todo_file = get_todo_path(opts); @@ -2165,7 +2172,7 @@ static int read_populate_todo(struct todo_list *todo_list, return error(_("could not stat '%s'"), todo_file); fill_stat_data(&todo_list->stat, &st); - res = parse_insn_buffer(todo_list->buf.buf, todo_list); + res = parse_insn_buffer(r, todo_list->buf.buf, todo_list); if (res) { if (is_rebase_i(opts)) return error(_("please fix this using " @@ -2196,7 +2203,7 @@ static int read_populate_todo(struct todo_list *todo_list, FILE *f = fopen_or_warn(rebase_path_msgtotal(), "w"); if (strbuf_read_file(&done.buf, rebase_path_done(), 0) > 0 && - !parse_insn_buffer(done.buf.buf, &done)) + !parse_insn_buffer(r, done.buf.buf, &done)) todo_list->done_nr = count_commands(&done); else todo_list->done_nr = 0; @@ -2459,12 +2466,12 @@ static int reset_for_rollback(const struct object_id *oid) return run_command_v_opt(argv, RUN_GIT_CMD); } -static int rollback_single_pick(void) +static int rollback_single_pick(struct repository *r) { struct object_id head_oid; - if (!file_exists(git_path_cherry_pick_head(the_repository)) && - !file_exists(git_path_revert_head(the_repository))) + if (!file_exists(git_path_cherry_pick_head(r)) && + !file_exists(git_path_revert_head(r))) return error(_("no cherry-pick or revert in progress")); if (read_ref_full("HEAD", 0, &head_oid, NULL)) return error(_("cannot resolve HEAD")); @@ -2473,7 +2480,7 @@ static int rollback_single_pick(void) return reset_for_rollback(&head_oid); } -int sequencer_rollback(struct replay_opts *opts) +int sequencer_rollback(struct repository *r, struct replay_opts *opts) { FILE *f; struct object_id oid; @@ -2487,7 +2494,7 @@ int sequencer_rollback(struct replay_opts *opts) * If CHERRY_PICK_HEAD or REVERT_HEAD indicates * a single-cherry-pick in progress, abort that. */ - return rollback_single_pick(); + return rollback_single_pick(r); } if (!f) return error_errno(_("cannot open '%s'"), git_path_head_file()); @@ -3441,7 +3448,7 @@ static int pick_commits(struct repository *r, get_todo_path(opts)); else if (match_stat_data(&todo_list->stat, &st)) { todo_list_release(todo_list); - if (read_populate_todo(todo_list, opts)) + if (read_populate_todo(r, todo_list, opts)) res = -1; /* message was printed */ /* `current` will be incremented below */ todo_list->current = -1; @@ -3601,12 +3608,12 @@ static int pick_commits(struct repository *r, return sequencer_remove_state(opts); } -static int continue_single_pick(void) +static int continue_single_pick(struct repository *r) { const char *argv[] = { "commit", NULL }; - if (!file_exists(git_path_cherry_pick_head(the_repository)) && - !file_exists(git_path_revert_head(the_repository))) + if (!file_exists(git_path_cherry_pick_head(r)) && + !file_exists(git_path_revert_head(r))) return error(_("no cherry-pick or revert in progress")); return run_command_v_opt(argv, RUN_GIT_CMD); } @@ -3705,7 +3712,7 @@ static int commit_staged_changes(struct repository *r, struct commit *commit; const char *path = rebase_path_squash_msg(); - if (parse_head(&commit) || + if (parse_head(r, &commit) || !(p = get_commit_buffer(commit, NULL)) || write_message(p, strlen(p), path, 0)) { unuse_commit_buffer(commit, p); @@ -3760,20 +3767,20 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts) if (read_populate_opts(opts)) return -1; if (is_rebase_i(opts)) { - if ((res = read_populate_todo(&todo_list, opts))) + if ((res = read_populate_todo(r, &todo_list, opts))) goto release_todo_list; if (commit_staged_changes(r, opts, &todo_list)) return -1; } else if (!file_exists(get_todo_path(opts))) - return continue_single_pick(); - else if ((res = read_populate_todo(&todo_list, opts))) + return continue_single_pick(r); + else if ((res = read_populate_todo(r, &todo_list, opts))) goto release_todo_list; if (!is_rebase_i(opts)) { /* Verify that the conflict has been resolved */ if (file_exists(git_path_cherry_pick_head(r)) || file_exists(git_path_revert_head(r))) { - res = continue_single_pick(); + res = continue_single_pick(r); if (res) goto release_todo_list; } @@ -4346,7 +4353,8 @@ int sequencer_make_script(struct repository *r, FILE *out, * Add commands after pick and (series of) squash/fixup commands * in the todo list. */ -int sequencer_add_exec_commands(const char *commands) +int sequencer_add_exec_commands(struct repository *r, + const char *commands) { const char *todo_file = rebase_path_todo(); struct todo_list todo_list = TODO_LIST_INIT; @@ -4357,7 +4365,7 @@ int sequencer_add_exec_commands(const char *commands) if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) return error(_("could not read '%s'."), todo_file); - if (parse_insn_buffer(todo_list.buf.buf, &todo_list)) { + if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) { todo_list_release(&todo_list); return error(_("unusable todo list: '%s'"), todo_file); } @@ -4402,7 +4410,7 @@ int sequencer_add_exec_commands(const char *commands) return i; } -int transform_todos(unsigned flags) +int transform_todos(struct repository *r, unsigned flags) { const char *todo_file = rebase_path_todo(); struct todo_list todo_list = TODO_LIST_INIT; @@ -4413,7 +4421,7 @@ int transform_todos(unsigned flags) if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) return error(_("could not read '%s'."), todo_file); - if (parse_insn_buffer(todo_list.buf.buf, &todo_list)) { + if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) { todo_list_release(&todo_list); return error(_("unusable todo list: '%s'"), todo_file); } @@ -4486,7 +4494,7 @@ define_commit_slab(commit_seen, unsigned char); * Check if there is an unrecognized command or a * bad SHA-1 in a command. */ -int check_todo_list(void) +int check_todo_list(struct repository *r) { enum check_level check_level = get_missing_commit_check_level(); struct strbuf todo_file = STRBUF_INIT; @@ -4503,7 +4511,7 @@ int check_todo_list(void) goto leave_check; } advise_to_edit_todo = res = - parse_insn_buffer(todo_list.buf.buf, &todo_list); + parse_insn_buffer(r, todo_list.buf.buf, &todo_list); if (res || check_level == CHECK_IGNORE) goto leave_check; @@ -4522,7 +4530,7 @@ int check_todo_list(void) goto leave_check; } strbuf_release(&todo_file); - res = !!parse_insn_buffer(todo_list.buf.buf, &todo_list); + res = !!parse_insn_buffer(r, todo_list.buf.buf, &todo_list); /* Find commits in git-rebase-todo.backup yet unseen */ for (i = todo_list.nr - 1; i >= 0; i--) { @@ -4586,7 +4594,7 @@ static int rewrite_file(const char *path, const char *buf, size_t len) } /* skip picking commits whose parents are unchanged */ -int skip_unnecessary_picks(void) +int skip_unnecessary_picks(struct repository *r) { const char *todo_file = rebase_path_todo(); struct strbuf buf = STRBUF_INIT; @@ -4604,7 +4612,7 @@ int skip_unnecessary_picks(void) if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0) return -1; - if (parse_insn_buffer(todo_list.buf.buf, &todo_list) < 0) { + if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) { todo_list_release(&todo_list); return -1; } @@ -4690,7 +4698,7 @@ define_commit_slab(commit_todo_item, struct todo_item *); * message will have to be retrieved from the commit (as the oneline in the * script cannot be trusted) in order to normalize the autosquash arrangement. */ -int rearrange_squash(void) +int rearrange_squash(struct repository *r) { const char *todo_file = rebase_path_todo(); struct todo_list todo_list = TODO_LIST_INIT; @@ -4701,7 +4709,7 @@ int rearrange_squash(void) if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0) return -1; - if (parse_insn_buffer(todo_list.buf.buf, &todo_list) < 0) { + if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) { todo_list_release(&todo_list); return -1; } diff --git a/sequencer.h b/sequencer.h index ad151e95c7..1232157da2 100644 --- a/sequencer.h +++ b/sequencer.h @@ -68,7 +68,7 @@ void sequencer_init_config(struct replay_opts *opts); int sequencer_pick_revisions(struct repository *repo, struct replay_opts *opts); int sequencer_continue(struct repository *repo, struct replay_opts *opts); -int sequencer_rollback(struct replay_opts *opts); +int sequencer_rollback(struct repository *repo, struct replay_opts *opts); int sequencer_remove_state(struct replay_opts *opts); #define TODO_LIST_KEEP_EMPTY (1U << 0) @@ -85,11 +85,11 @@ int sequencer_make_script(struct repository *repo, FILE *out, int argc, const char **argv, unsigned flags); -int sequencer_add_exec_commands(const char *command); -int transform_todos(unsigned flags); -int check_todo_list(void); -int skip_unnecessary_picks(void); -int rearrange_squash(void); +int sequencer_add_exec_commands(struct repository *repo, const char *command); +int transform_todos(struct repository *repo, unsigned flags); +int check_todo_list(struct repository *repo); +int skip_unnecessary_picks(struct repository *repo); +int rearrange_squash(struct repository *repo); extern const char sign_off_header[]; From patchwork Fri Oct 19 14:52:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10649597 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 192AC17DE for ; Fri, 19 Oct 2018 14:52:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 094DB205FD for ; Fri, 19 Oct 2018 14:52:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F2029207A7; Fri, 19 Oct 2018 14:52:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 09D4A205FD for ; Fri, 19 Oct 2018 14:52:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727652AbeJSW7V (ORCPT ); Fri, 19 Oct 2018 18:59:21 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:34057 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727641AbeJSW7U (ORCPT ); Fri, 19 Oct 2018 18:59:20 -0400 Received: by mail-lj1-f195.google.com with SMTP id j17-v6so31124323lja.1 for ; Fri, 19 Oct 2018 07:52:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=B5xBzOc+UuKpyYiZR4gxoNITKg2OIZpnjfUAj1CdhcM=; b=cfo0KeGInEzazXt01Qc7tWhK0kCbw0+t1OiRyj0ftWLMtU7BV2TvTMEzIa6JOECm8W dHTlqLyTgIxQgMxxaInF7YqtzNh8vTpNHtYC3GLIcoOspMsdk7XFZvxi9em/FZMsRsOV VA+DlmALdZdnCOV2IFq8uOn2CkWC48miCPO43EF1uNTwv/edeuze082FsXYt30BFgNhS 0GiTjcyn8uASUQLxxHDeM6AFBcUV0Rp4QUTFr2B3hp8V0wgDo/ncyDTEGvTTmBvCD+9X e/aP6JoueWHOp4B7Z34rX2gMRFgZV0M8zOVeyhSBtc4j6SQjARBAYTvmEaKnvz0LdsTd brjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=B5xBzOc+UuKpyYiZR4gxoNITKg2OIZpnjfUAj1CdhcM=; b=hkSnD4snZMiRJ6INwUH26Wi8kyc+TrwDX0zKkvnPE+8BLC919I+5R2fNvjGBauH5lL bNp5a/IDwOz6OvefcLZ4IPfy5x/izVGB2bs3Yd0cvoMN1KIlZmudneTf33krjWU+OonM avnAI6df5lfM6XfVTYyxIZ5uCB7kv7vKeI7ji30d6yTVN/z3Rj7YsVm3hwSIqx9+FQzy XriZelWmV7PhlCRsm2Cu+NtXsrorRkD24xq9tKsp01JuOt6ncxN2hdVDm6L5O+ab+l2P tQSScDprhdFWnL2OgLOxTcLdwLfqR7MPvNj0owc8jbPhAA88uU81CKz284gg70xDTsk8 +zOg== X-Gm-Message-State: ABuFfoiQn/84n9dIqKz6vOKg737DkK7+RpG71JMwbCM1P1/33qK34rsr lPBs5tR+eZ9fvZEwhWnGbGw93AoB X-Google-Smtp-Source: ACcGV61PKtEIi+b7X86W9VYOaT56PZAMSc4ChmMut5jq4mZ0/Qs/VHP7bJtUPQtgVowcBK1t+PbGBA== X-Received: by 2002:a2e:9e88:: with SMTP id f8-v6mr22758361ljk.142.1539960770904; Fri, 19 Oct 2018 07:52:50 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g64-v6sm4002414lfe.87.2018.10.19.07.52.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 07:52:50 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= Subject: [PATCH 07/19] notes-merge.c: remove implicit dependency on the_index Date: Fri, 19 Oct 2018 16:52:25 +0200 Message-Id: <20181019145237.16079-8-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181019145237.16079-1-pclouds@gmail.com> References: <20181019145237.16079-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/notes.c | 2 +- notes-merge.c | 12 +++++++----- notes-merge.h | 6 +++++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/builtin/notes.c b/builtin/notes.c index c05cd004ab..d8bd01656a 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -808,7 +808,7 @@ static int merge(int argc, const char **argv, const char *prefix) usage_with_options(git_notes_merge_usage, options); } - init_notes_merge_options(&o); + init_notes_merge_options(&o, the_repository); o.verbosity = verbosity + NOTES_MERGE_VERBOSITY_DEFAULT; if (do_abort) diff --git a/notes-merge.c b/notes-merge.c index bd05d50b05..c3bee1a87d 100644 --- a/notes-merge.c +++ b/notes-merge.c @@ -18,11 +18,13 @@ struct notes_merge_pair { struct object_id obj, base, local, remote; }; -void init_notes_merge_options(struct notes_merge_options *o) +void init_notes_merge_options(struct notes_merge_options *o, + struct repository *repo) { memset(o, 0, sizeof(struct notes_merge_options)); strbuf_init(&(o->commit_msg), 0); o->verbosity = NOTES_MERGE_VERBOSITY_DEFAULT; + o->repo = repo; } static int path_to_oid(const char *path, struct object_id *oid) @@ -127,7 +129,7 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o, trace_printf("\tdiff_tree_remote(base = %.7s, remote = %.7s)\n", oid_to_hex(base), oid_to_hex(remote)); - repo_diff_setup(the_repository, &opt); + repo_diff_setup(o->repo, &opt); opt.flags.recursive = 1; opt.output_format = DIFF_FORMAT_NO_OUTPUT; diff_setup_done(&opt); @@ -190,7 +192,7 @@ static void diff_tree_local(struct notes_merge_options *o, trace_printf("\tdiff_tree_local(len = %i, base = %.7s, local = %.7s)\n", len, oid_to_hex(base), oid_to_hex(local)); - repo_diff_setup(the_repository, &opt); + repo_diff_setup(o->repo, &opt); opt.flags.recursive = 1; opt.output_format = DIFF_FORMAT_NO_OUTPUT; diff_setup_done(&opt); @@ -350,7 +352,7 @@ static int ll_merge_in_worktree(struct notes_merge_options *o, status = ll_merge(&result_buf, oid_to_hex(&p->obj), &base, NULL, &local, o->local_ref, &remote, o->remote_ref, - &the_index, NULL); + o->repo->index, NULL); free(base.ptr); free(local.ptr); @@ -711,7 +713,7 @@ int notes_merge_commit(struct notes_merge_options *o, /* write file as blob, and add to partial_tree */ if (stat(path.buf, &st)) die_errno("Failed to stat '%s'", path.buf); - if (index_path(&the_index, &blob_oid, path.buf, &st, HASH_WRITE_OBJECT)) + if (index_path(o->repo->index, &blob_oid, path.buf, &st, HASH_WRITE_OBJECT)) die("Failed to write blob object from '%s'", path.buf); if (add_note(partial_tree, &obj_oid, &blob_oid, NULL)) die("Failed to add resolved note '%s' to notes tree", diff --git a/notes-merge.h b/notes-merge.h index 6c74e9385b..fe70cbd5e8 100644 --- a/notes-merge.h +++ b/notes-merge.h @@ -7,6 +7,8 @@ struct commit; struct object_id; +struct repository; + #define NOTES_MERGE_WORKTREE "NOTES_MERGE_WORKTREE" enum notes_merge_verbosity { @@ -15,6 +17,7 @@ enum notes_merge_verbosity { }; struct notes_merge_options { + struct repository *repo; const char *local_ref; const char *remote_ref; struct strbuf commit_msg; @@ -23,7 +26,8 @@ struct notes_merge_options { unsigned has_worktree:1; }; -void init_notes_merge_options(struct notes_merge_options *o); +void init_notes_merge_options(struct notes_merge_options *o, + struct repository *repo); /* * Merge notes from o->remote_ref into o->local_ref From patchwork Fri Oct 19 14:52:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10649593 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5664D1750 for ; Fri, 19 Oct 2018 14:52:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4656D205FD for ; Fri, 19 Oct 2018 14:52:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3AED020856; Fri, 19 Oct 2018 14:52:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C5FDB205FD for ; Fri, 19 Oct 2018 14:52:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727665AbeJSW7W (ORCPT ); Fri, 19 Oct 2018 18:59:22 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:39555 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727642AbeJSW7V (ORCPT ); Fri, 19 Oct 2018 18:59:21 -0400 Received: by mail-lj1-f195.google.com with SMTP id p1-v6so31091851ljg.6 for ; Fri, 19 Oct 2018 07:52:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p3/toxNXMg0bRBOAhYyLkrTQY3QNQREzLVmFI9h1ROU=; b=vITSUZKnJT4j3sjkUR824z6PAczlr5QEcTYqWe1xjmdoLHCnHEYuVwsmgS8h0+jT0d +qNWtLpt3oybMgG8taEQI/8GIRJgLpyjsznuhsXn+SK03Hqk+iBs4rOUoAapAJbPvT9K bSUGBUcgAy4P+wpWFQP38a8H0QlLgsUAUtO6aFnJWFAgS+55pBeQ0eGrCmiX0Z4x2F4k YHBOy9MVeHJ2GfopYMCp/Vn74sYKgX0RufGTQgre4SgAhtsNNKIECmZH2xwBkd38GP4h 03kreh5FZU9XMQOEo3Ky6ljlvi14olwIcikzrn2jw3QUBhu0Op9Hggq5j37qzIWjSwTm 2wFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p3/toxNXMg0bRBOAhYyLkrTQY3QNQREzLVmFI9h1ROU=; b=i+B5RX1923AZK/vlZu5S/NBucimK/HqdipqW3hUgssfojQITa07XRxmLWOhDF4kM8P naRxxY3Bfs/07LgLAEnAXeTiIzZhbK16lrsdGyv+iXBV9i/FjAPq/E4DT5UA4mz0Gao2 0FgD9hEMNQGzDpuNw7Q3DcF8Ds3SHXQ/kCvGe1FMyE0mv9IMbfoV03ZywE/4J3Jgy9FW JkuY6EOdYbqG27lBOZ136UHDUIo2XnWF20gqUEPJW9LJJRzf8V0KhjI/W4vfauMW/5SR oaLkTVNVqNoursT4ez2G4xwGB66d5AAXHyaco9simizO0E4sHrfYqHr6DDs4Ru5Ke2Fe x+sw== X-Gm-Message-State: ABuFfojW97Qwh3MAQcqaXSH9jkgRXSnbCwdow9uLGL8XgFvwermsokjt Luop5qF1RZfztglpAzozu76KBXc8 X-Google-Smtp-Source: ACcGV62PLQlTEJAo9kMNLkWt0KkYRpc5Wh56iUfEBr6jZIjQZSQMvvXwkpGTkNSuX8mZLArm2RyOYw== X-Received: by 2002:a2e:9ec5:: with SMTP id h5-v6mr7460875ljk.40.1539960772057; Fri, 19 Oct 2018 07:52:52 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g64-v6sm4002414lfe.87.2018.10.19.07.52.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 07:52:51 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= Subject: [PATCH 08/19] notes-merge.c: remove implicit dependency the_repository Date: Fri, 19 Oct 2018 16:52:26 +0200 Message-Id: <20181019145237.16079-9-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181019145237.16079-1-pclouds@gmail.com> References: <20181019145237.16079-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Nguyễn Thái Ngọc Duy --- notes-merge.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notes-merge.c b/notes-merge.c index c3bee1a87d..b6a998bfd4 100644 --- a/notes-merge.c +++ b/notes-merge.c @@ -558,7 +558,7 @@ int notes_merge(struct notes_merge_options *o, else if (!check_refname_format(o->local_ref, 0) && is_null_oid(&local_oid)) local = NULL; /* local_oid == null_oid indicates unborn ref */ - else if (!(local = lookup_commit_reference(the_repository, &local_oid))) + else if (!(local = lookup_commit_reference(o->repo, &local_oid))) die("Could not parse local commit %s (%s)", oid_to_hex(&local_oid), o->local_ref); trace_printf("\tlocal commit: %.7s\n", oid_to_hex(&local_oid)); @@ -576,7 +576,7 @@ int notes_merge(struct notes_merge_options *o, die("Failed to resolve remote notes ref '%s'", o->remote_ref); } - } else if (!(remote = lookup_commit_reference(the_repository, &remote_oid))) { + } else if (!(remote = lookup_commit_reference(o->repo, &remote_oid))) { die("Could not parse remote commit %s (%s)", oid_to_hex(&remote_oid), o->remote_ref); } From patchwork Fri Oct 19 14:52:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10649599 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1045E109C for ; Fri, 19 Oct 2018 14:52:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F364020748 for ; Fri, 19 Oct 2018 14:52:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E757E205FD; Fri, 19 Oct 2018 14:52:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FCA3205FD for ; Fri, 19 Oct 2018 14:52:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727681AbeJSW7Y (ORCPT ); Fri, 19 Oct 2018 18:59:24 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:36311 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727657AbeJSW7X (ORCPT ); Fri, 19 Oct 2018 18:59:23 -0400 Received: by mail-lf1-f65.google.com with SMTP id l1-v6so5674994lfc.3 for ; Fri, 19 Oct 2018 07:52:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gr2Q9WEgSs5sPeN+RXJPyeaXS7+OSR/dnPCGPR8+avk=; b=L0BNiXil2C0sRJVNwRlQkzKm5zDcRTj8iyUT/r7SBIwTu9pxrSj34XjI1Ot61M7pWL UVTzEBcuyOXxT7XJDyek/v4DPBTUOc73kYy72dicf5JcA632AyW+5jWmnGDvx8GlCAxj NRCwhjvgi7Eai1zN4+nn0pSGT1+v/keZxyw5ctOHDXeHhjR3m/YGLA+XTJgDgkrlsUkR BmorAze1x82eEe5tSgBkWzKGBqSBU6M+G9zR5/asweB/cpDPLOv+I+UckjMbSvX1uhtS rdgSZN7NjlWNTj+yYy4z8SWp3FE5LfkAEflmc5YHkcPrTZuth/SLY+VlR4nu1N66hIUf kXkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gr2Q9WEgSs5sPeN+RXJPyeaXS7+OSR/dnPCGPR8+avk=; b=KimcaTnGu7QTtK5igBHEUdfbJ380/Xzg1hpyxgRrIILWo9Cg5fheAZGiFFkac7CLnW UTKS4Puk7UCIKd9fK9tBwWM6KNZtDx6C/KjaQ9KJkyzP/HmBLSSFogKKQMWgpyz8icmq szRLM7GhBVP+hT3X4d+tIaQI/Ibb0LhX2WrWJL11oLqm+S8+2xHKVFWhpmYG/V5fsapu YaRW+aB2JEq6UbrYOLqjjkj0j6zHHhzjFox0UaoITkjjkFBmVpuL0mC7rxO16VGXjX5x OVEMuYSgMFTrW00G998m0YxllsVccu/Q4fhCnMF/HlBWw/O1vptQ14iyi36/V4b3hy/6 3iNA== X-Gm-Message-State: ABuFfogXMhKZDih8ZAiRuXGNHGus00lj3VG1Gq8elafdXB8J4M2zlcHH sjfaCO1WixQbnPcrGUF377cXXTQd X-Google-Smtp-Source: ACcGV61wxbcbZ5utE33E7fd+PCcGopngE/C4n+XunRuc7ucRtQb1wgYVPYJ9gCD4HnKb7B3XSNfwTw== X-Received: by 2002:a19:9f8c:: with SMTP id i134-v6mr3170531lfe.52.1539960773141; Fri, 19 Oct 2018 07:52:53 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g64-v6sm4002414lfe.87.2018.10.19.07.52.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 07:52:52 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= Subject: [PATCH 09/19] repository.c: replace hold_locked_index() with repo_hold_locked_index() Date: Fri, 19 Oct 2018 16:52:27 +0200 Message-Id: <20181019145237.16079-10-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181019145237.16079-1-pclouds@gmail.com> References: <20181019145237.16079-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP hold_locked_index() assumes the index path at $GIT_DIR/index. This is not good for places that take an arbitrary index_state instead of the_index, which is basically everywhere except builtin/. Replace it with repo_hold_locked_index(). hold_locked_index() remains as a wrapper around repo_hold_locked_index() to reduce changes in builtin/ Signed-off-by: Nguyễn Thái Ngọc Duy --- apply.c | 3 ++- builtin/clone.c | 1 + cache.h | 2 +- merge-recursive.c | 2 +- merge.c | 2 +- read-cache.c | 5 ----- repository.c | 8 ++++++++ repository.h | 4 ++++ rerere.c | 2 +- sequencer.c | 8 ++++---- wt-status.c | 2 +- 11 files changed, 24 insertions(+), 15 deletions(-) diff --git a/apply.c b/apply.c index fdae1d423b..122e6ddf92 100644 --- a/apply.c +++ b/apply.c @@ -4710,7 +4710,8 @@ static int apply_patch(struct apply_state *state, state->index_file, LOCK_DIE_ON_ERROR); else - hold_locked_index(&state->lock_file, LOCK_DIE_ON_ERROR); + repo_hold_locked_index(state->repo, &state->lock_file, + LOCK_DIE_ON_ERROR); } if (state->check_index && read_apply_cache(state) < 0) { diff --git a/builtin/clone.c b/builtin/clone.c index 15b142d646..dfefe85770 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -8,6 +8,7 @@ * Clone a repository into a different directory that does not yet exist. */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "config.h" #include "lockfile.h" diff --git a/cache.h b/cache.h index 59c8a93046..ef2483ce45 100644 --- a/cache.h +++ b/cache.h @@ -433,6 +433,7 @@ void validate_cache_entries(const struct index_state *istate); #define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at) #define unmerge_cache(pathspec) unmerge_index(&the_index, pathspec) #define read_blob_data_from_cache(path, sz) read_blob_data_from_index(&the_index, (path), (sz)) +#define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags)) #endif #define TYPE_BITS 3 @@ -826,7 +827,6 @@ extern struct cache_entry *refresh_cache_entry(struct index_state *, struct cach */ extern void update_index_if_able(struct index_state *, struct lock_file *); -extern int hold_locked_index(struct lock_file *, int); extern void set_alternate_index_output(const char *); extern int verify_index_checksum; diff --git a/merge-recursive.c b/merge-recursive.c index c0fb83d285..c186812ff2 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3510,7 +3510,7 @@ int merge_recursive_generic(struct merge_options *o, } } - hold_locked_index(&lock, LOCK_DIE_ON_ERROR); + repo_hold_locked_index(the_repository, &lock, LOCK_DIE_ON_ERROR); clean = merge_recursive(o, head_commit, next_commit, ca, result); if (clean < 0) { diff --git a/merge.c b/merge.c index 91008f7602..dbbc9d9f80 100644 --- a/merge.c +++ b/merge.c @@ -58,7 +58,7 @@ int checkout_fast_forward(struct repository *r, refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL); - if (hold_locked_index(&lock_file, LOCK_REPORT_ON_ERROR) < 0) + if (repo_hold_locked_index(r, &lock_file, LOCK_REPORT_ON_ERROR) < 0) return -1; memset(&trees, 0, sizeof(trees)); diff --git a/read-cache.c b/read-cache.c index 1df5c16dbc..7ad3330942 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1726,11 +1726,6 @@ static int read_index_extension(struct index_state *istate, return 0; } -int hold_locked_index(struct lock_file *lk, int lock_flags) -{ - return hold_lock_file_for_update(lk, get_index_file(), lock_flags); -} - int read_index(struct index_state *istate) { return read_index_from(istate, get_index_file(), get_git_dir()); diff --git a/repository.c b/repository.c index 5dd1486718..39b5a80d43 100644 --- a/repository.c +++ b/repository.c @@ -3,6 +3,7 @@ #include "object-store.h" #include "config.h" #include "object.h" +#include "lockfile.h" #include "submodule-config.h" /* The main repository */ @@ -257,3 +258,10 @@ int repo_read_index(struct repository *repo) return read_index_from(repo->index, repo->index_file, repo->gitdir); } + +int repo_hold_locked_index(struct repository *repo, + struct lock_file *lf, + int flags) +{ + return hold_lock_file_for_update(lf, repo->index_file, flags); +} diff --git a/repository.h b/repository.h index 9f16c42c1e..968330218f 100644 --- a/repository.h +++ b/repository.h @@ -6,6 +6,7 @@ struct config_set; struct git_hash_algo; struct index_state; +struct lock_file; struct raw_object_store; struct submodule_cache; @@ -130,5 +131,8 @@ void repo_clear(struct repository *repo); * populated then the number of entries will simply be returned. */ int repo_read_index(struct repository *repo); +int repo_hold_locked_index(struct repository *repo, + struct lock_file *lf, + int flags); #endif /* REPOSITORY_H */ diff --git a/rerere.c b/rerere.c index 887e26d45b..13927de7e0 100644 --- a/rerere.c +++ b/rerere.c @@ -702,7 +702,7 @@ static void update_paths(struct repository *r, struct string_list *update) struct lock_file index_lock = LOCK_INIT; int i; - hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR); + repo_hold_locked_index(r, &index_lock, LOCK_DIE_ON_ERROR); for (i = 0; i < update->nr; i++) { struct string_list_item *item = &update->items[i]; diff --git a/sequencer.c b/sequencer.c index 2c2ea2b45d..ced05cd73d 100644 --- a/sequencer.c +++ b/sequencer.c @@ -535,7 +535,7 @@ static int do_recursive_merge(struct repository *r, char **xopt; struct lock_file index_lock = LOCK_INIT; - if (hold_locked_index(&index_lock, LOCK_REPORT_ON_ERROR) < 0) + if (repo_hold_locked_index(r, &index_lock, LOCK_REPORT_ON_ERROR) < 0) return -1; read_index(r->index); @@ -1935,7 +1935,7 @@ static int read_and_refresh_cache(struct repository *r, struct replay_opts *opts) { struct lock_file index_lock = LOCK_INIT; - int index_fd = hold_locked_index(&index_lock, 0); + int index_fd = repo_hold_locked_index(r, &index_lock, 0); if (read_index_preload(r->index, NULL, 0) < 0) { rollback_lock_file(&index_lock); return error(_("git %s: failed to read the index"), @@ -2866,7 +2866,7 @@ static int do_reset(struct repository *r, struct unpack_trees_options unpack_tree_opts; int ret = 0, i; - if (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) + if (repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) return -1; if (len == 10 && !strncmp("[new root]", name, len)) { @@ -2981,7 +2981,7 @@ static int do_merge(struct repository *r, static struct lock_file lock; const char *p; - if (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) { + if (repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) { ret = -1; goto leave_merge; } diff --git a/wt-status.c b/wt-status.c index 3632276236..da28921772 100644 --- a/wt-status.c +++ b/wt-status.c @@ -2371,7 +2371,7 @@ int require_clean_work_tree(struct repository *r, struct lock_file lock_file = LOCK_INIT; int err = 0, fd; - fd = hold_locked_index(&lock_file, 0); + fd = repo_hold_locked_index(r, &lock_file, 0); refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL); if (0 <= fd) update_index_if_able(r->index, &lock_file); From patchwork Fri Oct 19 14:52:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10649601 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7D22B17DE for ; Fri, 19 Oct 2018 14:52:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CDCA205FD for ; Fri, 19 Oct 2018 14:52:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 60D33207A7; Fri, 19 Oct 2018 14:52:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A2E8205FD for ; Fri, 19 Oct 2018 14:52:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727673AbeJSW7Y (ORCPT ); Fri, 19 Oct 2018 18:59:24 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:39562 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727642AbeJSW7X (ORCPT ); Fri, 19 Oct 2018 18:59:23 -0400 Received: by mail-lj1-f196.google.com with SMTP id p1-v6so31091971ljg.6 for ; Fri, 19 Oct 2018 07:52:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=84qzXiIeP9mV0deTSbY4zzVupPShp2lNqVX616TDbXo=; b=X4p2aGdEhwmQ0cxln7/HG4Eq5cCkBnkTR1Nkzvo9AjKwwEkW68x4mPZ0RlZf/KTonq gZVJvgtZ72sG4s89WOmSSGkciSpEobMVgynu/Q8zsUYF8oR9jsZ89RweFsRulgZByCVz O9ShP3iUpfB5pbnym1g/kYwHUmJoq848o3toDHl1o+6oD2LJk8oCNhQWFvQk52xI7ClY o5CMtgEs7DwA32bvDW941htlhKRn0RfyLCTPLUCEBW7D6dRru7ZV5cR27BClliXM5w6U 43Q2xIEBuosdALIbJ1zk5R4Ut+rzcdnB6fSGDz8aDhw0IbasxM1qF3VXDGidATlEbpj/ 8dhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=84qzXiIeP9mV0deTSbY4zzVupPShp2lNqVX616TDbXo=; b=g+juD+UK0ETcoV35c6R06tIpCjQehAPW0kI0MeTivTB/bevzrvo+Sif8BSJhiwU9eE 9DHszv4bk5buWg0cJC8HxNPW25td/wJJI9FbxfPtjE3qUBEZLbD0Wx4W/0ZXg3BmStXF 3JeGf1Fd++uYcJoXlUbF/021oF2F59/uMNtKW4TqRAv0Ch2pz8xwu8HznxOrLXAWARDq jMKIf1ZkrG10+In8M/c+7x3qn9gxOs4v77gYG5RNVfhlPSbs7VWAhUxx4P7855E3MEK+ ROX33nB/DxCkEH++qTxwDeSW7EFkcVaJFS7D0wvdmSC8IfUTc261W8WaNe7TTPygzKg5 lZzw== X-Gm-Message-State: ABuFfohCE1nKS7qGtktHE7J3h9ZRUJwHps8h/B2F0XW39x+FAYCQUCgR h654R/4Gj2JmZC6Hnjnq6kES7LlH X-Google-Smtp-Source: ACcGV62Z/l8G3bPGZTY2zh8u0Nr2TgkRjuOIikeBWUNmmjbZ7uea6r6gtXoorTnob1wgRL73LkPToA== X-Received: by 2002:a2e:7312:: with SMTP id o18-v6mr22484243ljc.125.1539960774246; Fri, 19 Oct 2018 07:52:54 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g64-v6sm4002414lfe.87.2018.10.19.07.52.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 07:52:53 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= Subject: [PATCH 10/19] checkout: avoid the_index when possible Date: Fri, 19 Oct 2018 16:52:28 +0200 Message-Id: <20181019145237.16079-11-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181019145237.16079-1-pclouds@gmail.com> References: <20181019145237.16079-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/checkout.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index acdafc6e4c..38b28c20e2 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -284,7 +284,7 @@ static int checkout_paths(const struct checkout_opts *opts, return run_add_interactive(revision, "--patch=checkout", &opts->pathspec); - hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); + repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR); if (read_cache_preload(&opts->pathspec) < 0) return error(_("index file corrupt")); From patchwork Fri Oct 19 14:52:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10649609 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3A5A91750 for ; Fri, 19 Oct 2018 14:53:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28CC8205FD for ; Fri, 19 Oct 2018 14:53:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1CEFE207A7; Fri, 19 Oct 2018 14:53:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FFE3205FD for ; Fri, 19 Oct 2018 14:53:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727693AbeJSW71 (ORCPT ); Fri, 19 Oct 2018 18:59:27 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:42903 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727666AbeJSW70 (ORCPT ); Fri, 19 Oct 2018 18:59:26 -0400 Received: by mail-lj1-f196.google.com with SMTP id y71-v6so31082638lje.9 for ; Fri, 19 Oct 2018 07:52:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tgoHYdxKd3mq8WkmOaKCdottldfFDfZzUVpbfBX9cyA=; b=FIKB2Xe5qAL5pGNbuDICJL10x4+wDKNS0XwkBE4L0QB4D10ymBqhmC8e6yInSiZ88f zNnQeCvHbs3G/jVFSq2QJJwZqbYZxs8i64raxxQQcwiPhVJrIMYZTAX7uRgnr8Gxy0cE 0tnCHHz/F+2c9KEkY9KU063oBa0XQRdze+5vAvgLevCZsQa1KDQ3Oigm5KGhgdQ/86u6 czP8tWGYzhabsh1k2ATQonzBytQJS/vCzYd5RW/PM40sQMGI+oZoD3YTB415GGe+dr5t vZC0tt0vtMZvxayWb6ahy365KIf6whTp2myOQa+tA2VztU31r5vL0z/1wZL007W0WbP+ F9QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tgoHYdxKd3mq8WkmOaKCdottldfFDfZzUVpbfBX9cyA=; b=Y00JwM99WBbnSr1RTT0F/vAccfu2OqPldpsUhecGt2p5gJYgL0BjGZxaL63+W1hBrj c3AbAbsEa1JBfxv3XQ45qHGOQV6txyg51r4NHaY6Yem5KCRQqyXHV+W9sJNlASoA4IUl RgGe8+1XriYjzD890BfcVt/vVL55U9G7dWOHIoUI+qEp8BFR0VZ9uBSurNDI70H5cfkf pTFHeA3BuLVpHlgb4na8Bg2dTGdJ9xLDEtNm+kPCcDCsGgoRA5gNu3ZowqKc1SPEiJjE +MmeghDgAGuxse2e+hqbUC8AOU4YzU/zceZOv0HjPfEM9iEYWYKTSojFeXgHzTQfYI7S LebA== X-Gm-Message-State: ABuFfojJssZgCE3cBDxxDLYY65UNSbRdFJIgm5HxnjkNH4MFX0WZBVQ2 9zJGQYk+E6AQVIYxCFnhWyc0wsJv X-Google-Smtp-Source: ACcGV6279/VBgoMRcxlySSJ5Dh3cgkVF/qGwyqRUr9U1+MaO9XyJTO4zJuTvh7x5kE4lWagtOCnrPA== X-Received: by 2002:a2e:5645:: with SMTP id k66-v6mr22508514ljb.48.1539960775429; Fri, 19 Oct 2018 07:52:55 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g64-v6sm4002414lfe.87.2018.10.19.07.52.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 07:52:54 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= Subject: [PATCH 11/19] read-cache.c: kill read_index() Date: Fri, 19 Oct 2018 16:52:29 +0200 Message-Id: <20181019145237.16079-12-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181019145237.16079-1-pclouds@gmail.com> References: <20181019145237.16079-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP read_index() shares the same problem as hold_locked_index(): it assumes $GIT_DIR/index. Move all call sites to repo_read_index() instead. read_index_preload() and read_index_unmerged() are also killed as a consequence. Signed-off-by: Nguyễn Thái Ngọc Duy --- apply.c | 2 +- blame.c | 4 ++-- builtin/am.c | 2 +- builtin/commit.c | 2 +- builtin/diff-tree.c | 2 +- cache.h | 11 +++-------- merge-recursive.c | 2 +- merge.c | 2 +- preload-index.c | 11 ++++++----- read-cache.c | 11 ++++------- repository.h | 6 ++++++ rerere.c | 6 +++--- revision.c | 4 ++-- sequencer.c | 22 +++++++++++----------- sha1-name.c | 6 +++--- 15 files changed, 46 insertions(+), 47 deletions(-) diff --git a/apply.c b/apply.c index 122e6ddf92..f5d507a64f 100644 --- a/apply.c +++ b/apply.c @@ -4017,7 +4017,7 @@ static int read_apply_cache(struct apply_state *state) return read_index_from(state->repo->index, state->index_file, get_git_dir()); else - return read_index(state->repo->index); + return repo_read_index(state->repo); } /* This function tries to read the object name from the current index */ diff --git a/blame.c b/blame.c index d84c937780..6e3de62379 100644 --- a/blame.c +++ b/blame.c @@ -183,7 +183,7 @@ static struct commit *fake_working_tree_commit(struct repository *r, unsigned mode; struct strbuf msg = STRBUF_INIT; - read_index(r->index); + repo_read_index(r); time(&now); commit = alloc_commit_node(the_repository); commit->object.parsed = 1; @@ -265,7 +265,7 @@ static struct commit *fake_working_tree_commit(struct repository *r, * want to run "diff-index --cached". */ discard_index(r->index); - read_index(r->index); + repo_read_index(r); len = strlen(path); if (!mode) { diff --git a/builtin/am.c b/builtin/am.c index 3ee9a9d2a9..d2af94500c 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -2328,7 +2328,7 @@ int cmd_am(int argc, const char **argv, const char *prefix) /* Ensure a valid committer ident can be constructed */ git_committer_info(IDENT_STRICT); - if (read_index_preload(&the_index, NULL, 0) < 0) + if (repo_read_index_preload(the_repository, NULL, 0) < 0) die(_("failed to read the index")); if (in_progress) { diff --git a/builtin/commit.c b/builtin/commit.c index f7bbba944d..7eda5e4b7e 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1363,7 +1363,7 @@ int cmd_status(int argc, const char **argv, const char *prefix) if (status_format != STATUS_FORMAT_PORCELAIN && status_format != STATUS_FORMAT_PORCELAIN_V2) progress_flag = REFRESH_PROGRESS; - read_index_preload(&the_index, &s.pathspec, progress_flag); + repo_read_index_preload(the_repository, &s.pathspec, progress_flag); refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED|progress_flag, &s.pathspec, NULL, NULL); diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c index ef996126d7..42bc1eb41d 100644 --- a/builtin/diff-tree.c +++ b/builtin/diff-tree.c @@ -165,7 +165,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix) if (opt->diffopt.detect_rename) { if (!the_index.cache) - read_index(&the_index); + repo_read_index(the_repository); opt->diffopt.setup |= DIFF_SETUP_USE_SIZE_CACHE; } while (fgets(line, sizeof(line), stdin)) { diff --git a/cache.h b/cache.h index ef2483ce45..d9303ae25f 100644 --- a/cache.h +++ b/cache.h @@ -408,11 +408,11 @@ void validate_cache_entries(const struct index_state *istate); #define active_cache_changed (the_index.cache_changed) #define active_cache_tree (the_index.cache_tree) -#define read_cache() read_index(&the_index) +#define read_cache() repo_read_index(the_repository) #define read_cache_from(path) read_index_from(&the_index, (path), (get_git_dir())) -#define read_cache_preload(pathspec) read_index_preload(&the_index, (pathspec), 0) +#define read_cache_preload(pathspec) repo_read_index_preload(the_repository, (pathspec), 0) #define is_cache_unborn() is_index_unborn(&the_index) -#define read_cache_unmerged() read_index_unmerged(&the_index) +#define read_cache_unmerged() repo_read_index_unmerged(the_repository) #define discard_cache() discard_index(&the_index) #define unmerged_cache() unmerged_index(&the_index) #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen)) @@ -659,16 +659,11 @@ extern int daemonize(void); /* Initialize and use the cache information */ struct lock_file; -extern int read_index(struct index_state *); -extern int read_index_preload(struct index_state *, - const struct pathspec *pathspec, - unsigned int refresh_flags); extern int do_read_index(struct index_state *istate, const char *path, int must_exist); /* for testting only! */ extern int read_index_from(struct index_state *, const char *path, const char *gitdir); extern int is_index_unborn(struct index_state *); -extern int read_index_unmerged(struct index_state *); /* For use with `write_locked_index()`. */ #define COMMIT_LOCK (1 << 0) diff --git a/merge-recursive.c b/merge-recursive.c index c186812ff2..b025c10e31 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3443,7 +3443,7 @@ int merge_recursive(struct merge_options *o, discard_cache(); if (!o->call_depth) - read_cache(); + repo_read_index(the_repository); o->ancestor = "merged common ancestors"; clean = merge_trees(o, get_commit_tree(h1), get_commit_tree(h2), diff --git a/merge.c b/merge.c index dbbc9d9f80..7c1d756c3f 100644 --- a/merge.c +++ b/merge.c @@ -37,7 +37,7 @@ int try_merge_command(struct repository *r, argv_array_clear(&args); discard_index(r->index); - if (read_index(r->index) < 0) + if (repo_read_index(r) < 0) die(_("failed to read the cache")); resolve_undo_clear_index(r->index); diff --git a/preload-index.c b/preload-index.c index 9e7152ab14..5327c59923 100644 --- a/preload-index.c +++ b/preload-index.c @@ -7,6 +7,7 @@ #include "fsmonitor.h" #include "config.h" #include "progress.h" +#include "repository.h" #ifdef NO_PTHREADS static void preload_index(struct index_state *index, @@ -153,12 +154,12 @@ static void preload_index(struct index_state *index, } #endif -int read_index_preload(struct index_state *index, - const struct pathspec *pathspec, - unsigned int refresh_flags) +int repo_read_index_preload(struct repository *repo, + const struct pathspec *pathspec, + unsigned int refresh_flags) { - int retval = read_index(index); + int retval = repo_read_index(repo); - preload_index(index, pathspec, refresh_flags); + preload_index(repo->index, pathspec, refresh_flags); return retval; } diff --git a/read-cache.c b/read-cache.c index 7ad3330942..8844f723e9 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1726,11 +1726,6 @@ static int read_index_extension(struct index_state *istate, return 0; } -int read_index(struct index_state *istate) -{ - return read_index_from(istate, get_index_file(), get_git_dir()); -} - static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool, unsigned int version, struct ondisk_cache_entry *ondisk, @@ -3196,12 +3191,14 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock, * state can call this and check its return value, instead of calling * read_cache(). */ -int read_index_unmerged(struct index_state *istate) +int repo_read_index_unmerged(struct repository *repo) { + struct index_state *istate; int i; int unmerged = 0; - read_index(istate); + repo_read_index(repo); + istate = repo->index; for (i = 0; i < istate->cache_nr; i++) { struct cache_entry *ce = istate->cache[i]; struct cache_entry *new_ce; diff --git a/repository.h b/repository.h index 968330218f..cc3879add4 100644 --- a/repository.h +++ b/repository.h @@ -7,6 +7,7 @@ struct config_set; struct git_hash_algo; struct index_state; struct lock_file; +struct pathspec; struct raw_object_store; struct submodule_cache; @@ -135,4 +136,9 @@ int repo_hold_locked_index(struct repository *repo, struct lock_file *lf, int flags); +int repo_read_index_preload(struct repository *, + const struct pathspec *pathspec, + unsigned refresh_flags); +int repo_read_index_unmerged(struct repository *); + #endif /* REPOSITORY_H */ diff --git a/rerere.c b/rerere.c index 13927de7e0..7abf7c8d41 100644 --- a/rerere.c +++ b/rerere.c @@ -558,7 +558,7 @@ static int find_conflict(struct repository *r, struct string_list *conflict) { int i; - if (read_index(r->index) < 0) + if (repo_read_index(r) < 0) return error(_("index file corrupt")); for (i = 0; i < r->index->cache_nr;) { @@ -592,7 +592,7 @@ int rerere_remaining(struct repository *r, struct string_list *merge_rr) if (setup_rerere(merge_rr, RERERE_READONLY)) return 0; - if (read_index(r->index) < 0) + if (repo_read_index(r) < 0) return error(_("index file corrupt")); for (i = 0; i < r->index->cache_nr;) { @@ -1104,7 +1104,7 @@ int rerere_forget(struct repository *r, struct pathspec *pathspec) struct string_list conflict = STRING_LIST_INIT_DUP; struct string_list merge_rr = STRING_LIST_INIT_DUP; - if (read_index(r->index) < 0) + if (repo_read_index(r) < 0) return error(_("index file corrupt")); fd = setup_rerere(&merge_rr, RERERE_NOAUTOUPDATE); diff --git a/revision.c b/revision.c index b5108b75ab..3138c11ec5 100644 --- a/revision.c +++ b/revision.c @@ -1372,7 +1372,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags) { struct worktree **worktrees, **p; - read_index(revs->repo->index); + repo_read_index(revs->repo); do_add_index_objects_to_pending(revs, revs->repo->index); if (revs->single_worktree) @@ -1518,7 +1518,7 @@ static void prepare_show_merge(struct rev_info *revs) head->object.flags |= SYMMETRIC_LEFT; if (!istate->cache_nr) - read_index(istate); + repo_read_index(revs->repo); for (i = 0; i < istate->cache_nr; i++) { const struct cache_entry *ce = istate->cache[i]; if (!ce_stage(ce)) diff --git a/sequencer.c b/sequencer.c index ced05cd73d..3620a42649 100644 --- a/sequencer.c +++ b/sequencer.c @@ -441,9 +441,9 @@ static struct tree *empty_tree(struct repository *r) return lookup_tree(r, the_hash_algo->empty_tree); } -static int error_dirty_index(struct index_state *istate, struct replay_opts *opts) +static int error_dirty_index(struct repository *repo, struct replay_opts *opts) { - if (read_index_unmerged(istate)) + if (repo_read_index_unmerged(repo)) return error_resolve_conflict(_(action_name(opts))); error(_("your local changes would be overwritten by %s."), @@ -478,7 +478,7 @@ static int fast_forward_to(struct repository *r, struct strbuf sb = STRBUF_INIT; struct strbuf err = STRBUF_INIT; - read_index(r->index); + repo_read_index(r); if (checkout_fast_forward(r, from, to, 1)) return -1; /* the callee should have complained already */ @@ -538,7 +538,7 @@ static int do_recursive_merge(struct repository *r, if (repo_hold_locked_index(r, &index_lock, LOCK_REPORT_ON_ERROR) < 0) return -1; - read_index(r->index); + repo_read_index(r); init_merge_options(&o); o.ancestor = base ? base_label : "(empty tree)"; @@ -1709,7 +1709,7 @@ static int do_pick_commit(struct repository *r, oidcpy(&head, the_hash_algo->empty_tree); if (index_differs_from(unborn ? empty_tree_oid_hex() : "HEAD", NULL, 0)) - return error_dirty_index(r->index, opts); + return error_dirty_index(r, opts); } discard_index(r->index); @@ -1936,7 +1936,7 @@ static int read_and_refresh_cache(struct repository *r, { struct lock_file index_lock = LOCK_INIT; int index_fd = repo_hold_locked_index(r, &index_lock, 0); - if (read_index_preload(r->index, NULL, 0) < 0) { + if (repo_read_index_preload(r, NULL, 0) < 0) { rollback_lock_file(&index_lock); return error(_("git %s: failed to read the index"), _(action_name(opts))); @@ -2742,7 +2742,7 @@ static int do_exec(struct repository *r, const char *command_line) child_env.argv); /* force re-reading of the cache */ - if (discard_index(r->index) < 0 || read_index(r->index) < 0) + if (discard_index(r->index) < 0 || repo_read_index(r) < 0) return error(_("could not read index")); dirty = require_clean_work_tree(r, "rebase", NULL, 1, 1); @@ -2908,7 +2908,7 @@ static int do_reset(struct repository *r, unpack_tree_opts.merge = 1; unpack_tree_opts.update = 1; - if (read_index_unmerged(r->index)) { + if (repo_read_index_unmerged(r)) { rollback_lock_file(&lock); strbuf_release(&ref_name); return error_resolve_conflict(_(action_name(opts))); @@ -3162,7 +3162,7 @@ static int do_merge(struct repository *r, /* force re-reading of the cache */ if (!ret && (discard_index(r->index) < 0 || - read_index(r->index) < 0)) + repo_read_index(r) < 0)) ret = error(_("could not read index")); goto leave_merge; } @@ -3184,7 +3184,7 @@ static int do_merge(struct repository *r, commit_list_insert(j->item, &reversed); free_commit_list(bases); - read_index(r->index); + repo_read_index(r); init_merge_options(&o); o.branch1 = "HEAD"; o.branch2 = ref_name.buf; @@ -3785,7 +3785,7 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts) goto release_todo_list; } if (index_differs_from("HEAD", NULL, 0)) { - res = error_dirty_index(r->index, opts); + res = error_dirty_index(r, opts); goto release_todo_list; } todo_list.current++; diff --git a/sha1-name.c b/sha1-name.c index faa60f69e3..8669ad0b47 100644 --- a/sha1-name.c +++ b/sha1-name.c @@ -1749,9 +1749,9 @@ static int get_oid_with_context_1(const char *name, if (flags & GET_OID_RECORD_PATH) oc->path = xstrdup(cp); - if (!active_cache) - read_cache(); - pos = cache_name_pos(cp, namelen); + if (!the_index.cache) + repo_read_index(the_repository); + pos = index_name_pos(&the_index, cp, namelen); if (pos < 0) pos = -pos - 1; while (pos < active_nr) { From patchwork Fri Oct 19 14:52:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10649605 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B316A17DE for ; Fri, 19 Oct 2018 14:53:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A2942205FD for ; Fri, 19 Oct 2018 14:53:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96F1E2094F; Fri, 19 Oct 2018 14:53:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24B5C20748 for ; Fri, 19 Oct 2018 14:53:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727689AbeJSW70 (ORCPT ); Fri, 19 Oct 2018 18:59:26 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:34800 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727657AbeJSW7Z (ORCPT ); Fri, 19 Oct 2018 18:59:25 -0400 Received: by mail-lf1-f65.google.com with SMTP id n26-v6so6772551lfl.1 for ; Fri, 19 Oct 2018 07:52:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8krwI8jazZwikTc1uSFZPWbRtvj66KR4JS+8LcmKRtY=; b=p1AnLZBjibJTI8RcYRq31xxeZ+UruJykUjxaL64d1N4IiP6a87GhuW3hcxa/1TJsJ/ vHOZSoPEqC49cNTIhZRYREYEnX7rLDPfVaUL++kiicOfSh4MVQRE/2GYK5uurxxbAhXn MzALHiYtQH/eIJtOqvAXtxJ8PGffF8f7uNtbU6uB7puNmT8l0p/Jzc2otqVNAWIRLyU4 CGO9kcQDJhvvWRYAn96X136/6QA4WLot9O+jGvPUY1u3Fa55MgmOS+Zx2/FIK+y+nI1W 9Buz79oySm9tpNQJ26rfXNUFMU1jvkKl7ztTWrU6zmF1PsywEXxySMHA2klAaPvkglJx 281A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8krwI8jazZwikTc1uSFZPWbRtvj66KR4JS+8LcmKRtY=; b=Qe3IHec3HYZtVPkS+jMne0Nwe9vIDKGS2pAPz6OmmCDrz8toJe0bv/5x7+vJApFP8o QW9KPLGEOICe3NUYihUpEGjHUU6LrTBX8nQtvye+BYT9FwHphUIJ7bSM1og9zmVmzxOy L1R5bTJYYDuVLgjxRFqUm5e1PDaWrJzlaUreBM1slXMaF1UNM+wjZVokdXYdn/rNBTjz vOEiSOIi9KADbzzEizrctw4s7LVYm4DIYSBcLcIm40AfFjsL0GRzg85A1rN1lqHPurzU HD5IBLmEBndVxYIOOW7iv3hgDTYJY2OOREb00eu1j1Hvpaw+hVjqtT7t62KSMD5KCKbU WYOg== X-Gm-Message-State: ABuFfoiezFNzoRTJOqVj7uVeqfSDy3TlQqRfb0KDoswqSOVh+MTAdcTc AqEUFys9ev5Pzfg3mfj3ZTKnz/Xh X-Google-Smtp-Source: ACcGV61YkousLGV0uKeobO5wlsHfmcFp4hLFUZ8Cvev59J2IBSo1RWEJU12yeFp2OqAxsFsSCWMwPg== X-Received: by 2002:a19:d0c2:: with SMTP id h185-v6mr3160989lfg.81.1539960776389; Fri, 19 Oct 2018 07:52:56 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g64-v6sm4002414lfe.87.2018.10.19.07.52.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 07:52:55 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= Subject: [PATCH 12/19] read-cache.c: replace update_index_if_able with repo_& Date: Fri, 19 Oct 2018 16:52:30 +0200 Message-Id: <20181019145237.16079-13-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181019145237.16079-1-pclouds@gmail.com> References: <20181019145237.16079-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/commit.c | 2 +- builtin/describe.c | 2 +- builtin/diff.c | 2 +- cache.h | 6 ------ read-cache.c | 14 ++++++++------ repository.h | 6 ++++++ wt-status.c | 2 +- 7 files changed, 18 insertions(+), 16 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 7eda5e4b7e..d7afaa9ed4 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1392,7 +1392,7 @@ int cmd_status(int argc, const char **argv, const char *prefix) wt_status_collect(&s); if (0 <= fd) - update_index_if_able(&the_index, &index_lock); + repo_update_index_if_able(the_repository, &index_lock); if (s.relative_paths) s.prefix = prefix; diff --git a/builtin/describe.c b/builtin/describe.c index c48c34e866..cff8ec3d65 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -634,7 +634,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix) NULL, NULL, NULL); fd = hold_locked_index(&index_lock, 0); if (0 <= fd) - update_index_if_able(&the_index, &index_lock); + repo_update_index_if_able(the_repository, &index_lock); repo_init_revisions(the_repository, &revs, prefix); argv_array_pushv(&args, diff_index_args); diff --git a/builtin/diff.c b/builtin/diff.c index f0393bba23..ec78920ee2 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -212,7 +212,7 @@ static void refresh_index_quietly(void) discard_cache(); read_cache(); refresh_cache(REFRESH_QUIET|REFRESH_UNMERGED); - update_index_if_able(&the_index, &lock_file); + repo_update_index_if_able(the_repository, &lock_file); } static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv) diff --git a/cache.h b/cache.h index d9303ae25f..73bf68d8a5 100644 --- a/cache.h +++ b/cache.h @@ -816,12 +816,6 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st); extern int refresh_index(struct index_state *, unsigned int flags, const struct pathspec *pathspec, char *seen, const char *header_msg); extern struct cache_entry *refresh_cache_entry(struct index_state *, struct cache_entry *, unsigned int); -/* - * Opportunistically update the index but do not complain if we can't. - * The lockfile is always committed or rolled back. - */ -extern void update_index_if_able(struct index_state *, struct lock_file *); - extern void set_alternate_index_output(const char *); extern int verify_index_checksum; diff --git a/read-cache.c b/read-cache.c index 8844f723e9..46e5e4000a 100644 --- a/read-cache.c +++ b/read-cache.c @@ -2661,9 +2661,9 @@ static int verify_index_from(const struct index_state *istate, const char *path) return 0; } -static int verify_index(const struct index_state *istate) +static int repo_verify_index(struct repository *repo) { - return verify_index_from(istate, get_index_file()); + return verify_index_from(repo->index, repo->index_file); } static int has_racy_timestamp(struct index_state *istate) @@ -2679,11 +2679,13 @@ static int has_racy_timestamp(struct index_state *istate) return 0; } -void update_index_if_able(struct index_state *istate, struct lock_file *lockfile) +void repo_update_index_if_able(struct repository *repo, + struct lock_file *lockfile) { - if ((istate->cache_changed || has_racy_timestamp(istate)) && - verify_index(istate)) - write_locked_index(istate, lockfile, COMMIT_LOCK); + if ((repo->index->cache_changed || + has_racy_timestamp(repo->index)) && + repo_verify_index(repo)) + write_locked_index(repo->index, lockfile, COMMIT_LOCK); else rollback_lock_file(lockfile); } diff --git a/repository.h b/repository.h index cc3879add4..6fe1c089db 100644 --- a/repository.h +++ b/repository.h @@ -140,5 +140,11 @@ int repo_read_index_preload(struct repository *, const struct pathspec *pathspec, unsigned refresh_flags); int repo_read_index_unmerged(struct repository *); +/* + * Opportunistically update the index but do not complain if we can't. + * The lockfile is always committed or rolled back. + */ +void repo_update_index_if_able(struct repository *, struct lock_file *); + #endif /* REPOSITORY_H */ diff --git a/wt-status.c b/wt-status.c index da28921772..bdc4c36f93 100644 --- a/wt-status.c +++ b/wt-status.c @@ -2374,7 +2374,7 @@ int require_clean_work_tree(struct repository *r, fd = repo_hold_locked_index(r, &lock_file, 0); refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL); if (0 <= fd) - update_index_if_able(r->index, &lock_file); + repo_update_index_if_able(r, &lock_file); rollback_lock_file(&lock_file); if (has_unstaged_changes(r, ignore_submodules)) { From patchwork Fri Oct 19 14:52:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10649607 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C36B81750 for ; Fri, 19 Oct 2018 14:53:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B280F205FD for ; Fri, 19 Oct 2018 14:53:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A710A207A7; Fri, 19 Oct 2018 14:53:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DC1D205FD for ; Fri, 19 Oct 2018 14:53:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727705AbeJSW71 (ORCPT ); Fri, 19 Oct 2018 18:59:27 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:46806 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727596AbeJSW70 (ORCPT ); Fri, 19 Oct 2018 18:59:26 -0400 Received: by mail-lf1-f66.google.com with SMTP id p143-v6so14416797lfp.13 for ; Fri, 19 Oct 2018 07:52:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NEtBvUThpEHRlOETq3nx4SIUlA7bs6m2FUOX5N2XslI=; b=CXRv3XucMwi4u95FX/GtbIIbKpc/u88aftKox0yUq+w/rwB9gOezR3fq9vqEAwkFR6 MYW4B3oy7ucH2FANarB+EPEcQmulspVY5RJRk2wM1PeYtwmf84l/HTB1QsswTTibCe8E 9L3XUFKunYPeCSGO9sZIaka+NKZvynAtldle9DmUoD7zJLuk/F6/25hPINb7FyBrQBXS ssS61rLWxfSwe/7KjPEukxaOaOXcJVOK7YnSJBuEovOwdCi8J6RFSi+MZO+hiWZrqXHy 4cUG2MhdUYbeiscKaLOdV9TzgDyPaSFfiaed/gHPU3etDE8DKiqZ0hdGq7yj9IWP2zxy dBRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NEtBvUThpEHRlOETq3nx4SIUlA7bs6m2FUOX5N2XslI=; b=CHxnqjILxXTT/W6iEePGmyPRbowvdhJYIPf+bqVb1jIQYf6HapVlQCqoa6TCXsySyF dAHBgH5NH1pTkRvlHKaaExT5NFadACEhJgXh0dNEvTS5BdRuVz4aa5ExR8wyezeNnt3l +nC9Yw20LNdaCD61GDssR14TNzeujBqJgcekNlcRSO/VoX80pTcxbSroiwjHbm33X6yC iLin+ggNfKuP42d/x6aN67/VuGxmJi1G9S74RLgIL6O1+62iAoEGlKMfXphyqrsX78zt 0PU5sVOTz+rkYT+C7BebW2qeK6MZs/zo7cLdrJm9GV8nEetZVnNxOkhAcajJipE1EzHF k3BQ== X-Gm-Message-State: ABuFfoif+TVS63Em3TazDY8iZGMDVxcXS++I+oqFbJId8nKdb5zPUbmK yQ+zRGUerU5aUz8r9qpAYjY5z+hO X-Google-Smtp-Source: ACcGV621yJg6fQbXbzU8fdGJClrW0YUlKanh8DZOSQ5TqVFOwjsg7a9IHYXjCOS/ZuV7+OPdyFodAw== X-Received: by 2002:a19:8d11:: with SMTP id p17-v6mr3069124lfd.116.1539960777756; Fri, 19 Oct 2018 07:52:57 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g64-v6sm4002414lfe.87.2018.10.19.07.52.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 07:52:57 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= Subject: [PATCH 13/19] transport.c: remove implicit dependency on the_index Date: Fri, 19 Oct 2018 16:52:31 +0200 Message-Id: <20181019145237.16079-14-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181019145237.16079-1-pclouds@gmail.com> References: <20181019145237.16079-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP note, there's still another hidden dependency related to this: even though we pass a repo to transport_push() we still use is_bare_repository() which pretty much assumes the_repository (and some other global state). Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/push.c | 3 ++- transport.c | 7 ++++--- transport.h | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/builtin/push.c b/builtin/push.c index d09a42062c..efb3e38a8d 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -355,7 +355,8 @@ static int push_with_options(struct transport *transport, struct refspec *rs, if (verbosity > 0) fprintf(stderr, _("Pushing to %s\n"), transport->url); - err = transport_push(transport, rs, flags, &reject_reasons); + err = transport_push(the_repository, transport, + rs, flags, &reject_reasons); if (err != 0) { fprintf(stderr, "%s", push_get_color(PUSH_COLOR_ERROR)); error(_("failed to push some refs to '%s'"), transport->url); diff --git a/transport.c b/transport.c index f4ffbd96cb..b86b2b12c6 100644 --- a/transport.c +++ b/transport.c @@ -1105,7 +1105,8 @@ static int run_pre_push_hook(struct transport *transport, return ret; } -int transport_push(struct transport *transport, +int transport_push(struct repository *repo, + struct transport *transport, struct refspec *rs, int flags, unsigned int *reject_reasons) { @@ -1172,7 +1173,7 @@ int transport_push(struct transport *transport, oid_array_append(&commits, &ref->new_oid); - if (!push_unpushed_submodules(&the_index, + if (!push_unpushed_submodules(repo->index, &commits, transport->remote, rs, @@ -1197,7 +1198,7 @@ int transport_push(struct transport *transport, oid_array_append(&commits, &ref->new_oid); - if (find_unpushed_submodules(&the_index, + if (find_unpushed_submodules(repo->index, &commits, transport->remote->name, &needs_pushing)) { diff --git a/transport.h b/transport.h index 9baeca2d7a..f2ee7c4f49 100644 --- a/transport.h +++ b/transport.h @@ -223,7 +223,8 @@ void transport_set_verbosity(struct transport *transport, int verbosity, #define REJECT_FETCH_FIRST 0x08 #define REJECT_NEEDS_FORCE 0x10 -int transport_push(struct transport *connection, +int transport_push(struct repository *repo, + struct transport *connection, struct refspec *rs, int flags, unsigned int * reject_reasons); From patchwork Fri Oct 19 14:52:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10649611 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 30040109C for ; Fri, 19 Oct 2018 14:53:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E88A205FD for ; Fri, 19 Oct 2018 14:53:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 12DD6207A7; Fri, 19 Oct 2018 14:53:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 40F26205FD for ; Fri, 19 Oct 2018 14:53:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727712AbeJSW73 (ORCPT ); Fri, 19 Oct 2018 18:59:29 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:42904 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727657AbeJSW72 (ORCPT ); Fri, 19 Oct 2018 18:59:28 -0400 Received: by mail-lj1-f193.google.com with SMTP id y71-v6so31082754lje.9 for ; Fri, 19 Oct 2018 07:52:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Pskg+QzzV4GVnpM2RFu+JFZIp5wxuQH/+d8VIQ80gp4=; b=dIsFEF7ThDzLXXMkPoDgH4LHg4YJV/w7P9ISRctRYNdrIv38oawEmycIxeS1U/r6JO S1WHD/+JUxQ/w1JVZxDEYM5/ylgt8veRxO6Z1Px8B5ybWV2OYWgJX6ReatYUOpt6+eDg 6MX9TfDGvnGSaX2L1NRrWAm6K9DvegVpGN4SE0vyIWuXNpdFVsTIybJhctp7wevIuRjc +NdH5ckdPWW/3nlVY7BGaVdFu5gABIZyvOS3tIu/emjdG9sWbkI7+dKP3tg14CU5R37d L7pAwsVn7ec7iPhzAq/fcXwGJBZGaZiZypMb4RMvWyhNV4qxJJ98W79A8udom7vNTGrF uX6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Pskg+QzzV4GVnpM2RFu+JFZIp5wxuQH/+d8VIQ80gp4=; b=jWwS+7BI7wd1aimFYNyWqieuEFPPEfLn7d3Hp3s5PC+4wsZtzwF9RIIZvDVuyK32b4 eyCswL1uIrxtRycFAsLWdycrv4yiGFqnJc9MU1pmaJp4QL8B2FZbfP24Oi9t4N2+M7Gg YETF1C2aUiX+wrKJTHwfotml0Qb0ZOqwpqhdKl6TI9RGUpm5k0fD1MDeGotpSfhHZlof leNTXsNh/M07NtjRgqKTwv5jbAXBqPzn4XS7dtFuDz94mdQe3hjf9QYXHVQREu+K2osL Dko2DzdfgOKC8jx2XeeX2BJg1We6/PdPRTlx+aRFc5usvAS992iTxkDdULTo5o537LCD EGXQ== X-Gm-Message-State: ABuFfogXYuaHdWGSEs6JzrkUg17i2yZA9ch3VbocvktpfU5cVqZkEHB2 eqLVp/aEV3VGdtpSLwYuwLMwL3+S X-Google-Smtp-Source: ACcGV63k2IACT8vj5RLbxFvn2u7JOraRBFPSSB0Gn6d8Do7CqqYBNszwT3FBHXMgoVdAypZzVlQQuA== X-Received: by 2002:a2e:5d16:: with SMTP id r22-v6mr25184192ljb.89.1539960778707; Fri, 19 Oct 2018 07:52:58 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g64-v6sm4002414lfe.87.2018.10.19.07.52.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 07:52:58 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= Subject: [PATCH 14/19] sha1-name.c: remove implicit dependency on the_index Date: Fri, 19 Oct 2018 16:52:32 +0200 Message-Id: <20181019145237.16079-15-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181019145237.16079-1-pclouds@gmail.com> References: <20181019145237.16079-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This kills the_index dependency in get_oid_with_context() but for get_oid() and friends, they still assume the_repository (which also means the_index). Unfortunately the widespread use of get_oid() will make it hard to make the conversion now. We probably will add repo_get_oid() at some point and limit the use of get_oid() in builtin/ instead of forcing all get_oid() call sites to carry struct repository. Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/cat-file.c | 6 ++-- builtin/grep.c | 3 +- builtin/log.c | 3 +- builtin/rev-parse.c | 3 +- cache.h | 4 ++- list-objects-filter-options.c | 2 +- revision.c | 8 +++--- sha1-name.c | 54 +++++++++++++++++++++-------------- 8 files changed, 50 insertions(+), 33 deletions(-) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 8d97c84725..17faea8846 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -66,7 +66,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, if (unknown_type) flags |= OBJECT_INFO_ALLOW_UNKNOWN_TYPE; - if (get_oid_with_context(obj_name, GET_OID_RECORD_PATH, + if (get_oid_with_context(the_repository, obj_name, + GET_OID_RECORD_PATH, &oid, &obj_context)) die("Not a valid object name %s", obj_name); @@ -374,7 +375,8 @@ static void batch_one_object(const char *obj_name, int flags = opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0; enum follow_symlinks_result result; - result = get_oid_with_context(obj_name, flags, &data->oid, &ctx); + result = get_oid_with_context(the_repository, obj_name, + flags, &data->oid, &ctx); if (result != FOUND) { switch (result) { case MISSING_OBJECT: diff --git a/builtin/grep.c b/builtin/grep.c index d8508ddf79..9d40b5c073 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -1006,7 +1006,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix) break; } - if (get_oid_with_context(arg, GET_OID_RECORD_PATH, + if (get_oid_with_context(the_repository, arg, + GET_OID_RECORD_PATH, &oid, &oc)) { if (seen_dashdash) die(_("unable to resolve revision: %s"), arg); diff --git a/builtin/log.c b/builtin/log.c index 061d4fd864..ed28e81a22 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -506,7 +506,8 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c !rev->diffopt.flags.allow_textconv) return stream_blob_to_fd(1, oid, NULL, 0); - if (get_oid_with_context(obj_name, GET_OID_RECORD_PATH, + if (get_oid_with_context(the_repository, obj_name, + GET_OID_RECORD_PATH, &oidc, &obj_context)) die(_("Not a valid object name %s"), obj_name); if (!obj_context.path || diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 455f62246d..38d7d8fd74 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -932,7 +932,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) name++; type = REVERSED; } - if (!get_oid_with_context(name, flags, &oid, &unused)) { + if (!get_oid_with_context(the_repository, name, + flags, &oid, &unused)) { if (verify) revs_count++; else diff --git a/cache.h b/cache.h index 73bf68d8a5..91c092cf76 100644 --- a/cache.h +++ b/cache.h @@ -1327,7 +1327,9 @@ extern int get_oid_tree(const char *str, struct object_id *oid); extern int get_oid_treeish(const char *str, struct object_id *oid); extern int get_oid_blob(const char *str, struct object_id *oid); extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix); -extern int get_oid_with_context(const char *str, unsigned flags, struct object_id *oid, struct object_context *oc); +extern int get_oid_with_context(struct repository *repo, const char *str, + unsigned flags, struct object_id *oid, + struct object_context *oc); typedef int each_abbrev_fn(const struct object_id *oid, void *); diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c index c0e2bd6a06..a683a75a35 100644 --- a/list-objects-filter-options.c +++ b/list-objects-filter-options.c @@ -59,7 +59,7 @@ static int gently_parse_list_objects_filter( * command, but DO NOT complain if we don't have the blob or * ref locally. */ - if (!get_oid_with_context(v0, GET_OID_BLOB, + if (!get_oid_with_context(the_repository, v0, GET_OID_BLOB, &sparse_oid, &oc)) filter_options->sparse_oid_value = oiddup(&sparse_oid); filter_options->choice = LOFC_SPARSE_OID; diff --git a/revision.c b/revision.c index 3138c11ec5..ebbf382e3f 100644 --- a/revision.c +++ b/revision.c @@ -1577,8 +1577,8 @@ static int handle_dotdot_1(const char *arg, char *dotdot, if (!*b_name) b_name = "HEAD"; - if (get_oid_with_context(a_name, oc_flags, &a_oid, a_oc) || - get_oid_with_context(b_name, oc_flags, &b_oid, b_oc)) + if (get_oid_with_context(revs->repo, a_name, oc_flags, &a_oid, a_oc) || + get_oid_with_context(revs->repo, b_name, oc_flags, &b_oid, b_oc)) return -1; if (!cant_be_filename) { @@ -1712,7 +1712,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi if (revarg_opt & REVARG_COMMITTISH) get_sha1_flags |= GET_OID_COMMITTISH; - if (get_oid_with_context(arg, get_sha1_flags, &oid, &oc)) + if (get_oid_with_context(revs->repo, arg, get_sha1_flags, &oid, &oc)) return revs->ignore_missing ? 0 : -1; if (!cant_be_filename) verify_non_filename(revs->prefix, arg); @@ -2440,7 +2440,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s struct object_id oid; struct object *object; struct object_context oc; - if (get_oid_with_context(revs->def, 0, &oid, &oc)) + if (get_oid_with_context(revs->repo, revs->def, 0, &oid, &oc)) diagnose_missing_default(revs->def); object = get_reference(revs, revs->def, &oid, 0); add_pending_object_with_mode(revs, object, revs->def, oc.mode); diff --git a/sha1-name.c b/sha1-name.c index 8669ad0b47..1465b9f1da 100644 --- a/sha1-name.c +++ b/sha1-name.c @@ -1539,7 +1539,7 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name) int get_oid(const char *name, struct object_id *oid) { struct object_context unused; - return get_oid_with_context(name, 0, oid, &unused); + return get_oid_with_context(the_repository, name, 0, oid, &unused); } @@ -1556,35 +1556,40 @@ int get_oid(const char *name, struct object_id *oid) int get_oid_committish(const char *name, struct object_id *oid) { struct object_context unused; - return get_oid_with_context(name, GET_OID_COMMITTISH, + return get_oid_with_context(the_repository, + name, GET_OID_COMMITTISH, oid, &unused); } int get_oid_treeish(const char *name, struct object_id *oid) { struct object_context unused; - return get_oid_with_context(name, GET_OID_TREEISH, + return get_oid_with_context(the_repository, + name, GET_OID_TREEISH, oid, &unused); } int get_oid_commit(const char *name, struct object_id *oid) { struct object_context unused; - return get_oid_with_context(name, GET_OID_COMMIT, + return get_oid_with_context(the_repository, + name, GET_OID_COMMIT, oid, &unused); } int get_oid_tree(const char *name, struct object_id *oid) { struct object_context unused; - return get_oid_with_context(name, GET_OID_TREE, + return get_oid_with_context(the_repository, + name, GET_OID_TREE, oid, &unused); } int get_oid_blob(const char *name, struct object_id *oid) { struct object_context unused; - return get_oid_with_context(name, GET_OID_BLOB, + return get_oid_with_context(the_repository, + name, GET_OID_BLOB, oid, &unused); } @@ -1623,7 +1628,8 @@ static void diagnose_invalid_oid_path(const char *prefix, } /* Must be called only when :stage:filename doesn't exist. */ -static void diagnose_invalid_index_path(int stage, +static void diagnose_invalid_index_path(struct index_state *istate, + int stage, const char *prefix, const char *filename) { @@ -1636,11 +1642,11 @@ static void diagnose_invalid_index_path(int stage, prefix = ""; /* Wrong stage number? */ - pos = cache_name_pos(filename, namelen); + pos = index_name_pos(istate, filename, namelen); if (pos < 0) pos = -pos - 1; - if (pos < active_nr) { - ce = active_cache[pos]; + if (pos < istate->cache_nr) { + ce = istate->cache[pos]; if (ce_namelen(ce) == namelen && !memcmp(ce->name, filename, namelen)) die("Path '%s' is in the index, but not at stage %d.\n" @@ -1652,11 +1658,11 @@ static void diagnose_invalid_index_path(int stage, /* Confusion between relative and absolute filenames? */ strbuf_addstr(&fullname, prefix); strbuf_addstr(&fullname, filename); - pos = cache_name_pos(fullname.buf, fullname.len); + pos = index_name_pos(istate, fullname.buf, fullname.len); if (pos < 0) pos = -pos - 1; - if (pos < active_nr) { - ce = active_cache[pos]; + if (pos < istate->cache_nr) { + ce = istate->cache[pos]; if (ce_namelen(ce) == fullname.len && !memcmp(ce->name, fullname.buf, fullname.len)) die("Path '%s' is in the index, but not '%s'.\n" @@ -1690,7 +1696,8 @@ static char *resolve_relative_path(const char *rel) rel); } -static int get_oid_with_context_1(const char *name, +static int get_oid_with_context_1(struct repository *repo, + const char *name, unsigned flags, const char *prefix, struct object_id *oid, @@ -1749,13 +1756,13 @@ static int get_oid_with_context_1(const char *name, if (flags & GET_OID_RECORD_PATH) oc->path = xstrdup(cp); - if (!the_index.cache) + if (!repo->index->cache) repo_read_index(the_repository); - pos = index_name_pos(&the_index, cp, namelen); + pos = index_name_pos(repo->index, cp, namelen); if (pos < 0) pos = -pos - 1; - while (pos < active_nr) { - ce = active_cache[pos]; + while (pos < repo->index->cache_nr) { + ce = repo->index->cache[pos]; if (ce_namelen(ce) != namelen || memcmp(ce->name, cp, namelen)) break; @@ -1768,7 +1775,7 @@ static int get_oid_with_context_1(const char *name, pos++; } if (only_to_die && name[1] && name[1] != '/') - diagnose_invalid_index_path(stage, prefix, cp); + diagnose_invalid_index_path(repo->index, stage, prefix, cp); free(new_path); return -1; } @@ -1833,12 +1840,15 @@ void maybe_die_on_misspelt_object_name(const char *name, const char *prefix) { struct object_context oc; struct object_id oid; - get_oid_with_context_1(name, GET_OID_ONLY_TO_DIE, prefix, &oid, &oc); + get_oid_with_context_1(the_repository, name, GET_OID_ONLY_TO_DIE, + prefix, &oid, &oc); } -int get_oid_with_context(const char *str, unsigned flags, struct object_id *oid, struct object_context *oc) +int get_oid_with_context(struct repository *repo, const char *str, + unsigned flags, struct object_id *oid, + struct object_context *oc) { if (flags & GET_OID_FOLLOW_SYMLINKS && flags & GET_OID_ONLY_TO_DIE) BUG("incompatible flags for get_sha1_with_context"); - return get_oid_with_context_1(str, flags, NULL, oid, oc); + return get_oid_with_context_1(repo, str, flags, NULL, oid, oc); } From patchwork Fri Oct 19 14:52:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10649617 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2F5B317DE for ; Fri, 19 Oct 2018 14:53:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CD56205FD for ; Fri, 19 Oct 2018 14:53:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1125B207A7; Fri, 19 Oct 2018 14:53:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9691E205FD for ; Fri, 19 Oct 2018 14:53:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727722AbeJSW7b (ORCPT ); Fri, 19 Oct 2018 18:59:31 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:32827 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727596AbeJSW7b (ORCPT ); Fri, 19 Oct 2018 18:59:31 -0400 Received: by mail-lj1-f196.google.com with SMTP id z21-v6so31111490ljz.0 for ; Fri, 19 Oct 2018 07:53:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5swyvmleAEmD9tJk4RRn4C6cOnQmAFmEHsIEtdjbmiM=; b=NuQqo/aOcnNRLTEvrFytGTtGrP+A8Er5fZ7X1U2Zh5FKP4pbao+IotWDIYoDuCZlo/ wdk1KsAnXL9108oDvuYoTiE/aYh4eHyW/DLmqzSpIgJUtqR9FY1vhQk070gin+4DJLEM 3BVktibeKwuDVRhFt/KdPtlz6JT4g8dhnqUG9uY0S3+uL5hFNnGTwyCayYF5hGhg0A3N +yZKogNcDQrRRvIO1AWGCUFv347jVliU4Pogc7T9vRWnaC4sEVFvjHrbEIJ9IY55VWqg 5G0INk+Aa/sFkLm/16p90+FSp9YjPM834TL0EzDzsq+lXkwNosbUcTI5stuzucguJeTA Jd7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5swyvmleAEmD9tJk4RRn4C6cOnQmAFmEHsIEtdjbmiM=; b=iLWU35guPzoNlaHJ+sVbhWlDhS7NvekUnbNbLUPI0MLH6plLo2l7d/PYuSDmcx50pH Bdl7sTBuUqXz5TzJva8nFU5cFjVe2XKhO6RLmhc2TbXruwSJFpk59yyZrXDBIqJ8zkZR aIW1wBQKsnlnfoC3BgcgPSPSkB/X+nbySzBTwwlkv4ihAY7+Vs05k//eKSrtyAEVPDx+ zaWgNeMerc+HestmBM03K9BQlkvLzgqprKtA2gANWzOerSHRP+iyaZ6sUiP24GA975We N4UH2xEjZE25iaxa6qQus/+cc6p71HVdkkhNoo5Hmjs/KEekurLx1UeH2X7KzPcwGwky XuCw== X-Gm-Message-State: ABuFfoj7XNWOzK1svx0GJwPWQzgH4PpIRD7aMOzGP0RRDNrMytx/dyPu tzhBOjYnINfroJKeBGLHaqSJvfeX X-Google-Smtp-Source: ACcGV61VI7Wh5+tJ2DgPpL+cDRC9vAxKn8LDylPj+ib2DD7NdmPFvmvACyXL0z1voug/iwLwt/VHAA== X-Received: by 2002:a2e:5c89:: with SMTP id q131-v6mr24402466ljb.119.1539960779797; Fri, 19 Oct 2018 07:52:59 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g64-v6sm4002414lfe.87.2018.10.19.07.52.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 07:52:59 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= Subject: [PATCH 15/19] merge-recursive.c: remove implicit dependency on the_index Date: Fri, 19 Oct 2018 16:52:33 +0200 Message-Id: <20181019145237.16079-16-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181019145237.16079-1-pclouds@gmail.com> References: <20181019145237.16079-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/am.c | 2 +- builtin/checkout.c | 2 +- builtin/merge-recursive.c | 2 +- builtin/merge.c | 2 +- merge-recursive.c | 151 +++++++++++++++++++++----------------- merge-recursive.h | 6 +- sequencer.c | 4 +- 7 files changed, 94 insertions(+), 75 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index d2af94500c..65e10a5eb3 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1597,7 +1597,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa * changes. */ - init_merge_options(&o); + init_merge_options(&o, the_repository); o.branch1 = "HEAD"; their_tree_name = xstrfmt("%.*s", linelen(state->msg), state->msg); diff --git a/builtin/checkout.c b/builtin/checkout.c index 38b28c20e2..8ecb4c43c7 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -670,7 +670,7 @@ static int merge_working_tree(const struct checkout_opts *opts, * a pain; plumb in an option to set * o.renormalize? */ - init_merge_options(&o); + init_merge_options(&o, the_repository); o.verbosity = 0; work = write_tree_from_memory(&o); diff --git a/builtin/merge-recursive.c b/builtin/merge-recursive.c index 9b2f707c29..4864f7b22f 100644 --- a/builtin/merge-recursive.c +++ b/builtin/merge-recursive.c @@ -28,7 +28,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix) struct merge_options o; struct commit *result; - init_merge_options(&o); + init_merge_options(&o, the_repository); if (argv[0] && ends_with(argv[0], "-subtree")) o.subtree_shift = ""; diff --git a/builtin/merge.c b/builtin/merge.c index db22119c93..d2d636d979 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -701,7 +701,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common, return 2; } - init_merge_options(&o); + init_merge_options(&o, the_repository); if (!strcmp(strategy, "subtree")) o.subtree_shift = ""; diff --git a/merge-recursive.c b/merge-recursive.c index b025c10e31..184945ae67 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -318,22 +318,24 @@ static int add_cacheinfo(struct merge_options *o, unsigned int mode, const struct object_id *oid, const char *path, int stage, int refresh, int options) { + struct index_state *istate = o->repo->index; struct cache_entry *ce; int ret; - ce = make_cache_entry(&the_index, mode, oid ? oid : &null_oid, path, stage, 0); + ce = make_cache_entry(istate, mode, oid ? oid : &null_oid, path, stage, 0); if (!ce) return err(o, _("add_cacheinfo failed for path '%s'; merge aborting."), path); - ret = add_cache_entry(ce, options); + ret = add_index_entry(istate, ce, options); if (refresh) { struct cache_entry *nce; - nce = refresh_cache_entry(&the_index, ce, CE_MATCH_REFRESH | CE_MATCH_IGNORE_MISSING); + nce = refresh_cache_entry(istate, ce, + CE_MATCH_REFRESH | CE_MATCH_IGNORE_MISSING); if (!nce) return err(o, _("add_cacheinfo failed to refresh for path '%s'; merge aborting."), path); if (nce != ce) - ret = add_cache_entry(nce, options); + ret = add_index_entry(istate, nce, options); } return ret; } @@ -361,7 +363,7 @@ static int unpack_trees_start(struct merge_options *o, o->unpack_opts.merge = 1; o->unpack_opts.head_idx = 2; o->unpack_opts.fn = threeway_merge; - o->unpack_opts.src_index = &the_index; + o->unpack_opts.src_index = o->repo->index; o->unpack_opts.dst_index = &tmp_index; o->unpack_opts.aggressive = !merge_detect_rename(o); setup_unpack_trees_porcelain(&o->unpack_opts, "merge"); @@ -371,16 +373,16 @@ static int unpack_trees_start(struct merge_options *o, init_tree_desc_from_tree(t+2, merge); rc = unpack_trees(3, t, &o->unpack_opts); - cache_tree_free(&active_cache_tree); + cache_tree_free(&o->repo->index->cache_tree); /* - * Update the_index to match the new results, AFTER saving a copy + * Update o->repo->index to match the new results, AFTER saving a copy * in o->orig_index. Update src_index to point to the saved copy. * (verify_uptodate() checks src_index, and the original index is * the one that had the necessary modification timestamps.) */ - o->orig_index = the_index; - the_index = tmp_index; + o->orig_index = *o->repo->index; + *o->repo->index = tmp_index; o->unpack_opts.src_index = &o->orig_index; return rc; @@ -395,12 +397,13 @@ static void unpack_trees_finish(struct merge_options *o) struct tree *write_tree_from_memory(struct merge_options *o) { struct tree *result = NULL; + struct index_state *istate = o->repo->index; - if (unmerged_cache()) { + if (unmerged_index(istate)) { int i; fprintf(stderr, "BUG: There are unmerged index entries:\n"); - for (i = 0; i < active_nr; i++) { - const struct cache_entry *ce = active_cache[i]; + for (i = 0; i < istate->cache_nr; i++) { + const struct cache_entry *ce = istate->cache[i]; if (ce_stage(ce)) fprintf(stderr, "BUG: %d %.*s\n", ce_stage(ce), (int)ce_namelen(ce), ce->name); @@ -408,16 +411,16 @@ struct tree *write_tree_from_memory(struct merge_options *o) BUG("unmerged index entries in merge-recursive.c"); } - if (!active_cache_tree) - active_cache_tree = cache_tree(); + if (!istate->cache_tree) + istate->cache_tree = cache_tree(); - if (!cache_tree_fully_valid(active_cache_tree) && - cache_tree_update(&the_index, 0) < 0) { + if (!cache_tree_fully_valid(istate->cache_tree) && + cache_tree_update(istate, 0) < 0) { err(o, _("error building trees")); return NULL; } - result = lookup_tree(the_repository, &active_cache_tree->oid); + result = lookup_tree(the_repository, &istate->cache_tree->oid); return result; } @@ -487,17 +490,17 @@ static struct stage_data *insert_stage_data(const char *path, * Create a dictionary mapping file names to stage_data objects. The * dictionary contains one entry for every path with a non-zero stage entry. */ -static struct string_list *get_unmerged(void) +static struct string_list *get_unmerged(struct index_state *istate) { struct string_list *unmerged = xcalloc(1, sizeof(struct string_list)); int i; unmerged->strdup_strings = 1; - for (i = 0; i < active_nr; i++) { + for (i = 0; i < istate->cache_nr; i++) { struct string_list_item *item; struct stage_data *e; - const struct cache_entry *ce = active_cache[i]; + const struct cache_entry *ce = istate->cache[i]; if (!ce_stage(ce)) continue; @@ -657,7 +660,7 @@ static int update_stages(struct merge_options *opt, const char *path, int clear = 1; int options = ADD_CACHE_OK_TO_ADD | ADD_CACHE_SKIP_DFCHECK; if (clear) - if (remove_file_from_cache(path)) + if (remove_file_from_index(opt->repo->index, path)) return -1; if (o) if (add_cacheinfo(opt, o->mode, &o->oid, path, 1, 0, options)) @@ -713,13 +716,14 @@ static int remove_file(struct merge_options *o, int clean, int update_working_directory = !o->call_depth && !no_wd; if (update_cache) { - if (remove_file_from_cache(path)) + if (remove_file_from_index(o->repo->index, path)) return -1; } if (update_working_directory) { if (ignore_case) { struct cache_entry *ce; - ce = cache_file_exists(path, strlen(path), ignore_case); + ce = index_file_exists(o->repo->index, path, strlen(path), + ignore_case); if (ce && ce_stage(ce) == 0 && strcmp(path, ce->name)) return 0; } @@ -769,7 +773,8 @@ static char *unique_path(struct merge_options *o, const char *path, const char * * check the working directory. If empty_ok is non-zero, also return * 0 in the case where the working-tree dir exists but is empty. */ -static int dir_in_way(const char *path, int check_working_copy, int empty_ok) +static int dir_in_way(struct index_state *istate, const char *path, + int check_working_copy, int empty_ok) { int pos; struct strbuf dirpath = STRBUF_INIT; @@ -778,12 +783,12 @@ static int dir_in_way(const char *path, int check_working_copy, int empty_ok) strbuf_addstr(&dirpath, path); strbuf_addch(&dirpath, '/'); - pos = cache_name_pos(dirpath.buf, dirpath.len); + pos = index_name_pos(istate, dirpath.buf, dirpath.len); if (pos < 0) pos = -1 - pos; - if (pos < active_nr && - !strncmp(dirpath.buf, active_cache[pos]->name, dirpath.len)) { + if (pos < istate->cache_nr && + !strncmp(dirpath.buf, istate->cache[pos]->name, dirpath.len)) { strbuf_release(&dirpath); return 1; } @@ -826,7 +831,7 @@ static int was_tracked(struct merge_options *o, const char *path) return 0; } -static int would_lose_untracked(const char *path) +static int would_lose_untracked(struct index_state *istate, const char *path) { /* * This may look like it can be simplified to: @@ -845,19 +850,19 @@ static int would_lose_untracked(const char *path) * update_file()/would_lose_untracked(); see every comment in this * file which mentions "update_stages". */ - int pos = cache_name_pos(path, strlen(path)); + int pos = index_name_pos(istate, path, strlen(path)); if (pos < 0) pos = -1 - pos; - while (pos < active_nr && - !strcmp(path, active_cache[pos]->name)) { + while (pos < istate->cache_nr && + !strcmp(path, istate->cache[pos]->name)) { /* * If stage #0, it is definitely tracked. * If it has stage #2 then it was tracked * before this merge started. All other * cases the path was not tracked. */ - switch (ce_stage(active_cache[pos])) { + switch (ce_stage(istate->cache[pos])) { case 0: case 2: return 0; @@ -917,7 +922,7 @@ static int make_room_for_path(struct merge_options *o, const char *path) * Do not unlink a file in the work tree if we are not * tracking it. */ - if (would_lose_untracked(path)) + if (would_lose_untracked(o->repo->index, path)) return err(o, _("refusing to lose untracked file at '%s'"), path); @@ -967,7 +972,7 @@ static int update_file_flags(struct merge_options *o, } if (S_ISREG(mode)) { struct strbuf strbuf = STRBUF_INIT; - if (convert_to_working_tree(&the_index, path, buf, size, &strbuf)) { + if (convert_to_working_tree(o->repo->index, path, buf, size, &strbuf)) { free(buf); size = strbuf.len; buf = strbuf_detach(&strbuf, NULL); @@ -1085,7 +1090,7 @@ static int merge_3way(struct merge_options *o, merge_status = ll_merge(result_buf, a->path, &orig, base_name, &src1, name1, &src2, name2, - &the_index, &ll_opts); + o->repo->index, &ll_opts); free(base_name); free(name1); @@ -1096,7 +1101,8 @@ static int merge_3way(struct merge_options *o, return merge_status; } -static int find_first_merges(struct object_array *result, const char *path, +static int find_first_merges(struct repository *repo, + struct object_array *result, const char *path, struct commit *a, struct commit *b) { int i, j; @@ -1116,7 +1122,7 @@ static int find_first_merges(struct object_array *result, const char *path, /* get all revisions that merge commit a */ xsnprintf(merged_revision, sizeof(merged_revision), "^%s", oid_to_hex(&a->object.oid)); - repo_init_revisions(the_repository, &revs, NULL); + repo_init_revisions(repo, &revs, NULL); rev_opts.submodule = path; /* FIXME: can't handle linked worktrees in submodules yet */ revs.single_worktree = path != NULL; @@ -1246,7 +1252,8 @@ static int merge_submodule(struct merge_options *o, return 0; /* find commit which merges them */ - parent_count = find_first_merges(&merges, path, commit_a, commit_b); + parent_count = find_first_merges(o->repo, &merges, path, + commit_a, commit_b); switch (parent_count) { case 0: output(o, 1, _("Failed to merge submodule %s (merge following commits not found)"), path); @@ -1380,7 +1387,7 @@ static int handle_rename_via_dir(struct merge_options *o, */ const struct diff_filespec *dest = pair->two; - if (!o->call_depth && would_lose_untracked(dest->path)) { + if (!o->call_depth && would_lose_untracked(o->repo->index, dest->path)) { char *alt_path = unique_path(o, dest->path, rename_branch); output(o, 1, _("Error: Refusing to lose untracked file at %s; " @@ -1418,8 +1425,8 @@ static int handle_change_delete(struct merge_options *o, const char *update_path = path; int ret = 0; - if (dir_in_way(path, !o->call_depth, 0) || - (!o->call_depth && would_lose_untracked(path))) { + if (dir_in_way(o->repo->index, path, !o->call_depth, 0) || + (!o->call_depth && would_lose_untracked(o->repo->index, path))) { update_path = alt_path = unique_path(o, path, change_branch); } @@ -1429,7 +1436,7 @@ static int handle_change_delete(struct merge_options *o, * correct; since there is no true "middle point" between * them, simply reuse the base version for virtual merge base. */ - ret = remove_file_from_cache(path); + ret = remove_file_from_index(o->repo->index, path); if (!ret) ret = update_file(o, 0, o_oid, o_mode, update_path); } else { @@ -1505,7 +1512,7 @@ static int handle_rename_delete(struct merge_options *o, return -1; if (o->call_depth) - return remove_file_from_cache(dest->path); + return remove_file_from_index(o->repo->index, dest->path); else return update_stages(o, dest->path, NULL, rename_branch == o->branch1 ? dest : NULL, @@ -1567,12 +1574,12 @@ static int handle_file(struct merge_options *o, remove_file(o, 0, rename->path, ren_src_was_dirty); dst_name = unique_path(o, rename->path, cur_branch); } else { - if (dir_in_way(rename->path, !o->call_depth, 0)) { + if (dir_in_way(o->repo->index, rename->path, !o->call_depth, 0)) { dst_name = unique_path(o, rename->path, cur_branch); output(o, 1, _("%s is a directory in %s adding as %s instead"), rename->path, other_branch, dst_name); } else if (!o->call_depth && - would_lose_untracked(rename->path)) { + would_lose_untracked(o->repo->index, rename->path)) { dst_name = unique_path(o, rename->path, cur_branch); output(o, 1, _("Refusing to lose untracked file at %s; " "adding as %s instead"), @@ -1637,14 +1644,14 @@ static int handle_rename_rename_1to2(struct merge_options *o, return -1; } else - remove_file_from_cache(a->path); + remove_file_from_index(o->repo->index, a->path); add = filespec_from_entry(&other, ci->dst_entry2, 3 ^ 1); if (add) { if (update_file(o, 0, &add->oid, add->mode, b->path)) return -1; } else - remove_file_from_cache(b->path); + remove_file_from_index(o->repo->index, b->path); } else if (handle_file(o, a, 2, ci) || handle_file(o, b, 3, ci)) return -1; @@ -1654,6 +1661,7 @@ static int handle_rename_rename_1to2(struct merge_options *o, static int handle_rename_rename_2to1(struct merge_options *o, struct rename_conflict_info *ci) { + struct index_state *istate = o->repo->index; /* Two files, a & b, were renamed to the same thing, c. */ struct diff_filespec *a = ci->pair1->one; struct diff_filespec *b = ci->pair2->one; @@ -1672,8 +1680,12 @@ static int handle_rename_rename_2to1(struct merge_options *o, a->path, c1->path, ci->branch1, b->path, c2->path, ci->branch2); - remove_file(o, 1, a->path, o->call_depth || would_lose_untracked(a->path)); - remove_file(o, 1, b->path, o->call_depth || would_lose_untracked(b->path)); + remove_file(o, 1, a->path, + (o->call_depth || + would_lose_untracked(istate, a->path))); + remove_file(o, 1, b->path, + (o->call_depth || + would_lose_untracked(istate, b->path))); path_side_1_desc = xstrfmt("%s (was %s)", path, a->path); path_side_2_desc = xstrfmt("%s (was %s)", path, b->path); @@ -1706,7 +1718,7 @@ static int handle_rename_rename_2to1(struct merge_options *o, if (was_dirty(o, path)) output(o, 1, _("Refusing to lose dirty file at %s"), path); - else if (would_lose_untracked(path)) + else if (would_lose_untracked(istate, path)) /* * Only way we get here is if both renames were from * a directory rename AND user had an untracked file @@ -1757,7 +1769,7 @@ static struct diff_queue_struct *get_diffpairs(struct merge_options *o, struct diff_queue_struct *ret; struct diff_options opts; - repo_diff_setup(the_repository, &opts); + repo_diff_setup(o->repo, &opts); opts.flags.recursive = 1; opts.flags.rename_empty = 0; opts.detect_rename = merge_detect_rename(o); @@ -2936,8 +2948,8 @@ static int blob_unchanged(struct merge_options *opt, * performed. Comparison can be skipped if both files are * unchanged since their sha1s have already been compared. */ - if (renormalize_buffer(&the_index, path, o.buf, o.len, &o) | - renormalize_buffer(&the_index, path, a.buf, a.len, &a)) + if (renormalize_buffer(opt->repo->index, path, o.buf, o.len, &o) | + renormalize_buffer(opt->repo->index, path, a.buf, a.len, &a)) ret = (o.len == a.len && !memcmp(o.buf, a.buf, o.len)); error_return: @@ -3018,7 +3030,7 @@ static int handle_content_merge(struct merge_options *o, a.path = (char *)path1; b.path = (char *)path2; - if (dir_in_way(path, !o->call_depth, + if (dir_in_way(o->repo->index, path, !o->call_depth, S_ISGITLINK(pair1->two->mode))) df_conflict_remains = 1; } @@ -3051,8 +3063,8 @@ static int handle_content_merge(struct merge_options *o, pos = index_name_pos(&o->orig_index, path, strlen(path)); ce = o->orig_index.cache[pos]; if (ce_skip_worktree(ce)) { - pos = index_name_pos(&the_index, path, strlen(path)); - ce = the_index.cache[pos]; + pos = index_name_pos(o->repo->index, path, strlen(path)); + ce = o->repo->index->cache[pos]; ce->ce_flags |= CE_SKIP_WORKTREE; } return mfi.clean; @@ -3071,7 +3083,7 @@ static int handle_content_merge(struct merge_options *o, if (df_conflict_remains || is_dirty) { char *new_path; if (o->call_depth) { - remove_file_from_cache(path); + remove_file_from_index(o->repo->index, path); } else { if (!mfi.clean) { if (update_stages(o, path, &one, &a, &b)) @@ -3217,7 +3229,7 @@ static int process_entry(struct merge_options *o, oid = b_oid; conf = _("directory/file"); } - if (dir_in_way(path, + if (dir_in_way(o->repo->index, path, !o->call_depth && !S_ISGITLINK(a_mode), 0)) { char *new_path = unique_path(o, path, add_branch); @@ -3228,7 +3240,7 @@ static int process_entry(struct merge_options *o, if (update_file(o, 0, oid, mode, new_path)) clean_merge = -1; else if (o->call_depth) - remove_file_from_cache(path); + remove_file_from_index(o->repo->index, path); free(new_path); } else { output(o, 2, _("Adding %s"), path); @@ -3263,10 +3275,11 @@ int merge_trees(struct merge_options *o, struct tree *common, struct tree **result) { + struct index_state *istate = o->repo->index; int code, clean; struct strbuf sb = STRBUF_INIT; - if (!o->call_depth && index_has_changes(&the_index, head, &sb)) { + if (!o->call_depth && index_has_changes(istate, head, &sb)) { err(o, _("Your local changes to the following files would be overwritten by merge:\n %s"), sb.buf); return -1; @@ -3294,7 +3307,7 @@ int merge_trees(struct merge_options *o, return -1; } - if (unmerged_cache()) { + if (unmerged_index(istate)) { struct string_list *entries; struct rename_info re_info; int i; @@ -3309,7 +3322,7 @@ int merge_trees(struct merge_options *o, get_files_dirs(o, head); get_files_dirs(o, merge); - entries = get_unmerged(); + entries = get_unmerged(o->repo->index); clean = detect_and_process_renames(o, common, head, merge, entries, &re_info); record_df_conflict_files(o, entries); @@ -3425,7 +3438,7 @@ int merge_recursive(struct merge_options *o, * overwritten it: the committed "conflicts" were * already resolved. */ - discard_cache(); + discard_index(o->repo->index); saved_b1 = o->branch1; saved_b2 = o->branch2; o->branch1 = "Temporary merge branch 1"; @@ -3441,9 +3454,9 @@ int merge_recursive(struct merge_options *o, return err(o, _("merge returned no commit")); } - discard_cache(); + discard_index(o->repo->index); if (!o->call_depth) - repo_read_index(the_repository); + repo_read_index(o->repo); o->ancestor = "merged common ancestors"; clean = merge_trees(o, get_commit_tree(h1), get_commit_tree(h2), @@ -3510,7 +3523,7 @@ int merge_recursive_generic(struct merge_options *o, } } - repo_hold_locked_index(the_repository, &lock, LOCK_DIE_ON_ERROR); + repo_hold_locked_index(o->repo, &lock, LOCK_DIE_ON_ERROR); clean = merge_recursive(o, head_commit, next_commit, ca, result); if (clean < 0) { @@ -3518,7 +3531,7 @@ int merge_recursive_generic(struct merge_options *o, return clean; } - if (write_locked_index(&the_index, &lock, + if (write_locked_index(o->repo->index, &lock, COMMIT_LOCK | SKIP_IF_UNCHANGED)) return err(o, _("Unable to write index.")); @@ -3542,10 +3555,12 @@ static void merge_recursive_config(struct merge_options *o) git_config(git_xmerge_config, NULL); } -void init_merge_options(struct merge_options *o) +void init_merge_options(struct merge_options *o, + struct repository *repo) { const char *merge_verbosity; memset(o, 0, sizeof(struct merge_options)); + o->repo = repo; o->verbosity = 2; o->buffer_output = 1; o->diff_rename_limit = -1; diff --git a/merge-recursive.h b/merge-recursive.h index e6a0828eca..c2b7bb65c6 100644 --- a/merge-recursive.h +++ b/merge-recursive.h @@ -6,6 +6,8 @@ struct commit; +struct repository; + struct merge_options { const char *ancestor; const char *branch1; @@ -34,6 +36,7 @@ struct merge_options { struct string_list df_conflict_file_set; struct unpack_trees_options unpack_opts; struct index_state orig_index; + struct repository *repo; }; /* @@ -92,7 +95,8 @@ int merge_recursive_generic(struct merge_options *o, const struct object_id **ca, struct commit **result); -void init_merge_options(struct merge_options *o); +void init_merge_options(struct merge_options *o, + struct repository *repo); struct tree *write_tree_from_memory(struct merge_options *o); int parse_merge_opt(struct merge_options *out, const char *s); diff --git a/sequencer.c b/sequencer.c index 3620a42649..c5073e0b92 100644 --- a/sequencer.c +++ b/sequencer.c @@ -540,7 +540,7 @@ static int do_recursive_merge(struct repository *r, repo_read_index(r); - init_merge_options(&o); + init_merge_options(&o, r); o.ancestor = base ? base_label : "(empty tree)"; o.branch1 = "HEAD"; o.branch2 = next ? next_label : "(empty tree)"; @@ -3185,7 +3185,7 @@ static int do_merge(struct repository *r, free_commit_list(bases); repo_read_index(r); - init_merge_options(&o); + init_merge_options(&o, r); o.branch1 = "HEAD"; o.branch2 = ref_name.buf; o.buffer_output = 2; From patchwork Fri Oct 19 14:52:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10649613 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0371E109C for ; Fri, 19 Oct 2018 14:53:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7A84205FD for ; Fri, 19 Oct 2018 14:53:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC407207A7; Fri, 19 Oct 2018 14:53:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67027205FD for ; Fri, 19 Oct 2018 14:53:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727719AbeJSW7a (ORCPT ); Fri, 19 Oct 2018 18:59:30 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:37317 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727686AbeJSW7a (ORCPT ); Fri, 19 Oct 2018 18:59:30 -0400 Received: by mail-lf1-f67.google.com with SMTP id a82-v6so25459548lfa.4 for ; Fri, 19 Oct 2018 07:53:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4iEbt7bNNLTPd4MO+jWXzC0yX7NMt014yDKrHS/QyBk=; b=HvWhwMH78nXjIYNwQ7LDub5QYxzKRVP/vBCgFjpEqTMX0A7OEIzr8iO41pdW7Cn2tN B7xz5Wf9jgBZMj6QM4vNflbw7kzDZznj6rhTxXKFnRAIKAYAP/46kfMKGHe7AUpthME8 S/pfVrRO6csmPj0dgj1pdmQHjAOeyO9m6j3wpWEV39reyQDg08WzfqrghXEE0pG0F1ay bimJCZ0CCL6QdliFS9Qnw4rVrxOa9uaX27FWzPh/WfhNwTy1Vt/R2DgYsflIB3XDWLK8 LPFoZj7i7Cl7V+QEIsEvQOfE5wAJ1K/fQY/S84kkfHlnnzvtvO/MCVe75iE/AruujicX CavQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4iEbt7bNNLTPd4MO+jWXzC0yX7NMt014yDKrHS/QyBk=; b=f6efmJEqUNxuMOvdC+B7DkGUPZpzrTiCBMrwo69kJpqE13of1KiYc+harjeRTRnZpd 6NayDwkfs89nr7zrzg4uB+Q7Wwy5ClejjR0I4BdFcvpKusPedVGP6pSRlnCEwoCWJQzd MHRMQKPIaSHAZ4hU1+2t3ILnu4xeNe9qLcolMhBxEu7gp+dJRsi3oneu2AEmdfjPmrCf JlzruckLfWhelc8/NRDjgcFmr0izk9op3+g6DuwsegYHOn299wy0mNY1xPSc49s0h1NV le8EF7Edq33vNNZLvicY74kJZWUR259S9dLqEZZd7VKZBnFdH/8pxgaPYeCeO0dLZbQZ MaEw== X-Gm-Message-State: ABuFfojNaZ9h3Pqazv3lhtMjs3soe0w1Mq3eD4utRMH3rBrqU8MJDUP7 L0FUmUgmVLb4oOAKFq3OE+YZ5toj X-Google-Smtp-Source: ACcGV63SSSEa13rEcnEAbHO/YZ80125tp59jN/Nphqq2Lzm7mqY8eUSe2hlGp/NHer5B0ndn5b1ezg== X-Received: by 2002:a19:641d:: with SMTP id y29mr993297lfb.14.1539960780885; Fri, 19 Oct 2018 07:53:00 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g64-v6sm4002414lfe.87.2018.10.19.07.52.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 07:53:00 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= Subject: [PATCH 16/19] merge-recursive.c: remove implicit dependency on the_repository Date: Fri, 19 Oct 2018 16:52:34 +0200 Message-Id: <20181019145237.16079-17-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181019145237.16079-1-pclouds@gmail.com> References: <20181019145237.16079-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Nguyễn Thái Ngọc Duy --- merge-recursive.c | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index 184945ae67..ad0a5b0202 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -146,7 +146,8 @@ static int err(struct merge_options *o, const char *err, ...) return -1; } -static struct tree *shift_tree_object(struct tree *one, struct tree *two, +static struct tree *shift_tree_object(struct repository *repo, + struct tree *one, struct tree *two, const char *subtree_shift) { struct object_id shifted; @@ -159,12 +160,14 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two, } if (oideq(&two->object.oid, &shifted)) return two; - return lookup_tree(the_repository, &shifted); + return lookup_tree(repo, &shifted); } -static struct commit *make_virtual_commit(struct tree *tree, const char *comment) +static struct commit *make_virtual_commit(struct repository *repo, + struct tree *tree, + const char *comment) { - struct commit *commit = alloc_commit_node(the_repository); + struct commit *commit = alloc_commit_node(repo); set_merge_remote_desc(commit, comment, (struct object *)commit); commit->maybe_tree = tree; @@ -420,7 +423,7 @@ struct tree *write_tree_from_memory(struct merge_options *o) return NULL; } - result = lookup_tree(the_repository, &istate->cache_tree->oid); + result = lookup_tree(o->repo, &istate->cache_tree->oid); return result; } @@ -1200,9 +1203,9 @@ static int merge_submodule(struct merge_options *o, return 0; } - if (!(commit_base = lookup_commit_reference(the_repository, base)) || - !(commit_a = lookup_commit_reference(the_repository, a)) || - !(commit_b = lookup_commit_reference(the_repository, b))) { + if (!(commit_base = lookup_commit_reference(o->repo, base)) || + !(commit_a = lookup_commit_reference(o->repo, a)) || + !(commit_b = lookup_commit_reference(o->repo, b))) { output(o, 1, _("Failed to merge submodule %s (commits not present)"), path); return 0; } @@ -3286,8 +3289,8 @@ int merge_trees(struct merge_options *o, } if (o->subtree_shift) { - merge = shift_tree_object(head, merge, o->subtree_shift); - common = shift_tree_object(head, common, o->subtree_shift); + merge = shift_tree_object(o->repo, head, merge, o->subtree_shift); + common = shift_tree_object(o->repo, head, common, o->subtree_shift); } if (oid_eq(&common->object.oid, &merge->object.oid)) { @@ -3423,8 +3426,8 @@ int merge_recursive(struct merge_options *o, /* if there is no common ancestor, use an empty tree */ struct tree *tree; - tree = lookup_tree(the_repository, the_repository->hash_algo->empty_tree); - merged_common_ancestors = make_virtual_commit(tree, "ancestor"); + tree = lookup_tree(o->repo, o->repo->hash_algo->empty_tree); + merged_common_ancestors = make_virtual_commit(o->repo, tree, "ancestor"); } for (iter = ca; iter; iter = iter->next) { @@ -3468,7 +3471,7 @@ int merge_recursive(struct merge_options *o, } if (o->call_depth) { - *result = make_virtual_commit(mrtree, "merged tree"); + *result = make_virtual_commit(o->repo, mrtree, "merged tree"); commit_list_insert(h1, &(*result)->parents); commit_list_insert(h2, &(*result)->parents->next); } @@ -3481,17 +3484,17 @@ int merge_recursive(struct merge_options *o, return clean; } -static struct commit *get_ref(const struct object_id *oid, const char *name) +static struct commit *get_ref(struct repository *repo, const struct object_id *oid, + const char *name) { struct object *object; - object = deref_tag(the_repository, parse_object(the_repository, oid), - name, - strlen(name)); + object = deref_tag(repo, parse_object(repo, oid), + name, strlen(name)); if (!object) return NULL; if (object->type == OBJ_TREE) - return make_virtual_commit((struct tree*)object, name); + return make_virtual_commit(repo, (struct tree*)object, name); if (object->type != OBJ_COMMIT) return NULL; if (parse_commit((struct commit *)object)) @@ -3508,15 +3511,15 @@ int merge_recursive_generic(struct merge_options *o, { int clean; struct lock_file lock = LOCK_INIT; - struct commit *head_commit = get_ref(head, o->branch1); - struct commit *next_commit = get_ref(merge, o->branch2); + struct commit *head_commit = get_ref(o->repo, head, o->branch1); + struct commit *next_commit = get_ref(o->repo, merge, o->branch2); struct commit_list *ca = NULL; if (base_list) { int i; for (i = 0; i < num_base_list; ++i) { struct commit *base; - if (!(base = get_ref(base_list[i], oid_to_hex(base_list[i])))) + if (!(base = get_ref(o->repo, base_list[i], oid_to_hex(base_list[i])))) return err(o, _("Could not parse object '%s'"), oid_to_hex(base_list[i])); commit_list_insert(base, &ca); From patchwork Fri Oct 19 14:52:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10649615 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C581A1750 for ; Fri, 19 Oct 2018 14:53:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3F6420748 for ; Fri, 19 Oct 2018 14:53:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A8B5220856; Fri, 19 Oct 2018 14:53:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3FC9F20748 for ; Fri, 19 Oct 2018 14:53:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727729AbeJSW7c (ORCPT ); Fri, 19 Oct 2018 18:59:32 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:41341 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727657AbeJSW7b (ORCPT ); Fri, 19 Oct 2018 18:59:31 -0400 Received: by mail-lj1-f196.google.com with SMTP id u21-v6so31074456lja.8 for ; Fri, 19 Oct 2018 07:53:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JLQNLOu/+ibJEg9wfBfkj/YAoih8BQjN0jo9Ue9j3IM=; b=tbajN1mvmjJHhuVn6c/jtCCI6sDye6oyMfjj5PyjLb30/TZFiXluB5gMrv4g6CgX53 xCG1paYaOVTFR5/A8uDBkf3VcUd2B5dtzxydeM9pjqita88Qxu5W/aJ85I+h1naDmTfx 9y7T4I+OwGoqq2FRj3hQgoOxLPKFyCOyeZ+Rr6t2zELn0YcQx0/XHi+d4R17iLYJm6oy jlW9wrVx0Se8Olk1BOOWGQnzOOM89z3Ruvrsc/GFrvZtlyJco6c6pGzG+aEZFMnMLm6F Bu4aoTbMvaJHtTDiE1eKpiPPh20uJG8GvbhVXRKBPFllOo4dxUY8mS0kQC8En3pUFYgO ZNIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JLQNLOu/+ibJEg9wfBfkj/YAoih8BQjN0jo9Ue9j3IM=; b=sdxCFxJO+hcSwz/rmjygRuu1gEuxtnN30xDrw5LA9OXDZ+y/IhF08I6yF2WmRRox72 3raavqNG8vOI87ghQBFgGYGZ4fbyRrMzHdysIlu4Lhz94H4x7tbO44GoIi509GvZvHAJ hndLQ5GnvtjhM1QsqJ6zOF7/aNhVvEKhKH18Wnvj/TQb6vlwCp4MsVqMNax3dxS6T8Az sSl/g2doxZnADeSBSJL2E6wYjbPCZbufCxQE+ETaxtV8LWlAfzZAwZQdpjNrsLgevmF6 gSn+CHnAARwxuz7KjzzQd+/Of13m2DiXItb0M/sAGdfabYhYRquPHMivNcXH+GwwZINo vy3A== X-Gm-Message-State: ABuFfoiMpl7UD04BxgLvE8GlPxw8qsKs5/iLB4Bv7SHVXjn2I2VjvRsx pso2voAAlvQ++8RNi5mmw8dKhEE5 X-Google-Smtp-Source: AJdET5eXvauqwDVly/qFStNLweM9U3HWsdMtnicVhg2UFIUBGqAaoLixP1Vj7t0C2SCh9gwbP0IH3Q== X-Received: by 2002:a2e:8919:: with SMTP id d25-v6mr5207787lji.69.1539960782056; Fri, 19 Oct 2018 07:53:02 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g64-v6sm4002414lfe.87.2018.10.19.07.53.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 07:53:01 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= Subject: [PATCH 17/19] read-cache.c: remove the_* from index_has_changes() Date: Fri, 19 Oct 2018 16:52:35 +0200 Message-Id: <20181019145237.16079-18-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181019145237.16079-1-pclouds@gmail.com> References: <20181019145237.16079-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/am.c | 6 +++--- cache.h | 6 +++--- merge-recursive.c | 2 +- read-cache.c | 12 +++++------- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 65e10a5eb3..37b52be7db 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1771,7 +1771,7 @@ static void am_run(struct am_state *state, int resume) refresh_and_write_cache(); - if (index_has_changes(&the_index, NULL, &sb)) { + if (repo_index_has_changes(the_repository, NULL, &sb)) { write_state_bool(state, "dirtyindex", 1); die(_("Dirty index: cannot apply patches (dirty: %s)"), sb.buf); } @@ -1829,7 +1829,7 @@ static void am_run(struct am_state *state, int resume) * the result may have produced the same tree as ours. */ if (!apply_status && - !index_has_changes(&the_index, NULL, NULL)) { + !repo_index_has_changes(the_repository, NULL, NULL)) { say(state, stdout, _("No changes -- Patch already applied.")); goto next; } @@ -1883,7 +1883,7 @@ static void am_resolve(struct am_state *state) say(state, stdout, _("Applying: %.*s"), linelen(state->msg), state->msg); - if (!index_has_changes(&the_index, NULL, NULL)) { + if (!repo_index_has_changes(the_repository, NULL, NULL)) { printf_ln(_("No changes - did you forget to use 'git add'?\n" "If there is nothing left to stage, chances are that something else\n" "already introduced the same changes; you might want to skip this patch.")); diff --git a/cache.h b/cache.h index 91c092cf76..4b3ec4ff82 100644 --- a/cache.h +++ b/cache.h @@ -701,9 +701,9 @@ extern int unmerged_index(const struct index_state *); * provided, the space-separated list of files that differ will be appended * to it. */ -extern int index_has_changes(struct index_state *istate, - struct tree *tree, - struct strbuf *sb); +extern int repo_index_has_changes(struct repository *repo, + struct tree *tree, + struct strbuf *sb); extern int verify_path(const char *path, unsigned mode); extern int strcmp_offset(const char *s1, const char *s2, size_t *first_change); diff --git a/merge-recursive.c b/merge-recursive.c index ad0a5b0202..22b382e85f 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3282,7 +3282,7 @@ int merge_trees(struct merge_options *o, int code, clean; struct strbuf sb = STRBUF_INIT; - if (!o->call_depth && index_has_changes(istate, head, &sb)) { + if (!o->call_depth && repo_index_has_changes(o->repo, head, &sb)) { err(o, _("Your local changes to the following files would be overwritten by merge:\n %s"), sb.buf); return -1; diff --git a/read-cache.c b/read-cache.c index 46e5e4000a..19389c6f30 100644 --- a/read-cache.c +++ b/read-cache.c @@ -2372,22 +2372,20 @@ int unmerged_index(const struct index_state *istate) return 0; } -int index_has_changes(struct index_state *istate, - struct tree *tree, - struct strbuf *sb) +int repo_index_has_changes(struct repository *repo, + struct tree *tree, + struct strbuf *sb) { + struct index_state *istate = repo->index; struct object_id cmp; int i; - if (istate != &the_index) { - BUG("index_has_changes cannot yet accept istate != &the_index; do_diff_cache needs updating first."); - } if (tree) cmp = tree->object.oid; if (tree || !get_oid_tree("HEAD", &cmp)) { struct diff_options opt; - repo_diff_setup(the_repository, &opt); + repo_diff_setup(repo, &opt); opt.flags.exit_with_status = 1; if (!sb) opt.flags.quick = 1; From patchwork Fri Oct 19 14:52:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10649621 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9F41F1750 for ; Fri, 19 Oct 2018 14:53:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B6BA205FD for ; Fri, 19 Oct 2018 14:53:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F78F207A7; Fri, 19 Oct 2018 14:53:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D067205FD for ; Fri, 19 Oct 2018 14:53:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727740AbeJSW7e (ORCPT ); Fri, 19 Oct 2018 18:59:34 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:41128 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727596AbeJSW7e (ORCPT ); Fri, 19 Oct 2018 18:59:34 -0400 Received: by mail-lf1-f65.google.com with SMTP id q39-v6so25436291lfi.8 for ; Fri, 19 Oct 2018 07:53:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=daSTcRjymYSOjJnc8/UNLW+mEFxXIN6nl0eCdhsQdwM=; b=jp9M23Hq/0au91W9cfIzouk7OEgk1eeFNL5K24XuaDNG8lTplIxwYrNDqKvOHs8qsU JBGyQ7JsKwpTa48IDCtMIkp/udWj4gvqoq/tGo9oFOOteMPud05A0XEv9hNt8ban/8f0 1RY9zS0GmXKNrKBRabDtsCig7ckncYHJjcCvVteU9kOxx/8jSHs5CWl7+9tePMzFM0nz WSeOuXEjcyjswIQcmRSXrsAH9ZxsIjMMuFgK7JxINSAtzvw5esTl80Egv3jAVEtYLLVh MBsrlCS+NvOnl6yjVTpjLUn8OmKqz1wm1aRFJK0qac221FYOBMj8GveLBjuZqgItH3ec fMiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=daSTcRjymYSOjJnc8/UNLW+mEFxXIN6nl0eCdhsQdwM=; b=qFn6tgNdGZ2gifM01162fHeMqcQx7ERt4700rk/+l28mE9xY+JPTnjc8BqYsFuA2S1 wPFpJa7EUycCfvdZz4wbks3PPMDBfF5ebvxCYApdRgZ5TU9r8GHPVN10GeVlkPiIiy3P IEjoBSeGgPlComiIfYMjVmvPvuSd4GicWQhFBT+NsnXCYG437/aZU1R6EUEZ6LJtReGM DCHYZAKM31lJNGXCKP7r0PSFNYf84uCvQgxhuElNt50YKbmzSqFU7btX36U3SYFPS7DG EsaB/UrsORXBZNfCnOeOnHv2Bg2xeDhtKRt/Yn2zLm8p6J0u/txP1/24I7KbSVslzvPt Sh4g== X-Gm-Message-State: ABuFfogqYOBXLvh30Ct/a3mUfaTZziVu3JjOeUU28bCsH7l/hCkESRAj lzBTB/BWjsQNf0E1TK+EhuqLWU/O X-Google-Smtp-Source: ACcGV62Sxmbbn46A0Y6J8goE4Ud4RLsy1sLl7hssJH1a4n9iev3TdYCZxlYwCONo6o+n64V+iZn/Hw== X-Received: by 2002:a19:aa8b:: with SMTP id t133-v6mr3220646lfe.92.1539960783499; Fri, 19 Oct 2018 07:53:03 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g64-v6sm4002414lfe.87.2018.10.19.07.53.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 07:53:02 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= Subject: [PATCH 18/19] cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch Date: Fri, 19 Oct 2018 16:52:36 +0200 Message-Id: <20181019145237.16079-19-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181019145237.16079-1-pclouds@gmail.com> References: <20181019145237.16079-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From now on, by default index compat macros are off because they could hide the_index dependency. Only those in builtin can use it (and even so should be avoided if possible). Signed-off-by: Nguyễn Thái Ngọc Duy --- attr.c | 1 - builtin/add.c | 1 + builtin/am.c | 1 + builtin/blame.c | 3 ++- builtin/cat-file.c | 1 + builtin/check-attr.c | 1 + builtin/check-ignore.c | 1 + builtin/checkout-index.c | 1 + builtin/checkout.c | 1 + builtin/clean.c | 1 + builtin/commit.c | 1 + builtin/describe.c | 1 + builtin/diff-files.c | 1 + builtin/diff-index.c | 1 + builtin/diff-tree.c | 1 + builtin/diff.c | 1 + builtin/difftool.c | 1 + builtin/fsck.c | 1 + builtin/grep.c | 1 + builtin/hash-object.c | 3 ++- builtin/log.c | 1 + builtin/ls-files.c | 1 - builtin/merge-index.c | 1 + builtin/merge-ours.c | 1 + builtin/merge-tree.c | 3 ++- builtin/merge.c | 1 + builtin/mv.c | 1 + builtin/pack-objects.c | 2 +- builtin/pull.c | 1 + builtin/read-tree.c | 1 + builtin/replace.c | 2 +- builtin/reset.c | 1 + builtin/rev-parse.c | 1 + builtin/rm.c | 1 + builtin/submodule--helper.c | 1 + builtin/update-index.c | 1 + builtin/write-tree.c | 1 + cache-tree.h | 2 +- cache.h | 6 +++--- convert.c | 1 - dir.c | 1 - git.c | 4 ++-- name-hash.c | 1 - pathspec.c | 1 - read-cache.c | 2 -- repository.c | 1 + submodule.c | 1 - t/helper/test-dump-fsmonitor.c | 4 ++-- t/helper/test-dump-untracked-cache.c | 1 + t/helper/test-tool.h | 1 + tree.c | 1 - unpack-trees.c | 1 - 52 files changed, 49 insertions(+), 24 deletions(-) diff --git a/attr.c b/attr.c index 60d284796d..e56ffa9112 100644 --- a/attr.c +++ b/attr.c @@ -7,7 +7,6 @@ * an insanely large number of attributes. */ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "exec-cmd.h" diff --git a/builtin/add.c b/builtin/add.c index ad49806ebf..72e9765edf 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -3,6 +3,7 @@ * * Copyright (C) 2006 Linus Torvalds */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "builtin.h" diff --git a/builtin/am.c b/builtin/am.c index 37b52be7db..4e36c186fc 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -3,6 +3,7 @@ * * Based on git-am.sh by Junio C Hamano. */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "builtin.h" diff --git a/builtin/blame.c b/builtin/blame.c index a443af9ee9..d004343211 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -1001,7 +1001,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix) long bottom, top; if (parse_range_arg(range_list.items[range_i].string, nth_line_cb, &sb, lno, anchor, - &bottom, &top, sb.path, &the_index)) + &bottom, &top, sb.path, + the_repository->index)) usage(blame_usage); if ((!lno && (top || bottom)) || lno < bottom) die(Q_("file %s has only %lu line", diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 17faea8846..72be3e8065 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -3,6 +3,7 @@ * * Copyright (C) Linus Torvalds, 2005 */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "builtin.h" diff --git a/builtin/check-attr.c b/builtin/check-attr.c index 30a2f84274..dd83397786 100644 --- a/builtin/check-attr.c +++ b/builtin/check-attr.c @@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "cache.h" #include "config.h" diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c index ec9a959e08..599097304b 100644 --- a/builtin/check-ignore.c +++ b/builtin/check-ignore.c @@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "cache.h" #include "config.h" diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c index 88b86c8d9f..2f820910b7 100644 --- a/builtin/checkout-index.c +++ b/builtin/checkout-index.c @@ -4,6 +4,7 @@ * Copyright (C) 2005 Linus Torvalds * */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "config.h" #include "lockfile.h" diff --git a/builtin/checkout.c b/builtin/checkout.c index 8ecb4c43c7..b1ed49d020 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "config.h" #include "checkout.h" diff --git a/builtin/clean.c b/builtin/clean.c index 8d9a7dc206..7e21380200 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -6,6 +6,7 @@ * Based on git-clean.sh by Pavel Roskin */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "cache.h" #include "config.h" diff --git a/builtin/commit.c b/builtin/commit.c index d7afaa9ed4..9ba55b2653 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -5,6 +5,7 @@ * Based on git-commit.sh by Junio C Hamano and Linus Torvalds */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "lockfile.h" diff --git a/builtin/describe.c b/builtin/describe.c index cff8ec3d65..d673ba197d 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "lockfile.h" diff --git a/builtin/diff-files.c b/builtin/diff-files.c index 48cfcb935d..86ae474fbf 100644 --- a/builtin/diff-files.c +++ b/builtin/diff-files.c @@ -3,6 +3,7 @@ * * Copyright (C) Linus Torvalds, 2005 */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "diff.h" diff --git a/builtin/diff-index.c b/builtin/diff-index.c index fcccd1f10d..93ec642423 100644 --- a/builtin/diff-index.c +++ b/builtin/diff-index.c @@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "diff.h" diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c index 42bc1eb41d..a90681bcba 100644 --- a/builtin/diff-tree.c +++ b/builtin/diff-tree.c @@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "diff.h" diff --git a/builtin/diff.c b/builtin/diff.c index ec78920ee2..74351a5757 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -3,6 +3,7 @@ * * Copyright (c) 2006 Junio C Hamano */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "lockfile.h" diff --git a/builtin/difftool.c b/builtin/difftool.c index 544b0e8639..eeb9e370b9 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -11,6 +11,7 @@ * * Copyright (C) 2016 Johannes Schindelin */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "builtin.h" diff --git a/builtin/fsck.c b/builtin/fsck.c index 06eb421720..916f14e634 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "cache.h" #include "repository.h" diff --git a/builtin/grep.c b/builtin/grep.c index 9d40b5c073..75543fe458 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -3,6 +3,7 @@ * * Copyright (c) 2006 Junio C Hamano */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "repository.h" #include "config.h" diff --git a/builtin/hash-object.c b/builtin/hash-object.c index d6f06ea32f..e055c11103 100644 --- a/builtin/hash-object.c +++ b/builtin/hash-object.c @@ -40,7 +40,8 @@ static void hash_fd(int fd, const char *type, const char *path, unsigned flags, if (fstat(fd, &st) < 0 || (literally ? hash_literally(&oid, fd, type, flags) - : index_fd(&the_index, &oid, fd, &st, type_from_string(type), path, flags))) + : index_fd(the_repository->index, &oid, fd, &st, + type_from_string(type), path, flags))) die((flags & HASH_WRITE_OBJECT) ? "Unable to add %s to database" : "Unable to hash %s", path); diff --git a/builtin/log.c b/builtin/log.c index ed28e81a22..04682c02ad 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -4,6 +4,7 @@ * (C) Copyright 2006 Linus Torvalds * 2006 Junio Hamano */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "refs.h" diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 7f9919a362..c9ea56a214 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -5,7 +5,6 @@ * * Copyright (C) Linus Torvalds, 2005 */ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "repository.h" #include "config.h" diff --git a/builtin/merge-index.c b/builtin/merge-index.c index c99443b095..38ea6ad6ca 100644 --- a/builtin/merge-index.c +++ b/builtin/merge-index.c @@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "run-command.h" diff --git a/builtin/merge-ours.c b/builtin/merge-ours.c index c84c6e05e9..7c4a80ed3b 100644 --- a/builtin/merge-ours.c +++ b/builtin/merge-ours.c @@ -7,6 +7,7 @@ * * Pretend we resolved the heads, but declare our tree trumps everybody else. */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "git-compat-util.h" #include "builtin.h" #include "diff.h" diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index 8fc108d305..6fd6586069 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -76,7 +76,8 @@ static void *result(struct merge_list *entry, unsigned long *size) their = NULL; if (entry) their = entry->blob; - return merge_blobs(&the_index, path, base, our, their, size); + return merge_blobs(the_repository->index, path, + base, our, their, size); } static void *origin(struct merge_list *entry, unsigned long *size) diff --git a/builtin/merge.c b/builtin/merge.c index d2d636d979..eaf5608948 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -6,6 +6,7 @@ * Based on git-merge.sh by Junio C Hamano. */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "parse-options.h" diff --git a/builtin/mv.c b/builtin/mv.c index 80bb967a63..be15ba7044 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -3,6 +3,7 @@ * * Copyright (C) 2006 Johannes Schindelin */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "config.h" #include "pathspec.h" diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index b059b86aee..d6f9b749ab 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -970,7 +970,7 @@ static int no_try_delta(const char *path) if (!check) check = attr_check_initl("delta", NULL); - git_check_attr(&the_index, path, check); + git_check_attr(the_repository->index, path, check); if (ATTR_FALSE(check->items[0].value)) return 1; return 0; diff --git a/builtin/pull.c b/builtin/pull.c index 9b0fce07ca..61af382d98 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -5,6 +5,7 @@ * * Fetch one or more remote refs and merge it/them into the current HEAD. */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "builtin.h" diff --git a/builtin/read-tree.c b/builtin/read-tree.c index fbbc98e516..6bbe614b02 100644 --- a/builtin/read-tree.c +++ b/builtin/read-tree.c @@ -4,6 +4,7 @@ * Copyright (C) Linus Torvalds, 2005 */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "lockfile.h" diff --git a/builtin/replace.c b/builtin/replace.c index a58b9c6d13..379e220949 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -295,7 +295,7 @@ static int import_object(struct object_id *oid, enum object_type type, close(fd); return -1; } - if (index_fd(&the_index, oid, fd, &st, type, NULL, flags) < 0) + if (index_fd(the_repository->index, oid, fd, &st, type, NULL, flags) < 0) return error(_("unable to write object to database")); /* index_fd close()s fd for us */ } diff --git a/builtin/reset.c b/builtin/reset.c index 6d37a35e2e..1d8f3c6235 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -7,6 +7,7 @@ * * Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "config.h" #include "lockfile.h" diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 38d7d8fd74..baa5514038 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -3,6 +3,7 @@ * * Copyright (C) Linus Torvalds, 2005 */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "commit.h" diff --git a/builtin/rm.c b/builtin/rm.c index 17086d3d97..db85b33982 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -3,6 +3,7 @@ * * Copyright (C) Linus Torvalds 2006 */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "config.h" #include "lockfile.h" diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 80474c3ff5..972209452e 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "repository.h" #include "cache.h" diff --git a/builtin/update-index.c b/builtin/update-index.c index 07c10bcb7d..d8a879b19c 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -3,6 +3,7 @@ * * Copyright (C) Linus Torvalds, 2005 */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "lockfile.h" diff --git a/builtin/write-tree.c b/builtin/write-tree.c index cdcbf8264e..3d46d22ee5 100644 --- a/builtin/write-tree.c +++ b/builtin/write-tree.c @@ -3,6 +3,7 @@ * * Copyright (C) Linus Torvalds, 2005 */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "cache.h" #include "config.h" diff --git a/cache-tree.h b/cache-tree.h index 0ab6784ffe..f0e470a508 100644 --- a/cache-tree.h +++ b/cache-tree.h @@ -51,7 +51,7 @@ void prime_cache_tree(struct index_state *, struct tree *); int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info); -#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS +#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS static inline int write_cache_as_tree(struct object_id *oid, int flags, const char *prefix) { return write_index_as_tree(oid, &the_index, get_index_file(), flags, prefix); diff --git a/cache.h b/cache.h index 4b3ec4ff82..2df03a1ab1 100644 --- a/cache.h +++ b/cache.h @@ -338,8 +338,6 @@ struct index_state { struct mem_pool *ce_mem_pool; }; -extern struct index_state the_index; - /* Name hashing */ extern int test_lazy_init_name_hash(struct index_state *istate, int try_threaded); extern void add_name_hash(struct index_state *istate, struct cache_entry *ce); @@ -401,7 +399,9 @@ struct cache_entry *dup_cache_entry(const struct cache_entry *ce, struct index_s */ void validate_cache_entries(const struct index_state *istate); -#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS +#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS +extern struct index_state the_index; + #define active_cache (the_index.cache) #define active_nr (the_index.cache_nr) #define active_alloc (the_index.cache_alloc) diff --git a/convert.c b/convert.c index e0848226d2..df8c6a0bf8 100644 --- a/convert.c +++ b/convert.c @@ -1,4 +1,3 @@ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "object-store.h" diff --git a/dir.c b/dir.c index 47c2fca8dc..5e713ddf5f 100644 --- a/dir.c +++ b/dir.c @@ -7,7 +7,6 @@ * Copyright (C) Linus Torvalds, 2005-2006 * Junio Hamano, 2005-2006 */ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "dir.h" diff --git a/git.c b/git.c index 5920f8019b..c1eb62acd6 100644 --- a/git.c +++ b/git.c @@ -414,9 +414,9 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) trace_argv_printf(argv, "trace: built-in: git"); - validate_cache_entries(&the_index); + validate_cache_entries(the_repository->index); status = p->fn(argc, argv, prefix); - validate_cache_entries(&the_index); + validate_cache_entries(the_repository->index); if (status) return status; diff --git a/name-hash.c b/name-hash.c index 1fcda73cb3..b0ae38563c 100644 --- a/name-hash.c +++ b/name-hash.c @@ -5,7 +5,6 @@ * * Copyright (C) 2008 Linus Torvalds */ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" struct dir_entry { diff --git a/pathspec.c b/pathspec.c index 6f005996fd..f1505cfd0a 100644 --- a/pathspec.c +++ b/pathspec.c @@ -1,4 +1,3 @@ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "dir.h" diff --git a/read-cache.c b/read-cache.c index 19389c6f30..7255f453f6 100644 --- a/read-cache.c +++ b/read-cache.c @@ -3,7 +3,6 @@ * * Copyright (C) Linus Torvalds, 2005 */ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "diff.h" @@ -95,7 +94,6 @@ static struct mem_pool *find_mem_pool(struct index_state *istate) return *pool_ptr; } -struct index_state the_index; static const char *alternate_index_output; static void set_index_entry(struct index_state *istate, int nr, struct cache_entry *ce) diff --git a/repository.c b/repository.c index 39b5a80d43..fca30c1086 100644 --- a/repository.c +++ b/repository.c @@ -9,6 +9,7 @@ /* The main repository */ static struct repository the_repo; struct repository *the_repository; +struct index_state the_index; void initialize_the_repository(void) { diff --git a/submodule.c b/submodule.c index d9d3046689..4c727d2459 100644 --- a/submodule.c +++ b/submodule.c @@ -1,4 +1,3 @@ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "repository.h" diff --git a/t/helper/test-dump-fsmonitor.c b/t/helper/test-dump-fsmonitor.c index 08e3684aff..2786f47088 100644 --- a/t/helper/test-dump-fsmonitor.c +++ b/t/helper/test-dump-fsmonitor.c @@ -3,11 +3,11 @@ int cmd__dump_fsmonitor(int ac, const char **av) { - struct index_state *istate = &the_index; + struct index_state *istate = the_repository->index; int i; setup_git_directory(); - if (do_read_index(istate, get_index_file(), 0) < 0) + if (do_read_index(istate, the_repository->index_file, 0) < 0) die("unable to read index file"); if (!istate->fsmonitor_last_update) { printf("no fsmonitor\n"); diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c index 52870ebbb3..cf0f2c7228 100644 --- a/t/helper/test-dump-untracked-cache.c +++ b/t/helper/test-dump-untracked-cache.c @@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "test-tool.h" #include "cache.h" #include "dir.h" diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h index e4890566da..6f223f3870 100644 --- a/t/helper/test-tool.h +++ b/t/helper/test-tool.h @@ -1,6 +1,7 @@ #ifndef __TEST_TOOL_H__ #define __TEST_TOOL_H__ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "git-compat-util.h" int cmd__chmtime(int argc, const char **argv); diff --git a/tree.c b/tree.c index 215d3fdc7c..181a3778f3 100644 --- a/tree.c +++ b/tree.c @@ -1,4 +1,3 @@ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "cache-tree.h" #include "tree.h" diff --git a/unpack-trees.c b/unpack-trees.c index 51bfac6aa0..dbb62d61aa 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1,4 +1,3 @@ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "argv-array.h" #include "repository.h" From patchwork Fri Oct 19 14:52:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10649619 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 03781109C for ; Fri, 19 Oct 2018 14:53:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7BAF205FD for ; Fri, 19 Oct 2018 14:53:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC6C4207A7; Fri, 19 Oct 2018 14:53:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8653A205FD for ; Fri, 19 Oct 2018 14:53:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727736AbeJSW7e (ORCPT ); Fri, 19 Oct 2018 18:59:34 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:40351 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727657AbeJSW7d (ORCPT ); Fri, 19 Oct 2018 18:59:33 -0400 Received: by mail-lf1-f68.google.com with SMTP id t22-v6so25456188lfb.7 for ; Fri, 19 Oct 2018 07:53:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Z71lYxtfETFJn6Exe58pkZX4fqjUaV+EXNVDX3aliPg=; b=bkaZYICcOPAUjGXcvXDstoiAtBQojKn95ijo/EQ74hhgW1bx7VOZRA1Pvu9o3k7T/v SFA4QYz0WqUFD1HVlBBsyVSPAUkT3xQXqXKrG2NhLWCtLv3NsXk6w0lHLDmw/j+KjX0r 1Pivm2BEE99AOaSVugeUyCxRulba1TGeomy7uB0dxDMBlpofby8Nk/XWFgIYmbChT/xB 0/2YLcZy+O59tHsPiSo2QejReCuU8cKoPpinvj+dvvsq3oVj/4nQVseCzqI2Ap8tmmc0 OtPQDocMaguk0hCv+VLGpaFjiDjWfK6IkFy20W8cMkZhyG1cw5i5/Clw9nHy/WH7aG7D 61Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Z71lYxtfETFJn6Exe58pkZX4fqjUaV+EXNVDX3aliPg=; b=Jx9AA1OrBWf+KBAjmK/oSYHbctoEzSe7RjO8V0B+CdkDHkV9tMjAn+91fR/hUSWQ2e pOEYdZKN3nRbJWjLO7f8bcnBz5qy1+sFygSI52QuWnwnLiFUDVT8LqxBwKDDdbN7UPSH xJK/wJxFfsaM9QibqaMrwaUuV6kYzqIOs4u1U0KeQmKsj5uDiF7nDpt7gj9Q3iiBWrFy GcFBgUkDQUsygrHgghtDp1N2M2bGgVe6vosMXe1lhLXdAJU2/x4HMAobmXMSZBvEbRkB LQG+NR7nR/6d4yOfmkJsQ6VdgEJgf5XZmqldmzwGXAunalrGwLtmz8/fUGBcgMiVdtmi 2WsQ== X-Gm-Message-State: ABuFfog6PrZCl1Xbj2a9jF4qlbh39qwILfTa31X5JqnlAkM6+PAk6y/t 51uKFXCm3haYSWdP1A8zuZ4RH6W7 X-Google-Smtp-Source: ACcGV62JpdiG+JxRv5KDnPVMYjdNXt7nENIcB/6UVXyTGVtrV2inl9uhDdMQeQt0GFzdZu867VfUNw== X-Received: by 2002:a19:fc09:: with SMTP id a9mr1327520lfi.21.1539960784532; Fri, 19 Oct 2018 07:53:04 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g64-v6sm4002414lfe.87.2018.10.19.07.53.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 07:53:03 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= Subject: [PATCH 19/19] Flip NO_THE_REPOSITORY_COMPATIBILITY_MACROS Date: Fri, 19 Oct 2018 16:52:37 +0200 Message-Id: <20181019145237.16079-20-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181019145237.16079-1-pclouds@gmail.com> References: <20181019145237.16079-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Similar to NO_THE_INDEX_COMPATIBILITY_MACROS, this switch is now off by default. It remains here just to make it easier to merge in-flight topics where the old functions are still used. Then you can just stick #define USE_THE_REPOSITORY_COMPATIBILITY_MACROS at the beginning of those files. Signed-off-by: Nguyễn Thái Ngọc Duy --- diff.h | 2 +- rerere.h | 2 +- revision.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/diff.h b/diff.h index ce5e8a8183..de7cb7018f 100644 --- a/diff.h +++ b/diff.h @@ -341,7 +341,7 @@ int git_diff_basic_config(const char *var, const char *value, void *cb); int git_diff_heuristic_config(const char *var, const char *value, void *cb); void init_diff_ui_defaults(void); int git_diff_ui_config(const char *var, const char *value, void *cb); -#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS +#ifdef USE_THE_REPOSITORY_COMPATIBILITY_MACROS #define diff_setup(diffopts) repo_diff_setup(the_repository, diffopts) #endif void repo_diff_setup(struct repository *, struct diff_options *); diff --git a/rerere.h b/rerere.h index 5ad8864b3c..8ddd0b20da 100644 --- a/rerere.h +++ b/rerere.h @@ -24,7 +24,7 @@ struct rerere_id { }; int setup_rerere(struct string_list *, int); -#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS +#ifdef USE_THE_REPOSITORY_COMPATIBILITY_MACROS #define rerere(flags) repo_rerere(the_repository, flags) #endif int repo_rerere(struct repository *, int); diff --git a/revision.h b/revision.h index bc30a3023e..5b6ab10143 100644 --- a/revision.h +++ b/revision.h @@ -271,7 +271,7 @@ struct setup_revision_opt { unsigned revarg_opt; }; -#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS +#ifdef USE_THE_REPOSITORY_COMPATIBILITY_MACROS #define init_revisions(revs, prefix) repo_init_revisions(the_repository, revs, prefix) #endif void repo_init_revisions(struct repository *r,