@@ -139,6 +139,42 @@ static struct command *commands;
139
139
static const char pre_receive_hook [] = "hooks/pre-receive" ;
140
140
static const char post_receive_hook [] = "hooks/post-receive" ;
141
141
142
+ static void rp_error (const char * err , ...) __attribute__((format (printf , 1 , 2 )));
143
+ static void rp_warning (const char * err , ...) __attribute__((format (printf , 1 , 2 )));
144
+
145
+ static void report_message (const char * prefix , const char * err , va_list params )
146
+ {
147
+ int sz = strlen (prefix );
148
+ char msg [4096 ];
149
+
150
+ strncpy (msg , prefix , sz );
151
+ sz += vsnprintf (msg + sz , sizeof (msg ) - sz , err , params );
152
+ if (sz > (sizeof (msg ) - 1 ))
153
+ sz = sizeof (msg ) - 1 ;
154
+ msg [sz ++ ] = '\n' ;
155
+
156
+ if (use_sideband )
157
+ send_sideband (1 , 2 , msg , sz , use_sideband );
158
+ else
159
+ xwrite (2 , msg , sz );
160
+ }
161
+
162
+ static void rp_warning (const char * err , ...)
163
+ {
164
+ va_list params ;
165
+ va_start (params , err );
166
+ report_message ("warning: " , err , params );
167
+ va_end (params );
168
+ }
169
+
170
+ static void rp_error (const char * err , ...)
171
+ {
172
+ va_list params ;
173
+ va_start (params , err );
174
+ report_message ("error: " , err , params );
175
+ va_end (params );
176
+ }
177
+
142
178
static int copy_to_sideband (int in , int out , void * arg )
143
179
{
144
180
char data [128 ];
@@ -276,7 +312,7 @@ static void warn_unconfigured_deny(void)
276
312
{
277
313
int i ;
278
314
for (i = 0 ; i < ARRAY_SIZE (warn_unconfigured_deny_msg ); i ++ )
279
- warning ("%s" , warn_unconfigured_deny_msg [i ]);
315
+ rp_warning ("%s" , warn_unconfigured_deny_msg [i ]);
280
316
}
281
317
282
318
static char * warn_unconfigured_deny_delete_current_msg [] = {
@@ -302,7 +338,7 @@ static void warn_unconfigured_deny_delete_current(void)
302
338
for (i = 0 ;
303
339
i < ARRAY_SIZE (warn_unconfigured_deny_delete_current_msg );
304
340
i ++ )
305
- warning ("%s" , warn_unconfigured_deny_delete_current_msg [i ]);
341
+ rp_warning ("%s" , warn_unconfigured_deny_delete_current_msg [i ]);
306
342
}
307
343
308
344
static const char * update (struct command * cmd )
@@ -314,7 +350,7 @@ static const char *update(struct command *cmd)
314
350
315
351
/* only refs/... are allowed */
316
352
if (prefixcmp (name , "refs/" ) || check_ref_format (name + 5 )) {
317
- error ("refusing to create funny ref '%s' remotely" , name );
353
+ rp_error ("refusing to create funny ref '%s' remotely" , name );
318
354
return "funny refname" ;
319
355
}
320
356
@@ -324,12 +360,12 @@ static const char *update(struct command *cmd)
324
360
break ;
325
361
case DENY_UNCONFIGURED :
326
362
case DENY_WARN :
327
- warning ("updating the current branch" );
363
+ rp_warning ("updating the current branch" );
328
364
if (deny_current_branch == DENY_UNCONFIGURED )
329
365
warn_unconfigured_deny ();
330
366
break ;
331
367
case DENY_REFUSE :
332
- error ("refusing to update checked out branch: %s" , name );
368
+ rp_error ("refusing to update checked out branch: %s" , name );
333
369
return "branch is currently checked out" ;
334
370
}
335
371
}
@@ -342,7 +378,7 @@ static const char *update(struct command *cmd)
342
378
343
379
if (!is_null_sha1 (old_sha1 ) && is_null_sha1 (new_sha1 )) {
344
380
if (deny_deletes && !prefixcmp (name , "refs/heads/" )) {
345
- error ("denying ref deletion for %s" , name );
381
+ rp_error ("denying ref deletion for %s" , name );
346
382
return "deletion prohibited" ;
347
383
}
348
384
@@ -354,10 +390,10 @@ static const char *update(struct command *cmd)
354
390
case DENY_UNCONFIGURED :
355
391
if (deny_delete_current == DENY_UNCONFIGURED )
356
392
warn_unconfigured_deny_delete_current ();
357
- warning ("deleting the current branch" );
393
+ rp_warning ("deleting the current branch" );
358
394
break ;
359
395
case DENY_REFUSE :
360
- error ("refusing to delete the current branch: %s" , name );
396
+ rp_error ("refusing to delete the current branch: %s" , name );
361
397
return "deletion of the current branch prohibited" ;
362
398
}
363
399
}
@@ -387,31 +423,31 @@ static const char *update(struct command *cmd)
387
423
break ;
388
424
free_commit_list (bases );
389
425
if (!ent ) {
390
- error ("denying non-fast-forward %s"
391
- " (you should pull first)" , name );
426
+ rp_error ("denying non-fast-forward %s"
427
+ " (you should pull first)" , name );
392
428
return "non-fast-forward" ;
393
429
}
394
430
}
395
431
if (run_update_hook (cmd )) {
396
- error ("hook declined to update %s" , name );
432
+ rp_error ("hook declined to update %s" , name );
397
433
return "hook declined" ;
398
434
}
399
435
400
436
if (is_null_sha1 (new_sha1 )) {
401
437
if (!parse_object (old_sha1 )) {
402
- warning ("Allowing deletion of corrupt ref." );
438
+ rp_warning ("Allowing deletion of corrupt ref." );
403
439
old_sha1 = NULL ;
404
440
}
405
441
if (delete_ref (name , old_sha1 , 0 )) {
406
- error ("failed to delete %s" , name );
442
+ rp_error ("failed to delete %s" , name );
407
443
return "failed to delete" ;
408
444
}
409
445
return NULL ; /* good */
410
446
}
411
447
else {
412
448
lock = lock_any_ref_for_update (name , old_sha1 , 0 );
413
449
if (!lock ) {
414
- error ("failed to lock %s" , name );
450
+ rp_error ("failed to lock %s" , name );
415
451
return "failed to lock" ;
416
452
}
417
453
if (write_ref_sha1 (lock , new_sha1 , "push" )) {
0 commit comments