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

[PATCH 4/5] format-support: move `format_sanitized_subject()` from pretty

From
HGHariom Verma via GitGitGadget <gitgitgadget@gmail.com>
Date
Jul 27, 2020, 20:43 UTC
Message-ID
<9dc619b44888024201d9ae1f83a4b34c81fa693f.1595882588.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.684.git.1595882588.gitgitgadget@gmail.com>
From: Hariom Verma <hariom18599@gmail.com>

In hope of some new features in `subject` atom, move funtion `format_sanitized_subject()` and all the function it uses to new file format-support.[c/h].

Consider this new file as a common interface between functions that pretty.c and ref-filter.c shares.

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 +
 format-support.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 format-support.h |  6 ++++++
 pretty.c         | 40 +---------------------------------------
 4 files changed, 51 insertions(+), 39 deletions(-)
 create mode 100644 format-support.c
 create mode 100644 format-support.h
diff --git a/Makefile b/Makefile
index 372139f1f2..4dfc384b49 100644
--- a/Makefile
+++ b/Makefile
@@ -882,6 +882,7 @@ LIB_OBJS += exec-cmd.o
 LIB_OBJS += fetch-negotiator.o
 LIB_OBJS += fetch-pack.o
 LIB_OBJS += fmt-merge-msg.o
+LIB_OBJS += format-support.o
 LIB_OBJS += fsck.o
 LIB_OBJS += fsmonitor.o
 LIB_OBJS += gettext.o
diff --git a/format-support.c b/format-support.c
new file mode 100644
index 0000000000..d693aa1744
--- /dev/null
+++ b/format-support.c
@@ -0,0 +1,43 @@
+#include "diff.h"
+#include "log-tree.h"
+#include "color.h"
+#include "format-support.h"
+
+static int istitlechar(char c)
+{
+	return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
+		(c >= '0' && c <= '9') || c == '.' || c == '_';
+}
+
+void format_sanitized_subject(struct strbuf *sb, const char *msg, size_t len)
+{
+	char *r = xmemdupz(msg, len);
+	size_t trimlen;
+	size_t start_len = sb->len;
+	int space = 2;
+	int i;
+
+	for (i = 0; i < len; i++) {
+		if (r[i] == '\n')
+			r[i] = ' ';
+		if (istitlechar(r[i])) {
+			if (space == 1)
+				strbuf_addch(sb, '-');
+			space = 0;
+			strbuf_addch(sb, r[i]);
+			if (r[i] == '.')
+				while (r[i+1] == '.')
+					i++;
+		} else
+			space |= 1;
+	}
+	free(r);
+
+	/* trim any trailing '.' or '-' characters */
+	trimlen = 0;
+	while (sb->len - trimlen > start_len &&
+		(sb->buf[sb->len - 1 - trimlen] == '.'
+		|| sb->buf[sb->len - 1 - trimlen] == '-'))
+		trimlen++;
+	strbuf_remove(sb, sb->len - trimlen, trimlen);
+}
diff --git a/format-support.h b/format-support.h
new file mode 100644
index 0000000000..c344ccbc33
--- /dev/null
+++ b/format-support.h
@@ -0,0 +1,6 @@
+#ifndef FORMAT_SUPPORT_H
+#define FORMAT_SUPPORT_H
+
+void format_sanitized_subject(struct strbuf *sb, const char *msg, size_t len);
+
+#endif /* FORMAT_SUPPORT_H */
diff --git a/pretty.c b/pretty.c
index 8d08e8278a..2de01b7115 100644
--- a/pretty.c
+++ b/pretty.c
@@ -12,6 +12,7 @@
 #include "reflog-walk.h"
 #include "gpg-interface.h"
 #include "trailer.h"
+#include "format-support.h"
 
 static char *user_format;
 static struct cmt_fmt_map {
@@ -833,45 +834,6 @@ static void parse_commit_header(struct format_commit_context *context)
 	context->commit_header_parsed = 1;
 }
 
