All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] [GSoC][RFC] print commits using ref-filter's logic
@ 2020-06-15 10:57 Hariom Verma via GitGitGadget
  2020-06-15 10:57 ` [PATCH 1/5] builtin/log: new config log.useRefFilter Hariom Verma via GitGitGadget
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Hariom Verma via GitGitGadget @ 2020-06-15 10:57 UTC (permalink / raw)
  To: git; +Cc: Hariom Verma

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
-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/5] builtin/log: new config log.useRefFilter
  2020-06-15 10:57 [PATCH 0/5] [GSoC][RFC] print commits using ref-filter's logic Hariom Verma via GitGitGadget
@ 2020-06-15 10:57 ` Hariom Verma via GitGitGadget
  2020-06-15 10:57 ` [PATCH 2/5] revision: add `use_ref_filter` in struct rev_info Hariom Verma via GitGitGadget
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Hariom Verma via GitGitGadget @ 2020-06-15 10:57 UTC (permalink / raw)
  To: git; +Cc: Hariom Verma, Hariom Verma

From: Hariom Verma <hariom18599@gmail.com>

Add a new boolean config variable "log.useRefFilter"
for `log` command, allowing log to switch to use ref-filters
logic.

*experimental*

Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Heba Waly <heba.waly@gmail.com>
Signed-off-by: Hariom Verma <hariom18599@gmail.com>
---
 Documentation/config/log.txt | 4 ++++
 builtin/log.c                | 7 +++++++
 2 files changed, 11 insertions(+)

diff --git a/Documentation/config/log.txt b/Documentation/config/log.txt
index 208d5fdcaa6..603f635df86 100644
--- a/Documentation/config/log.txt
+++ b/Documentation/config/log.txt
@@ -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.
diff --git a/builtin/log.c b/builtin/log.c
index d104d5c6889..4eb13d1ef88 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -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;
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/5] revision: add `use_ref_filter` in struct rev_info
  2020-06-15 10:57 [PATCH 0/5] [GSoC][RFC] print commits using ref-filter's logic Hariom Verma via GitGitGadget
  2020-06-15 10:57 ` [PATCH 1/5] builtin/log: new config log.useRefFilter Hariom Verma via GitGitGadget
@ 2020-06-15 10:57 ` Hariom Verma via GitGitGadget
  2020-06-15 10:57 ` [PATCH 3/5] pretty: introduce `get_user_format()` Hariom Verma via GitGitGadget
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Hariom Verma via GitGitGadget @ 2020-06-15 10:57 UTC (permalink / raw)
  To: git; +Cc: Hariom Verma, Hariom Verma

From: Hariom Verma <hariom18599@gmail.com>

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.

Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Heba Waly <heba.waly@gmail.com>
Signed-off-by: Hariom Verma <hariom18599@gmail.com>
---
 builtin/log.c | 1 +
 revision.h    | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/builtin/log.c b/builtin/log.c
index 4eb13d1ef88..2634c520847 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -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;
 
diff --git a/revision.h b/revision.h
index 93491b79d47..8acf9b918bf 100644
--- a/revision.h
+++ b/revision.h
@@ -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,
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/5] pretty: introduce `get_user_format()`
  2020-06-15 10:57 [PATCH 0/5] [GSoC][RFC] print commits using ref-filter's logic Hariom Verma via GitGitGadget
  2020-06-15 10:57 ` [PATCH 1/5] builtin/log: new config log.useRefFilter Hariom Verma via GitGitGadget
  2020-06-15 10:57 ` [PATCH 2/5] revision: add `use_ref_filter` in struct rev_info Hariom Verma via GitGitGadget
@ 2020-06-15 10:57 ` Hariom Verma via GitGitGadget
  2020-06-15 10:57 ` [PATCH 4/5] ref_format: add option to skip `\n` at eol Hariom Verma via GitGitGadget
  2020-06-15 10:57 ` [PATCH 5/5] pretty-lib: print commits using ref-filters logic Hariom Verma via GitGitGadget
  4 siblings, 0 replies; 6+ messages in thread
From: Hariom Verma via GitGitGadget @ 2020-06-15 10:57 UTC (permalink / raw)
  To: git; +Cc: Hariom Verma, Hariom Verma

From: Hariom Verma <hariom18599@gmail.com>

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()`.

Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Heba Waly <heba.waly@gmail.com>
Signed-off-by: Hariom Verma <hariom18599@gmail.com>
---
 pretty.c | 5 +++++
 pretty.h | 3 +++
 2 files changed, 8 insertions(+)

