git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "John Cai via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: John Cai <johncai86@gmail.com>, John Cai <johncai86@gmail.com>
Subject: [PATCH 1/4] oneline: parse --newlineafter flag
Date: Fri, 29 Oct 2021 21:15:24 +0000	[thread overview]
Message-ID: <c5e0eda3321043093abbf3a43af994a0222b3e4c.1635542128.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1065.git.1635542128.gitgitgadget@gmail.com>

From: John Cai <johncai86@gmail.com>

* revision.h: add newlineafter flag type
* builtin/log.c: parse newlineafter flag with callback

Signed-off-by: John Cai <johncai86@gmail.com>
---
 builtin/log.c | 25 +++++++++++++++++++++++++
 revision.h    |  4 ++++
 2 files changed, 29 insertions(+)

diff --git a/builtin/log.c b/builtin/log.c
index f75d87e8d7f..3758c73760c 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -53,6 +53,7 @@ static int decoration_given;
 static int use_mailmap_config = 1;
 static const char *fmt_patch_subject_prefix = "PATCH";
 static int fmt_patch_name_max = FORMAT_PATCH_NAME_MAX_DEFAULT;
+static int newlineafter = NEWLINEAFTER_NONE;
 static const char *fmt_pretty;
 
 static const char * const builtin_log_usage[] = {
@@ -132,6 +133,27 @@ static int log_line_range_callback(const struct option *option, const char *arg,
 	return 0;
 }
 
+static int parse_newlineafter(const char *value)
+{
+	if (!strcmp(value, "decorations"))
+		return NEWLINEAFTER_DECORATIONS;
+
+	return NEWLINEAFTER_NONE;
+}
+
+static int option_parse_newlineafter(const struct option *opt,
+				   const char *arg, int unset)
+{
+	int *newlineafter = opt->value;
+
+	if (unset)
+		*newlineafter = NEWLINEAFTER_NONE;
+	else
+		*newlineafter = parse_newlineafter(arg);
+
+	return 0;
+}
+
 static void init_log_defaults(void)
 {
 	init_diff_ui_defaults();
@@ -156,6 +178,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->newlineafter = NEWLINEAFTER_NONE;
 
 	if (default_date_mode)
 		parse_date_format(default_date_mode, &rev->date_mode);
@@ -189,6 +212,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
 		OPT_CALLBACK('L', NULL, &line_cb, "range:file",
 			     N_("trace the evolution of line range <start>,<end> or function :<funcname> in <file>"),
 			     log_line_range_callback),
+		OPT_CALLBACK(0, "newlineafter", &newlineafter, N_("field"), N_("new line after <field>"), option_parse_newlineafter),
 		OPT_END()
 	};
 
@@ -265,6 +289,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
 		load_ref_decorations(&decoration_filter, decoration_style);
 	}
 
+	rev->newlineafter = newlineafter;
 	if (rev->line_level_traverse)
 		line_log_init(rev, line_cb.prefix, &line_cb.args);
 
diff --git a/revision.h b/revision.h
index 5578bb4720a..ff0b89c1f40 100644
--- a/revision.h
+++ b/revision.h
@@ -243,6 +243,10 @@ struct rev_info {
 	int		no_inline;
 	int		show_log_size;
 	struct string_list *mailmap;
+	enum {
+			NEWLINEAFTER_NONE,
+			NEWLINEAFTER_DECORATIONS
+		} newlineafter;
 
 	/* Filter by commit log message */
 	struct grep_opt	grep_filter;
-- 
gitgitgadget


  reply	other threads:[~2021-10-29 21:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-29 21:15 [PATCH 0/4] Flag to add a newline after decorations for --oneline log output John Cai via GitGitGadget
2021-10-29 21:15 ` John Cai via GitGitGadget [this message]
2021-10-29 21:15 ` [PATCH 2/4] oneline: print newline after decorations if flag provided John Cai via GitGitGadget
2021-10-29 21:15 ` [PATCH 3/4] oneline: test for --newlineafter feature John Cai via GitGitGadget
2021-10-29 21:15 ` [PATCH 4/4] doc: add docs for newlineafter flag John Cai via GitGitGadget
2021-11-12 16:27 ` [PATCH 0/4] Flag to add a newline after decorations for --oneline log output Christian Couder
2021-11-21  1:19   ` John Cai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c5e0eda3321043093abbf3a43af994a0222b3e4c.1635542128.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=johncai86@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).