log: fix memory leak if --graph is passed multiple times
PATCH v2 1/4 log: fix memory leak if --graph is passed multiple times
---
v2: introduce graph_clear function
--- graph.c | 12 ++++++++++++ graph.h | 5 +++++ revision.c | 1 + 3 files changed, 18 insertions(+)
graph.c +12 -0
@@ -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;
graph.h +5 -0
@@ -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
revision.c +1 -0
@@ -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 ;
Signature · 1 line
2.32.0.2645.gc109162a1f
PATCH v2 2/4 log: add a --no-graph option
It's useful to be able to countermand a previous --graph option, for example if git log --graph is run via an alias.
---
v2: new patch
--- builtin/blame.c | 1 + builtin/shortlog.c | 1 + revision.c | 19 ++++++++++--- revision.h | 1 + t/t4202-log.sh | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 86 insertions(+), 4 deletions(-)
builtin/blame.c +1 -0
@@ -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 ;
builtin/shortlog.c +1 -0
@@ -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 ) {
revision.c +15 -4
@@ -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 sbreak ; } } +revision_opts_finish (revs);if (prune_data.nr) {/*
revision.h +1 -0
@@ -372,6 +372,7 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,#define REVARG_COMMITTISH 02int 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
t/t4202-log.sh +68 -0
74 lines not on this page · raw message
Signature · 1 line
2.32.0.2645.gc109162a1f
PATCH v2 3/4 log: add a log.graph config option
In reply to Alex HenrieA 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.
---
v2: ensure that --no-graph on the command line takes precedence over log.graph=true in the config file
--- 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(+)
Documentation/config/log.txt +5 -0
@@ -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`.
Documentation/git-log.txt +5 -0
@@ -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
builtin/log.c +6 -0
@@ -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 ;
revision.c +10 -0
@@ -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 sbreak ; } } +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) {
revision.h +2 -0
@@ -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;
t/t4202-log.sh +42 -0
72 lines not on this page · raw message
Signature · 1 line
2.32.0.2645.gc109162a1f
PATCH v2 4/4 gitk: pass --no-graph to `git log`
In reply to Alex Henrie---
v2: use --no-graph instead of log.graph=false
--- gitk-git/gitk | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
gitk-git/gitk +5 -4
@@ -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
Signature · 1 line
2.32.0.2645.gc109162a1f