diff --git a/pretty.c b/pretty.c
index 2a3d46bf42f..3767c144b0a 100644
--- a/pretty.c
+++ b/pretty.c
@@ -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;
+}
diff --git a/pretty.h b/pretty.h
index 071f2fb8e44..517450f72f8 100644
--- a/pretty.h
+++ b/pretty.h
@@ -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 */
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/5] ref_format: add option to skip `\n` at eol
  2020-06-15 10:57 [PATCH 0/5] [GSoC][RFC] print commits using ref-filter's logic Hariom Verma via GitGitGadget
                   ` (2 preceding siblings ...)
  2020-06-15 10:57 ` [PATCH 3/5] pretty: introduce `get_user_format()` Hariom Verma via GitGitGadget
@ 2020-06-15 10:57 ` Hariom Verma via GitGitGadget
  2020-06-15 10:57 ` [PATCH 5/5] pretty-lib: print commits using ref-filters logic Hariom Verma via GitGitGadget
  4 siblings, 0 replies; 6+ messages in thread
From: Hariom Verma via GitGitGadget @ 2020-06-15 10:57 UTC (permalink / raw)
  To: git; +Cc: Hariom Verma, Hariom Verma

From: Hariom Verma <hariom18599@gmail.com>

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.

Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Heba Waly <heba.waly@gmail.com>
Signed-off-by: Hariom Verma <hariom18599@gmail.com>
---
 ref-filter.c | 3 ++-
 ref-filter.h | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index bf7b70299b4..0e2fecbda4c 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -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,
diff --git a/ref-filter.h b/ref-filter.h
index 8ecc33cdfa5..410446dc412 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -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) \
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 5/5] pretty-lib: print commits using ref-filters logic
  2020-06-15 10:57 [PATCH 0/5] [GSoC][RFC] print commits using ref-filter's logic Hariom Verma via GitGitGadget
                   ` (3 preceding siblings ...)
  2020-06-15 10:57 ` [PATCH 4/5] ref_format: add option to skip `\n` at eol Hariom Verma via GitGitGadget
