git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Hariom Verma via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Hariom Verma <hariom18599@gmail.com>,
	Hariom Verma <hariom18599@gmail.com>
Subject: [PATCH 4/5] format-support: move `format_sanitized_subject()` from pretty
Date: Mon, 27 Jul 2020 20:43:07 +0000	[thread overview]
Message-ID: <9dc619b44888024201d9ae1f83a4b34c81fa693f.1595882588.git.gitgitgadget@gmail.com> (raw)
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


  parent reply	other threads:[~2020-07-27 20:43 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-27 20:43 [PATCH 0/5] [GSoC] Improvements to ref-filter Hariom Verma via GitGitGadget
2020-07-27 20:43 ` [PATCH 1/5] ref-filter: support different email formats Hariom Verma via GitGitGadget
2020-07-27 22:51   ` Junio C Hamano
2020-07-28 20:31     ` Hariom verma
2020-07-28 20:43       ` Junio C Hamano
2020-07-28 13:58   ` Đoàn Trần Công Danh
2020-07-28 16:45     ` Junio C Hamano
2020-07-27 20:43 ` [PATCH 2/5] ref-filter: add `short` option for 'tree' and 'parent' Hariom Verma via GitGitGadget
2020-07-27 23:21   ` Junio C Hamano
2020-07-27 20:43 ` [PATCH 3/5] pretty: refactor `format_sanitized_subject()` Hariom Verma via GitGitGadget
2020-07-27 20:43 ` Hariom Verma via GitGitGadget [this message]
2020-07-27 20:43 ` [PATCH 5/5] ref-filter: add `sanitize` option for 'subject' atom Hariom Verma via GitGitGadget
2020-08-05 21:51 ` [PATCH v2 0/9] [GSoC] Improvements to ref-filter Hariom Verma via GitGitGadget
2020-08-05 21:51   ` [PATCH v2 1/9] ref-filter: support different email formats Hariom Verma via GitGitGadget
2020-08-05 21:51   ` [PATCH v2 2/9] ref-filter: refactor `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-05 21:51   ` [PATCH v2 3/9] ref-filter: modify error messages in `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-05 21:51   ` [PATCH v2 4/9] ref-filter: rename `objectname` related functions and fields Hariom Verma via GitGitGadget
2020-08-05 21:51   ` [PATCH v2 5/9] ref-filter: add `short` modifier to 'tree' atom Hariom Verma via GitGitGadget
2020-08-05 21:51   ` [PATCH v2 6/9] ref-filter: add `short` modifier to 'parent' atom Hariom Verma via GitGitGadget
2020-08-05 21:51   ` [PATCH v2 7/9] pretty: refactor `format_sanitized_subject()` Hariom Verma via GitGitGadget
2020-08-05 21:51   ` [PATCH v2 8/9] format-support: move `format_sanitized_subject()` from pretty Hariom Verma via GitGitGadget
2020-08-05 21:51   ` [PATCH v2 9/9] ref-filter: add `sanitize` option for 'subject' atom Hariom Verma via GitGitGadget
2020-08-05 22:04   ` [PATCH v2 0/9] [GSoC] Improvements to ref-filter Junio C Hamano
2020-08-06 13:47     ` Hariom verma
2020-08-17 18:10   ` [PATCH v3 0/9] [Resend][GSoC] " Hariom Verma via GitGitGadget
2020-08-17 18:10     ` [PATCH v3 1/9] ref-filter: support different email formats Hariom Verma via GitGitGadget
2020-08-17 18:10     ` [PATCH v3 2/9] ref-filter: refactor `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-17 18:10     ` [PATCH v3 3/9] ref-filter: modify error messages in `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-17 18:10     ` [PATCH v3 4/9] ref-filter: rename `objectname` related functions and fields Hariom Verma via GitGitGadget
2020-08-17 18:10     ` [PATCH v3 5/9] ref-filter: add `short` modifier to 'tree' atom Hariom Verma via GitGitGadget
2020-08-17 18:10     ` [PATCH v3 6/9] ref-filter: add `short` modifier to 'parent' atom Hariom Verma via GitGitGadget
2020-08-17 18:10     ` [PATCH v3 7/9] pretty: refactor `format_sanitized_subject()` Hariom Verma via GitGitGadget
2020-08-17 19:29       ` Junio C Hamano
2020-08-19 13:36         ` Hariom verma
2020-08-19 16:01           ` Junio C Hamano
2020-08-19 16:08             ` Junio C Hamano
2020-08-20 17:33               ` Hariom verma
2020-08-20 17:27             ` Hariom verma
2020-08-17 18:10     ` [PATCH v3 8/9] format-support: move `format_sanitized_subject()` from pretty Hariom Verma via GitGitGadget
2020-08-17 19:33       ` Junio C Hamano
2020-08-17 18:10     ` [PATCH v3 9/9] ref-filter: add `sanitize` option for 'subject' atom Hariom Verma via GitGitGadget
2020-08-17 19:37     ` [PATCH v3 0/9] [Resend][GSoC] Improvements to ref-filter Junio C Hamano
2020-08-21 21:41     ` [PATCH v4 0/8] [GSoC] " Hariom Verma via GitGitGadget
2020-08-21 21:41       ` [PATCH v4 1/8] ref-filter: support different email formats Hariom Verma via GitGitGadget
2020-08-21 21:41       ` [PATCH v4 2/8] ref-filter: refactor `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-21 21:41       ` [PATCH v4 3/8] ref-filter: modify error messages in `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-21 21:41       ` [PATCH v4 4/8] ref-filter: rename `objectname` related functions and fields Hariom Verma via GitGitGadget
2020-08-21 21:41       ` [PATCH v4 5/8] ref-filter: add `short` modifier to 'tree' atom Hariom Verma via GitGitGadget
2020-08-21 21:41       ` [PATCH v4 6/8] ref-filter: add `short` modifier to 'parent' atom Hariom Verma via GitGitGadget
2020-08-21 21:41       ` [PATCH v4 7/8] pretty: refactor `format_sanitized_subject()` Hariom Verma via GitGitGadget
2020-08-21 21:41       ` [PATCH v4 8/8] ref-filter: add `sanitize` option for 'subject' atom Hariom Verma via GitGitGadget

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=9dc619b44888024201d9ae1f83a4b34c81fa693f.1595882588.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=hariom18599@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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).