[RFC/PATCHv0 3/4] fast-import: Support adding notes to non-commits

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"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@xxxxxxxxxxxx>
Signed-off-by: Johan Herland <johan@xxxxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]