@ 2020-06-15 10:57 ` Hariom Verma via GitGitGadget
  4 siblings, 0 replies; 6+ messages in thread
From: Hariom Verma via GitGitGadget @ 2020-06-15 10:57 UTC (permalink / raw)
  To: git; +Cc: Hariom Verma, Hariom Verma

From: Hariom Verma <hariom18599@gmail.com>

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.

Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Heba Waly <heba.waly@gmail.com>
Signed-off-by: Hariom Verma <hariom18599@gmail.com>
---
 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

diff --git a/Makefile b/Makefile
index 372139f1f24..bcc65e87827 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/log-tree.c b/log-tree.c
index 55a68d0c610..663056664f9 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -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);
diff --git a/pretty-lib.c b/pretty-lib.c
new file mode 100644
index 00000000000..abe4228290b
--- /dev/null
+++ b/pretty-lib.c
@@ -0,0 +1,84 @@
+#include "commit.h"
+#include "ref-filter.h"
+#include "pretty-lib.h"
+
+static size_t convert_format(struct strbuf *sb, const char *start, void *data)
+{
+	/* TODO - Add support for more formatting options */
+	switch (*start) {
+	case 'H':
+		strbuf_addstr(sb, "%(objectname)");
+		return 1;
+	case 'h':
+		strbuf_addstr(sb, "%(objectname:short)");
+		return 1;
+	case 'T':
+		strbuf_addstr(sb, "%(tree)");
+		return 1;
+	case 'P':
+		strbuf_addstr(sb, "%(parent)");
+		return 1;
+	case 'a':
+		if (start[1] == 'n')
+			strbuf_addstr(sb, "%(authorname)");
+		else if (start[1] == 'e')
+			strbuf_addstr(sb, "%(authoremail)");
+		else if (start[1] == 'd')
+			strbuf_addstr(sb, "%(authordate)");
+		else
+			die(_("invalid formatting option '%c'"), *start);
+		return 2;
+	case 'c':
+		if (start[1] == 'n')
+			strbuf_addstr(sb, "%(committername)");
+		else if (start[1] == 'e')
+			strbuf_addstr(sb, "%(committeremail)");
+		else if (start[1] == 'd')
+			strbuf_addstr(sb, "%(committerdate)");
+		else
+			die(_("invalid formatting option '%c'"), *start);
+		return 2;
+	case 's':
+		strbuf_addstr(sb, "%(subject)");
+		return 1;
+	case 'b':
+		strbuf_addstr(sb, "%(body)");
+		return 1;
+	case 'n':
+		strbuf_addstr(sb, "\n");
+		return 1;
+	default:
+		die(_("invalid formatting option '%c'"), *start);
+	}
+}
+
+void ref_pretty_print_commit(struct pretty_print_context *pp,
+			 const struct commit *commit,
+			 struct strbuf *sb)
+{
+	struct ref_format format = REF_FORMAT_INIT;
+	struct strbuf sb_fmt = STRBUF_INIT;
+	const char *name = "refs";
+	const char *usr_fmt = get_user_format();
+
+	if (pp->fmt == CMIT_FMT_USERFORMAT) {
+		strbuf_expand(&sb_fmt, usr_fmt, convert_format, NULL);
+		format.format = sb_fmt.buf;
+	} else if (pp->fmt == CMIT_FMT_DEFAULT || pp->fmt == CMIT_FMT_MEDIUM) {
+		format.format = "Author: %(authorname) %(authoremail)\nDate:\t%(authordate)\n\n%(subject)\n\n%(body)";
+	} else if (pp->fmt == CMIT_FMT_ONELINE) {
+		format.format = "%(subject)";
+	} else if (pp->fmt == CMIT_FMT_SHORT) {
+		format.format = "Author: %(authorname) %(authoremail)\n\n\t%(subject)\n";
+	} else if (pp->fmt == CMIT_FMT_FULL) {
+		format.format = "Author: %(authorname) %(authoremail)\nCommit: %(committername) %(committeremail)\n\n%(subject)\n\n%(body)";
+	} else if (pp->fmt == CMIT_FMT_FULLER) {
+		format.format = "Author:\t\t%(authorname) %(authoremail)\nAuthorDate:\t%(authordate)\nCommit:\t\t%(committername) %(committeremail)\nCommitDate:\t%(committerdate)\n\n%(subject)\n\n%(body)";
+	}
+
+	format.need_newline_at_eol = 0;
+
+	verify_ref_format(&format);
+	pretty_print_ref(name, &commit->object.oid, &format);
+	strbuf_release(&sb_fmt);
+}
diff --git a/pretty-lib.h b/pretty-lib.h
new file mode 100644
index 00000000000..324499b1150
--- /dev/null
+++ b/pretty-lib.h
@@ -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 */
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-06-15 10:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-15 10:57 [PATCH 0/5] [GSoC][RFC] print commits using ref-filter's logic Hariom Verma via GitGitGadget
2020-06-15 10:57 ` [PATCH 1/5] builtin/log: new config log.useRefFilter Hariom Verma via GitGitGadget
2020-06-15 10:57 ` [PATCH 2/5] revision: add `use_ref_filter` in struct rev_info Hariom Verma via GitGitGadget
2020-06-15 10:57 ` [PATCH 3/5] pretty: introduce `get_user_format()` Hariom Verma via GitGitGadget
2020-06-15 10:57 ` [PATCH 4/5] ref_format: add option to skip `\n` at eol Hariom Verma via GitGitGadget
2020-06-15 10:57 ` [PATCH 5/5] pretty-lib: print commits using ref-filters logic Hariom Verma via GitGitGadget

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.