@@ -139,6 +139,42 @@ static struct command *commands;
139139static const char pre_receive_hook [] = "hooks/pre-receive" ;
140140static const char post_receive_hook [] = "hooks/post-receive" ;
141141
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+
142178static int copy_to_sideband (int in , int out , void * arg )
143179{
144180 char data [128 ];
@@ -276,7 +312,7 @@ static void warn_unconfigured_deny(void)
276312{
277313 int i ;
278314 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 ]);
280316}
281317
282318static char * warn_unconfigured_deny_delete_current_msg [] = {
@@ -302,7 +338,7 @@ static void warn_unconfigured_deny_delete_current(void)
302338 for (i = 0 ;
303339 i < ARRAY_SIZE (warn_unconfigured_deny_delete_current_msg );
304340 i ++ )
305- warning ("%s" , warn_unconfigured_deny_delete_current_msg [i ]);
341+ rp_warning ("%s" , warn_unconfigured_deny_delete_current_msg [i ]);
306342}
307343
308344static const char * update (struct command * cmd )
@@ -314,7 +350,7 @@ static const char *update(struct command *cmd)
314350
315351 /* only refs/... are allowed */
316352 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 );
318354 return "funny refname" ;
319355 }
320356
@@ -324,12 +360,12 @@ static const char *update(struct command *cmd)
324360 break ;
325361 case DENY_UNCONFIGURED :
326362 case DENY_WARN :
327- warning ("updating the current branch" );
363+ rp_warning ("updating the current branch" );
328364 if (deny_current_branch == DENY_UNCONFIGURED )
329365 warn_unconfigured_deny ();
330366 break ;
331367 case DENY_REFUSE :
332- error ("refusing to update checked out branch: %s" , name );
368+ rp_error ("refusing to update checked out branch: %s" , name );
333369 return "branch is currently checked out" ;
334370 }
335371 }
@@ -342,7 +378,7 @@ static const char *update(struct command *cmd)
342378
343379 if (!is_null_sha1 (old_sha1 ) && is_null_sha1 (new_sha1 )) {
344380 if (deny_deletes && !prefixcmp (name , "refs/heads/" )) {
345- error ("denying ref deletion for %s" , name );
381+ rp_error ("denying ref deletion for %s" , name );
346382 return "deletion prohibited" ;
347383 }
348384
@@ -354,10 +390,10 @@ static const char *update(struct command *cmd)
354390 case DENY_UNCONFIGURED :
355391 if (deny_delete_current == DENY_UNCONFIGURED )
356392 warn_unconfigured_deny_delete_current ();
357- warning ("deleting the current branch" );
393+ rp_warning ("deleting the current branch" );
358394 break ;
359395 case DENY_REFUSE :
360- error ("refusing to delete the current branch: %s" , name );
396+ rp_error ("refusing to delete the current branch: %s" , name );
361397 return "deletion of the current branch prohibited" ;
362398 }
363399 }
@@ -387,31 +423,31 @@ static const char *update(struct command *cmd)
387423 break ;
388424 free_commit_list (bases );
389425 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 );
392428 return "non-fast-forward" ;
393429 }
394430 }
395431 if (run_update_hook (cmd )) {
396- error ("hook declined to update %s" , name );
432+ rp_error ("hook declined to update %s" , name );
397433 return "hook declined" ;
398434 }
399435
400436 if (is_null_sha1 (new_sha1 )) {
401437 if (!parse_object (old_sha1 )) {
402- warning ("Allowing deletion of corrupt ref." );
438+ rp_warning ("Allowing deletion of corrupt ref." );
403439 old_sha1 = NULL ;
404440 }
405441 if (delete_ref (name , old_sha1 , 0 )) {
406- error ("failed to delete %s" , name );
442+ rp_error ("failed to delete %s" , name );
407443 return "failed to delete" ;
408444 }
409445 return NULL ; /* good */
410446 }
411447 else {
412448 lock = lock_any_ref_for_update (name , old_sha1 , 0 );
413449 if (!lock ) {
414- error ("failed to lock %s" , name );
450+ rp_error ("failed to lock %s" , name );
415451 return "failed to lock" ;
416452 }
417453 if (write_ref_sha1 (lock , new_sha1 , "push" )) {
0 commit comments