@@ -351,35 +351,118 @@ static int init_object_disambiguation(struct repository *r,
351
351
return 0 ;
352
352
}
353
353
354
+ struct ambiguous_output {
355
+ const struct disambiguate_state * ds ;
356
+ struct strbuf advice ;
357
+ struct strbuf sb ;
358
+ };
359
+
354
360
static int show_ambiguous_object (const struct object_id * oid , void * data )
355
361
{
356
- const struct disambiguate_state * ds = data ;
357
- struct strbuf desc = STRBUF_INIT ;
362
+ struct ambiguous_output * state = data ;
363
+ const struct disambiguate_state * ds = state -> ds ;
364
+ struct strbuf * advice = & state -> advice ;
365
+ struct strbuf * sb = & state -> sb ;
358
366
int type ;
367
+ const char * hash ;
359
368
360
369
if (ds -> fn && !ds -> fn (ds -> repo , oid , ds -> cb_data ))
361
370
return 0 ;
362
371
372
+ hash = repo_find_unique_abbrev (ds -> repo , oid , DEFAULT_ABBREV );
363
373
type = oid_object_info (ds -> repo , oid , NULL );
374
+
375
+ if (type < 0 ) {
376
+ /*
377
+ * TRANSLATORS: This is a line of ambiguous object
378
+ * output shown when we cannot look up or parse the
379
+ * object in question. E.g. "deadbeef [bad object]".
380
+ */
381
+ strbuf_addf (sb , _ ("%s [bad object]" ), hash );
382
+ goto out ;
383
+ }
384
+
385
+ assert (type == OBJ_TREE || type == OBJ_COMMIT ||
386
+ type == OBJ_BLOB || type == OBJ_TAG );
387
+
364
388
if (type == OBJ_COMMIT ) {
389
+ struct strbuf date = STRBUF_INIT ;
390
+ struct strbuf msg = STRBUF_INIT ;
365
391
struct commit * commit = lookup_commit (ds -> repo , oid );
392
+
366
393
if (commit ) {
367
394
struct pretty_print_context pp = {0 };
368
395
pp .date_mode .type = DATE_SHORT ;
369
- format_commit_message (commit , " %ad - %s" , & desc , & pp );
396
+ format_commit_message (commit , "%ad" , & date , & pp );
397
+ format_commit_message (commit , "%s" , & msg , & pp );
370
398
}
399
+
400
+ /*
401
+ * TRANSLATORS: This is a line of ambiguous commit
402
+ * object output. E.g.:
403
+ *
404
+ * "deadbeef commit 2021-01-01 - Some Commit Message"
405
+ */
406
+ strbuf_addf (sb , _ ("%s commit %s - %s" ), hash , date .buf ,
407
+ msg .buf );
408
+
409
+ strbuf_release (& date );
410
+ strbuf_release (& msg );
371
411
} else if (type == OBJ_TAG ) {
372
412
struct tag * tag = lookup_tag (ds -> repo , oid );
373
- if (!parse_tag (tag ) && tag -> tag )
374
- strbuf_addf (& desc , " %s" , tag -> tag );
413
+
414
+ if (!parse_tag (tag ) && tag -> tag ) {
415
+ /*
416
+ * TRANSLATORS: This is a line of ambiguous
417
+ * tag object output. E.g.:
418
+ *
419
+ * "deadbeef tag 2022-01-01 - Some Tag Message"
420
+ *
421
+ * The second argument is the YYYY-MM-DD found
422
+ * in the tag.
423
+ *
424
+ * The third argument is the "tag" string
425
+ * from object.c.
426
+ */
427
+ strbuf_addf (sb , _ ("%s tag %s - %s" ), hash ,
428
+ show_date (tag -> date , 0 , DATE_MODE (SHORT )),
429
+ tag -> tag );
430
+ } else {
431
+ /*
432
+ * TRANSLATORS: This is a line of ambiguous
433
+ * tag object output where we couldn't parse
434
+ * the tag itself. E.g.:
435
+ *
436
+ * "deadbeef [bad tag, could not parse it]"
437
+ */
438
+ strbuf_addf (sb , _ ("%s [bad tag, could not parse it]" ),
439
+ hash );
440
+ }
441
+ } else if (type == OBJ_TREE ) {
442
+ /*
443
+ * TRANSLATORS: This is a line of ambiguous <type>
444
+ * object output. E.g. "deadbeef tree".
445
+ */
446
+ strbuf_addf (sb , _ ("%s tree" ), hash );
447
+ } else if (type == OBJ_BLOB ) {
448
+ /*
449
+ * TRANSLATORS: This is a line of ambiguous <type>
450
+ * object output. E.g. "deadbeef blob".
451
+ */
452
+ strbuf_addf (sb , _ ("%s blob" ), hash );
375
453
}
376
454
377
- advise (" %s %s%s" ,
378
- repo_find_unique_abbrev (ds -> repo , oid , DEFAULT_ABBREV ),
379
- type_name (type ) ? type_name (type ) : "unknown type" ,
380
- desc .buf );
381
455
382
- strbuf_release (& desc );
456
+ out :
457
+ /*
458
+ * TRANSLATORS: This is line item of ambiguous object output
459
+ * from describe_ambiguous_object() above. For RTL languages
460
+ * you'll probably want to swap the "%s" and leading " " space
461
+ * around.
462
+ */
463
+ strbuf_addf (advice , _ (" %s\n" ), sb -> buf );
464
+
465
+ strbuf_reset (sb );
383
466
return 0 ;
384
467
}
385
468
@@ -476,6 +559,11 @@ static enum get_oid_result get_short_oid(struct repository *r,
476
559
477
560
if (!quietly && (status == SHORT_NAME_AMBIGUOUS )) {
478
561
struct oid_array collect = OID_ARRAY_INIT ;
562
+ struct ambiguous_output out = {
563
+ .ds = & ds ,
564
+ .sb = STRBUF_INIT ,
565
+ .advice = STRBUF_INIT ,
566
+ };
479
567
480
568
error (_ ("short object ID %s is ambiguous" ), ds .hex_pfx );
481
569
@@ -488,13 +576,22 @@ static enum get_oid_result get_short_oid(struct repository *r,
488
576
if (!ds .ambiguous )
489
577
ds .fn = NULL ;
490
578
491
- advise (_ ("The candidates are:" ));
492
579
repo_for_each_abbrev (r , ds .hex_pfx , collect_ambiguous , & collect );
493
580
sort_ambiguous_oid_array (r , & collect );
494
581
495
- if (oid_array_for_each (& collect , show_ambiguous_object , & ds ))
582
+ if (oid_array_for_each (& collect , show_ambiguous_object , & out ))
496
583
BUG ("show_ambiguous_object shouldn't return non-zero" );
584
+
585
+ /*
586
+ * TRANSLATORS: The argument is the list of ambiguous
587
+ * objects composed in show_ambiguous_object(). See
588
+ * its "TRANSLATORS" comments for details.
589
+ */
590
+ advise (_ ("The candidates are:\n%s" ), out .advice .buf );
591
+
497
592
oid_array_clear (& collect );
593
+ strbuf_release (& out .advice );
594
+ strbuf_release (& out .sb );
498
595
}
499
596
500
597
return status ;
0 commit comments