--- v8
+++ v6
@@ -1,141 +1,60 @@
-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.
+Make the ambiguous tag object output nicer in the case of tag objects
+such as ebf3c04b262 (Git 2.32, 2021-06-06) by including the date in
+the "tagger" header. I.e.:
-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".
+ $ git rev-parse b7e68
+ error: short object ID b7e68 is ambiguous
+ hint: The candidates are:
+ hint: b7e68c41d92 tag 2021-06-06 - v2.32.0
+ hint: b7e68ae18e0 commit 2019-12-23 - bisect: use the standard 'if (!var)' way to check for 0
+ hint: b7e68f6b413 tree
+ hint: b7e68490b97 blob
+ b7e68
+ [...]
-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.
+Before this we'd emit a "tag" line of:
-1. 1ffa26c461 (get_short_sha1: list ambiguous objects on error,
- 2016-09-26)
-2. 5cc044e0257 (get_short_oid: sort ambiguous objects by type,
- then SHA-1, 2018-05-10)
+ hint: b7e68c41d92 tag v2.32.0
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
-Signed-off-by: Josh Steadmon <steadmon@google.com>
---
- object-name.c | 78 ++++++++++++++++++++++++++++++++++++++++++++-------
- 1 file changed, 68 insertions(+), 10 deletions(-)
+ object-name.c | 11 ++++++++---
+ 1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/object-name.c b/object-name.c
-index 298b742bac9..f31b50bc315 100644
+index dcf3ab99990..990f384129e 100644
--- a/object-name.c
+++ b/object-name.c
-@@ -356,40 +356,98 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
- const struct disambiguate_state *ds = data;
- struct strbuf desc = STRBUF_INIT;
- int type;
-+ const char *hash;
-
- if (ds->fn && !ds->fn(ds->repo, oid, ds->cb_data))
- return 0;
-
-+ hash = repo_find_unique_abbrev(ds->repo, oid, DEFAULT_ABBREV);
- type = oid_object_info(ds->repo, oid, NULL);
-
- if (type < 0) {
-- strbuf_addstr(&desc, "[bad object]");
-+ /*
-+ * TRANSLATORS: This is a line of ambiguous object
-+ * output shown when we cannot look up or parse the
-+ * object in question. E.g. "deadbeef [bad object]".
-+ */
-+ strbuf_addf(&desc, _("%s [bad object]"), hash);
- goto out;
- }
-
- assert(type == OBJ_TREE || type == OBJ_COMMIT ||
- type == OBJ_BLOB || type == OBJ_TAG);
-- strbuf_addstr(&desc, type_name(type));
-
- if (type == OBJ_COMMIT) {
-+ struct strbuf date = STRBUF_INIT;
-+ struct strbuf msg = STRBUF_INIT;
- struct commit *commit = lookup_commit(ds->repo, oid);
-+
- if (commit) {
- struct pretty_print_context pp = {0};
- pp.date_mode.type = DATE_SHORT;
-- format_commit_message(commit, " %ad - %s", &desc, &pp);
-+ format_commit_message(commit, "%ad", &date, &pp);
-+ format_commit_message(commit, "%s", &msg, &pp);
- }
-+
-+ /*
-+ * TRANSLATORS: This is a line of ambiguous commit
-+ * object output. E.g.:
-+ *
-+ * "deadbeef commit 2021-01-01 - Some Commit Message"
-+ */
-+ strbuf_addf(&desc, _("%s commit %s - %s"),
-+ hash, date.buf, msg.buf);
-+
-+ strbuf_release(&date);
-+ strbuf_release(&msg);
+@@ -403,21 +403,26 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
} else if (type == OBJ_TAG) {
struct tag *tag = lookup_tag(ds->repo, oid);
+ const char *tag_tag = "";
++ timestamp_t tag_date = 0;
+
- if (!parse_tag(tag) && tag->tag)
-- strbuf_addf(&desc, " %s", tag->tag);
-- else
-- strbuf_addstr(&desc, " [tag could not be parsed]");
-+
+ if (!parse_tag(tag) && tag->tag) {
-+ /*
-+ * TRANSLATORS: This is a line of ambiguous
-+ * tag object output. E.g.:
-+ *
-+ * "deadbeef tag Some Tag Message"
-+ *
-+ * The second argument is the "tag" string
-+ * from object.c.
-+ */
-+ strbuf_addf(&desc, _("%s tag %s"), hash, tag->tag);
-+ } else {
-+ /*
-+ * TRANSLATORS: This is a line of ambiguous
-+ * tag object output where we couldn't parse
-+ * the tag itself. E.g.:
-+ *
-+ * "deadbeef tag [bad tag, could not parse it]"
-+ */
-+ strbuf_addf(&desc, _("%s [bad tag, could not parse it]"),
-+ hash);
+ tag_tag = tag->tag;
++ tag_date = tag->date;
+ }
-+ } else if (type == OBJ_TREE) {
-+ /*
-+ * TRANSLATORS: This is a line of ambiguous <type>
-+ * object output. E.g. "deadbeef tree".
-+ */
-+ strbuf_addf(&desc, _("%s tree"), hash);
-+ } else if (type == OBJ_BLOB) {
-+ /*
-+ * TRANSLATORS: This is a line of ambiguous <type>
-+ * object output. E.g. "deadbeef blob".
-+ */
-+ strbuf_addf(&desc, _("%s blob"), hash);
- }
-+
- out:
-- advise(" %s %s",
-- repo_find_unique_abbrev(ds->repo, oid, DEFAULT_ABBREV),
-- desc.buf);
-+ /*
-+ * TRANSLATORS: This is line item of ambiguous object output
-+ * from describe_ambiguous_object() above. For RTL languages
-+ * you'll probably want to swap the "%s" and leading " " space
-+ * around.
-+ */
-+ advise(_(" %s"), desc.buf);
-
- strbuf_release(&desc);
- return 0;
+ /*
+ * TRANSLATORS: This is a line of
+ * ambiguous tag object output. E.g.:
+ *
+- * "deadbeef tag Some Tag Message"
++ * "deadbeef tag 2021-01-01 - Some Tag Message"
+ *
+ * The second argument is the "tag" string from
+ * object.c, it should (hopefully) already be
+ * translated.
+ */
+- strbuf_addf(&desc, _("%s tag %s"), hash, tag_tag);
++ strbuf_addf(&desc, _("%s tag %s - %s"), hash,
++ show_date(tag_date, 0, DATE_MODE(SHORT)),
++ tag_tag);
+ } else if (type == OBJ_TREE) {
+ /*
+ * TRANSLATORS: This is a line of ambiguous <type>
--
-2.35.0.890.gd7e422415d9
+2.34.1.1257.g2af47340c7b