{"thread":{"id":"53678","subject":"[PATCH 0/5] [GSoC][RFC] print commits using ref-filter's logic","startedAt":"2020-06-15T10:57:49Z","lastAt":"2020-06-15T10:57:58Z","messageCount":6,"participants":["Hariom Verma via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"399750","messageId":"pull.658.git.1592218662.gitgitgadget@gmail.com","threadId":"53678","inReplyTo":null,"subject":"[PATCH 0/5] [GSoC][RFC] print commits using ref-filter's logic","fromName":"Hariom Verma via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-15T10:57:37Z","receivedAt":"2020-06-15T10:57:49Z","isPatch":true,"sender":{"key":"name:Hariom Verma","avatar":null},"body":"This is a step toward reusing ref-filter formatting logic in pretty to have\none unified interface to extract all needed data from the object and to\nprint it properly. \n\nIn the process, I made few modifications. Although it doesn't impact the\ncurrent flow of git log unless log.usereffilter is set true.\n\nThanks, Hariom\n\nHariom Verma (5):\n  builtin/log: new config log.useRefFilter\n  revision: add `use_ref_filter` in struct rev_info\n  pretty: introduce `get_user_format()`\n  ref_format: add option to skip `\\n` at eol\n  pretty-lib: print commits using ref-filters logic\n\n Documentation/config/log.txt |  4 ++\n Makefile                     |  1 +\n builtin/log.c                |  8 ++++\n log-tree.c                   |  7 ++-\n pretty-lib.c                 | 84 ++++++++++++++++++++++++++++++++++++\n pretty-lib.h                 | 21 +++++++++\n pretty.c                     |  5 +++\n pretty.h                     |  3 ++\n ref-filter.c                 |  3 +-\n ref-filter.h                 |  4 +-\n revision.h                   |  3 +-\n 11 files changed, 139 insertions(+), 4 deletions(-)\n create mode 100644 pretty-lib.c\n create mode 100644 pretty-lib.h\n\n\nbase-commit: eebb51ba8cab97c0b3f3f18eaab7796803b8494b\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-658%2Fharry-hov%2Flog-ref-filter-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-658/harry-hov/log-ref-filter-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/658\n-- \ngitgitgadget\n"},{"id":"399751","messageId":"1c01de3d79bfc9a971e1539b114ba27a89c4004d.1592218662.git.gitgitgadget@gmail.com","threadId":"53678","inReplyTo":"pull.658.git.1592218662.gitgitgadget@gmail.com","subject":"[PATCH 2/5] revision: add `use_ref_filter` in struct rev_info","fromName":"Hariom Verma via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-15T10:57:39Z","receivedAt":"2020-06-15T10:57:49Z","isPatch":true,"sender":{"key":"name:Hariom Verma","avatar":null},"body":"From: Hariom Verma <hariom18599@gmail.com>\n\nAdd a use_ref_filter flag in struct rev_info, to make it easier to\nmanipulate behavior at certain places according to the newly added\nlog.usereffilter config option.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Heba Waly <heba.waly@gmail.com>\nSigned-off-by: Hariom Verma <hariom18599@gmail.com>\n---\n builtin/log.c | 1 +\n revision.h    | 3 ++-\n 2 files changed, 3 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 4eb13d1ef88..2634c520847 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -155,6 +155,7 @@ static void cmd_log_init_defaults(struct rev_info *rev)\n \trev->show_root_diff = default_show_root;\n \trev->subject_prefix = fmt_patch_subject_prefix;\n \trev->show_signature = default_show_signature;\n+\trev->use_ref_filter = log_use_ref_filter;\n \trev->encode_email_headers = default_encode_email_headers;\n \trev->diffopt.flags.allow_textconv = 1;\n \ndiff --git a/revision.h b/revision.h\nindex 93491b79d47..8acf9b918bf 100644\n--- a/revision.h\n+++ b/revision.h\n@@ -210,7 +210,8 @@ struct rev_info {\n \t\t\tmissing_newline:1,\n \t\t\tdate_mode_explicit:1,\n \t\t\tpreserve_subject:1,\n-\t\t\tencode_email_headers:1;\n+\t\t\tencode_email_headers:1,\n+\t\t\tuse_ref_filter:1;\n \tunsigned int\tdisable_stdin:1;\n \t/* --show-linear-break */\n \tunsigned int\ttrack_linear:1,\n-- \ngitgitgadget\n\n"},{"id":"399752","messageId":"b568d097159ff9d89bc4fc7c9076d9a8a1e29a1e.1592218662.git.gitgitgadget@gmail.com","threadId":"53678","inReplyTo":"pull.658.git.1592218662.gitgitgadget@gmail.com","subject":"[PATCH 3/5] pretty: introduce `get_user_format()`","fromName":"Hariom Verma via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-15T10:57:40Z","receivedAt":"2020-06-15T10:57:51Z","isPatch":true,"sender":{"key":"name:Hariom Verma","avatar":null},"body":"From: Hariom Verma <hariom18599@gmail.com>\n\nIn the quest of porting pretty formats to use ref-filters logic,\nuser_format must need to interact with other functions too.\nSo, to get user_format, introduced `const char *get_user_format()`.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Heba Waly <heba.waly@gmail.com>\nSigned-off-by: Hariom Verma <hariom18599@gmail.com>\n---\n pretty.c | 5 +++++\n pretty.h | 3 +++\n 2 files changed, 8 insertions(+)\n\ndiff --git a/pretty.c b/pretty.c\nindex 2a3d46bf42f..3767c144b0a 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -2016,3 +2016,8 @@ void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,\n \tpp.fmt = fmt;\n \tpretty_print_commit(&pp, commit, sb);\n }\n+\n+const char *get_user_format(void)\n+{\n+\treturn user_format;\n+}\ndiff --git a/pretty.h b/pretty.h\nindex 071f2fb8e44..517450f72f8 100644\n--- a/pretty.h\n+++ b/pretty.h\n@@ -139,4 +139,7 @@ const char *format_subject(struct strbuf *sb, const char *msg,\n /* Check if \"cmit_fmt\" will produce an empty output. */\n int commit_format_is_empty(enum cmit_fmt);\n \n+/* Returns user_format */\n+const char *get_user_format(void);\n+\n #endif /* PRETTY_H */\n-- \ngitgitgadget\n\n"},{"id":"399753","messageId":"0eecb653d21355d7d2ab3dd209cfdb3c24365417.1592218662.git.gitgitgadget@gmail.com","threadId":"53678","inReplyTo":"pull.658.git.1592218662.gitgitgadget@gmail.com","subject":"[PATCH 4/5] ref_format: add option to skip `\\n` at eol","fromName":"Hariom Verma via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-15T10:57:41Z","receivedAt":"2020-06-15T10:57:54Z","isPatch":true,"sender":{"key":"name:Hariom Verma","avatar":null},"body":"From: Hariom Verma <hariom18599@gmail.com>\n\nWe might always need a `\\n` at end of line in the case of\n`git for-each-ref`. But as we intend to use ref-filter's logic\nin pretty, having an option to skip `\\n` will be useful.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Heba Waly <heba.waly@gmail.com>\nSigned-off-by: Hariom Verma <hariom18599@gmail.com>\n---\n ref-filter.c | 3 ++-\n ref-filter.h | 4 +++-\n 2 files changed, 5 insertions(+), 2 deletions(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex bf7b70299b4..0e2fecbda4c 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -2410,7 +2410,8 @@ void show_ref_array_item(struct ref_array_item *info,\n \tfwrite(final_buf.buf, 1, final_buf.len, stdout);\n \tstrbuf_release(&error_buf);\n \tstrbuf_release(&final_buf);\n-\tputchar('\\n');\n+\tif(format->need_newline_at_eol)\n+\t\tputchar('\\n');\n }\n \n void pretty_print_ref(const char *name, const struct object_id *oid,\ndiff --git a/ref-filter.h b/ref-filter.h\nindex 8ecc33cdfa5..410446dc412 100644\n--- a/ref-filter.h\n+++ b/ref-filter.h\n@@ -81,11 +81,13 @@ struct ref_format {\n \tint quote_style;\n \tint use_color;\n \n+\tint need_newline_at_eol;\n+\n \t/* Internal state to ref-filter */\n \tint need_color_reset_at_eol;\n };\n \n-#define REF_FORMAT_INIT { NULL, 0, -1 }\n+#define REF_FORMAT_INIT { NULL, 0, -1, 1 }\n \n /*  Macros for checking --merged and --no-merged options */\n #define _OPT_MERGED_NO_MERGED(option, filter, h) \\\n-- \ngitgitgadget\n\n"},{"id":"399754","messageId":"a5ce1235a03a49ad394da8d227f5abf52ef3179a.1592218662.git.gitgitgadget@gmail.com","threadId":"53678","inReplyTo":"pull.658.git.1592218662.gitgitgadget@gmail.com","subject":"[PATCH 1/5] builtin/log: new config log.useRefFilter","fromName":"Hariom Verma via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-15T10:57:38Z","receivedAt":"2020-06-15T10:57:55Z","isPatch":true,"sender":{"key":"name:Hariom Verma","avatar":null},"body":"From: Hariom Verma <hariom18599@gmail.com>\n\nAdd a new boolean config variable \"log.useRefFilter\"\nfor `log` command, allowing log to switch to use ref-filters\nlogic.\n\n*experimental*\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Heba Waly <heba.waly@gmail.com>\nSigned-off-by: Hariom Verma <hariom18599@gmail.com>\n---\n Documentation/config/log.txt | 4 ++++\n builtin/log.c                | 7 +++++++\n 2 files changed, 11 insertions(+)\n\ndiff --git a/Documentation/config/log.txt b/Documentation/config/log.txt\nindex 208d5fdcaa6..603f635df86 100644\n--- a/Documentation/config/log.txt\n+++ b/Documentation/config/log.txt\n@@ -48,3 +48,7 @@ log.mailmap::\n \tIf true, makes linkgit:git-log[1], linkgit:git-show[1], and\n \tlinkgit:git-whatchanged[1] assume `--use-mailmap`, otherwise\n \tassume `--no-use-mailmap`. True by default.\n+\n+log.useRefFilter::\n+\t[EXPERIMENTAL] If true, forces `git log` to use ref-filter's logic.\n+\tIs `false` by default.\ndiff --git a/builtin/log.c b/builtin/log.c\nindex d104d5c6889..4eb13d1ef88 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -39,6 +39,9 @@\n #define MAIL_DEFAULT_WRAP 72\n #define COVER_FROM_AUTO_MAX_SUBJECT_LEN 100\n \n+/* Set true to use ref-filter's logic in git log */\n+static int log_use_ref_filter;\n+\n /* Set a default date-time format for git log (\"log.date\" config variable) */\n static const char *default_date_mode = NULL;\n \n@@ -489,6 +492,10 @@ static int git_log_config(const char *var, const char *value, void *cb)\n \t\tdefault_show_signature = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"log.usereffilter\")) {\n+\t\tlog_use_ref_filter = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n \n \tif (grep_config(var, value, cb) < 0)\n \t\treturn -1;\n-- \ngitgitgadget\n\n"},{"id":"399755","messageId":"a83270485be2bebb1ce77be55ff73d136b735922.1592218662.git.gitgitgadget@gmail.com","threadId":"53678","inReplyTo":"pull.658.git.1592218662.gitgitgadget@gmail.com","subject":"[PATCH 5/5] pretty-lib: print commits using ref-filters logic","fromName":"Hariom Verma via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-15T10:57:42Z","receivedAt":"2020-06-15T10:57:58Z","isPatch":true,"sender":{"key":"name:Hariom Verma","avatar":null},"body":"From: Hariom Verma <hariom18599@gmail.com>\n\nThis change intends to use ref-filters logic to print commits.\n\nAdd `ref_pretty_print_commit()` which might be a future possible replacement\nfor `pretty_print_commit()`.\n\nThis is an introductory commit. Some features of `git log` might not work.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Heba Waly <heba.waly@gmail.com>\nSigned-off-by: Hariom Verma <hariom18599@gmail.com>\n---\n Makefile     |  1 +\n log-tree.c   |  7 ++++-\n pretty-lib.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++\n pretty-lib.h | 21 +++++++++++++\n 4 files changed, 112 insertions(+), 1 deletion(-)\n create mode 100644 pretty-lib.c\n create mode 100644 pretty-lib.h\n\ndiff --git a/Makefile b/Makefile\nindex 372139f1f24..bcc65e87827 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -943,6 +943,7 @@ LIB_OBJS += pathspec.o\n LIB_OBJS += pkt-line.o\n LIB_OBJS += preload-index.o\n LIB_OBJS += pretty.o\n+LIB_OBJS += pretty-lib.o\n LIB_OBJS += prio-queue.o\n LIB_OBJS += progress.o\n LIB_OBJS += promisor-remote.o\ndiff --git a/log-tree.c b/log-tree.c\nindex 55a68d0c610..663056664f9 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -17,6 +17,7 @@\n #include \"help.h\"\n #include \"interdiff.h\"\n #include \"range-diff.h\"\n+#include \"pretty-lib.h\"\n \n static struct decoration name_decoration = { \"object names\" };\n static int decoration_loaded;\n@@ -756,7 +757,11 @@ void show_log(struct rev_info *opt)\n \t\tctx.from_ident = &opt->from_ident;\n \tif (opt->graph)\n \t\tctx.graph_width = graph_width(opt->graph);\n-\tpretty_print_commit(&ctx, commit, &msgbuf);\n+\n+\tif (opt->use_ref_filter)\n+\t\tref_pretty_print_commit(&ctx, commit, &msgbuf);\n+\telse\n+\t\tpretty_print_commit(&ctx, commit, &msgbuf);\n \n \tif (opt->add_signoff)\n \t\tappend_signoff(&msgbuf, 0, APPEND_SIGNOFF_DEDUP);\ndiff --git a/pretty-lib.c b/pretty-lib.c\nnew file mode 100644\nindex 00000000000..abe4228290b\n--- /dev/null\n+++ b/pretty-lib.c\n@@ -0,0 +1,84 @@\n+#include \"commit.h\"\n+#include \"ref-filter.h\"\n+#include \"pretty-lib.h\"\n+\n+static size_t convert_format(struct strbuf *sb, const char *start, void *data)\n+{\n+\t/* TODO - Add support for more formatting options */\n+\tswitch (*start) {\n+\tcase 'H':\n+\t\tstrbuf_addstr(sb, \"%(objectname)\");\n+\t\treturn 1;\n+\tcase 'h':\n+\t\tstrbuf_addstr(sb, \"%(objectname:short)\");\n+\t\treturn 1;\n+\tcase 'T':\n+\t\tstrbuf_addstr(sb, \"%(tree)\");\n+\t\treturn 1;\n+\tcase 'P':\n+\t\tstrbuf_addstr(sb, \"%(parent)\");\n+\t\treturn 1;\n+\tcase 'a':\n+\t\tif (start[1] == 'n')\n+\t\t\tstrbuf_addstr(sb, \"%(authorname)\");\n+\t\telse if (start[1] == 'e')\n+\t\t\tstrbuf_addstr(sb, \"%(authoremail)\");\n+\t\telse if (start[1] == 'd')\n+\t\t\tstrbuf_addstr(sb, \"%(authordate)\");\n+\t\telse\n+\t\t\tdie(_(\"invalid formatting option '%c'\"), *start);\n+\t\treturn 2;\n+\tcase 'c':\n+\t\tif (start[1] == 'n')\n+\t\t\tstrbuf_addstr(sb, \"%(committername)\");\n+\t\telse if (start[1] == 'e')\n+\t\t\tstrbuf_addstr(sb, \"%(committeremail)\");\n+\t\telse if (start[1] == 'd')\n+\t\t\tstrbuf_addstr(sb, \"%(committerdate)\");\n+\t\telse\n+\t\t\tdie(_(\"invalid formatting option '%c'\"), *start);\n+\t\treturn 2;\n+\tcase 's':\n+\t\tstrbuf_addstr(sb, \"%(subject)\");\n+\t\treturn 1;\n+\tcase 'b':\n+\t\tstrbuf_addstr(sb, \"%(body)\");\n+\t\treturn 1;\n+\tcase 'n':\n+\t\tstrbuf_addstr(sb, \"\\n\");\n+\t\treturn 1;\n+\tdefault:\n+\t\tdie(_(\"invalid formatting option '%c'\"), *start);\n+\t}\n+}\n+\n+void ref_pretty_print_commit(struct pretty_print_context *pp,\n+\t\t\t const struct commit *commit,\n+\t\t\t struct strbuf *sb)\n+{\n+\tstruct ref_format format = REF_FORMAT_INIT;\n+\tstruct strbuf sb_fmt = STRBUF_INIT;\n+\tconst char *name = \"refs\";\n+\tconst char *usr_fmt = get_user_format();\n+\n+\tif (pp->fmt == CMIT_FMT_USERFORMAT) {\n+\t\tstrbuf_expand(&sb_fmt, usr_fmt, convert_format, NULL);\n+\t\tformat.format = sb_fmt.buf;\n+\t} else if (pp->fmt == CMIT_FMT_DEFAULT || pp->fmt == CMIT_FMT_MEDIUM) {\n+\t\tformat.format = \"Author: %(authorname) %(authoremail)\\nDate:\\t%(authordate)\\n\\n%(subject)\\n\\n%(body)\";\n+\t} else if (pp->fmt == CMIT_FMT_ONELINE) {\n+\t\tformat.format = \"%(subject)\";\n+\t} else if (pp->fmt == CMIT_FMT_SHORT) {\n+\t\tformat.format = \"Author: %(authorname) %(authoremail)\\n\\n\\t%(subject)\\n\";\n+\t} else if (pp->fmt == CMIT_FMT_FULL) {\n+\t\tformat.format = \"Author: %(authorname) %(authoremail)\\nCommit: %(committername) %(committeremail)\\n\\n%(subject)\\n\\n%(body)\";\n+\t} else if (pp->fmt == CMIT_FMT_FULLER) {\n+\t\tformat.format = \"Author:\\t\\t%(authorname) %(authoremail)\\nAuthorDate:\\t%(authordate)\\nCommit:\\t\\t%(committername) %(committeremail)\\nCommitDate:\\t%(committerdate)\\n\\n%(subject)\\n\\n%(body)\";\n+\t}\n+\n+\tformat.need_newline_at_eol = 0;\n+\n+\tverify_ref_format(&format);\n+\tpretty_print_ref(name, &commit->object.oid, &format);\n+\tstrbuf_release(&sb_fmt);\n+}\ndiff --git a/pretty-lib.h b/pretty-lib.h\nnew file mode 100644\nindex 00000000000..324499b1150\n--- /dev/null\n+++ b/pretty-lib.h\n@@ -0,0 +1,21 @@\n+#ifndef PRETTY_LIB_H\n+#define PRETTY_LIB_H\n+\n+/**\n+ * This is a possibly temporary interface between\n+ * ref-filter and pretty. This interface may disappear in the\n+ * future if a way to use ref-filter directly is found.\n+ * In the meantime, this interface would enable us to\n+ * step by step replace the formatting code in pretty by the\n+ * ref-filter code.\n+*/\n+\n+/**\n+ * Possible future replacement for \"pretty_print_commit()\".\n+ * Uses ref-filter's logic.\n+*/\n+void ref_pretty_print_commit(struct pretty_print_context *pp,\n+\t\t\tconst struct commit *commit,\n+\t\t\tstruct strbuf *sb);\n+\n+#endif /* PRETTY_LIB_H */\n-- \ngitgitgadget\n"}]}