@@ -50,6 +50,21 @@ static int non_common_revs, multi_ack, use_sideband;
50
50
#define ALLOW_REACHABLE_SHA1 02
51
51
static unsigned int allow_unadvertised_object_request ;
52
52
53
+ __attribute__((format (printf , 2 , 3 )))
54
+ static inline void print_verbose (const struct fetch_pack_args * args ,
55
+ const char * fmt , ...)
56
+ {
57
+ va_list params ;
58
+
59
+ if (!args -> verbose )
60
+ return ;
61
+
62
+ va_start (params , fmt );
63
+ vfprintf (stderr , fmt , params );
64
+ va_end (params );
65
+ fputc ('\n' , stderr );
66
+ }
67
+
53
68
static void rev_list_push (struct commit * commit , int mark )
54
69
{
55
70
if (!(commit -> object .flags & mark )) {
@@ -375,8 +390,7 @@ static int find_common(struct fetch_pack_args *args,
375
390
retval = -1 ;
376
391
while ((sha1 = get_rev ())) {
377
392
packet_buf_write (& req_buf , "have %s\n" , sha1_to_hex (sha1 ));
378
- if (args -> verbose )
379
- fprintf (stderr , "have %s\n" , sha1_to_hex (sha1 ));
393
+ print_verbose (args , "have %s" , sha1_to_hex (sha1 ));
380
394
in_vain ++ ;
381
395
if (flush_at <= ++ count ) {
382
396
int ack ;
@@ -397,9 +411,9 @@ static int find_common(struct fetch_pack_args *args,
397
411
consume_shallow_list (args , fd [0 ]);
398
412
do {
399
413
ack = get_ack (fd [0 ], result_sha1 );
400
- if (args -> verbose && ack )
401
- fprintf ( stderr , "got ack %d %s\n " , ack ,
402
- sha1_to_hex (result_sha1 ));
414
+ if (ack )
415
+ print_verbose ( args , "got ack %d %s" , ack ,
416
+ sha1_to_hex (result_sha1 ));
403
417
switch (ack ) {
404
418
case ACK :
405
419
flushes = 0 ;
@@ -438,8 +452,7 @@ static int find_common(struct fetch_pack_args *args,
438
452
} while (ack );
439
453
flushes -- ;
440
454
if (got_continue && MAX_IN_VAIN < in_vain ) {
441
- if (args -> verbose )
442
- fprintf (stderr , "giving up\n" );
455
+ print_verbose (args , "giving up" );
443
456
break ; /* give up */
444
457
}
445
458
}
@@ -449,8 +462,7 @@ static int find_common(struct fetch_pack_args *args,
449
462
packet_buf_write (& req_buf , "done\n" );
450
463
send_request (args , fd [1 ], & req_buf );
451
464
}
452
- if (args -> verbose )
453
- fprintf (stderr , "done\n" );
465
+ print_verbose (args , "done" );
454
466
if (retval != 0 ) {
455
467
multi_ack = 0 ;
456
468
flushes ++ ;
@@ -462,9 +474,8 @@ static int find_common(struct fetch_pack_args *args,
462
474
while (flushes || multi_ack ) {
463
475
int ack = get_ack (fd [0 ], result_sha1 );
464
476
if (ack ) {
465
- if (args -> verbose )
466
- fprintf (stderr , "got ack (%d) %s\n" , ack ,
467
- sha1_to_hex (result_sha1 ));
477
+ print_verbose (args , "got ack (%d) %s" , ack ,
478
+ sha1_to_hex (result_sha1 ));
468
479
if (ack == ACK )
469
480
return 0 ;
470
481
multi_ack = 1 ;
@@ -509,9 +520,8 @@ static void mark_recent_complete_commits(struct fetch_pack_args *args,
509
520
unsigned long cutoff )
510
521
{
511
522
while (complete && cutoff <= complete -> item -> date ) {
512
- if (args -> verbose )
513
- fprintf (stderr , "Marking %s as complete\n" ,
514
- oid_to_hex (& complete -> item -> object .oid ));
523
+ print_verbose (args , "Marking %s as complete" ,
524
+ oid_to_hex (& complete -> item -> object .oid ));
515
525
pop_most_recent_commit (& complete , COMPLETE );
516
526
}
517
527
}
@@ -652,18 +662,12 @@ static int everything_local(struct fetch_pack_args *args,
652
662
o = lookup_object (remote );
653
663
if (!o || !(o -> flags & COMPLETE )) {
654
664
retval = 0 ;
655
- if (!args -> verbose )
656
- continue ;
657
- fprintf (stderr ,
658
- "want %s (%s)\n" , sha1_to_hex (remote ),
659
- ref -> name );
665
+ print_verbose (args , "want %s (%s)" , sha1_to_hex (remote ),
666
+ ref -> name );
660
667
continue ;
661
668
}
662
- if (!args -> verbose )
663
- continue ;
664
- fprintf (stderr ,
665
- "already have %s (%s)\n" , sha1_to_hex (remote ),
666
- ref -> name );
669
+ print_verbose (args , "already have %s (%s)" , sha1_to_hex (remote ),
670
+ ref -> name );
667
671
}
668
672
return retval ;
669
673
}
@@ -810,39 +814,32 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
810
814
if ((args -> depth > 0 || is_repository_shallow ()) && !server_supports ("shallow" ))
811
815
die ("Server does not support shallow clients" );
812
816
if (server_supports ("multi_ack_detailed" )) {
813
- if (args -> verbose )
814
- fprintf (stderr , "Server supports multi_ack_detailed\n" );
817
+ print_verbose (args , "Server supports multi_ack_detailed" );
815
818
multi_ack = 2 ;
816
819
if (server_supports ("no-done" )) {
817
- if (args -> verbose )
818
- fprintf (stderr , "Server supports no-done\n" );
820
+ print_verbose (args , "Server supports no-done" );
819
821
if (args -> stateless_rpc )
820
822
no_done = 1 ;
821
823
}
822
824
}
823
825
else if (server_supports ("multi_ack" )) {
824
- if (args -> verbose )
825
- fprintf (stderr , "Server supports multi_ack\n" );
826
+ print_verbose (args , "Server supports multi_ack" );
826
827
multi_ack = 1 ;
827
828
}
828
829
if (server_supports ("side-band-64k" )) {
829
- if (args -> verbose )
830
- fprintf (stderr , "Server supports side-band-64k\n" );
830
+ print_verbose (args , "Server supports side-band-64k" );
831
831
use_sideband = 2 ;
832
832
}
833
833
else if (server_supports ("side-band" )) {
834
- if (args -> verbose )
835
- fprintf (stderr , "Server supports side-band\n" );
834
+ print_verbose (args , "Server supports side-band" );
836
835
use_sideband = 1 ;
837
836
}
838
837
if (server_supports ("allow-tip-sha1-in-want" )) {
839
- if (args -> verbose )
840
- fprintf (stderr , "Server supports allow-tip-sha1-in-want\n" );
838
+ print_verbose (args , "Server supports allow-tip-sha1-in-want" );
841
839
allow_unadvertised_object_request |= ALLOW_TIP_SHA1 ;
842
840
}
843
841
if (server_supports ("allow-reachable-sha1-in-want" )) {
844
- if (args -> verbose )
845
- fprintf (stderr , "Server supports allow-reachable-sha1-in-want\n" );
842
+ print_verbose (args , "Server supports allow-reachable-sha1-in-want" );
846
843
allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1 ;
847
844
}
848
845
if (!server_supports ("thin-pack" ))
@@ -851,17 +848,16 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
851
848
args -> no_progress = 0 ;
852
849
if (!server_supports ("include-tag" ))
853
850
args -> include_tag = 0 ;
854
- if (server_supports ("ofs-delta" )) {
855
- if (args -> verbose )
856
- fprintf (stderr , "Server supports ofs-delta\n" );
857
- } else
851
+ if (server_supports ("ofs-delta" ))
852
+ print_verbose (args , "Server supports ofs-delta" );
853
+ else
858
854
prefer_ofs_delta = 0 ;
859
855
860
856
if ((agent_feature = server_feature_value ("agent" , & agent_len ))) {
861
857
agent_supported = 1 ;
862
- if (args -> verbose && agent_len )
863
- fprintf ( stderr , "Server version is %.*s\n " ,
864
- agent_len , agent_feature );
858
+ if (agent_len )
859
+ print_verbose ( args , "Server version is %.*s" ,
860
+ agent_len , agent_feature );
865
861
}
866
862
867
863
if (everything_local (args , & ref , sought , nr_sought )) {
0 commit comments