From patchwork Fri Feb 11 16:36:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Henrie X-Patchwork-Id: 12743640 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFDFFC433EF for ; Fri, 11 Feb 2022 16:37:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351591AbiBKQhX (ORCPT ); Fri, 11 Feb 2022 11:37:23 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244029AbiBKQhW (ORCPT ); Fri, 11 Feb 2022 11:37:22 -0500 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AE7AD66 for ; Fri, 11 Feb 2022 08:37:21 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id p6so4913666plf.10 for ; Fri, 11 Feb 2022 08:37:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=RoPGnZ3megEgKMguJWV/dkqP4GvLBc/JHQ0pSnelzpk=; b=JlVZM7Rl2c41mQ66CpWlUdPojLNnzmryL+F8FbbKqjegBBAogtL0tkduj9SH4uG21k ESBxn5x4TdeacM42H4Wr5v31dOQM7HYw/BeU0zjw54ujEPUJ2daYG258/diDSQVpJQ12 a6dutmYz4IUgu0QpcLmVQZUUBPDb8lJ7o/y68jo5b4BAq8+vIOtq7p8KAxa+TMlEb+lZ GLviI9sz3ytVWdssu5+jUaROyosH4YdBz0mYiy0bCW8hpAMo3cJOe4zEkO8oUjOPLVuM uiWxroVAF5ZRkFWjwerh+/nkv9hJyD2GmRIhARzoqrOzCVjZqtALd8SkgU96MXFhW++I bCfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=RoPGnZ3megEgKMguJWV/dkqP4GvLBc/JHQ0pSnelzpk=; b=2+cTqG5vrtcMxla0IEzJKmJI1wlSS0bC11oyNJEhDZoaG/jjlyA9c7dG+K3bq3vayb tDdNboMdb5ndktrIjqqk4CzGzX7KivlHwF93GOL6PobCP7qGGbNWHz5fIgKp7GnqxwlU Zk9u65gtWl5pfWq66NAQG6nUF9j3Ff1n3IVTlUBMOZcRTQbggGpAdUMDO3KmH8AwUivN 1gZCqB8I1kqxFyAdc9ei4OVhf4UMe2eWKHSVJXQw9LOkv4nf/FbPKtYCIi9fnrRC+7sv u9VCOBzgp2pc52Ge1WAgQrFQ+3AFcgi78xGTs6e6+z2H8Phm1DwtfOeybVWUMn5d1Lvj 5/wA== X-Gm-Message-State: AOAM5335l+IokFA/XLwSCwoVyHp6YI4NWRqbHO63vnRIu6u6WslMDZSR rT8JhDUrHht3kIyzfoXxbf3u3AUDtgk= X-Google-Smtp-Source: ABdhPJzhFminZ9QiLmd0MF2CySK4G+twR1fDTpakriZpL1qig1thmOnJncd8+cMzcZEGr0Vvrude3w== X-Received: by 2002:a17:90b:4a52:: with SMTP id lb18mr1252919pjb.92.1644597440136; Fri, 11 Feb 2022 08:37:20 -0800 (PST) Received: from xavier.lan ([2001:470:b:114::cc1]) by smtp.gmail.com with ESMTPSA id l17sm27450568pfu.61.2022.02.11.08.37.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Feb 2022 08:37:19 -0800 (PST) From: Alex Henrie To: git@vger.kernel.org, paulus@ozlabs.org Cc: Alex Henrie Subject: [PATCH v3 1/4] log: fix memory leak if --graph is passed multiple times Date: Fri, 11 Feb 2022 09:36:24 -0700 Message-Id: <20220211163627.598166-1-alexhenrie24@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: Alex Henrie --- v3: no changes --- graph.c | 12 ++++++++++++ graph.h | 5 +++++ revision.c | 1 + 3 files changed, 18 insertions(+) diff --git a/graph.c b/graph.c index e3828eb8f2..568b6e7cd4 100644 --- a/graph.c +++ b/graph.c @@ -401,6 +401,18 @@ struct git_graph *graph_init(struct rev_info *opt) return graph; } +void graph_clear(struct git_graph *graph) +{ + if (!graph) + return; + + free(graph->columns); + free(graph->new_columns); + free(graph->mapping); + free(graph->old_mapping); + free(graph); +} + static void graph_update_state(struct git_graph *graph, enum graph_state s) { graph->prev_state = graph->state; diff --git a/graph.h b/graph.h index 8313e293c7..e88632a014 100644 --- a/graph.h +++ b/graph.h @@ -139,6 +139,11 @@ void graph_set_column_colors(const char **colors, unsigned short colors_max); */ struct git_graph *graph_init(struct rev_info *opt); +/* + * Free a struct git_graph. + */ +void graph_clear(struct git_graph *graph); + /* * Update a git_graph with a new commit. * This will cause the graph to begin outputting lines for the new commit diff --git a/revision.c b/revision.c index ad4286fbdd..816061f3d9 100644 --- a/revision.c +++ b/revision.c @@ -2426,6 +2426,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg } else if (!strcmp(arg, "--graph")) { revs->topo_order = 1; revs->rewrite_parents = 1; + graph_clear(revs->graph); revs->graph = graph_init(revs); } else if (!strcmp(arg, "--encode-email-headers")) { revs->encode_email_headers = 1; From patchwork Fri Feb 11 16:36:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Henrie X-Patchwork-Id: 12743641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D048AC433EF for ; Fri, 11 Feb 2022 16:37:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351597AbiBKQh0 (ORCPT ); Fri, 11 Feb 2022 11:37:26 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244029AbiBKQhY (ORCPT ); Fri, 11 Feb 2022 11:37:24 -0500 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D3BBD66 for ; Fri, 11 Feb 2022 08:37:22 -0800 (PST) Received: by mail-pf1-x42e.google.com with SMTP id u16so11505539pfg.3 for ; Fri, 11 Feb 2022 08:37:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GyWTUz04uc9eqMjTAroEY6jsrHaVQJZzB8OrSXt0Gug=; b=ZpaA0WveKqtNps0LdG5/x/Gt7BLYDtm9MsZHuGQwH3P5hGOObvNqvFupL+rhBBYtPQ W8X5sOZ2LEswta5wCr4GId5u45ZMyOG0I4rO48FeomLno4o3IhgfsO/z5aWhwARlFVv0 NT7qcZZS//JqPOOuIZJcvDLJ26/t1iZEKGvicIbfb0BngvmDw7yQn76e7JjkSOWMo25c Dx3/F0BVbMC5Rw3rUGP7LvJR9J2XS49lRdvEc6iAvE/mjX7G1IZ6tkheVzRBPrdsWNiI OHYbkZstz5TtIJDWn/Vsy2NapJstr9WOlWrvIh8LeiDdxrxpSBhSJTCL9UlFRIikw7V0 CWKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GyWTUz04uc9eqMjTAroEY6jsrHaVQJZzB8OrSXt0Gug=; b=55fi1y2gce92zVPYcmEbOGhcHouKWaXe846ZRuppmhGz16nUSnMmLLa9dRkz0C0CAp mAuusAoGi/3mB457UR9EV/VS02T1Y5K/UAu+PbbC2oQtwBcU6YUiqK0pvKXi2eKcZQlL UBQqHb+E1h1DFaNnMLfUSKL++HdiYQWov41UJAxrBSE8Z8NbPDWguVytvodGS2N0Xu8q V14MohnYzUOkNqq9U2EtTDsPlcqRywbb+4kstHu7RuLfjph1jFAjkbeWq5OvsKsPQNnf 7I4AZBIMnfQ8Yu/atX8b9UleWSg8dW5TWN3ZTLwuq6fYdaQFrfAi5EO7hPBPDEG2fxoQ Kybw== X-Gm-Message-State: AOAM531YhVw+/IryM3XmqOq8nz/WjH3/Iv/wx36jU1Drhy1WfCLWCQP7 a/NxVKb/oJknTY7bPtEk2t01hO56WKA= X-Google-Smtp-Source: ABdhPJzEwYegHW0Wl1lQsHRUXU5A8t9EPGut606K/eGoBIr1miz5exLGCQP2+38FDhKUmcvKsCkiKA== X-Received: by 2002:a63:f00b:: with SMTP id k11mr2021518pgh.469.1644597441628; Fri, 11 Feb 2022 08:37:21 -0800 (PST) Received: from xavier.lan ([2001:470:b:114::cc1]) by smtp.gmail.com with ESMTPSA id l17sm27450568pfu.61.2022.02.11.08.37.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Feb 2022 08:37:21 -0800 (PST) From: Alex Henrie To: git@vger.kernel.org, paulus@ozlabs.org Cc: Alex Henrie Subject: [PATCH v3 2/4] log: add a --no-graph option Date: Fri, 11 Feb 2022 09:36:25 -0700 Message-Id: <20220211163627.598166-2-alexhenrie24@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220211163627.598166-1-alexhenrie24@gmail.com> References: <20220211163627.598166-1-alexhenrie24@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org It's useful to be able to countermand a previous --graph option, for example if `git log --graph` is run via an alias. Signed-off-by: Alex Henrie --- v3: don't pass a regular expression with parentheses to grep, so that the tests pass in all configurations on GitHub --- builtin/blame.c | 1 + builtin/shortlog.c | 1 + revision.c | 19 ++++++++++--- revision.h | 1 + t/t4202-log.sh | 69 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 87 insertions(+), 4 deletions(-) diff --git a/builtin/blame.c b/builtin/blame.c index 7fafeac408..ef831de5ac 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -934,6 +934,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix) parse_revision_opt(&revs, &ctx, options, blame_opt_usage); } parse_done: + revision_opts_finish(&revs); no_whole_file_rename = !revs.diffopt.flags.follow_renames; xdl_opts |= revs.diffopt.xdl_opts & XDF_INDENT_HEURISTIC; revs.diffopt.flags.follow_renames = 0; diff --git a/builtin/shortlog.c b/builtin/shortlog.c index e7f7af5de3..228d782754 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -388,6 +388,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix) parse_revision_opt(&rev, &ctx, options, shortlog_usage); } parse_done: + revision_opts_finish(&rev); argc = parse_options_end(&ctx); if (nongit && argc > 1) { diff --git a/revision.c b/revision.c index 816061f3d9..a39fd1c278 100644 --- a/revision.c +++ b/revision.c @@ -2424,10 +2424,11 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg revs->pretty_given = 1; revs->abbrev_commit = 1; } else if (!strcmp(arg, "--graph")) { - revs->topo_order = 1; - revs->rewrite_parents = 1; graph_clear(revs->graph); revs->graph = graph_init(revs); + } else if (!strcmp(arg, "--no-graph")) { + graph_clear(revs->graph); + revs->graph = NULL; } else if (!strcmp(arg, "--encode-email-headers")) { revs->encode_email_headers = 1; } else if (!strcmp(arg, "--no-encode-email-headers")) { @@ -2524,8 +2525,6 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg unkv[(*unkc)++] = arg; return opts; } - if (revs->graph && revs->track_linear) - die(_("options '%s' and '%s' cannot be used together"), "--show-linear-break", "--graph"); return 1; } @@ -2544,6 +2543,17 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx, ctx->argc -= n; } +void revision_opts_finish(struct rev_info *revs) +{ + if (revs->graph && revs->track_linear) + die(_("options '%s' and '%s' cannot be used together"), "--show-linear-break", "--graph"); + + if (revs->graph) { + revs->topo_order = 1; + revs->rewrite_parents = 1; + } +} + static int for_each_bisect_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data, const char *term) { @@ -2786,6 +2796,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s break; } } + revision_opts_finish(revs); if (prune_data.nr) { /* diff --git a/revision.h b/revision.h index 3f66147bfd..5a507db202 100644 --- a/revision.h +++ b/revision.h @@ -372,6 +372,7 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx, #define REVARG_COMMITTISH 02 int handle_revision_arg(const char *arg, struct rev_info *revs, int flags, unsigned revarg_opt); +void revision_opts_finish(struct rev_info *revs); /** * Reset the flags used by the revision walking api. You can use this to do diff --git a/t/t4202-log.sh b/t/t4202-log.sh index dc884107de..a7d5edf720 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -1671,6 +1671,75 @@ test_expect_success 'log --graph with --name-only' ' test_cmp_graph --name-only tangle..reach ' +test_expect_success '--no-graph countermands --graph' ' + git log >expect && + git log --graph --no-graph >actual && + test_cmp expect actual +' + +test_expect_success '--graph countermands --no-graph' ' + git log --graph >expect && + git log --no-graph --graph >actual && + test_cmp expect actual +' + +test_expect_success '--no-graph does not unset --topo-order' ' + git log --topo-order >expect && + git log --topo-order --no-graph >actual && + test_cmp expect actual +' + +test_expect_success '--no-graph does not unset --parents' ' + git log --parents >expect && + git log --parents --no-graph >actual && + test_cmp expect actual +' + +test_expect_success '--reverse and --graph conflict' ' + test_must_fail git log --reverse --graph 2>stderr && + test_i18ngrep "cannot be used together" stderr +' + +test_expect_success '--reverse --graph --no-graph works' ' + git log --reverse >expect && + git log --reverse --graph --no-graph >actual && + test_cmp expect actual +' + +test_expect_success '--show-linear-break and --graph conflict' ' + test_must_fail git log --show-linear-break --graph 2>stderr && + test_i18ngrep "cannot be used together" stderr +' + +test_expect_success '--show-linear-break --graph --no-graph works' ' + git log --show-linear-break >expect && + git log --show-linear-break --graph --no-graph >actual && + test_cmp expect actual +' + +test_expect_success '--no-walk and --graph conflict' ' + test_must_fail git log --no-walk --graph 2>stderr && + test_i18ngrep "cannot be used together" stderr +' + +test_expect_success '--no-walk --graph --no-graph works' ' + git log --no-walk >expect && + git log --no-walk --graph --no-graph >actual && + test_cmp expect actual +' + +test_expect_success '--walk-reflogs and --graph conflict' ' + test_must_fail git log --walk-reflogs --graph 2>stderr && + (test_i18ngrep "cannot combine" stderr || + test_i18ngrep "cannot be used together" stderr) +' + +test_expect_success '--walk-reflogs --graph --no-graph works' ' + git log --walk-reflogs >expect && + git log --walk-reflogs --graph --no-graph >actual && + test_cmp expect actual +' + test_expect_success 'dotdot is a parent directory' ' mkdir -p a/b && ( echo sixth && echo fifth ) >expect && From patchwork Fri Feb 11 16:36:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Henrie X-Patchwork-Id: 12743643 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FED5C433F5 for ; Fri, 11 Feb 2022 16:37:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351598AbiBKQh1 (ORCPT ); Fri, 11 Feb 2022 11:37:27 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351594AbiBKQhZ (ORCPT ); Fri, 11 Feb 2022 11:37:25 -0500 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 236BDD6A for ; Fri, 11 Feb 2022 08:37:24 -0800 (PST) Received: by mail-pl1-x62f.google.com with SMTP id u12so5083461plf.13 for ; Fri, 11 Feb 2022 08:37:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dPmgpdjLP/MggR30+L3byWkr3JrUdgjLVfTV0A0GHPI=; b=B4Z79dj1lgpIRTMUfgtefXwHLdNIHi39OcIoNlMDtGgv7J2yi0ZJT+e/xtNYVRcdpF a8hrIpVsbpEKZ9zKpGn3yZlCgoiJcXBMWehevDxn5dEXDNWft74SIZyLiTBUvwnFhFvF 5LcwyP6n9oJ6N4kv6erI0uSgIa4jOFKCymxGwUK/Vbq70ClKcLAgTP8i+/w/Hm+7AUn8 yi1D7XjT20JjxNuGPXGv2Skd+rDTMO91dnKAMNPQT/BBAzYOzkWXyLzofSpByM5tHDnb Epf3sIb+TG/oGGbkGKJy4Kc7KEQMYyDjIyTSpeeno3ncWZIu0E0lnpOnFj0DXTEdIJxS YRVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dPmgpdjLP/MggR30+L3byWkr3JrUdgjLVfTV0A0GHPI=; b=vmf2FeG14U5Rcs/iHb/4IWsYYWT0iRfisHcAaZgXk+eaGKr4zGPvLgaoIKBqBqn9EA vVIoeKMNhSDV+0XWguhSVnn+gv5AWIeG4xdqYdJ2yzNmkM685gDUTHUaGkOyjhB1KyV4 bnR6xcuRXP/3j4VswGGjk1UP78XBEX8rQkaLZ8P6kRzMo4s36bThMP/L3dEkmgeehWyg KybGHUqGUdQzdFZ15chdL7Hsn628VgkihcWgHoZ4lG5agSwO+fSob1Uvv+jfyk44YBtN sJzpq+bvKRvdGJjiR8mrRX3GqH2Vxc2OjuAJs3kxUMgf/cfj3xSZzWGeuss4RUr4AqIq 9mNw== X-Gm-Message-State: AOAM533DxG0dXNb03C7rD3G1Ac3xJyNg76U7I8RzBnOtXiwsYmYJUOiA 95Ijys7R1N92bP4tK74UM6QGQJz8i2M= X-Google-Smtp-Source: ABdhPJxFu/ils6p3165nqDXRS9Bxmy2AdI9yStu5QOILJGznttUjULW5R1k7spySoSyEHnNaZ5tuNw== X-Received: by 2002:a17:902:ce84:: with SMTP id f4mr2326963plg.66.1644597443180; Fri, 11 Feb 2022 08:37:23 -0800 (PST) Received: from xavier.lan ([2001:470:b:114::cc1]) by smtp.gmail.com with ESMTPSA id l17sm27450568pfu.61.2022.02.11.08.37.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Feb 2022 08:37:22 -0800 (PST) From: Alex Henrie To: git@vger.kernel.org, paulus@ozlabs.org Cc: Alex Henrie Subject: [PATCH v3 3/4] log: add a log.graph config option Date: Fri, 11 Feb 2022 09:36:26 -0700 Message-Id: <20220211163627.598166-3-alexhenrie24@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220211163627.598166-1-alexhenrie24@gmail.com> References: <20220211163627.598166-1-alexhenrie24@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org A coworker recently asked me how to turn on --graph by default in `git log`. I googled it and found that several people have asked that before on Stack Overflow, with no good solution: https://stackoverflow.com/questions/43555256/how-do-i-make-git-log-graph-the-default Add a log.graph option to turn on graph mode in the absence of any incompatible options. Signed-off-by: Alex Henrie --- v3: no changes --- Documentation/config/log.txt | 5 +++++ Documentation/git-log.txt | 5 +++++ builtin/log.c | 6 ++++++ revision.c | 10 +++++++++ revision.h | 2 ++ t/t4202-log.sh | 42 ++++++++++++++++++++++++++++++++++++ 6 files changed, 70 insertions(+) diff --git a/Documentation/config/log.txt b/Documentation/config/log.txt index 456eb07800..3e356cfce6 100644 --- a/Documentation/config/log.txt +++ b/Documentation/config/log.txt @@ -35,6 +35,11 @@ log.follow:: i.e. it cannot be used to follow multiple files and does not work well on non-linear history. +log.graph:: + If true, makes linkgit:git-log[1], linkgit:git-show[1], and + linkgit:git-whatchanged[1] assume `--graph` unless an incompatible + option is also specified. + log.graphColors:: A list of colors, separated by commas, that can be used to draw history lines in `git log --graph`. diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt index 20e87cecf4..7e9e0f8afe 100644 --- a/Documentation/git-log.txt +++ b/Documentation/git-log.txt @@ -214,6 +214,11 @@ log.follow:: i.e. it cannot be used to follow multiple files and does not work well on non-linear history. +log.graph:: + If `true`, `git log` and related commands will act as if the + `--graph` option was passed to them unless an incompatible option is + also specified. + log.showRoot:: If `false`, `git log` and related commands will not treat the initial commit as a big creation event. Any root commits in diff --git a/builtin/log.c b/builtin/log.c index 4b493408cc..5eaefab046 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -48,6 +48,7 @@ static int default_show_root = 1; static int default_follow; static int default_show_signature; static int default_encode_email_headers = 1; +static int default_graph; static int decoration_style; static int decoration_given; static int use_mailmap_config = 1; @@ -156,6 +157,7 @@ static void cmd_log_init_defaults(struct rev_info *rev) rev->show_signature = default_show_signature; rev->encode_email_headers = default_encode_email_headers; rev->diffopt.flags.allow_textconv = 1; + rev->graph_default = default_graph; if (default_date_mode) parse_date_format(default_date_mode, &rev->date_mode); @@ -519,6 +521,10 @@ static int git_log_config(const char *var, const char *value, void *cb) default_show_signature = git_config_bool(var, value); return 0; } + if (!strcmp(var, "log.graph")) { + default_graph = git_config_bool(var, value); + return 0; + } if (grep_config(var, value, cb) < 0) return -1; diff --git a/revision.c b/revision.c index a39fd1c278..55e12cd401 100644 --- a/revision.c +++ b/revision.c @@ -2426,9 +2426,11 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg } else if (!strcmp(arg, "--graph")) { graph_clear(revs->graph); revs->graph = graph_init(revs); + revs->graph_default = 0; } else if (!strcmp(arg, "--no-graph")) { graph_clear(revs->graph); revs->graph = NULL; + revs->graph_default = 0; } else if (!strcmp(arg, "--encode-email-headers")) { revs->encode_email_headers = 1; } else if (!strcmp(arg, "--no-encode-email-headers")) { @@ -2796,6 +2798,14 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s break; } } + if (revs->graph_default && + !revs->graph && + /* check for incompatible options */ + !revs->track_linear && + !revs->reverse && + !revs->reflog_info && + !revs->no_walk) + revs->graph = graph_init(revs); revision_opts_finish(revs); if (prune_data.nr) { diff --git a/revision.h b/revision.h index 5a507db202..62a0ef4c53 100644 --- a/revision.h +++ b/revision.h @@ -249,6 +249,8 @@ struct rev_info { /* Display history graph */ struct git_graph *graph; + /* whether to initialize graph if it has not been initialized already */ + int graph_default; /* special limits */ int skip_count; diff --git a/t/t4202-log.sh b/t/t4202-log.sh index a7d5edf720..9f052ccce6 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -1695,6 +1695,20 @@ test_expect_success '--no-graph does not unset --parents' ' test_cmp expect actual ' +test_expect_success 'log.graph=true behaves like --graph' ' + git log --graph >expect && + test_config log.graph true && + git log >actual && + test_cmp expect actual +' + +test_expect_success '--no-graph countermands log.graph=true' ' + git log >expect && + test_config log.graph true && + git log --no-graph >actual && + test_cmp expect actual +' + test_expect_success '--reverse and --graph conflict' ' test_must_fail git log --reverse --graph 2>stderr && test_i18ngrep "cannot be used together" stderr @@ -1706,6 +1720,13 @@ test_expect_success '--reverse --graph --no-graph works' ' test_cmp expect actual ' +test_expect_success '--reverse ignores log.graph' ' + git log --reverse >expect && + test_config log.graph true && + git log --reverse >actual && + test_cmp expect actual +' + test_expect_success '--show-linear-break and --graph conflict' ' test_must_fail git log --show-linear-break --graph 2>stderr && test_i18ngrep "cannot be used together" stderr @@ -1717,6 +1738,13 @@ test_expect_success '--show-linear-break --graph --no-graph works' ' test_cmp expect actual ' +test_expect_success '--show-linear-break ignores log.graph' ' + git log --show-linear-break >expect && + test_config log.graph true && + git log --show-linear-break >actual && + test_cmp expect actual +' + test_expect_success '--no-walk and --graph conflict' ' test_must_fail git log --no-walk --graph 2>stderr && test_i18ngrep "cannot be used together" stderr @@ -1728,6 +1756,13 @@ test_expect_success '--no-walk --graph --no-graph works' ' test_cmp expect actual ' +test_expect_success '--no-walk ignores log.graph' ' + git log --no-walk >expect && + test_config log.graph true && + git log --no-walk >actual && + test_cmp expect actual +' + test_expect_success '--walk-reflogs and --graph conflict' ' test_must_fail git log --walk-reflogs --graph 2>stderr && (test_i18ngrep "cannot combine" stderr || @@ -1740,6 +1775,13 @@ test_expect_success '--walk-reflogs --graph --no-graph works' ' test_cmp expect actual ' +test_expect_success '--walk-reflogs ignores log.graph' ' + git log --walk-reflogs >expect && + test_config log.graph true && + git log --walk-reflogs >actual && + test_cmp expect actual +' + test_expect_success 'dotdot is a parent directory' ' mkdir -p a/b && ( echo sixth && echo fifth ) >expect && From patchwork Fri Feb 11 16:36:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Henrie X-Patchwork-Id: 12743642 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAE03C4332F for ; Fri, 11 Feb 2022 16:37:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351603AbiBKQh3 (ORCPT ); Fri, 11 Feb 2022 11:37:29 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351595AbiBKQh0 (ORCPT ); Fri, 11 Feb 2022 11:37:26 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6174CD66 for ; Fri, 11 Feb 2022 08:37:25 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id om7so8552285pjb.5 for ; Fri, 11 Feb 2022 08:37:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/JGYhFn8Ke93ParmBIyzq8v6MMMmqm9taRndYwlXlQM=; b=czVCPTrTzp2/7G8Y0ywV+OWhjZRAZTGsfFp8r/SHv8sxA1TSOtwYxEDaYiCYtHIhVI 1RZlDVKtKM9rD4sbcMEV3fPvXvTCv62s6RqoGVLZa2SirhMfo0OB4m0V1vVWKFj7PDlk t3FXbX3V/4jxuPIeZt4f/pE1d3XhJQAH1uM2Pm/kN1X7FAHo8+7KRwIm14rzJzH48a5x WH9f73mPL6ISKDtBOHzXq2WqsjGxPVomtSMj0+c2hF+9ybn5UvPItL5RfjQ24GDmG9sA MZ2te3qT9SM8lWSycbzCNmGEHr9pgr8KVDlv/GyAJjr1oauw0fIPhbz4zOmwjwGozhlu QKNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/JGYhFn8Ke93ParmBIyzq8v6MMMmqm9taRndYwlXlQM=; b=VLFSysKj4qNYNVpwmiuiW3BFPMRL21HJn+E4yw0oYaKOd7PCiF2VBuD3087+CtVNqW KXhc/xKm7igWrCVOecaaAEtWlROk6103CLGWhtFgRzXPjlm0w+AKwQ/BPxa5hZbgCKto bWh0zXR9LcygkBPCoHYjTEi8iE/Yvo0x0rgBBoapb5odZVa1Ba2BNYhc59e/it27PpwX Kvqa4ZpCBf/vzPRziSULMtTGpovH0UcMOrRofKKL7GuwEqnWlMYjNt3ypeTuBKi3sfcN 8TOYiC+VHlEBA3mj0GUahhaEeMxq/eIjuQCxciMPNXObRE3Ip46d/qDfcI9xnGlxbufH QvfQ== X-Gm-Message-State: AOAM5334idyqDljVaNoMVMs+DFC5IvSECKA04zg6I+f11Oz7jlvlU56L HXqCaJh6f3HeFpYWxXm4yTFKkUhrlsk= X-Google-Smtp-Source: ABdhPJzH2Z2ByqzOFn9wY2ckKT5tItI3O4ZtbKwwRL2qBZuQ1yvvttk27HFTGihJjZ7MR+RXJGbcwg== X-Received: by 2002:a17:902:8c84:: with SMTP id t4mr2417076plo.78.1644597444554; Fri, 11 Feb 2022 08:37:24 -0800 (PST) Received: from xavier.lan ([2001:470:b:114::cc1]) by smtp.gmail.com with ESMTPSA id l17sm27450568pfu.61.2022.02.11.08.37.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Feb 2022 08:37:24 -0800 (PST) From: Alex Henrie To: git@vger.kernel.org, paulus@ozlabs.org Cc: Alex Henrie Subject: [PATCH v3 4/4] gitk: pass --no-graph to `git log` Date: Fri, 11 Feb 2022 09:36:27 -0700 Message-Id: <20220211163627.598166-4-alexhenrie24@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220211163627.598166-1-alexhenrie24@gmail.com> References: <20220211163627.598166-1-alexhenrie24@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: Alex Henrie --- v3: no changes --- gitk-git/gitk | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gitk-git/gitk b/gitk-git/gitk index 23d9dd1fe0..24099ce0b8 100755 --- a/gitk-git/gitk +++ b/gitk-git/gitk @@ -411,8 +411,8 @@ proc start_rev_list {view} { } if {[catch { - set fd [open [concat | git log --no-color -z --pretty=raw $show_notes \ - --parents --boundary $args "--" $files] r] + set fd [open [concat | git log --no-color --no-graph -z --pretty=raw \ + $show_notes --parents --boundary $args "--" $files] r] } err]} { error_popup "[mc "Error executing git log:"] $err" return 0 @@ -559,8 +559,9 @@ proc updatecommits {} { set args $vorigargs($view) } if {[catch { - set fd [open [concat | git log --no-color -z --pretty=raw $show_notes \ - --parents --boundary $args "--" $vfilelimit($view)] r] + set fd [open [concat | git log --no-color --no-graph -z --pretty=raw + $show_notes --parents --boundary $args "--" + $vfilelimit($view)] r] } err]} { error_popup "[mc "Error executing git log:"] $err" return