From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
"Johannes Sixt" <j.sixt@viscovery.net>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 1/4] notes: preserve object type given by "add -C"
Date: Fri, 11 May 2012 08:25:03 +0700 [thread overview]
Message-ID: <1336699506-28388-2-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1336658701-9004-1-git-send-email-pclouds@gmail.com>
_Automatically_ converting a non-blob object to a blob is
wrong. Either this way, or reject non-blob objects upfront.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
builtin/notes.c | 8 +++++---
t/t3301-notes.sh | 10 ++++++++++
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/builtin/notes.c b/builtin/notes.c
index 3644d14..9840269 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -98,6 +98,7 @@ struct msg_arg {
int given;
int use_editor;
struct strbuf buf;
+ enum object_type type;
};
static int list_each_note(const unsigned char *object_sha1,
@@ -211,7 +212,7 @@ static void create_note(const unsigned char *object, struct msg_arg *msg,
sha1_to_hex(object));
hashclr(result);
} else {
- if (write_sha1_file(msg->buf.buf, msg->buf.len, blob_type, result)) {
+ if (write_sha1_file(msg->buf.buf, msg->buf.len, typename(msg->type), result)) {
error(_("unable to write note object"));
if (path)
error(_("The note contents has been left in %s"),
@@ -278,6 +279,7 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
free(buf);
msg->given = 1;
+ msg->type = type;
return 0;
}
@@ -529,7 +531,7 @@ static int add(int argc, const char **argv, const char *prefix)
unsigned char object[20], new_note[20];
char logmsg[100];
const unsigned char *note;
- struct msg_arg msg = { 0, 0, STRBUF_INIT };
+ struct msg_arg msg = { 0, 0, STRBUF_INIT, OBJ_BLOB };
struct option options[] = {
{ OPTION_CALLBACK, 'm', "message", &msg, "msg",
"note contents as a string", PARSE_OPT_NONEG,
@@ -686,7 +688,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
const unsigned char *note;
char logmsg[100];
const char * const *usage;
- struct msg_arg msg = { 0, 0, STRBUF_INIT };
+ struct msg_arg msg = { 0, 0, STRBUF_INIT, OBJ_BLOB };
struct option options[] = {
{ OPTION_CALLBACK, 'm', "message", &msg, "msg",
"note contents as a string", PARSE_OPT_NONEG,
diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index 16de05a..d3fd341 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -1222,4 +1222,14 @@ test_expect_success 'git notes get-ref (--ref)' '
test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz"
'
+test_expect_success 'add -C happily takes object of any kind' '
+ git notes add -f -C HEAD^{tree}
+'
+
+test_expect_success 'non-blobs notes are shown in human-readable form' '
+ git notes show HEAD >actual &&
+ git show `git rev-parse HEAD^{tree}` >expected &&
+ test_cmp expected actual
+'
+
test_done
--
1.7.3.1.256.g2539c.dirty
next prev parent reply other threads:[~2012-05-11 1:26 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-08 13:11 [PATCH] notes: do not accept non-blobs as new notes Nguyễn Thái Ngọc Duy
2012-05-08 16:03 ` Jeff King
2012-05-08 16:26 ` Junio C Hamano
2012-05-09 8:19 ` Nguyen Thai Ngoc Duy
2012-05-09 17:37 ` Jeff King
2012-05-09 17:52 ` Junio C Hamano
2012-05-09 18:43 ` Jeff King
2012-05-10 14:04 ` [PATCH 0/4] git-notes ui fixes regarding non-blobs notes Nguyễn Thái Ngọc Duy
2012-05-10 14:04 ` [PATCH 1/4] notes: preserve object type given by "add -C" Nguyễn Thái Ngọc Duy
2012-05-10 14:04 ` [PATCH 2/4] notes: "add -c" refuses to open an editor with non-blobs Nguyễn Thái Ngọc Duy
2012-05-10 15:26 ` Johannes Sixt
2012-05-11 1:11 ` Nguyen Thai Ngoc Duy
2012-05-10 14:05 ` [PATCH 3/4] notes: refuse to edit non-blobs Nguyễn Thái Ngọc Duy
2012-05-10 14:05 ` [PATCH 4/4] notes: refuse to append to non-blob notes Nguyễn Thái Ngọc Duy
2012-05-10 14:43 ` [PATCH 4/4] notes: only append a blob to a blob Nguyễn Thái Ngọc Duy
2012-05-10 15:19 ` Jeff King
2012-05-10 15:31 ` Nguyen Thai Ngoc Duy
2012-05-10 15:45 ` Jeff King
2012-05-11 3:57 ` Junio C Hamano
2012-05-10 14:29 ` [PATCH 0/4] git-notes ui fixes regarding non-blobs notes Jeff King
2012-05-11 1:25 ` [PATCH v2 0/4] non-blob notes fixes Nguyễn Thái Ngọc Duy
2012-05-11 1:25 ` Nguyễn Thái Ngọc Duy [this message]
2012-05-11 21:16 ` [PATCH v2 1/4] notes: preserve object type given by "add -C" Junio C Hamano
2012-05-12 5:20 ` Nguyen Thai Ngoc Duy
2012-05-12 6:12 ` Junio C Hamano
2012-05-12 6:58 ` Nguyen Thai Ngoc Duy
2012-05-11 1:25 ` [PATCH v2 2/4] notes: "add -c" refuses to open an editor with non-blobs Nguyễn Thái Ngọc Duy
2012-05-11 1:25 ` [PATCH v2 3/4] notes: refuse to edit non-blobs Nguyễn Thái Ngọc Duy
2012-05-11 1:25 ` [PATCH v2 4/4] notes: only allow to append a blob to a blob Nguyễn Thái Ngọc Duy
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1336699506-28388-2-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j.sixt@viscovery.net \
--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.
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 NNTP newsgroup(s).