git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Herland <johan@herland.net>
To: Mike Hommey <mh@glandium.org>
Cc: Git mailing list <git@vger.kernel.org>,
	Johan Herland <johan@herland.net>
Subject: [RFC/PATCHv0 3/4] fast-import: Support adding notes to non-commits
Date: Mon,  5 Jan 2015 04:39:37 +0100	[thread overview]
Message-ID: <1420429178-20336-3-git-send-email-johan@herland.net> (raw)
In-Reply-To: <1420429178-20336-1-git-send-email-johan@herland.net>

"git notes" allows adding notes to non-commit objects, but fast-import
restricts the 'notemodify' command to only add notes for commit objects.
Remove that silly restriction from fast-import.

Suggested-by: Mike Hommey <mh@glandium.org>
Signed-off-by: Johan Herland <johan@herland.net>
---
 fast-import.c                | 12 ++++------
 t/t9301-fast-import-notes.sh | 56 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 8 deletions(-)

diff --git a/fast-import.c b/fast-import.c
index aa7b64e..b6df00b 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -2498,16 +2498,12 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
 	} else if (*p == ':') {
 		uintmax_t commit_mark = parse_mark_ref_eol(p);
 		struct object_entry *commit_oe = find_mark(commit_mark);
-		if (commit_oe->type != OBJ_COMMIT)
-			die("Mark :%" PRIuMAX " not a commit", commit_mark);
 		hashcpy(commit_sha1, commit_oe->idx.sha1);
 	} else if (!get_sha1(p, commit_sha1)) {
-		unsigned long size;
-		char *buf = read_object_with_reference(commit_sha1,
-			commit_type, &size, commit_sha1);
-		if (!buf || size < 46)
-			die("Not a valid commit: %s", p);
-		free(buf);
+		if (!find_object(commit_sha1)) {
+			if (sha1_object_info(commit_sha1, NULL) < 0)
+				die("Not a valid object: %s", p);
+		}
 	} else
 		die("Invalid ref name or SHA1 expression: %s", p);
 
diff --git a/t/t9301-fast-import-notes.sh b/t/t9301-fast-import-notes.sh
index 83acf68..b8ff673 100755
--- a/t/t9301-fast-import-notes.sh
+++ b/t/t9301-fast-import-notes.sh
@@ -679,4 +679,60 @@ test_expect_success "add notes to $num_commits commits in each of $num_notes_ref
 
 '
 
+tree4=$(git rev-parse refs/heads/master^{tree})
+blob4=$(git rev-parse refs/heads/master:bar)
+
+test_tick
+cat >input <<INPUT_END
+commit refs/notes/noncommits
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+data <<COMMIT
+adding notes to non-commits
+COMMIT
+
+N inline $tree4
+data <<EOF
+note for tree object
+EOF
+
+N inline $blob4
+data <<EOF
+note for blob object
+EOF
+
+INPUT_END
+
+test_expect_success 'add notes to non-commits' "
+
+	git fast-import <input &&
+	echo 'note for tree object' >expect &&
+	git notes --ref noncommits show $tree4 >actual &&
+	test_cmp expect actual &&
+	echo 'note for blob object' >expect &&
+	git notes --ref noncommits show $blob4 >actual &&
+	test_cmp expect actual
+
+"
+
+test_tick
+cat >input <<INPUT_END
+commit refs/notes/nonobjects
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+data <<COMMIT
+adding notes to non-objects MUST FAIL
+COMMIT
+
+N inline deadbeefdeadbeefdeadbeefdeadbeefdeadbeef
+data <<EOF
+note for missing object
+EOF
+
+INPUT_END
+
+test_expect_success 'cannot add notes to non-objects' "
+
+	test_must_fail git fast-import <input
+
+"
+
 test_done
-- 
2.1.1.392.g062cc5d

  parent reply	other threads:[~2015-01-05  3:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-23  0:06 fast-import's notemodify doesn't work the same as git notes Mike Hommey
2015-01-05  3:37 ` Johan Herland
2015-01-05  3:39   ` [RFC/PATCHv0 1/4] fast-import.c:do_change_note_fanout(): Remove unneeded local var 't' Johan Herland
2015-01-05  3:39     ` [RFC/PATCHv0 2/4] fast-import.c:do_change_note_fanout(): Also apply load_tree() to initial root Johan Herland
2015-01-05  3:39     ` Johan Herland [this message]
2015-01-05  3:39     ` [RFC/PATCHv0 4/4] fast-import.c:note_change_n(): Rename commit_* to target_* Johan Herland

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=1420429178-20336-3-git-send-email-johan@herland.net \
    --to=johan@herland.net \
    --cc=git@vger.kernel.org \
    --cc=mh@glandium.org \
    /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).