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

[PATCH 4/5] ref_format: add option to skip `\n` at eol

From
HGHariom Verma via GitGitGadget <gitgitgadget@gmail.com>
Date
Jun 15, 2020, 10:57 UTC
Message-ID
<0eecb653d21355d7d2ab3dd209cfdb3c24365417.1592218662.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.658.git.1592218662.gitgitgadget@gmail.com>
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
Previous: Hariom Verma via GitGitGadgetNext: Hariom Verma via GitGitGadget
Message 4 of 6 in “[GSoC][RFC] print commits using ref-filter's logic”
  1. 0/5 [GSoC][RFC] print commits using ref-filter's logicHariom Verma via GitGitGadget, Jun 15, 2020
  2. 2/5 revision: add `use_ref_filter` in struct rev_infoHariom Verma via GitGitGadget, Jun 15, 2020
  3. 3/5 pretty: introduce `get_user_format()`Hariom Verma via GitGitGadget, Jun 15, 2020
  4. 4/5 ref_format: add option to skip `\n` at eolHariom Verma via GitGitGadget, Jun 15, 2020
  5. 1/5 builtin/log: new config log.useRefFilterHariom Verma via GitGitGadget, Jun 15, 2020
  6. 5/5 pretty-lib: print commits using ref-filters logicHariom Verma via GitGitGadget, Jun 15, 2020

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.