[PATCH 1/2] advice: extract function to print messages with prefix

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Extract a function that allows to print messages
with a prefix.

Signed-off-by: Ralf Thielow <ralf.thielow@xxxxxxxxx>
---
 advice.c | 14 ++++++++++----
 advice.h |  1 +
 2 Dateien geändert, 11 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)

diff --git a/advice.c b/advice.c
index edfbd4a..e73d53b 100644
--- a/advice.c
+++ b/advice.c
@@ -25,25 +25,31 @@ static struct {
 	{ "detachedhead", &advice_detached_head },
 };
 
-void advise(const char *advice, ...)
+void print_with_prefix(const char *prefix, const char *msg, ...)
 {
 	struct strbuf buf = STRBUF_INIT;
 	va_list params;
 	const char *cp, *np;
 
-	va_start(params, advice);
-	strbuf_vaddf(&buf, advice, params);
+	va_start(params, msg);
+	strbuf_vaddf(&buf, msg, params);
 	va_end(params);
 
 	for (cp = buf.buf; *cp; cp = np) {
 		np = strchrnul(cp, '\n');
-		fprintf(stderr,	_("hint: %.*s\n"), (int)(np - cp), cp);
+		fprintf(stderr,	 "%s %.*s\n", prefix, (int)(np - cp), cp);
 		if (*np)
 			np++;
 	}
 	strbuf_release(&buf);
 }
 
+void advise(const char *advice, ...)
+{
+	va_list vl;
+	print_with_prefix(_("hint:"), advice, vl);
+}
+
 int git_default_advice_config(const char *var, const char *value)
 {
 	const char *k = skip_prefix(var, "advice.");
diff --git a/advice.h b/advice.h
index f3cdbbf..328e255 100644
--- a/advice.h
+++ b/advice.h
@@ -14,6 +14,7 @@ extern int advice_implicit_identity;
 extern int advice_detached_head;
 
 int git_default_advice_config(const char *var, const char *value);
+void print_with_prefix(const char *prefix, const char *msg, ...);
 void advise(const char *advice, ...);
 int error_resolve_conflict(const char *me);
 extern void NORETURN die_resolve_conflict(const char *me);
-- 
1.7.12.176.g3fc0e4c.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]