@@ -256,7 +256,7 @@ static unsigned long finish_depth_computation(
256
256
return seen_commits ;
257
257
}
258
258
259
- static void display_name (struct commit_name * n )
259
+ static void append_name (struct commit_name * n , struct strbuf * dst )
260
260
{
261
261
if (n -> prio == 2 && !n -> tag ) {
262
262
n -> tag = lookup_tag (& n -> oid );
@@ -272,19 +272,18 @@ static void display_name(struct commit_name *n)
272
272
}
273
273
274
274
if (n -> tag )
275
- printf ( "%s" , n -> tag -> tag );
275
+ strbuf_addstr ( dst , n -> tag -> tag );
276
276
else
277
- printf ( "%s" , n -> path );
277
+ strbuf_addstr ( dst , n -> path );
278
278
}
279
279
280
- static void show_suffix (int depth , const struct object_id * oid )
280
+ static void append_suffix (int depth , const struct object_id * oid , struct strbuf * dst )
281
281
{
282
- printf ( "-%d-g%s" , depth , find_unique_abbrev (oid -> hash , abbrev ));
282
+ strbuf_addf ( dst , "-%d-g%s" , depth , find_unique_abbrev (oid -> hash , abbrev ));
283
283
}
284
284
285
- static void describe ( const char * arg , int last_one )
285
+ static void describe_commit ( struct object_id * oid , struct strbuf * dst )
286
286
{
287
- struct object_id oid ;
288
287
struct commit * cmit , * gave_up_on = NULL ;
289
288
struct commit_list * list ;
290
289
struct commit_name * n ;
@@ -293,26 +292,18 @@ static void describe(const char *arg, int last_one)
293
292
unsigned long seen_commits = 0 ;
294
293
unsigned int unannotated_cnt = 0 ;
295
294
296
- if (debug )
297
- fprintf (stderr , _ ("describe %s\n" ), arg );
298
-
299
- if (get_oid (arg , & oid ))
300
- die (_ ("Not a valid object name %s" ), arg );
301
- cmit = lookup_commit_reference (& oid );
302
- if (!cmit )
303
- die (_ ("%s is not a valid '%s' object" ), arg , commit_type );
295
+ cmit = lookup_commit_reference (oid );
304
296
305
297
n = find_commit_name (& cmit -> object .oid );
306
298
if (n && (tags || all || n -> prio == 2 )) {
307
299
/*
308
300
* Exact match to an existing ref.
309
301
*/
310
- display_name ( n );
302
+ append_name ( n , dst );
311
303
if (longformat )
312
- show_suffix (0 , n -> tag ? & n -> tag -> tagged -> oid : & oid );
304
+ append_suffix (0 , n -> tag ? & n -> tag -> tagged -> oid : oid , dst );
313
305
if (suffix )
314
- printf ("%s" , suffix );
315
- printf ("\n" );
306
+ strbuf_addstr (dst , suffix );
316
307
return ;
317
308
}
318
309
@@ -386,10 +377,9 @@ static void describe(const char *arg, int last_one)
386
377
if (!match_cnt ) {
387
378
struct object_id * cmit_oid = & cmit -> object .oid ;
388
379
if (always ) {
389
- printf ( "%s" , find_unique_abbrev (cmit_oid -> hash , abbrev ));
380
+ strbuf_addstr ( dst , find_unique_abbrev (cmit_oid -> hash , abbrev ));
390
381
if (suffix )
391
- printf ("%s" , suffix );
392
- printf ("\n" );
382
+ strbuf_addstr (dst , suffix );
393
383
return ;
394
384
}
395
385
if (unannotated_cnt )
@@ -437,15 +427,36 @@ static void describe(const char *arg, int last_one)
437
427
}
438
428
}
439
429
440
- display_name (all_matches [0 ].name );
430
+ append_name (all_matches [0 ].name , dst );
441
431
if (abbrev )
442
- show_suffix (all_matches [0 ].depth , & cmit -> object .oid );
432
+ append_suffix (all_matches [0 ].depth , & cmit -> object .oid , dst );
443
433
if (suffix )
444
- printf ("%s" , suffix );
445
- printf ("\n" );
434
+ strbuf_addstr (dst , suffix );
435
+ }
436
+
437
+ static void describe (const char * arg , int last_one )
438
+ {
439
+ struct object_id oid ;
440
+ struct commit * cmit ;
441
+ struct strbuf sb = STRBUF_INIT ;
442
+
443
+ if (debug )
444
+ fprintf (stderr , _ ("describe %s\n" ), arg );
445
+
446
+ if (get_oid (arg , & oid ))
447
+ die (_ ("Not a valid object name %s" ), arg );
448
+ cmit = lookup_commit_reference (& oid );
449
+ if (!cmit )
450
+ die (_ ("%s is not a valid '%s' object" ), arg , commit_type );
451
+
452
+ describe_commit (& oid , & sb );
453
+
454
+ puts (sb .buf );
446
455
447
456
if (!last_one )
448
457
clear_commit_marks (cmit , -1 );
458
+
459
+ strbuf_release (& sb );
449
460
}
450
461
451
462
int cmd_describe (int argc , const char * * argv , const char * prefix )
0 commit comments