Skip to content

Commit ba5e8a0

Browse files
avargitster
authored andcommitted
object-name: make ambiguous object output translatable
Change the output of show_ambiguous_object() added in [1] and last tweaked in [2] and the preceding commit to be more friendly to translators. By being able to customize the "<SP><SP>%s\n" format we're even ready for RTL languages, who'd presumably like to change that to "%s<SP><SP>\n". In the case of the existing "tag [tag could not be parsed]" output we'll now instead emit "[bad tag, could not parse it]". This is consistent with the "[bad object]" output. Rephrasing the message like this is possible because we're not unconditionally adding the type_name() at the beginning. 1. 1ffa26c (get_short_sha1: list ambiguous objects on error, 2016-09-26) 2. 5cc044e (get_short_oid: sort ambiguous objects by type, then SHA-1, 2018-05-10) Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Josh Steadmon <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 667a560 commit ba5e8a0

File tree

1 file changed

+68
-10
lines changed

1 file changed

+68
-10
lines changed

object-name.c

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -356,40 +356,98 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
356356
const struct disambiguate_state *ds = data;
357357
struct strbuf desc = STRBUF_INIT;
358358
int type;
359+
const char *hash;
359360

360361
if (ds->fn && !ds->fn(ds->repo, oid, ds->cb_data))
361362
return 0;
362363

364+
hash = repo_find_unique_abbrev(ds->repo, oid, DEFAULT_ABBREV);
363365
type = oid_object_info(ds->repo, oid, NULL);
364366

365367
if (type < 0) {
366-
strbuf_addstr(&desc, "[bad object]");
368+
/*
369+
* TRANSLATORS: This is a line of ambiguous object
370+
* output shown when we cannot look up or parse the
371+
* object in question. E.g. "deadbeef [bad object]".
372+
*/
373+
strbuf_addf(&desc, _("%s [bad object]"), hash);
367374
goto out;
368375
}
369376

370377
assert(type == OBJ_TREE || type == OBJ_COMMIT ||
371378
type == OBJ_BLOB || type == OBJ_TAG);
372-
strbuf_addstr(&desc, type_name(type));
373379

374380
if (type == OBJ_COMMIT) {
381+
struct strbuf date = STRBUF_INIT;
382+
struct strbuf msg = STRBUF_INIT;
375383
struct commit *commit = lookup_commit(ds->repo, oid);
384+
376385
if (commit) {
377386
struct pretty_print_context pp = {0};
378387
pp.date_mode.type = DATE_SHORT;
379-
format_commit_message(commit, " %ad - %s", &desc, &pp);
388+
format_commit_message(commit, "%ad", &date, &pp);
389+
format_commit_message(commit, "%s", &msg, &pp);
380390
}
391+
392+
/*
393+
* TRANSLATORS: This is a line of ambiguous commit
394+
* object output. E.g.:
395+
*
396+
* "deadbeef commit 2021-01-01 - Some Commit Message"
397+
*/
398+
strbuf_addf(&desc, _("%s commit %s - %s"),
399+
hash, date.buf, msg.buf);
400+
401+
strbuf_release(&date);
402+
strbuf_release(&msg);
381403
} else if (type == OBJ_TAG) {
382404
struct tag *tag = lookup_tag(ds->repo, oid);
383-
if (!parse_tag(tag) && tag->tag)
384-
strbuf_addf(&desc, " %s", tag->tag);
385-
else
386-
strbuf_addstr(&desc, " [tag could not be parsed]");
405+
406+
if (!parse_tag(tag) && tag->tag) {
407+
/*
408+
* TRANSLATORS: This is a line of ambiguous
409+
* tag object output. E.g.:
410+
*
411+
* "deadbeef tag Some Tag Message"
412+
*
413+
* The second argument is the "tag" string
414+
* from object.c.
415+
*/
416+
strbuf_addf(&desc, _("%s tag %s"), hash, tag->tag);
417+
} else {
418+
/*
419+
* TRANSLATORS: This is a line of ambiguous
420+
* tag object output where we couldn't parse
421+
* the tag itself. E.g.:
422+
*
423+
* "deadbeef tag [bad tag, could not parse it]"
424+
*/
425+
strbuf_addf(&desc, _("%s [bad tag, could not parse it]"),
426+
hash);
427+
}
428+
} else if (type == OBJ_TREE) {
429+
/*
430+
* TRANSLATORS: This is a line of ambiguous <type>
431+
* object output. E.g. "deadbeef tree".
432+
*/
433+
strbuf_addf(&desc, _("%s tree"), hash);
434+
} else if (type == OBJ_BLOB) {
435+
/*
436+
* TRANSLATORS: This is a line of ambiguous <type>
437+
* object output. E.g. "deadbeef blob".
438+
*/
439+
strbuf_addf(&desc, _("%s blob"), hash);
387440
}
388441

442+
389443
out:
390-
advise(" %s %s",
391-
repo_find_unique_abbrev(ds->repo, oid, DEFAULT_ABBREV),
392-
desc.buf);
444+
/*
445+
* TRANSLATORS: This is line item of ambiguous object output
446+
* from describe_ambiguous_object() above. For RTL languages
447+
* you'll probably want to swap the "%s" and leading " " space
448+
* around.
449+
*/
450+
advise(_(" %s"), desc.buf);
393451

394452
strbuf_release(&desc);
395453
return 0;

0 commit comments

Comments
 (0)