-static int istitlechar(char c)
-{
-	return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
-		(c >= '0' && c <= '9') || c == '.' || c == '_';
-}
-
-static void format_sanitized_subject(struct strbuf *sb, const char *msg, size_t len)
-{
-	char *r = xmemdupz(msg, len);
-	size_t trimlen;
-	size_t start_len = sb->len;
-	int space = 2;
-	int i;
-
-	for (i = 0; i < len; i++) {
-		if (r[i] == '\n')
-			r[i] = ' ';
-		if (istitlechar(r[i])) {
-			if (space == 1)
-				strbuf_addch(sb, '-');
-			space = 0;
-			strbuf_addch(sb, r[i]);
-			if (r[i] == '.')
-				while (r[i+1] == '.')
-					i++;
-		} else
-			space |= 1;
-	}
-	free(r);
-
-	/* trim any trailing '.' or '-' characters */
-	trimlen = 0;
-	while (sb->len - trimlen > start_len &&
-		(sb->buf[sb->len - 1 - trimlen] == '.'
-		|| sb->buf[sb->len - 1 - trimlen] == '-'))
-		trimlen++;
-	strbuf_remove(sb, sb->len - trimlen, trimlen);
-}
-
 const char *format_subject(struct strbuf *sb, const char *msg,
 			   const char *line_separator)
 {
-- 
gitgitgadget
Previous: Hariom Verma via GitGitGadgetNext: Hariom Verma via GitGitGadget
Message 11 of 51 in “[GSoC] Improvements to ref-filter”
  1. 0/5 [GSoC] Improvements to ref-filterHariom Verma via GitGitGadget, Jul 27, 2020
  2. 1/5 ref-filter: support different email formatsHariom Verma via GitGitGadget, Jul 27, 2020
  3. Junio C HamanoJul 27, 2020
  4. Hariom vermaJul 28, 2020
  5. Junio C HamanoJul 28, 2020
  6. Đoàn Trần Công DanhJul 28, 2020
  7. Junio C HamanoJul 28, 2020
  8. 2/5 ref-filter: add `short` option for 'tree' and 'parent'Hariom Verma via GitGitGadget, Jul 27, 2020
  9. Junio C HamanoJul 27, 2020
  10. 3/5 pretty: refactor `format_sanitized_subject()`Hariom Verma via GitGitGadget, Jul 27, 2020
  11. 4/5 format-support: move `format_sanitized_subject()` from prettyHariom Verma via GitGitGadget, Jul 27, 2020
  12. 5/5 ref-filter: add `sanitize` option for 'subject' atomHariom Verma via GitGitGadget, Jul 27, 2020
  13. 0/9 [GSoC] Improvements to ref-filterHariom Verma via GitGitGadget, Aug 5, 2020
  14. 1/9 ref-filter: support different email formatsHariom Verma via GitGitGadget, Aug 5, 2020
  15. 2/9 ref-filter: refactor `grab_objectname()`Hariom Verma via GitGitGadget, Aug 5, 2020
  16. 3/9 ref-filter: modify error messages in `grab_objectname()`Hariom Verma via GitGitGadget, Aug 5, 2020
  17. 4/9 ref-filter: rename `objectname` related functions and fieldsHariom Verma via GitGitGadget, Aug 5, 2020
  18. 5/9 ref-filter: add `short` modifier to 'tree' atomHariom Verma via GitGitGadget, Aug 5, 2020
  19. 6/9 ref-filter: add `short` modifier to 'parent' atomHariom Verma via GitGitGadget, Aug 5, 2020
  20. 8/9 format-support: move `format_sanitized_subject()` from prettyHariom Verma via GitGitGadget, Aug 5, 2020
  21. 9/9 ref-filter: add `sanitize` option for 'subject' atomHariom Verma via GitGitGadget, Aug 5, 2020
  22. 7/9 pretty: refactor `format_sanitized_subject()`Hariom Verma via GitGitGadget, Aug 5, 2020
  23. Junio C HamanoAug 5, 2020
  24. Hariom vermaAug 6, 2020
  25. 0/9 [Resend][GSoC] Improvements to ref-filterHariom Verma via GitGitGadget, Aug 17, 2020
  26. 2/9 ref-filter: refactor `grab_objectname()`Hariom Verma via GitGitGadget, Aug 17, 2020
  27. 3/9 ref-filter: modify error messages in `grab_objectname()`Hariom Verma via GitGitGadget, Aug 17, 2020
  28. 1/9 ref-filter: support different email formatsHariom Verma via GitGitGadget, Aug 17, 2020
  29. 4/9 ref-filter: rename `objectname` related functions and fieldsHariom Verma via GitGitGadget, Aug 17, 2020
  30. 7/9 pretty: refactor `format_sanitized_subject()`Hariom Verma via GitGitGadget, Aug 17, 2020
  31. Junio C HamanoAug 17, 2020
  32. Hariom vermaAug 19, 2020
  33. Junio C HamanoAug 19, 2020
  34. Junio C HamanoAug 19, 2020
  35. Hariom vermaAug 20, 2020
  36. Hariom vermaAug 20, 2020
  37. 6/9 ref-filter: add `short` modifier to 'parent' atomHariom Verma via GitGitGadget, Aug 17, 2020
  38. 5/9 ref-filter: add `short` modifier to 'tree' atomHariom Verma via GitGitGadget, Aug 17, 2020
  39. 8/9 format-support: move `format_sanitized_subject()` from prettyHariom Verma via GitGitGadget, Aug 17, 2020
  40. Junio C HamanoAug 17, 2020
  41. 9/9 ref-filter: add `sanitize` option for 'subject' atomHariom Verma via GitGitGadget, Aug 17, 2020
  42. Junio C HamanoAug 17, 2020
  43. 0/8 [GSoC] Improvements to ref-filterHariom Verma via GitGitGadget, Aug 21, 2020
  44. 1/8 ref-filter: support different email formatsHariom Verma via GitGitGadget, Aug 21, 2020
  45. 2/8 ref-filter: refactor `grab_objectname()`Hariom Verma via GitGitGadget, Aug 21, 2020
  46. 3/8 ref-filter: modify error messages in `grab_objectname()`Hariom Verma via GitGitGadget, Aug 21, 2020
  47. 5/8 ref-filter: add `short` modifier to 'tree' atomHariom Verma via GitGitGadget, Aug 21, 2020
  48. 6/8 ref-filter: add `short` modifier to 'parent' atomHariom Verma via GitGitGadget, Aug 21, 2020
  49. 8/8 ref-filter: add `sanitize` option for 'subject' atomHariom Verma via GitGitGadget, Aug 21, 2020
  50. 4/8 ref-filter: rename `objectname` related functions and fieldsHariom Verma via GitGitGadget, Aug 21, 2020
  51. 7/8 pretty: refactor `format_sanitized_subject()`Hariom Verma via GitGitGadget, Aug 21, 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.