From patchwork Sat Nov 21 18:31:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_=C3=85gren?= X-Patchwork-Id: 11923601 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D582C388F9 for ; Sat, 21 Nov 2020 18:31:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1084522202 for ; Sat, 21 Nov 2020 18:31:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qEpGqL8n" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728188AbgKUSbk (ORCPT ); Sat, 21 Nov 2020 13:31:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727298AbgKUSbj (ORCPT ); Sat, 21 Nov 2020 13:31:39 -0500 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55DF0C0613CF for ; Sat, 21 Nov 2020 10:31:39 -0800 (PST) Received: by mail-lj1-x243.google.com with SMTP id l10so13570358lji.4 for ; Sat, 21 Nov 2020 10:31:39 -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=MpzEtaiZqKT0T5CsKXtV24LR2pR24pv/lx03VIGA7iI=; b=qEpGqL8nR9amI0ib+g/DDr49kN7FAfgifH1lweA1OnQGkJPad/mWfa3A3ysBrLJ9X0 5CFNbSTj2He/cLd9x9/Qyye6nhczm+lbiEHe26C2FMtSJYjgCCGIgt7UtlCgJ87Np32D /zGcr5wMcGC03hVgGoZC6RdH3NM+O6rVX321jxx87+qfbQV4xIvP0lVIHdYH7iT8xtgE 5QU44YkDxqD5C26KV0MRe5ZCPS1h0FBmGwphndOCq9R12Aqfqgx83ZXKpo3JWlRXOhJi v97yeMKiB4g2SRkVigalw4Ts21IFSF1QRwuz7/DTmwUUzyztZ5vxkOch4TUSYS0Swkoz PRzg== 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=MpzEtaiZqKT0T5CsKXtV24LR2pR24pv/lx03VIGA7iI=; b=aQI379jlopu+eM7cIMPKWYtKFRVOPGZAztBt/EQaheyGXuLN95oWfx6ntLbEu4vOq1 wLdH9YNhZVItvwPkYiv3PGw8dDpe7z9t4CPrdU90bGw31OABN8xYGc67wpQFG84FR/dg HRqjOCz9bUgyjRPRS1nvSUxWqrMAEoqpsDJNaFVRNSS7w5eF/cjsz+s9uybqJyO/yE5J xt3szO/M5oBSQyB980j0H1Jr2S7roxsqGY0695DnzZctNWdN7OZdH4sLJBRC1zt+iqzt TJTJc3Ef7wDWxpRkPNkwEE3nUCsFLeZSp9ogOvkZ5fCEz9J3td+EvUIdas8xO4h2UiiT SraQ== X-Gm-Message-State: AOAM530oY6k6QHBmYtz0m/phcPuuDQRXbnp2BS/TGm4A8TTl3qZSIPzc MTco02ND4ZOJ+4G5dXTljCjiEw8tTSaL0g== X-Google-Smtp-Source: ABdhPJyBh+0UHxi7CHzPwlgVpqctzRrNN5uf4xhgRV/Ji3rOgmo8ccwCcl1Fc3axJ8dMcft0FAK+Cw== X-Received: by 2002:a2e:9046:: with SMTP id n6mr10924251ljg.22.1605983497577; Sat, 21 Nov 2020 10:31:37 -0800 (PST) Received: from localhost.localdomain (h-79-136-100-70.NA.cust.bahnhof.se. [79.136.100.70]) by smtp.gmail.com with ESMTPSA id m7sm786531lfj.113.2020.11.21.10.31.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2020 10:31:37 -0800 (PST) From: =?utf-8?q?Martin_=C3=85gren?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King 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> X-Mailer: git-send-email 2.29.2.454.gaff20da3a2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org `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 --- 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; From patchwork Sat Nov 21 18:31:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_=C3=85gren?= X-Patchwork-Id: 11923603 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22EC5C5519F for ; Sat, 21 Nov 2020 18:31:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D30EE22202 for ; Sat, 21 Nov 2020 18:31:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GqqJ7iGZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728197AbgKUSbn (ORCPT ); Sat, 21 Nov 2020 13:31:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727298AbgKUSbm (ORCPT ); Sat, 21 Nov 2020 13:31:42 -0500 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 419EFC0613CF for ; Sat, 21 Nov 2020 10:31:42 -0800 (PST) Received: by mail-lj1-x243.google.com with SMTP id 11so13567728ljf.2 for ; Sat, 21 Nov 2020 10:31:42 -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=ZnHzUHnlCjCOTsw1W382RHdrwzaQ8sz3XpGiOYbXZ7M=; b=GqqJ7iGZj3Td7tcVQIPhUVLn0QoE4nkFqmTekJ1KY8lCKIoMC5+Sf6h4EYvrdvrNlM GJFQbkGVcQGAzHEDtNTb2sX/Y5AZdl0h11NnxvYMDUw5k3AjYN8gXS3VtNWybJw8sQsk 4cq8UbE2q6K+Dyy0sgbL4W8jhT8qWI5ktfY2WJ/lC4tJC4kxczqftuRGmRNDZ/hAq1TR hrgQye3HFuTDkMIn/3XiX+3iQqqtaVe+kwKMqDEbdN0deYewzkm8bwgxZRYglQ1L77nX DeHiz8xpvf7C6ayTCOsdTEef/GWtEhtw7N1FYG00R/rzCxiJBwxCcbNyAHuZePACRPAH T1BA== 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=ZnHzUHnlCjCOTsw1W382RHdrwzaQ8sz3XpGiOYbXZ7M=; b=VZHK7V9TOZQQjC0Cn8rHxRxM9T7jC2zsqDEvK88fhyq44+w8eAirk4Ckeoj2IdqprA EA/N17px/61m0B0Qp0AKRyp3FVuyKRhoJUQCInFE8seoDMsk741N/Gdq09BB6pkLNjc8 ItsByvs/AYXW3fAqO6d+x2DJwGg/mnzQal1dwGUiAUnUPuchlDn62ks6AGZrQSDcZ4X3 Tqsn1+x0CU5cp4JQIznC7sGyW9h24bXRbl+KGzO+2QLmj+xJic6X5zG0QAYUkUJo6rN1 e6ypghpNXe/Amzrqk9DMPEvydr1jMdVgY9qVEy1Es/YuWMraZmR8kXVDsxOrKS6meldj 8I6Q== X-Gm-Message-State: AOAM532bL+6DJSFAoGi8NLDA671XyBCKBk5MK/c536Zd9NIC2Yw0NE7x 8R0WMcX+AEi8YYXOwuL1xEMIVY+JqFRxfQ== X-Google-Smtp-Source: ABdhPJx9EzeygQcLseIngKsTUA1HIuRY3WUAZ0TOTFTZjNjtoQYMsm1JZRaUsUVtetuYqcZo8ZkIgg== X-Received: by 2002:a2e:8053:: with SMTP id p19mr9741744ljg.321.1605983500437; Sat, 21 Nov 2020 10:31:40 -0800 (PST) Received: from localhost.localdomain (h-79-136-100-70.NA.cust.bahnhof.se. [79.136.100.70]) by smtp.gmail.com with ESMTPSA id m7sm786531lfj.113.2020.11.21.10.31.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2020 10:31:39 -0800 (PST) From: =?utf-8?q?Martin_=C3=85gren?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King Subject: [PATCH 2/4] grep: use designated initializers for `grep_defaults` Date: Sat, 21 Nov 2020 19:31:08 +0100 Message-Id: <5aad7bb31f955a6adf41febfd16f2f483294f939.1605972564.git.martin.agren@gmail.com> X-Mailer: git-send-email 2.29.2.454.gaff20da3a2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In 15fabd1bbd ("builtin/grep.c: make configuration callback more reusable", 2012-10-09), we learned to fill a `static struct grep_opt grep_defaults` which we can use as a blueprint for other such structs. At the time, we didn't consider designated initializers to be widely useable, but these days, we do. (See, e.g., cbc0f81d96 ("strbuf: use designated initializers in STRBUF_INIT", 2017-07-10).) Use designated initializers to let the compiler set up the struct and so that we don't need to remember to call `init_grep_defaults()`. Signed-off-by: Martin Ågren --- If we've messed up and our color strings are too large for our buffers, we will no longer hit a BUG within `color_set()`, but we should be able to rely on the compiler detecting the truncation. We'll probably be *better* off than before, since the compiler will know exactly how large the buffer is. Documentation/MyFirstObjectWalk.txt | 10 +---- grep.h | 1 - builtin/grep.c | 1 - builtin/log.c | 1 - grep.c | 64 +++++++++++------------------ revision.c | 1 - 6 files changed, 26 insertions(+), 52 deletions(-) diff --git a/Documentation/MyFirstObjectWalk.txt b/Documentation/MyFirstObjectWalk.txt index 85434d1938..7f4bffc4dd 100644 --- a/Documentation/MyFirstObjectWalk.txt +++ b/Documentation/MyFirstObjectWalk.txt @@ -388,17 +388,9 @@ Next, let's try to filter the commits we see based on their author. This is equivalent to running `git log --author=`. We can add a filter by modifying `rev_info.grep_filter`, which is a `struct grep_opt`. -First some setup. Add `init_grep_defaults()` to `init_walken_defaults()` and add -`grep_config()` to `git_walken_config()`: +First some setup. Add `grep_config()` to `git_walken_config()`: ---- -static void init_walken_defaults(void) -{ - init_grep_defaults(); -} - -... - static int git_walken_config(const char *var, const char *value, void *cb) { grep_config(var, value, cb); diff --git a/grep.h b/grep.h index 1c5478f381..b5c4e223a8 100644 --- a/grep.h +++ b/grep.h @@ -170,7 +170,6 @@ struct grep_opt { void *output_priv; }; -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 2b96efa8c2..ca259af441 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -950,7 +950,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix) OPT_END() }; - 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 eee4beca4d..cf41714fb0 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -131,7 +131,6 @@ static int log_line_range_callback(const struct option *option, const char *arg, static void init_log_defaults(void) { - init_grep_defaults(); init_diff_ui_defaults(); decoration_style = auto_decoration_style(); diff --git a/grep.c b/grep.c index b351449f7f..8f2009ec9f 100644 --- a/grep.c +++ b/grep.c @@ -14,7 +14,31 @@ static int grep_source_load(struct grep_source *gs); static int grep_source_is_binary(struct grep_source *gs, struct index_state *istate); -static struct grep_opt grep_defaults; +static void std_output(struct grep_opt *opt, const void *buf, size_t size) +{ + fwrite(buf, size, 1, stdout); +} + +static struct grep_opt grep_defaults = { + .relative = 1, + .pathname = 1, + .max_depth = -1, + .pattern_type_option = GREP_PATTERN_TYPE_UNSPECIFIED, + .colors = { + [GREP_COLOR_CONTEXT] = "", + [GREP_COLOR_FILENAME] = "", + [GREP_COLOR_FUNCTION] = "", + [GREP_COLOR_LINENO] = "", + [GREP_COLOR_COLUMNNO] = "", + [GREP_COLOR_MATCH_CONTEXT] = GIT_COLOR_BOLD_RED, + [GREP_COLOR_MATCH_SELECTED] = GIT_COLOR_BOLD_RED, + [GREP_COLOR_SELECTED] = "", + [GREP_COLOR_SEP] = GIT_COLOR_CYAN, + }, + .only_matching = 0, + .color = -1, + .output = std_output, +}; #ifdef USE_LIBPCRE2 static pcre2_general_context *pcre2_global_context; @@ -42,49 +66,11 @@ static const char *color_grep_slots[] = { [GREP_COLOR_SEP] = "separator", }; -static void std_output(struct grep_opt *opt, const void *buf, size_t size) -{ - fwrite(buf, size, 1, stdout); -} - static void color_set(char *dst, const char *color_bytes) { xsnprintf(dst, COLOR_MAXLEN, "%s", color_bytes); } -/* - * Initialize the grep_defaults template with hardcoded defaults. - * We could let the compiler do this, but without C99 initializers - * the code gets unwieldy and unreadable, so... - */ -void init_grep_defaults(void) -{ - struct grep_opt *opt = &grep_defaults; - static int run_once; - - if (run_once) - return; - run_once++; - - memset(opt, 0, sizeof(*opt)); - opt->relative = 1; - opt->pathname = 1; - opt->max_depth = -1; - opt->pattern_type_option = GREP_PATTERN_TYPE_UNSPECIFIED; - color_set(opt->colors[GREP_COLOR_CONTEXT], ""); - color_set(opt->colors[GREP_COLOR_FILENAME], ""); - color_set(opt->colors[GREP_COLOR_FUNCTION], ""); - color_set(opt->colors[GREP_COLOR_LINENO], ""); - color_set(opt->colors[GREP_COLOR_COLUMNNO], ""); - color_set(opt->colors[GREP_COLOR_MATCH_CONTEXT], GIT_COLOR_BOLD_RED); - color_set(opt->colors[GREP_COLOR_MATCH_SELECTED], GIT_COLOR_BOLD_RED); - color_set(opt->colors[GREP_COLOR_SELECTED], ""); - color_set(opt->colors[GREP_COLOR_SEP], GIT_COLOR_CYAN); - opt->only_matching = 0; - opt->color = -1; - opt->output = std_output; -} - static int parse_pattern_type_arg(const char *opt, const char *arg) { if (!strcmp(arg, "default")) diff --git a/revision.c b/revision.c index f35ea1db11..963868f699 100644 --- a/revision.c +++ b/revision.c @@ -1834,7 +1834,6 @@ void repo_init_revisions(struct repository *r, revs->commit_format = CMIT_FMT_DEFAULT; revs->expand_tabs_in_log_default = 8; - init_grep_defaults(); grep_init(&revs->grep_filter, revs->repo, prefix); revs->grep_filter.status_only = 1; From patchwork Sat Nov 21 18:31:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_=C3=85gren?= X-Patchwork-Id: 11923605 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D474C388F9 for ; Sat, 21 Nov 2020 18:31:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2139922202 for ; Sat, 21 Nov 2020 18:31:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YJiVQXkH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728205AbgKUSbp (ORCPT ); Sat, 21 Nov 2020 13:31:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727298AbgKUSbp (ORCPT ); Sat, 21 Nov 2020 13:31:45 -0500 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 969E1C0613CF for ; Sat, 21 Nov 2020 10:31:44 -0800 (PST) Received: by mail-lj1-x244.google.com with SMTP id p12so13539614ljc.9 for ; Sat, 21 Nov 2020 10:31:44 -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=3zPufgRiT/vUmgycWyCMOs29nBjPPWDV3tYC75/7HQA=; b=YJiVQXkHvZ8jy8kEPNpGtNF8beFmSq51InsIImxICIoen5ooXaEri+E8GLQe53aHpU edEq76Tejb6XlvSvFu4dNoalZ1G/qVDUAIEgYyVGmQTwP2J/XVI5LHf0UVIBi7m2EMvX RNClEtcnv7bEV9Stl3cnAqVFZvVVN69sNV544RIJ4VQeGQwJY/TqnY3Wp8QV2yJS+avP wH8LBHOaC2GZ2hpxWsYIwzdPn5wXWm80DN/qMGAq1E88EPieUnBQ8Ym2zA9SmkV+W25D Yo6Arns+GzmMMc1nPEX0aGKcJ7vM4Da42ZZWpf4SWiNe2MPqwnj2+CFvi13pfmB8ALrM aswg== 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=3zPufgRiT/vUmgycWyCMOs29nBjPPWDV3tYC75/7HQA=; b=bpeig6oWcA7eqAnvOkh/nTTo2b0rLuCs10hIX0LBkfHaIwPharFmT/HJVhsXmbwmcr htgFgeVXRd0RXrCMl0YEcqGiOVtCh9c63COIChCw/6kS4tQjMyBEzemFiwpb9zfy1+ue 8czelJwpKP41yuPWU287Oag0+x39Eg6lQt/Xm7KRKWGeyv2HgYv2TALbDmcKj9wYOqYY tJ9971gbmXbyxyExKp4Cudjw9N8F2VIO3DTqsDG33fG4bS+hup+wyasXbNMulapHVjTf 09BAIZtrX3l6rUJOjWdXSCRt24KISRDqju9Mp0/o2gsOAyJf00+BlQJ+XGrr/0bKiVRy 1ygg== X-Gm-Message-State: AOAM530KE1GXb2TyrRkdvb81ZwhbqvdZr0yFlIESa5Er+Atn1y5zOjsb 82l3Kb/D5qp7v42qhV/Jnmk+SV3V/PVLPw== X-Google-Smtp-Source: ABdhPJxXWUm7oDhtRKGNTCXNr086TtdFR1fP3QMtM35laoUCIQJJUiYXwcsSnEHtZ8fU38RkAJynJg== X-Received: by 2002:a2e:8846:: with SMTP id z6mr10370695ljj.311.1605983502768; Sat, 21 Nov 2020 10:31:42 -0800 (PST) Received: from localhost.localdomain (h-79-136-100-70.NA.cust.bahnhof.se. [79.136.100.70]) by smtp.gmail.com with ESMTPSA id m7sm786531lfj.113.2020.11.21.10.31.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2020 10:31:42 -0800 (PST) From: =?utf-8?q?Martin_=C3=85gren?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King Subject: [PATCH 3/4] grep: simplify color setup Date: Sat, 21 Nov 2020 19:31:09 +0100 Message-Id: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The previous commit left us with only one user of the one-line wrapper `color_set()`. We could inline it, but note how we're `xsnprintf()`-ing all the entries in one array into another array of the same type. We might as well just `memcpy()` everything into place. Signed-off-by: Martin Ågren --- Cc-ing Peff, who initially introduced this helper. After having inlined the function into the for loop, it seemed better to just copy the whole array. Happy to hear arguments against. Come to think of it, I suppose we could copy the whole struct and not just the color array. Hmmm... grep.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/grep.c b/grep.c index 8f2009ec9f..9597cec67e 100644 --- a/grep.c +++ b/grep.c @@ -66,11 +66,6 @@ static const char *color_grep_slots[] = { [GREP_COLOR_SEP] = "separator", }; -static void color_set(char *dst, const char *color_bytes) -{ - xsnprintf(dst, COLOR_MAXLEN, "%s", color_bytes); -} - static int parse_pattern_type_arg(const char *opt, const char *arg) { if (!strcmp(arg, "default")) @@ -158,7 +153,6 @@ int grep_config(const char *var, const char *value, void *cb) void grep_init(struct grep_opt *opt, struct repository *repo, const char *prefix) { struct grep_opt *def = &grep_defaults; - int i; #if defined(USE_LIBPCRE2) if (!pcre2_global_context) @@ -189,8 +183,7 @@ void grep_init(struct grep_opt *opt, struct repository *repo, const char *prefix opt->relative = def->relative; opt->output = def->output; - for (i = 0; i < NR_GREP_COLORS; i++) - color_set(opt->colors[i], def->colors[i]); + memcpy(opt->colors, def->colors, sizeof(def->colors)); } void grep_destroy(void) From patchwork Sat Nov 21 18:31:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_=C3=85gren?= X-Patchwork-Id: 11923607 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77077C388F9 for ; Sat, 21 Nov 2020 18:31:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D04E22202 for ; Sat, 21 Nov 2020 18:31:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UbC490ja" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728213AbgKUSbr (ORCPT ); Sat, 21 Nov 2020 13:31:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727298AbgKUSbr (ORCPT ); Sat, 21 Nov 2020 13:31:47 -0500 Received: from mail-lf1-x143.google.com (mail-lf1-x143.google.com [IPv6:2a00:1450:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B57D4C0613CF for ; Sat, 21 Nov 2020 10:31:46 -0800 (PST) Received: by mail-lf1-x143.google.com with SMTP id t6so2006014lfl.13 for ; Sat, 21 Nov 2020 10:31:46 -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=8DUdSd6pQs4jmskCyVGNyzDYV2RBm7j5o4x+7rAAh1I=; b=UbC490jaVPm+z2mofaKpcg0pjaSp6wA76oC1GNgt0g8U2XvswUfZD/Lz9RczeiTe2Y NVXvZuGOjC8beqududUGffW0UOXBadqHNDzUh5whxWCDpgo1d654Re8+qH7HP14WnsJK jduQ5AE1liPBihNawusE1k8zOiehVdT8Y6OAldCDRsgeHjSpwFGr8u635i23zr+an3QL R//i268ek+mBsEGo0lYSGpQLBo66oIu8SkRzMs0blNgDMikB+MUEELWrMK1kS/poARKC npy8osZW6UOaYjbgQ5DhUoTirXO5biAJeJaS36lUhbGhJ/jvqYfn1dG6auSOilGym9in t3Fw== 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=8DUdSd6pQs4jmskCyVGNyzDYV2RBm7j5o4x+7rAAh1I=; b=o66QreFssjW1Tn86Pkn8+kVSq00M2xYBNrBfdVyXrvejj92uqFDpVBqp1L3zlh94aN qbo7pGfYcbZVpLXyYgmg7n46LIuIxPpdQ6dhyfIBYX/0S8XuumEjEHvmllzCa4FAaTTZ mXXDHuI4E/eZ9T2ZwTdEBsJD5w4+UNfoClwoHJ9/99+UaQpjqAvC8LyI0GX9L2Y3KU6r aBo+zLjBuuLUQZ6RrfAW6kWB26vadv19jYCTsUgDZHSg8PV1yrMdk70cxHORsfBKR9W3 lIcmSu+w26h/py5BYuz+ZdyQfitFMzDYhrwwnYnJHz16MKRe/hFG6lDB8FWtJslICA6P 4g2Q== X-Gm-Message-State: AOAM533bkUDjGieuek8MIgN0NqPFdB+qpTqWWF+7ebN8EwHMrjQ4/fQJ zXI5JLQAZWdq8KTpqRWpbBv3akXgZwYPog== X-Google-Smtp-Source: ABdhPJzSxFxV1vKTZyLcxGnw713tTx/h5I1kgLRbtfyn9myVneNoT5qL15zytB1sC2EjUW/zi0+QXA== X-Received: by 2002:a19:be14:: with SMTP id o20mr10799108lff.453.1605983504895; Sat, 21 Nov 2020 10:31:44 -0800 (PST) Received: from localhost.localdomain (h-79-136-100-70.NA.cust.bahnhof.se. [79.136.100.70]) by smtp.gmail.com with ESMTPSA id m7sm786531lfj.113.2020.11.21.10.31.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2020 10:31:44 -0800 (PST) From: =?utf-8?q?Martin_=C3=85gren?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Jeff King Subject: [PATCH 4/4] MyFirstObjectWalk: drop `init_walken_defaults()` Date: Sat, 21 Nov 2020 19:31:10 +0100 Message-Id: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In a recent commit, we stopped calling `init_grep_defaults()` from this function. Thus, by the end of the tutorial, we still haven't added any contents to this function. Let's remove it for simplicity. Signed-off-by: Martin Ågren --- Documentation/MyFirstObjectWalk.txt | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/Documentation/MyFirstObjectWalk.txt b/Documentation/MyFirstObjectWalk.txt index 7f4bffc4dd..2d10eea7a9 100644 --- a/Documentation/MyFirstObjectWalk.txt +++ b/Documentation/MyFirstObjectWalk.txt @@ -182,30 +182,6 @@ its `init_log_defaults()` sets its own state (`decoration_style`) and asks `grep` and `diff` to initialize themselves by calling each of their initialization functions. -For our first example within `git walken`, we don't intend to use any other -components within Git, and we don't have any configuration to do. However, we -may want to add some later, so for now, we can add an empty placeholder. Create -a new function in `builtin/walken.c`: - ----- -static void init_walken_defaults(void) -{ - /* - * We don't actually need the same components `git log` does; leave this - * empty for now. - */ -} ----- - -Make sure to add a line invoking it inside of `cmd_walken()`. - ----- -int cmd_walken(int argc, const char **argv, const char *prefix) -{ - init_walken_defaults(); -} ----- - ==== Configuring From `.gitconfig` Next, we should have a look at any relevant configuration settings (i.e.,