[PATCH 22/24] Let usage() take a printf-style format

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

 



merge-recursive and diff --no-index are not able to use usage()
because their usage strings depend on the circumstances in which
they are called.

Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
---
 git-compat-util.h |    2 +-
 usage.c           |   14 +++++++++-----
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/git-compat-util.h b/git-compat-util.h
index ef60803..42048e7 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -188,7 +188,7 @@ extern char *gitbasename(char *);
 #include "compat/bswap.h"
 
 /* General helper functions */
-extern NORETURN void usage(const char *err);
+extern NORETURN void usage(const char *err, ...) __attribute__((format (printf, 1, 2)));
 extern NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2)));
 extern NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
 extern int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
diff --git a/usage.c b/usage.c
index c488f3a..f6d9ff5 100644
--- a/usage.c
+++ b/usage.c
@@ -12,9 +12,9 @@ static void report(const char *prefix, const char *err, va_list params)
 	fprintf(stderr, "%s%s\n", prefix, msg);
 }
 
-static NORETURN void usage_builtin(const char *err)
+static NORETURN void usage_builtin(const char *err, va_list params)
 {
-	fprintf(stderr, "usage: %s\n", err);
+	report("usage: ", err, params);
 	exit(129);
 }
 
@@ -36,7 +36,7 @@ static void warn_builtin(const char *warn, va_list params)
 
 /* If we are in a dlopen()ed .so write to a global variable would segfault
  * (ugh), so keep things static. */
-static NORETURN_PTR void (*usage_routine)(const char *err) = usage_builtin;
+static NORETURN_PTR void (*usage_routine)(const char *err, va_list params) = usage_builtin;
 static NORETURN_PTR void (*die_routine)(const char *err, va_list params) = die_builtin;
 static void (*error_routine)(const char *err, va_list params) = error_builtin;
 static void (*warn_routine)(const char *err, va_list params) = warn_builtin;
@@ -46,9 +46,13 @@ void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list param
 	die_routine = routine;
 }
 
-void usage(const char *err)
+void usage(const char *err, ...)
 {
-	usage_routine(err);
+	va_list params;
+
+	va_start(params, err);
+	usage_routine(err, params);
+	va_end(params);
 }
 
 void die(const char *err, ...)
-- 
1.6.5.2

--
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]