From patchwork Sun Sep 9 08:54:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10593277 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 83A6514E0 for ; Sun, 9 Sep 2018 08:54:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 73A5928F7B for ; Sun, 9 Sep 2018 08:54:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 680CB29276; Sun, 9 Sep 2018 08:54: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 D92C828F7B for ; Sun, 9 Sep 2018 08:54:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726719AbeIINno (ORCPT ); Sun, 9 Sep 2018 09:43:44 -0400 Received: from mail-lj1-f182.google.com ([209.85.208.182]:35119 "EHLO mail-lj1-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726658AbeIINni (ORCPT ); Sun, 9 Sep 2018 09:43:38 -0400 Received: by mail-lj1-f182.google.com with SMTP id p10-v6so15407495ljg.2 for ; Sun, 09 Sep 2018 01:54:40 -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=q9SI6nOgBE4fzArx/WibJAJD6ivT6HwfmDpVxsLOQqg=; b=gBFvqNdwZLdeSGfJP2vIcoukTegdKUDDmuE2ok3GZ4C2vQ3hNziU4+trRP2mOG6Zli /qRmDr81VoPQL8tw1GnbpHZdUHHwrDybDs0olligg3SlMiHKqZLULWNRRzcDg3Lwz2jk dYYSLPcrFqkbLogN7g+ZNFQeXZHkFY5JquzhOLNiTKunmCpG1n/7/F7xn0JkvIXvT78q 6Is1XFBEu10+4WAIZFrnSxM/pWe/K7OYaycF1JUxD78kUxxe9+YbYP8Jn1itgJjKeB1s ya/36VPHFXyHRr4a6axdBveyOMiidGYpRZLZOOwWaM7NYPSAGoOYyDBvqfle0y/EPUKo YZNA== 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=q9SI6nOgBE4fzArx/WibJAJD6ivT6HwfmDpVxsLOQqg=; b=B8/bAZFyCRDOC0ypxaNnAROX9cl8LL2rOzzu1HtPyCwUZal1ioBF5J+rTyMlyNZTFo JLdkyKVWqJC7/0qMNNs5NT9uMfuoAAOK9HaENlPcNsUWA30B7YpvkhhWVQKuNLx6Tirc 0kznO98TDVCXZbYXk+R0OvGMUVUo+0jk0nrFVf1e3p09/BQC1c21qJMJKpkUSOstu9R2 QeTtOfO6bnr8pCONhiY2dLhFzgNE0ogT18obIZ1Xgf9HSX8ptIfxb0NlWFwHhQ08tKl8 ISEo3wSRj8m+/+ilADWqklxIt1XSok53KQEAbanTD2ZjLgJJnxwNmjc05teETWsx/GDR urpA== X-Gm-Message-State: APzg51DEQ0qjyRrePiwV8Btq8hlUKSo3za6BDF1VRq/r8g8qCGiDT8C+ wYmFW71cL3z1DDl50CQXg0SYPcPx X-Google-Smtp-Source: ANB0VdaMg7tnrUnB+p7iMvLRHRTXH6z5qcyq0av13n6WQ+bERXXdkbzzBbwOUE/dyVzff+rawkIDAA== X-Received: by 2002:a2e:9095:: with SMTP id l21-v6mr9840075ljg.15.1536483279395; Sun, 09 Sep 2018 01:54:39 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id g16-v6sm2102525lfb.5.2018.09.09.01.54.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Sep 2018 01:54:38 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: git@vger.kernel.org, sbeller@google.com, Junio C Hamano Subject: [PATCH v3 07/23] grep.c: remove implicit dependency on the_index Date: Sun, 9 Sep 2018 10:54:02 +0200 Message-Id: <20180909085418.31531-8-pclouds@gmail.com> X-Mailer: git-send-email 2.19.0.rc0.337.ge906d732e7 In-Reply-To: <20180909085418.31531-1-pclouds@gmail.com> References: <20180903180932.32260-1-pclouds@gmail.com> <20180909085418.31531-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 --- builtin/grep.c | 4 ++-- builtin/log.c | 2 +- grep.c | 13 ++++++++----- grep.h | 7 +++++-- revision.c | 4 ++-- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/builtin/grep.c b/builtin/grep.c index 601f801158..0667ffde84 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -904,9 +904,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix) OPT_END() }; - init_grep_defaults(); + init_grep_defaults(the_repository); git_config(grep_cmd_config, NULL); - grep_init(&opt, prefix); + grep_init(&opt, the_repository, prefix); /* * If there is no -- then the paths must exist in the working diff --git a/builtin/log.c b/builtin/log.c index f32a07f6a9..b62082472c 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -115,7 +115,7 @@ static int log_line_range_callback(const struct option *option, const char *arg, static void init_log_defaults(void) { - init_grep_defaults(); + init_grep_defaults(the_repository); init_diff_ui_defaults(); decoration_style = auto_decoration_style(); diff --git a/grep.c b/grep.c index e146ff20bb..6c0eede3a1 100644 --- a/grep.c +++ b/grep.c @@ -42,7 +42,7 @@ static void color_set(char *dst, const char *color_bytes) * We could let the compiler do this, but without C99 initializers * the code gets unwieldy and unreadable, so... */ -void init_grep_defaults(void) +void init_grep_defaults(struct repository *repo) { struct grep_opt *opt = &grep_defaults; static int run_once; @@ -52,6 +52,7 @@ void init_grep_defaults(void) run_once++; memset(opt, 0, sizeof(*opt)); + opt->repo = repo; opt->relative = 1; opt->pathname = 1; opt->max_depth = -1; @@ -149,12 +150,13 @@ int grep_config(const char *var, const char *value, void *cb) * default values from the template we read the configuration * information in an earlier call to git_config(grep_config). */ -void grep_init(struct grep_opt *opt, const char *prefix) +void grep_init(struct grep_opt *opt, struct repository *repo, const char *prefix) { struct grep_opt *def = &grep_defaults; int i; memset(opt, 0, sizeof(*opt)); + opt->repo = repo; opt->prefix = prefix; opt->prefix_length = (prefix && *prefix) ? strlen(prefix) : 0; opt->pattern_tail = &opt->pattern_list; @@ -1708,7 +1710,8 @@ static int look_ahead(struct grep_opt *opt, return 0; } -static int fill_textconv_grep(struct userdiff_driver *driver, +static int fill_textconv_grep(struct repository *r, + struct userdiff_driver *driver, struct grep_source *gs) { struct diff_filespec *df; @@ -1741,7 +1744,7 @@ static int fill_textconv_grep(struct userdiff_driver *driver, * structure. */ grep_read_lock(); - size = fill_textconv(the_repository, driver, df, &buf); + size = fill_textconv(r, driver, df, &buf); grep_read_unlock(); free_filespec(df); @@ -1837,7 +1840,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle try_lookahead = should_lookahead(opt); - if (fill_textconv_grep(textconv, gs) < 0) + if (fill_textconv_grep(opt->repo, textconv, gs) < 0) return 0; bol = gs->buf; diff --git a/grep.h b/grep.h index 0ba62a11c5..3651183971 100644 --- a/grep.h +++ b/grep.h @@ -36,6 +36,8 @@ typedef int pcre2_jit_stack; #include "thread-utils.h" #include "userdiff.h" +struct repository; + enum grep_pat_token { GREP_PATTERN, GREP_PATTERN_HEAD, @@ -136,6 +138,7 @@ struct grep_opt { struct grep_pat *header_list; struct grep_pat **header_tail; struct grep_expr *pattern_expression; + struct repository *repo; const char *prefix; int prefix_length; regex_t regexp; @@ -183,9 +186,9 @@ struct grep_opt { void *output_priv; }; -extern void init_grep_defaults(void); +extern void init_grep_defaults(struct repository *); extern int grep_config(const char *var, const char *value, void *); -extern void grep_init(struct grep_opt *, const char *prefix); +extern void grep_init(struct grep_opt *, struct repository *repo, const char *prefix); void grep_commit_pattern_type(enum grep_pattern_type, struct grep_opt *opt); extern void append_grep_pat(struct grep_opt *opt, const char *pat, size_t patlen, const char *origin, int no, enum grep_pat_token t); diff --git a/revision.c b/revision.c index de4dce600d..3457064ff3 100644 --- a/revision.c +++ b/revision.c @@ -1464,8 +1464,8 @@ void init_revisions(struct rev_info *revs, const char *prefix) revs->commit_format = CMIT_FMT_DEFAULT; revs->expand_tabs_in_log_default = 8; - init_grep_defaults(); - grep_init(&revs->grep_filter, prefix); + init_grep_defaults(the_repository); + grep_init(&revs->grep_filter, the_repository, prefix); revs->grep_filter.status_only = 1; diff_setup(&revs->diffopt);