Skip to content

Commit fa39b6b

Browse files
spearceJunio C Hamano
authored andcommitted
Introduce a global level warn() function.
Like the existing error() function the new warn() function can be used to describe a situation that probably should not be occuring, but which the user (and Git) can continue to work around without running into too many problems. An example situation is a bad commit SHA1 found in a reflog. Attempting to read this record out of the reflog isn't really an error as we have skipped over it in the past. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 51dcaa9 commit fa39b6b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

git-compat-util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@
7171
extern void usage(const char *err) NORETURN;
7272
extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
7373
extern int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
74+
extern void warn(const char *err, ...) __attribute__((format (printf, 1, 2)));
7475

7576
extern void set_usage_routine(void (*routine)(const char *err) NORETURN);
7677
extern void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN);
7778
extern void set_error_routine(void (*routine)(const char *err, va_list params));
79+
extern void set_warn_routine(void (*routine)(const char *warn, va_list params));
7880

7981
#ifdef NO_MMAP
8082

usage.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,17 @@ static void error_builtin(const char *err, va_list params)
2929
report("error: ", err, params);
3030
}
3131

32+
static void warn_builtin(const char *warn, va_list params)
33+
{
34+
report("warning: ", warn, params);
35+
}
3236

3337
/* If we are in a dlopen()ed .so write to a global variable would segfault
3438
* (ugh), so keep things static. */
3539
static void (*usage_routine)(const char *err) NORETURN = usage_builtin;
3640
static void (*die_routine)(const char *err, va_list params) NORETURN = die_builtin;
3741
static void (*error_routine)(const char *err, va_list params) = error_builtin;
42+
static void (*warn_routine)(const char *err, va_list params) = warn_builtin;
3843

3944
void set_usage_routine(void (*routine)(const char *err) NORETURN)
4045
{
@@ -51,6 +56,11 @@ void set_error_routine(void (*routine)(const char *err, va_list params))
5156
error_routine = routine;
5257
}
5358

59+
void set_warn_routine(void (*routine)(const char *warn, va_list params))
60+
{
61+
warn_routine = routine;
62+
}
63+
5464

5565
void usage(const char *err)
5666
{
@@ -75,3 +85,12 @@ int error(const char *err, ...)
7585
va_end(params);
7686
return -1;
7787
}
88+
89+
void warn(const char *warn, ...)
90+
{
91+
va_list params;
92+
93+
va_start(params, warn);
94+
warn_routine(warn, params);
95+
va_end(params);
96+
}

0 commit comments

Comments
 (0)