From: "Martin Ågren" <martin.agren@gmail.com> To: git@vger.kernel.org Cc: Junio C Hamano <gitster@pobox.com>, Emily Shaffer <emilyshaffer@google.com>, Jeff King <peff@peff.net> Subject: [PATCH 1/4] grep: don't set up a "default" repo for grep Date: Sat, 21 Nov 2020 19:31:07 +0100 Message-ID: <02c9c38f53cc6b1faa0b58e846f9f1f36c6a3df1.1605972564.git.martin.agren@gmail.com> (raw) In-Reply-To: <cover.1605972564.git.martin.agren@gmail.com> `init_grep_defaults()` fills a `static struct grep_opt grep_defaults`. This struct is then used by `grep_init()` as a blueprint for other such structs. Notably, `grep_init()` takes a `struct repo *` and assigns it into the target struct. As a result, it is unnecessary for us to take a `struct repo *` in `init_grep_defaults()` as well. We assign it into the default struct and never look at it again. And in light of how we return early if we have already set up the default struct, it's not just unnecessary, but is also a bit confusing: If we are called twice and with different repos, is it a bug or a feature that we ignore the second repo? Drop the repo parameter for `init_grep_defaults()`. Signed-off-by: Martin Ågren <martin.agren@gmail.com> --- Documentation/MyFirstObjectWalk.txt | 2 +- grep.h | 2 +- builtin/grep.c | 2 +- builtin/log.c | 2 +- grep.c | 3 +-- revision.c | 2 +- 6 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Documentation/MyFirstObjectWalk.txt b/Documentation/MyFirstObjectWalk.txt index c3f2d1a831..85434d1938 100644 --- a/Documentation/MyFirstObjectWalk.txt +++ b/Documentation/MyFirstObjectWalk.txt @@ -394,7 +394,7 @@ First some setup. Add `init_grep_defaults()` to `init_walken_defaults()` and add ---- static void init_walken_defaults(void) { - init_grep_defaults(the_repository); + init_grep_defaults(); } ... diff --git a/grep.h b/grep.h index 9115db8515..1c5478f381 100644 --- a/grep.h +++ b/grep.h @@ -170,7 +170,7 @@ struct grep_opt { void *output_priv; }; -void init_grep_defaults(struct repository *); +void init_grep_defaults(void); int grep_config(const char *var, const char *value, void *); void grep_init(struct grep_opt *, struct repository *repo, const char *prefix); void grep_destroy(void); diff --git a/builtin/grep.c b/builtin/grep.c index e58e57504c..2b96efa8c2 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -950,7 +950,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix) OPT_END() }; - init_grep_defaults(the_repository); + init_grep_defaults(); git_config(grep_cmd_config, NULL); grep_init(&opt, the_repository, prefix); diff --git a/builtin/log.c b/builtin/log.c index 49eb8f6431..eee4beca4d 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -131,7 +131,7 @@ static int log_line_range_callback(const struct option *option, const char *arg, static void init_log_defaults(void) { - init_grep_defaults(the_repository); + init_grep_defaults(); init_diff_ui_defaults(); decoration_style = auto_decoration_style(); diff --git a/grep.c b/grep.c index 54af9f813e..b351449f7f 100644 --- a/grep.c +++ b/grep.c @@ -57,7 +57,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(struct repository *repo) +void init_grep_defaults(void) { struct grep_opt *opt = &grep_defaults; static int run_once; @@ -67,7 +67,6 @@ void init_grep_defaults(struct repository *repo) run_once++; memset(opt, 0, sizeof(*opt)); - opt->repo = repo; opt->relative = 1; opt->pathname = 1; opt->max_depth = -1; diff --git a/revision.c b/revision.c index aa62212040..f35ea1db11 100644 --- a/revision.c +++ b/revision.c @@ -1834,7 +1834,7 @@ void repo_init_revisions(struct repository *r, revs->commit_format = CMIT_FMT_DEFAULT; revs->expand_tabs_in_log_default = 8; - init_grep_defaults(revs->repo); + init_grep_defaults(); grep_init(&revs->grep_filter, revs->repo, prefix); revs->grep_filter.status_only = 1; -- 2.29.2.454.gaff20da3a2
next prev parent reply other threads:[~2020-11-21 18:33 UTC|newest] Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-11-21 18:31 [PATCH 0/4] grep: retire `init_grep_defaults()` Martin Ågren 2020-11-21 18:31 ` Martin Ågren [this message] 2020-11-21 18:31 ` [PATCH 2/4] grep: use designated initializers for `grep_defaults` Martin Ågren 2020-11-21 18:31 ` [PATCH 3/4] grep: simplify color setup Martin Ågren 2020-11-21 20:23 ` Jeff King 2020-11-21 20:52 ` Martin Ågren 2020-11-21 22:46 ` Junio C Hamano 2020-11-24 6:54 ` Jeff King 2020-11-21 18:31 ` [PATCH 4/4] MyFirstObjectWalk: drop `init_walken_defaults()` Martin Ågren 2020-11-23 11:03 ` [PATCH 0/4] grep: retire `init_grep_defaults()` Johannes Schindelin 2020-11-24 21:04 ` [PATCH v2 0/4] grep: simplify "grep defaults" handling Martin Ågren 2020-11-24 21:04 ` [PATCH v2 1/4] grep: don't set up a "default" repo for grep Martin Ågren 2020-11-24 21:04 ` [PATCH v2 2/4] grep: use designated initializers for `grep_defaults` Martin Ågren 2020-11-24 21:04 ` [PATCH v2 3/4] grep: copy struct in one fell swoop Martin Ågren 2020-11-24 22:34 ` Junio C Hamano 2020-11-25 6:25 ` Martin Ågren 2020-11-25 7:53 ` Junio C Hamano 2020-11-26 20:25 ` Martin Ågren 2020-11-24 21:04 ` [PATCH v2 4/4] MyFirstObjectWalk: drop `init_walken_defaults()` Martin Ågren 2020-11-25 9:27 ` [PATCH v2 0/4] grep: simplify "grep defaults" handling Ævar Arnfjörð Bjarmason 2020-11-29 19:52 ` [PATCH v3 " Martin Ågren 2020-11-29 19:52 ` [PATCH v3 1/4] grep: don't set up a "default" repo for grep Martin Ågren 2020-11-29 19:52 ` [PATCH v3 2/4] grep: use designated initializers for `grep_defaults` Martin Ågren 2020-11-29 19:52 ` [PATCH v3 3/4] grep: copy struct in one fell swoop Martin Ågren 2020-11-29 19:52 ` [PATCH v3 4/4] MyFirstObjectWalk: drop `init_walken_defaults()` Martin Ågren 2020-12-01 4:46 ` [PATCH v3 0/4] grep: simplify "grep defaults" handling Junio C Hamano
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style List information: http://vger.kernel.org/majordomo-info.html * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=02c9c38f53cc6b1faa0b58e846f9f1f36c6a3df1.1605972564.git.martin.agren@gmail.com \ --to=martin.agren@gmail.com \ --cc=emilyshaffer@google.com \ --cc=git@vger.kernel.org \ --cc=gitster@pobox.com \ --cc=peff@peff.net \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
git@vger.kernel.org list mirror (unofficial, one of many) This inbox may be cloned and mirrored by anyone: git clone --mirror https://public-inbox.org/git git clone --mirror http://ou63pmih66umazou.onion/git git clone --mirror http://czquwvybam4bgbro.onion/git git clone --mirror http://hjrcffqmbrq6wope.onion/git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V1 git git/ https://public-inbox.org/git \ git@vger.kernel.org public-inbox-index git Example config snippet for mirrors. Newsgroups are available over NNTP: nntp://news.public-inbox.org/inbox.comp.version-control.git nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git nntp://news.gmane.io/gmane.comp.version-control.git note: .onion URLs require Tor: https://www.torproject.org/ code repositories for the project(s) associated with this inbox: https://80x24.org/mirrors/git.git AGPL code for this site: git clone https://public-inbox.org/public-inbox.git