From: cornelius.weig@tngtech.com
To: git@vger.kernel.org
Cc: Cornelius Weig <cornelius.weig@tngtech.com>,
karthik.188@gmail.com, peff@peff.net, gitster@pobox.com,
bitte.keine.werbung.einwerfen@googlemail.com
Subject: [PATCH v4] tag: generate useful reflog message
Date: Mon, 6 Feb 2017 23:24:15 +0100 [thread overview]
Message-ID: <20170206222416.28720-1-cornelius.weig@tngtech.com> (raw)
In-Reply-To: <xmqqpoiv15ew.fsf@gitster.mtv.corp.google.com>
From: Cornelius Weig <cornelius.weig@tngtech.com>
Thanks for taking a look at my last version.
> On the other hand, it's not like failing to describe the tagged
> commit in the reflog is such a grave error. If we can get away with
> being vague on a tag that points at an object of unknown type like
> the above code does, we could loosen the "oops, we thought we got a
> commit, but it turns out that we cannot read it" case below from
> die() to just stuffing generic _("commit object") in the reflog.
Good point. I agree that failing to create the message should be no reason to
die().
As you also pointed out, "internal object" is no reliable description
for unhandled object types. I changed that as well.
Changes wrt v3 (interdiff below):
- change default message for unhandled object types
- do not die if commit is not readable, but use default description instead
- test: use verbatim HT character instead of \t
Cornelius Weig (1):
tag: generate useful reflog message
builtin/tag.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
t/t7004-tag.sh | 16 +++++++++++++++-
2 files changed, 68 insertions(+), 2 deletions(-)
Interdiff v3..v4:
diff --git a/builtin/tag.c b/builtin/tag.c
index 638b68e..9b2eabd 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -323,19 +323,19 @@ static void create_reflog_msg(const unsigned char *sha1, struct strbuf *sb)
type = sha1_object_info(sha1, NULL);
switch (type) {
default:
- strbuf_addstr(sb, _("internal object"));
+ strbuf_addstr(sb, _("object of unknown type"));
break;
case OBJ_COMMIT:
- c = lookup_commit_reference(sha1);
- buf = read_sha1_file(sha1, &type, &size);
- if (!c || !buf) {
- die(_("commit object %s could not be read"),
- sha1_to_hex(sha1));
+ if ((buf = read_sha1_file(sha1, &type, &size)) != NULL) {
+ subject_len = find_commit_subject(buf, &subject_start);
+ strbuf_insert(sb, sb->len, subject_start, subject_len);
+ } else {
+ strbuf_addstr(sb, _("commit object"));
}
- subject_len = find_commit_subject(buf, &subject_start);
- strbuf_insert(sb, sb->len, subject_start, subject_len);
- strbuf_addf(sb, ", %s", show_date(c->date, 0, DATE_MODE(SHORT)));
free(buf);
+
+ if ((c = lookup_commit_reference(sha1)) != NULL)
+ strbuf_addf(sb, ", %s", show_date(c->date, 0, DATE_MODE(SHORT)));
break;
case OBJ_TREE:
strbuf_addstr(sb, _("tree object"));
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index 3c4cb58..894959f 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -86,7 +86,7 @@ test_expect_success 'creating a tag with --create-reflog should create reflog' '
test_when_finished "git tag -d tag_with_reflog" &&
git tag --create-reflog tag_with_reflog &&
git reflog exists refs/tags/tag_with_reflog &&
- sed -e "s/^.*\t//" .git/logs/refs/tags/tag_with_reflog > actual &&
+ sed -e "s/^.* //" .git/logs/refs/tags/tag_with_reflog > actual &&
test_cmp expected actual
'
@@ -96,7 +96,7 @@ test_expect_success 'annotated tag with --create-reflog has correct message' '
test_when_finished "git tag -d tag_with_reflog" &&
git tag -m "annotated tag" --create-reflog tag_with_reflog &&
git reflog exists refs/tags/tag_with_reflog &&
- sed -e "s/^.*\t//" .git/logs/refs/tags/tag_with_reflog > actual &&
+ sed -e "s/^.* //" .git/logs/refs/tags/tag_with_reflog > actual &&
test_cmp expected actual
'
--
2.10.2
next prev parent reply other threads:[~2017-02-06 22:25 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-05 21:42 [PATCH] tag: generate useful reflog message cornelius.weig
2017-02-05 23:18 ` [PATCH v2] " cornelius.weig
2017-02-05 23:25 ` [PATCH] " Junio C Hamano
2017-02-06 13:58 ` [PATCH v3] " cornelius.weig
2017-02-06 19:32 ` Junio C Hamano
2017-02-06 22:24 ` cornelius.weig [this message]
2017-02-06 22:24 ` [PATCH v4] " cornelius.weig
2017-02-08 21:28 ` Junio C Hamano
2017-02-08 22:28 ` Cornelius Weig
2017-02-08 23:44 ` Junio C Hamano
2017-02-08 22:41 ` [PATCH v5] " cornelius.weig
2017-02-06 16:54 ` [PATCH] " Cornelius Weig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170206222416.28720-1-cornelius.weig@tngtech.com \
--to=cornelius.weig@tngtech.com \
--cc=bitte.keine.werbung.einwerfen@googlemail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=karthik.188@gmail.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).