Skip to content

Commit d2ef3cb

Browse files
avargitster
authored andcommitted
object-name: iterate ambiguous objects before showing header
Change the "The candidates are" header that's shown for ambiguous objects to be shown after we've iterated over all of the objects. If we get any errors while doing so we don't want to split up the the header and the list as a result. The two will now be printed together, as shown in the updated testcase. As we're accumulating the lines into as "struct strbuf" before emitting them we need to add a trailing newline to the call in show_ambiguous_object(). This and the change from "The candidates are:" to "The candidates are:\n%s" helps to give translators more context. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 851b3d7 commit d2ef3cb

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

object-name.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,16 @@ static int init_object_disambiguation(struct repository *r,
351351
return 0;
352352
}
353353

354+
struct ambiguous_output {
355+
const struct disambiguate_state *ds;
356+
struct strbuf advice;
357+
};
358+
354359
static int show_ambiguous_object(const struct object_id *oid, void *data)
355360
{
356-
const struct disambiguate_state *ds = data;
361+
struct ambiguous_output *state = data;
362+
const struct disambiguate_state *ds = state->ds;
363+
struct strbuf *advice = &state->advice;
357364
struct strbuf desc = STRBUF_INIT;
358365
int type;
359366
const char *hash;
@@ -452,7 +459,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
452459
* you'll probably want to swap the "%s" and leading " " space
453460
* around.
454461
*/
455-
advise(_(" %s"), desc.buf);
462+
strbuf_addf(advice, _(" %s\n"), desc.buf);
456463

457464
strbuf_release(&desc);
458465
return 0;
@@ -551,6 +558,10 @@ static enum get_oid_result get_short_oid(struct repository *r,
551558

552559
if (!quietly && (status == SHORT_NAME_AMBIGUOUS)) {
553560
struct oid_array collect = OID_ARRAY_INIT;
561+
struct ambiguous_output out = {
562+
.ds = &ds,
563+
.advice = STRBUF_INIT,
564+
};
554565

555566
error(_("short object ID %s is ambiguous"), ds.hex_pfx);
556567

@@ -563,13 +574,21 @@ static enum get_oid_result get_short_oid(struct repository *r,
563574
if (!ds.ambiguous)
564575
ds.fn = NULL;
565576

566-
advise(_("The candidates are:"));
567577
repo_for_each_abbrev(r, ds.hex_pfx, collect_ambiguous, &collect);
568578
sort_ambiguous_oid_array(r, &collect);
569579

570-
if (oid_array_for_each(&collect, show_ambiguous_object, &ds))
580+
if (oid_array_for_each(&collect, show_ambiguous_object, &out))
571581
BUG("show_ambiguous_object shouldn't return non-zero");
582+
583+
/*
584+
* TRANSLATORS: The argument is the list of ambiguous
585+
* objects composed in show_ambiguous_object(). See
586+
* its "TRANSLATORS" comments for details.
587+
*/
588+
advise(_("The candidates are:\n%s"), out.advice.buf);
589+
572590
oid_array_clear(&collect);
591+
strbuf_release(&out.advice);
573592
}
574593

575594
return status;

t/t1512-rev-parse-disambiguation.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ test_expect_success 'ambiguous loose bad object parsed as OBJ_BAD' '
7373
7474
test_cmp_failed_rev_parse blob.bad bad0 <<-\EOF
7575
error: short object ID bad0... is ambiguous
76-
hint: The candidates are:
7776
fatal: invalid object type
7877
EOF
7978
'
@@ -94,11 +93,11 @@ test_expect_success POSIXPERM 'ambigous zlib corrupt loose blob' '
9493
9594
test_cmp_failed_rev_parse blob.corrupt cafe <<-\EOF
9695
error: short object ID cafe... is ambiguous
97-
hint: The candidates are:
9896
error: inflate: data stream error (incorrect header check)
9997
error: unable to unpack cafe... header
10098
error: inflate: data stream error (incorrect header check)
10199
error: unable to unpack cafe... header
100+
hint: The candidates are:
102101
hint: cafe... [bad object]
103102
hint: cafe... blob
104103
fatal: ambiguous argument '\''cafe...'\'': unknown revision or path not in the working tree.

0 commit comments

Comments
 (0)