git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/4] oneline: parse --newlineafter flag

From
John Cai via GitGitGadget <gitgitgadget@gmail.com>
Date
Oct 29, 2021, 21:15 UTC
Message-ID
<c5e0eda3321043093abbf3a43af994a0222b3e4c.1635542128.git.gitgitgadget@gmail.com>
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
Previous: John Cai via GitGitGadgetNext: John Cai via GitGitGadget
Message 2 of 7 in “Flag to add a newline after decorations for --oneline log output”
  1. 0/4 Flag to add a newline after decorations for --oneline log outputJohn Cai via GitGitGadget, Oct 29, 2021
  2. 1/4 oneline: parse --newlineafter flagJohn Cai via GitGitGadget, Oct 29, 2021
  3. 2/4 oneline: print newline after decorations if flag providedJohn Cai via GitGitGadget, Oct 29, 2021
  4. 3/4 oneline: test for --newlineafter featureJohn Cai via GitGitGadget, Oct 29, 2021
  5. 4/4 doc: add docs for newlineafter flagJohn Cai via GitGitGadget, Oct 29, 2021
  6. Christian CouderNov 12, 2021
  7. John CaiNov 21, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.