print commits using ref-filter's logic
Subsystems (2)
cover print commits using ref-filter's logic
This is a step toward reusing ref-filter formatting logic in pretty to have one unified interface to extract all needed data from the object and to print it properly.
In the process, I made few modifications. Although it doesn't impact the current flow of git log unless log.usereffilter is set true.
Thanks, Hariom
Hariom Verma (5):
builtin/log: new config log.useRefFilter
revision: add use_ref_filter in struct rev_info
pretty: introduce get_user_format()
ref_format: add option to skip \n at eol
pretty-lib: print commits using ref-filters logic
Documentation/config/log.txt | 4 ++ Makefile | 1 + builtin/log.c | 8 ++++ log-tree.c | 7 ++- pretty-lib.c | 84 ++++++++++++++++++++++++++++++++++++ pretty-lib.h | 21 +++++++++ pretty.c | 5 +++ pretty.h | 3 ++ ref-filter.c | 3 +- ref-filter.h | 4 +- revision.h | 3 +- 11 files changed, 139 insertions(+), 4 deletions(-) create mode 100644 pretty-lib.c create mode 100644 pretty-lib.h
base-commit: eebb51ba8cab97c0b3f3f18eaab7796803b8494b
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-658%2Fharry-hov%2Flog-ref-filter-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-658/harry-hov/log-ref-filter-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/658
Signature · 1 line
gitgitgadget
PATCH 1/5 builtin/log: new config log.useRefFilter
From: Hariom Verma <[email protected]>
Add a new boolean config variable "log.useRefFilter" for log command, allowing log to switch to use ref-filters logic.
*experimental*
--- Documentation/config/log.txt | 4 ++++ builtin/log.c | 7 +++++++ 2 files changed, 11 insertions(+)
Documentation/config/log.txt +4 -0
@@ -48,3 +48,7 @@ log.mailmap:: If true, makes linkgit:git-log[1], linkgit:git-show[1], and linkgit:git-whatchanged[1] assume `--use-mailmap`, otherwise assume `--no-use-mailmap`. True by default. + +log.useRefFilter:: + [EXPERIMENTAL] If true, forces `git log` to use ref-filter's logic. + Is `false` by default.
builtin/log.c +7 -0
@@ -39,6 +39,9 @@#define MAIL_DEFAULT_WRAP 72#define COVER_FROM_AUTO_MAX_SUBJECT_LEN 100 +/* Set true to use ref-filter's logic in git log */ +static int log_use_ref_filter; +/* Set a default date-time format for git log ("log.date" config variable) */ static const char *default_date_mode =NULL ;
@@ -489,6 +492,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.usereffilter" )) { + log_use_ref_filter =git_config_bool (var, value); +return 0 ; + }if (grep_config (var, value, cb) <0 )return -1 ;
Signature · 1 line
gitgitgadget
PATCH 2/5 revision: add `use_ref_filter` in struct rev_info
In reply to Hariom Verma via GitGitGadgetFrom: Hariom Verma <[email protected]>
Add a use_ref_filter flag in struct rev_info, to make it easier to manipulate behavior at certain places according to the newly added log.usereffilter config option.
--- builtin/log.c | 1 + revision.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-)
builtin/log.c +1 -0
@@ -155,6 +155,7 @@ static void cmd_log_init_defaults(struct rev_info *rev) rev->show_root_diff = default_show_root; rev->subject_prefix = fmt_patch_subject_prefix; rev->show_signature = default_show_signature; + rev->use_ref_filter = log_use_ref_filter; rev->encode_email_headers = default_encode_email_headers; rev->diffopt.flags.allow_textconv =1 ;
revision.h +2 -1
@@ -210,7 +210,8 @@ struct rev_info { missing_newline:1, date_mode_explicit:1, preserve_subject:1, - encode_email_headers:1; + encode_email_headers:1, + use_ref_filter:1; unsigned int disable_stdin:1;/* --show-linear-break */ unsigned int track_linear:1,
Signature · 1 line
gitgitgadget
PATCH 3/5 pretty: introduce `get_user_format()`
In reply to Hariom Verma via GitGitGadgetFrom: Hariom Verma <[email protected]>
In the quest of porting pretty formats to use ref-filters logic, user_format must need to interact with other functions too. So, to get user_format, introduced const char *get_user_format().
--- pretty.c | 5 +++++ pretty.h | 3 +++ 2 files changed, 8 insertions(+)
pretty.c +5 -0
@@ -2016,3 +2016,8 @@ void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit, pp.fmt = fmt;pretty_print_commit (&pp, commit, sb); } + +const char *get_user_format (void ) +{ +return user_format; +}
pretty.h +3 -0
@@ -139,4 +139,7 @@ const char *format_subject(struct strbuf *sb, const char *msg,/* Check if "cmit_fmt" will produce an empty output. */ int commit_format_is_empty (enum cmit_fmt ); +/* Returns user_format */ +const char *get_user_format (void ); +#endif /* PRETTY_H */
Signature · 1 line
gitgitgadget
PATCH 4/5 ref_format: add option to skip `\n` at eol
In reply to Hariom Verma via GitGitGadgetFrom: Hariom Verma <[email protected]>
We might always need a \n at end of line in the case of git for-each-ref. But as we intend to use ref-filter's logic in pretty, having an option to skip \n will be useful.
--- ref-filter.c | 3 ++- ref-filter.h | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-)
ref-filter.c +2 -1
@@ -2410,7 +2410,8 @@ void show_ref_array_item(struct ref_array_item *info,fwrite (final_buf.buf,1 , final_buf.len, stdout);strbuf_release (&error_buf);strbuf_release (&final_buf); -putchar ('\n' ); +if (format->need_newline_at_eol) +putchar ('\n' ); } void pretty_print_ref(const char *name, const struct object_id *oid,
ref-filter.h +3 -1
@@ -81,11 +81,13 @@ struct ref_format {int quote_style;int use_color; +int need_newline_at_eol; +/* Internal state to ref-filter */ int need_color_reset_at_eol; }; -#define REF_FORMAT_INIT { NULL, 0, -1 } +#define REF_FORMAT_INIT { NULL, 0, -1, 1 }/* Macros for checking --merged and --no-merged options */ #define _OPT_MERGED_NO_MERGED (option, filter, h) \
Signature · 1 line
gitgitgadget
PATCH 5/5 pretty-lib: print commits using ref-filters logic
In reply to Hariom Verma via GitGitGadgetFrom: Hariom Verma <[email protected]>
This change intends to use ref-filters logic to print commits.
Add ref_pretty_print_commit() which might be a future possible replacement for pretty_print_commit().
This is an introductory commit. Some features of git log might not work.
--- Makefile | 1 + log-tree.c | 7 ++++- pretty-lib.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ pretty-lib.h | 21 +++++++++++++ 4 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 pretty-lib.c create mode 100644 pretty-lib.h
Makefile +1 -0
@@ -943,6 +943,7 @@ LIB_OBJS += pathspec.o LIB_OBJS += pkt-line.o LIB_OBJS += preload-index.o LIB_OBJS += pretty.o +LIB_OBJS += pretty-lib.o LIB_OBJS += prio-queue.o LIB_OBJS += progress.o LIB_OBJS += promisor-remote.o
log-tree.c +6 -1
@@ -17,6 +17,7 @@#include "help.h" #include "interdiff.h" #include "range-diff.h" +#include "pretty-lib.h" static struct decoration name_decoration = {"object names" };static int decoration_loaded;
@@ -756,7 +757,11 @@ void show_log(struct rev_info *opt) ctx.from_ident = &opt->from_ident;if (opt->graph) ctx.graph_width =graph_width (opt->graph); -pretty_print_commit (&ctx, commit, &msgbuf); + +if (opt->use_ref_filter) +ref_pretty_print_commit (&ctx, commit, &msgbuf); +else +pretty_print_commit (&ctx, commit, &msgbuf);if (opt->add_signoff)append_signoff (&msgbuf,0 ,APPEND_SIGNOFF_DEDUP );
pretty-lib.c new file +84 -0
84 lines not on this page · raw message
pretty-lib.h new file +21 -0
@@ -0,0 +1,21 @@ +#ifndef PRETTY_LIB_H +#define PRETTY_LIB_H + +/** +* This is a possibly temporary interface between +* ref-filter and pretty. This interface may disappear in the +* future if a way to use ref-filter directly is found. +* In the meantime, this interface would enable us to +* step by step replace the formatting code in pretty by the +* ref-filter code. +*/ + +/** +* Possible future replacement for "pretty_print_commit()". +* Uses ref-filter's logic. +*/ +void ref_pretty_print_commit (struct pretty_print_context *pp, +const struct commit *commit, +struct strbuf *sb); + +#endif /* PRETTY_LIB_H */
Signature · 1 line
gitgitgadget