From patchwork Sat Nov 10 05:46: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: 10676893 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 16FAC109C for ; Sat, 10 Nov 2018 05:47:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 061832E3DC for ; Sat, 10 Nov 2018 05:47:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EDE472E3FA; Sat, 10 Nov 2018 05:46: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 DD7042E3DC for ; Sat, 10 Nov 2018 05:46:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728910AbeKJPam (ORCPT ); Sat, 10 Nov 2018 10:30:42 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:43954 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728580AbeKJPam (ORCPT ); Sat, 10 Nov 2018 10:30:42 -0500 Received: by mail-lf1-f66.google.com with SMTP id u18so2815278lff.10 for ; Fri, 09 Nov 2018 21:46:55 -0800 (PST) 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=uMS9j06YdD85fbjplFFHEePeqtWkhVO8ReNL27iZ+qo=; b=AC+MiRYvCu1qjHfLKIl1eU0kWjDlQVE1BOzzFLx/SWJd2x9ul3zUgNxIxrepgyPifX ENoP4BLz/On8FxUJbJBSpyZSif9Jc53nbMi/4vvwIG8rCiQ+oWdA+ZKnS5kA3C5rRDE5 60o4W2jhqn849E4hS+nT0q83tULeu2r5J7eMaEY+LOx5PCVkoggMslBTq0/Rl8t+ZPId OVRAO9G1J92YQi88MHpeE3qCmZ+Ll7a5yiMTf0sdyFSdtDrHbHQ1pDteJJsgF21DHqeN BnyxSQrf/ccORiz2cXGjanxGjW5yygOBXXjF2Mg0MyOvVY960xV8y76UZmeQWYi2HxXQ fWYw== 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=uMS9j06YdD85fbjplFFHEePeqtWkhVO8ReNL27iZ+qo=; b=r7Oa5vwNFKk6K4D2S+5/OnwqSrvTyVJM5HKfIos7aXUeZIRTLs3Ry5+QIb0N78AHDF erlwgKUhot5ZNO/3XRrv0rvZG+XGJcNkEIni949AhEOrm4yBHT5RdYDQRw3tijs1ymR5 7bF+NYbLj730WeBxTnXMIKYeWK6O3gBJzrXz3lvrbHRfYBcGTz1fs9Hgcqkq+YPeubmA ewPU/Q4L2y+YhqN5WKJikzQX6nJC7ynWaPo2O7tr1/HQm1vajIYgavpXZwHtyRG4/WLY 6jvlmceYgxsPaQyZP6w9MtPo0O91q7yr9eM15dsq3JKee/4CBkt/+Ks6xvq6MWvnZbe9 t3Mw== X-Gm-Message-State: AGRZ1gKLlY9T4650QFLgUD7KHpgmVxbw3rUCWz349tNmlQTqbc3OffBW M6AxS8ZqjyOcVe2tkuklJoUPj+f9 X-Google-Smtp-Source: AJdET5fRNOAja0Tgo5Sx9RN8QFnbLLNP38O/hr/n57O4zt7f4YLH6Fydbh+dky4hhPRV/AybXcesuA== X-Received: by 2002:a19:aace:: with SMTP id t197mr6912603lfe.7.1541828814344; Fri, 09 Nov 2018 21:46:54 -0800 (PST) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g2-v6sm2441597ljg.9.2018.11.09.21.46.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Nov 2018 21:46:53 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 01/22] wt-status.c: remove implicit dependency on the_index Date: Sat, 10 Nov 2018 06:46:25 +0100 Message-Id: <20181110054646.10149-3-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1231.g84aef82467 In-Reply-To: <20181110054646.10149-1-pclouds@gmail.com> References: <20181110054646.10149-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 +- builtin/rebase.c | 7 +++-- sequencer.c | 8 ++--- wt-status.c | 76 +++++++++++++++++++++++++++--------------------- wt-status.h | 17 +++++++---- 6 files changed, 66 insertions(+), 47 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 074bd9a551..6637a928a7 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(the_repository, s); init_diff_ui_defaults(); git_config(fn, s); determine_whence(s); diff --git a/builtin/pull.c b/builtin/pull.c index c21aa276f1..6026ce1a69 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/builtin/rebase.c b/builtin/rebase.c index 0ee06aa363..b9eb958454 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -983,7 +983,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) &lock_file); rollback_lock_file(&lock_file); - if (has_unstaged_changes(1)) { + if (has_unstaged_changes(the_repository, 1)) { puts(_("You must edit all merge conflicts and then\n" "mark them as resolved using git add")); exit(1); @@ -1351,7 +1351,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) update_index_if_able(&the_index, &lock_file); rollback_lock_file(&lock_file); - if (has_unstaged_changes(1) || has_uncommitted_changes(1)) { + if (has_unstaged_changes(the_repository, 1) || + has_uncommitted_changes(the_repository, 1)) { const char *autostash = state_dir_path("autostash", &options); struct child_process stash = CHILD_PROCESS_INIT; @@ -1397,7 +1398,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) } } - if (require_clean_work_tree("rebase", + if (require_clean_work_tree(the_repository, "rebase", _("Please commit or stash them."), 1, 1)) { ret = 1; goto cleanup; diff --git a/sequencer.c b/sequencer.c index 9e1ab3a2a7..0b8f18fd36 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2773,7 +2773,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" @@ -3714,10 +3714,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; @@ -4847,7 +4847,7 @@ int complete_action(struct replay_opts *opts, unsigned flags, if (checkout_onto(opts, onto_name, oid_to_hex(&oid), orig_head)) return -1; ; - if (require_clean_work_tree("rebase", "", 1, 1)) + if (require_clean_work_tree(the_repository, "rebase", "", 1, 1)) return -1; return sequencer_continue(opts); diff --git a/wt-status.c b/wt-status.c index 187568a112..6d401b2c24 100644 --- a/wt-status.c +++ b/wt-status.c @@ -119,9 +119,10 @@ 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 repository *r, struct wt_status *s) { memset(s, 0, sizeof(*s)); + s->repo = r; memcpy(s->color_palette, default_wt_status_colors, sizeof(default_wt_status_colors)); s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES; @@ -494,19 +495,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 +567,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 +587,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 +612,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 +645,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 +687,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 +702,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 +1013,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 +1330,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 +2139,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 +2178,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 +2307,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 +2326,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 +2346,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 +2359,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..8375e816fb 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 repository *r, struct wt_status *s); 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 Sat Nov 10 05:46: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: 10676895 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 0439B14DB for ; Sat, 10 Nov 2018 05:47:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E82C52E3DC for ; Sat, 10 Nov 2018 05:47:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC8B72E3FA; Sat, 10 Nov 2018 05:47: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 63D3D2E3DC for ; Sat, 10 Nov 2018 05:47:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728916AbeKJPao (ORCPT ); Sat, 10 Nov 2018 10:30:44 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:36368 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728875AbeKJPan (ORCPT ); Sat, 10 Nov 2018 10:30:43 -0500 Received: by mail-lf1-f66.google.com with SMTP id h192so2843912lfg.3 for ; Fri, 09 Nov 2018 21:46:56 -0800 (PST) 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=SmNnVQOLU1ncYiVyTuDFVBgarxfg6sFni5/84VW23S0=; b=UaQtPtx6/dfOH4xQ/e+/l4CuhR4uMqk1skL9Dal9giNWHRhBNNxREh9uWjY7PQIRUM tXKHGr0K9y/shXmGsvw4JBx0x2HAYCN2WQj5UAJDVv6x+bnf4UEwZEOETlL2rLVf6hlD K4lnN7ChTZvV5PzGRDEAt6yRWnztBW3+QNmmgVxZ1HoEmFbr/nSTOHu5qQkgTCzEhbAS CRk6CsRu63xkSs3LYVQ+d4tHWAGq7PcwHCrXMcxDkWhV1fJwZNmbgnOxePaf4mw8Qpo9 h4Ni7EJxg51WVpMBnQPByoOqgt1OAB6jkp6HorUEsf0DfpHPLHgdFkfz/+DzTI8lEwl0 OC8Q== 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=SmNnVQOLU1ncYiVyTuDFVBgarxfg6sFni5/84VW23S0=; b=AHCulGXnYdilgTgCOuRqgQX6wJ6qIb1xdtiBgVklkWrJix+zT9KfEAvCq8aAY2sJ6j VONXZwAbp+DmP85tfOaQeqqcNjgUYUMAeWA3sfLmIj6KMpCHN8a+fxOxxzx5TPxDWsiW V4HOZe/Xhp2ZNWLOWppS7s1qBzol2rkKXshsNPxJyTFfxNseoYooFf1avI2Ek5l7xZok hrOlqZs7TsrdLVi0VOwMhDcmTjIpNbIjDsryB6Gjia57y9ar//NrdYMuZZl+zZAyF8nn nygCiYn/r2lEJUgzn+RPpwWoU46tlGUAb5rgS/GQqPXnkjTrdgJCOFDA/6KuiCePXQhZ Vg3g== X-Gm-Message-State: AGRZ1gJ1i6UWK7h9YUo7zpLjhhwETXVUV7i1ZwD6mdoTAyQFKtMk2qYn pn9VWCS2qKAZjI+kzLMYLgJA83xo X-Google-Smtp-Source: AJdET5cukRubxzVucvwt+OpuQU22ie9YTIokDI7OM2DIVG89j0N2xY5y899Xc/0CLDj4LlkQO8mJ8Q== X-Received: by 2002:a19:d5:: with SMTP id 204mr6507581lfa.116.1541828815857; Fri, 09 Nov 2018 21:46:55 -0800 (PST) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g2-v6sm2441597ljg.9.2018.11.09.21.46.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Nov 2018 21:46:54 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 02/22] wt-status.c: remove implicit dependency the_repository Date: Sat, 10 Nov 2018 06:46:26 +0100 Message-Id: <20181110054646.10149-4-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1231.g84aef82467 In-Reply-To: <20181110054646.10149-1-pclouds@gmail.com> References: <20181110054646.10149-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 0c45ed9d94..c4eaf30313 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1413,7 +1413,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 6d401b2c24..e582c54238 100644 --- a/wt-status.c +++ b/wt-status.c @@ -755,7 +755,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; } @@ -1482,7 +1482,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; @@ -1499,7 +1500,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)) @@ -1556,30 +1557,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 8375e816fb..3a95975032 100644 --- a/wt-status.h +++ b/wt-status.h @@ -134,7 +134,9 @@ void wt_status_prepare(struct repository *r, struct wt_status *s); 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 Sat Nov 10 05:46: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: 10676897 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 52C8C14DB for ; Sat, 10 Nov 2018 05:47:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42E8F2E3DC for ; Sat, 10 Nov 2018 05:47:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3708B2E3FA; Sat, 10 Nov 2018 05:47:02 +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 B84D32E3DC for ; Sat, 10 Nov 2018 05:47:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728917AbeKJPap (ORCPT ); Sat, 10 Nov 2018 10:30:45 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:37281 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728580AbeKJPao (ORCPT ); Sat, 10 Nov 2018 10:30:44 -0500 Received: by mail-lj1-f195.google.com with SMTP id e5-v6so3380583lja.4 for ; Fri, 09 Nov 2018 21:46:58 -0800 (PST) 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=OpV8xhNLB/scWysqMZej/wGnQkc4j31hL9ZxATH0HSQ=; b=CIGWuwTJmTgInnRG/MX+ebLD4pqYBnpJOWpJOvTdFAfIHzAPcDHjCTkXNNXpCnAsdL MeQN9CKMFVUzN5PYpydh7pA5SFWVOUAVfrCxRMNLTsQApX2JMz3UntVg3rG3xP+bCtgz ZC95vnYP2lJi7kX8CDrOsFqEVSGDQYVkwfjCTsYMBya4OAiQW84h6qr1v/sDHyuUu8Hv 6rWBoDv91oDFTeIBt4LEIBFFM+gd03d3rBpAclO/7MaJipvtqptuwUzzoM7lJJBLX5+U uav1GYY4ZgSj9nhIFMcPr2JaGQgXILVsDti2OOlSgPAR0F6k1cCf2UsWmOYCK6GQ3oEi NQiQ== 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=OpV8xhNLB/scWysqMZej/wGnQkc4j31hL9ZxATH0HSQ=; b=LxWG5WB8W750Jx5oT8R7M6+U30W7Y9btntuW6zFb/rNRElxwbKirZ0Hgs+WuVgMPPc VPRAINf2oyR2Ji1PgDpku3yy9AF7KrerpEJ9Dkm567PfgmOb8nb/7OgzBkh8rAc/NQSQ lAGPE9R6LSY7FKg3NjLXbL34Fy1kYLIGpZuCvrRQ1zfk6QHgvTYq/eLDwtj+nHzcMZ0q HZ04AUC6yd5EIt+aL7LIaeJFkaMgL+K0U1KnScstDzOqyzQuH1v9m1FWFt0cKdEr/S7d W+7jphFnkWo6ZIxhbIbGNmosVnOErNVZMc2U+yUgcZaOmgBwX4wK0e6XrCqj5NPw/yaN +Ttg== X-Gm-Message-State: AGRZ1gJTGLdg4bx5tfT/MoUgt4m4c6UEvPRy2P0Lbhg6B56rbDoOfC4G rVvBRuUUI973VsCXEFhZ1IF3IfQv X-Google-Smtp-Source: AJdET5f4b1ORt1SspFesmpzI496+enXi+QydvMI2tFftXb/6HhwbE957AQXZl/G08DwNdiSQJ2ho/Q== X-Received: by 2002:a2e:9694:: with SMTP id q20-v6mr7260511lji.173.1541828816956; Fri, 09 Nov 2018 21:46:56 -0800 (PST) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g2-v6sm2441597ljg.9.2018.11.09.21.46.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Nov 2018 21:46:56 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 03/22] list-objects-filter.c: remove implicit dependency on the_index Date: Sat, 10 Nov 2018 06:46:27 +0100 Message-Id: <20181110054646.10149-5-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1231.g84aef82467 In-Reply-To: <20181110054646.10149-1-pclouds@gmail.com> References: <20181110054646.10149-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 While at there, since we have access to struct repository now, eliminate the only the_repository reference in this file. Signed-off-by: Nguyễn Thái Ngọc Duy --- list-objects-filter.c | 10 +++++++--- list-objects-filter.h | 2 ++ list-objects.c | 9 ++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/list-objects-filter.c b/list-objects-filter.c index 765f3df3b0..a62624a1ce 100644 --- a/list-objects-filter.c +++ b/list-objects-filter.c @@ -34,6 +34,7 @@ struct filter_blobs_none_data { }; static enum list_objects_filter_result filter_blobs_none( + struct repository *r, enum list_objects_filter_situation filter_situation, struct object *obj, const char *pathname, @@ -88,6 +89,7 @@ struct filter_trees_none_data { }; static enum list_objects_filter_result filter_trees_none( + struct repository *r, enum list_objects_filter_situation filter_situation, struct object *obj, const char *pathname, @@ -144,6 +146,7 @@ struct filter_blobs_limit_data { }; static enum list_objects_filter_result filter_blobs_limit( + struct repository *r, enum list_objects_filter_situation filter_situation, struct object *obj, const char *pathname, @@ -171,7 +174,7 @@ static enum list_objects_filter_result filter_blobs_limit( assert(obj->type == OBJ_BLOB); assert((obj->flags & SEEN) == 0); - t = oid_object_info(the_repository, &obj->oid, &object_length); + t = oid_object_info(r, &obj->oid, &object_length); if (t != OBJ_BLOB) { /* probably OBJ_NONE */ /* * We DO NOT have the blob locally, so we cannot @@ -249,6 +252,7 @@ struct filter_sparse_data { }; static enum list_objects_filter_result filter_sparse( + struct repository *r, enum list_objects_filter_situation filter_situation, struct object *obj, const char *pathname, @@ -268,7 +272,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); + r->index); if (val < 0) val = filter_data->array_frame[filter_data->nr].defval; @@ -331,7 +335,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); + r->index); if (val < 0) val = frame->defval; if (val > 0) { diff --git a/list-objects-filter.h b/list-objects-filter.h index 52b4a84da9..1d45a4ad57 100644 --- a/list-objects-filter.h +++ b/list-objects-filter.h @@ -4,6 +4,7 @@ struct list_objects_filter_options; struct object; struct oidset; +struct repository; /* * During list-object traversal we allow certain objects to be @@ -60,6 +61,7 @@ enum list_objects_filter_situation { }; typedef enum list_objects_filter_result (*filter_object_fn)( + struct repository *r, enum list_objects_filter_situation filter_situation, struct object *obj, const char *pathname, diff --git a/list-objects.c b/list-objects.c index c41cc80db5..0cfd646026 100644 --- a/list-objects.c +++ b/list-objects.c @@ -55,7 +55,8 @@ static void process_blob(struct traversal_context *ctx, pathlen = path->len; strbuf_addstr(path, name); if ((obj->flags & NOT_USER_GIVEN) && ctx->filter_fn) - r = ctx->filter_fn(LOFS_BLOB, obj, + r = ctx->filter_fn(ctx->revs->repo, + LOFS_BLOB, obj, path->buf, &path->buf[pathlen], ctx->filter_data); if (r & LOFR_MARK_SEEN) @@ -175,7 +176,8 @@ static void process_tree(struct traversal_context *ctx, strbuf_addstr(base, name); if ((obj->flags & NOT_USER_GIVEN) && ctx->filter_fn) - r = ctx->filter_fn(LOFS_BEGIN_TREE, obj, + r = ctx->filter_fn(ctx->revs->repo, + LOFS_BEGIN_TREE, obj, base->buf, &base->buf[baselen], ctx->filter_data); if (r & LOFR_MARK_SEEN) @@ -191,7 +193,8 @@ static void process_tree(struct traversal_context *ctx, process_tree_contents(ctx, tree, base); if ((obj->flags & NOT_USER_GIVEN) && ctx->filter_fn) { - r = ctx->filter_fn(LOFS_END_TREE, obj, + r = ctx->filter_fn(ctx->revs->repo, + LOFS_END_TREE, obj, base->buf, &base->buf[baselen], ctx->filter_data); if (r & LOFR_MARK_SEEN)