git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv4 0/9] Handling empty notes
@ 2014-11-09 12:30 Johan Herland
  2014-11-09 12:30 ` [PATCHv4 1/9] builtin/notes: Fix premature failure when trying to add the empty blob Johan Herland
                   ` (8 more replies)
  0 siblings, 9 replies; 17+ messages in thread
From: Johan Herland @ 2014-11-09 12:30 UTC (permalink / raw)
  To: gitster; +Cc: git, mackyle, jhf, sunshine, Johan Herland

Changes v3 -> v4:
 - Incorporate more feedback from Junio:
    - Patch #1: s/git config --unset/test_unconfig/
 - Add patches #3 - #6 to refactor add()/append_edit()/create_note()
   for supporting the direction suggested by Junio
 - Revamp the last patch to more fully modernize t3301


Have fun! :)

...Johan

Johan Herland (9):
  builtin/notes: Fix premature failure when trying to add the empty blob
  t3301: Verify that 'git notes' removes empty notes by default
  builtin/notes: Improve naming
  builtin/notes: Refactor note file path into struct note_data
  builtin/notes: Simplify early exit code in add()
  builtin/notes: Split create_note() to clarify add vs. remove logic
  builtin/notes: Add --allow-empty, to allow storing empty notes
  notes: Empty notes should be shown by 'git log'
  t3301: Modernize

 Documentation/git-notes.txt |   12 +-
 builtin/notes.c             |  235 +++++----
 notes.c                     |    3 +-
 t/t3301-notes.sh            | 1189 ++++++++++++++++++++-----------------------
 4 files changed, 698 insertions(+), 741 deletions(-)

-- 
2.1.1.392.g062cc5d

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCHv4 1/9] builtin/notes: Fix premature failure when trying to add the empty blob
  2014-11-09 12:30 [PATCHv4 0/9] Handling empty notes Johan Herland
@ 2014-11-09 12:30 ` Johan Herland
  2014-11-09 12:30 ` [PATCHv4 2/9] t3301: Verify that 'git notes' removes empty notes by default Johan Herland
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 17+ messages in thread
From: Johan Herland @ 2014-11-09 12:30 UTC (permalink / raw)
  To: gitster; +Cc: git, mackyle, jhf, sunshine, Johan Herland

This fixes a small buglet when trying to explicitly add the empty blob
as a note object using the -c or -C option to git notes add/append.
Instead of failing with a nonsensical error message indicating that the
empty blob does not exist, we should rather behave as if an empty notes
message was given (e.g. using -m "" or -F /dev/null).

The next patch contains a test that verifies the fixed behavior.

Found-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Johan Herland <johan@herland.net>
---
 builtin/notes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/notes.c b/builtin/notes.c
index 68b6cd8..9ee6816 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -266,7 +266,7 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
 
 	if (get_sha1(arg, object))
 		die(_("Failed to resolve '%s' as a valid ref."), arg);
-	if (!(buf = read_sha1_file(object, &type, &len)) || !len) {
+	if (!(buf = read_sha1_file(object, &type, &len))) {
 		free(buf);
 		die(_("Failed to read object '%s'."), arg);
 	}
-- 
2.1.1.392.g062cc5d

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCHv4 2/9] t3301: Verify that 'git notes' removes empty notes by default
  2014-11-09 12:30 [PATCHv4 0/9] Handling empty notes Johan Herland
  2014-11-09 12:30 ` [PATCHv4 1/9] builtin/notes: Fix premature failure when trying to add the empty blob Johan Herland
@ 2014-11-09 12:30 ` Johan Herland
  2014-11-09 12:30 ` [PATCHv4 3/9] builtin/notes: Improve naming Johan Herland
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 17+ messages in thread
From: Johan Herland @ 2014-11-09 12:30 UTC (permalink / raw)
  To: gitster; +Cc: git, mackyle, jhf, sunshine, Johan Herland

Add test cases documenting the current behavior when trying to
add/append/edit empty notes. This is in preparation for adding
--allow-empty; to allow empty notes to be stored.

Improved-by: Eric Sunshine <sunshine@sunshineco.com>
Improved-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Johan Herland <johan@herland.net>
---
 t/t3301-notes.sh | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index cfd67ff..f74b3fa 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -1239,4 +1239,31 @@ 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 'setup testing of empty notes' '
+	test_unconfig core.notesRef &&
+	test_commit 16th &&
+	empty_blob=$(git hash-object -w /dev/null)
+'
+
+while read cmd
+do
+	test_expect_success "'git notes $cmd' removes empty note" "
+		test_might_fail git notes remove HEAD &&
+		MSG= git notes $cmd &&
+		test_must_fail git notes list HEAD
+	"
+done <<\EOF
+add
+add -F /dev/null
+add -m ""
+add -c "$empty_blob"
+add -C "$empty_blob"
+append
+append -F /dev/null
+append -m ""
+append -c "$empty_blob"
+append -C "$empty_blob"
+edit
+EOF
+
 test_done
-- 
2.1.1.392.g062cc5d

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCHv4 3/9] builtin/notes: Improve naming
  2014-11-09 12:30 [PATCHv4 0/9] Handling empty notes Johan Herland
  2014-11-09 12:30 ` [PATCHv4 1/9] builtin/notes: Fix premature failure when trying to add the empty blob Johan Herland
  2014-11-09 12:30 ` [PATCHv4 2/9] t3301: Verify that 'git notes' removes empty notes by default Johan Herland
@ 2014-11-09 12:30 ` Johan Herland
  2014-11-09 12:30 ` [PATCHv4 4/9] builtin/notes: Refactor note file path into struct note_data Johan Herland
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 17+ messages in thread
From: Johan Herland @ 2014-11-09 12:30 UTC (permalink / raw)
  To: gitster; +Cc: git, mackyle, jhf, sunshine, Johan Herland

In preparation for some needed refactoring, rename struct msg_arg to
struct note_data, and rename its instances from "msg" to "d" (also
removing some unnecessary parentheses). The 'msg_arg' name was
inherited from tag.c, but is not really a good name for the contents
of a note.

Also rename write_note_data() to copy_obj_to_fd(), which more aptly
describes what it actually does: Copying the contents of a git object
(given by its SHA1) into a given file descriptor.

Signed-off-by: Johan Herland <johan@herland.net>
---
 builtin/notes.c | 109 ++++++++++++++++++++++++++++----------------------------
 1 file changed, 54 insertions(+), 55 deletions(-)

diff --git a/builtin/notes.c b/builtin/notes.c
index 9ee6816..3cf22cb 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -92,7 +92,7 @@ static const char * const git_notes_get_ref_usage[] = {
 static const char note_template[] =
 	"\nWrite/edit the notes for the following object:\n";
 
-struct msg_arg {
+struct note_data {
 	int given;
 	int use_editor;
 	struct strbuf buf;
@@ -106,7 +106,7 @@ static int list_each_note(const unsigned char *object_sha1,
 	return 0;
 }
 
-static void write_note_data(int fd, const unsigned char *sha1)
+static void copy_obj_to_fd(int fd, const unsigned char *sha1)
 {
 	unsigned long size;
 	enum object_type type;
@@ -149,13 +149,13 @@ static void write_commented_object(int fd, const unsigned char *object)
 		    sha1_to_hex(object));
 }
 
-static void create_note(const unsigned char *object, struct msg_arg *msg,
+static void create_note(const unsigned char *object, struct note_data *d,
 			int append_only, const unsigned char *prev,
 			unsigned char *result)
 {
 	char *path = NULL;
 
-	if (msg->use_editor || !msg->given) {
+	if (d->use_editor || !d->given) {
 		int fd;
 		struct strbuf buf = STRBUF_INIT;
 
@@ -165,10 +165,10 @@ static void create_note(const unsigned char *object, struct msg_arg *msg,
 		if (fd < 0)
 			die_errno(_("could not create file '%s'"), path);
 
-		if (msg->given)
-			write_or_die(fd, msg->buf.buf, msg->buf.len);
+		if (d->given)
+			write_or_die(fd, d->buf.buf, d->buf.len);
 		else if (prev && !append_only)
-			write_note_data(fd, prev);
+			copy_obj_to_fd(fd, prev);
 
 		strbuf_addch(&buf, '\n');
 		strbuf_add_commented_lines(&buf, note_template, strlen(note_template));
@@ -179,13 +179,12 @@ static void create_note(const unsigned char *object, struct msg_arg *msg,
 
 		close(fd);
 		strbuf_release(&buf);
-		strbuf_reset(&(msg->buf));
+		strbuf_reset(&d->buf);
 
-		if (launch_editor(path, &(msg->buf), NULL)) {
-			die(_("Please supply the note contents using either -m" \
-			    " or -F option"));
+		if (launch_editor(path, &d->buf, NULL)) {
+			die(_("Please supply the note contents using either -m or -F option"));
 		}
-		stripspace(&(msg->buf), 1);
+		stripspace(&d->buf, 1);
 	}
 
 	if (prev && append_only) {
@@ -194,20 +193,20 @@ static void create_note(const unsigned char *object, struct msg_arg *msg,
 		enum object_type type;
 		char *prev_buf = read_sha1_file(prev, &type, &size);
 
-		strbuf_grow(&(msg->buf), size + 1);
-		if (msg->buf.len && prev_buf && size)
-			strbuf_insert(&(msg->buf), 0, "\n", 1);
+		strbuf_grow(&d->buf, size + 1);
+		if (d->buf.len && prev_buf && size)
+			strbuf_insert(&d->buf, 0, "\n", 1);
 		if (prev_buf && size)
-			strbuf_insert(&(msg->buf), 0, prev_buf, size);
+			strbuf_insert(&d->buf, 0, prev_buf, size);
 		free(prev_buf);
 	}
 
-	if (!msg->buf.len) {
+	if (!d->buf.len) {
 		fprintf(stderr, _("Removing note for object %s\n"),
 			sha1_to_hex(object));
 		hashclr(result);
 	} else {
-		if (write_sha1_file(msg->buf.buf, msg->buf.len, blob_type, result)) {
+		if (write_sha1_file(d->buf.buf, d->buf.len, blob_type, result)) {
 			error(_("unable to write note object"));
 			if (path)
 				error(_("The note contents have been left in %s"),
@@ -224,45 +223,45 @@ static void create_note(const unsigned char *object, struct msg_arg *msg,
 
 static int parse_msg_arg(const struct option *opt, const char *arg, int unset)
 {
-	struct msg_arg *msg = opt->value;
+	struct note_data *d = opt->value;
 
-	strbuf_grow(&(msg->buf), strlen(arg) + 2);
-	if (msg->buf.len)
-		strbuf_addch(&(msg->buf), '\n');
-	strbuf_addstr(&(msg->buf), arg);
-	stripspace(&(msg->buf), 0);
+	strbuf_grow(&d->buf, strlen(arg) + 2);
+	if (d->buf.len)
+		strbuf_addch(&d->buf, '\n');
+	strbuf_addstr(&d->buf, arg);
+	stripspace(&d->buf, 0);
 
-	msg->given = 1;
+	d->given = 1;
 	return 0;
 }
 
 static int parse_file_arg(const struct option *opt, const char *arg, int unset)
 {
-	struct msg_arg *msg = opt->value;
+	struct note_data *d = opt->value;
 
-	if (msg->buf.len)
-		strbuf_addch(&(msg->buf), '\n');
+	if (d->buf.len)
+		strbuf_addch(&d->buf, '\n');
 	if (!strcmp(arg, "-")) {
-		if (strbuf_read(&(msg->buf), 0, 1024) < 0)
+		if (strbuf_read(&d->buf, 0, 1024) < 0)
 			die_errno(_("cannot read '%s'"), arg);
-	} else if (strbuf_read_file(&(msg->buf), arg, 1024) < 0)
+	} else if (strbuf_read_file(&d->buf, arg, 1024) < 0)
 		die_errno(_("could not open or read '%s'"), arg);
-	stripspace(&(msg->buf), 0);
+	stripspace(&d->buf, 0);
 
-	msg->given = 1;
+	d->given = 1;
 	return 0;
 }
 
 static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
 {
-	struct msg_arg *msg = opt->value;
+	struct note_data *d = opt->value;
 	char *buf;
 	unsigned char object[20];
 	enum object_type type;
 	unsigned long len;
 
-	if (msg->buf.len)
-		strbuf_addch(&(msg->buf), '\n');
+	if (d->buf.len)
+		strbuf_addch(&d->buf, '\n');
 
 	if (get_sha1(arg, object))
 		die(_("Failed to resolve '%s' as a valid ref."), arg);
@@ -274,17 +273,17 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
 		free(buf);
 		die(_("Cannot read note data from non-blob object '%s'."), arg);
 	}
-	strbuf_add(&(msg->buf), buf, len);
+	strbuf_add(&d->buf, buf, len);
 	free(buf);
 
-	msg->given = 1;
+	d->given = 1;
 	return 0;
 }
 
 static int parse_reedit_arg(const struct option *opt, const char *arg, int unset)
 {
-	struct msg_arg *msg = opt->value;
-	msg->use_editor = 1;
+	struct note_data *d = opt->value;
+	d->use_editor = 1;
 	return parse_reuse_arg(opt, arg, unset);
 }
 
@@ -403,18 +402,18 @@ 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 note_data d = { 0, 0, STRBUF_INIT };
 	struct option options[] = {
-		{ OPTION_CALLBACK, 'm', "message", &msg, N_("message"),
+		{ OPTION_CALLBACK, 'm', "message", &d, N_("message"),
 			N_("note contents as a string"), PARSE_OPT_NONEG,
 			parse_msg_arg},
-		{ OPTION_CALLBACK, 'F', "file", &msg, N_("file"),
+		{ OPTION_CALLBACK, 'F', "file", &d, N_("file"),
 			N_("note contents in a file"), PARSE_OPT_NONEG,
 			parse_file_arg},
-		{ OPTION_CALLBACK, 'c', "reedit-message", &msg, N_("object"),
+		{ OPTION_CALLBACK, 'c', "reedit-message", &d, N_("object"),
 			N_("reuse and edit specified note object"), PARSE_OPT_NONEG,
 			parse_reedit_arg},
-		{ OPTION_CALLBACK, 'C', "reuse-message", &msg, N_("object"),
+		{ OPTION_CALLBACK, 'C', "reuse-message", &d, N_("object"),
 			N_("reuse specified note object"), PARSE_OPT_NONEG,
 			parse_reuse_arg},
 		OPT__FORCE(&force, N_("replace existing notes")),
@@ -439,7 +438,7 @@ static int add(int argc, const char **argv, const char *prefix)
 
 	if (note) {
 		if (!force) {
-			if (!msg.given) {
+			if (!d.given) {
 				/*
 				 * Redirect to "edit" subcommand.
 				 *
@@ -460,7 +459,7 @@ static int add(int argc, const char **argv, const char *prefix)
 			sha1_to_hex(object));
 	}
 
-	create_note(object, &msg, 0, note, new_note);
+	create_note(object, &d, 0, note, new_note);
 
 	if (is_null_sha1(new_note))
 		remove_note(t, object);
@@ -472,7 +471,7 @@ static int add(int argc, const char **argv, const char *prefix)
 	commit_notes(t, logmsg);
 out:
 	free_notes(t);
-	strbuf_release(&(msg.buf));
+	strbuf_release(&d.buf);
 	return retval;
 }
 
@@ -560,18 +559,18 @@ 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 note_data d = { 0, 0, STRBUF_INIT };
 	struct option options[] = {
-		{ OPTION_CALLBACK, 'm', "message", &msg, N_("message"),
+		{ OPTION_CALLBACK, 'm', "message", &d, N_("message"),
 			N_("note contents as a string"), PARSE_OPT_NONEG,
 			parse_msg_arg},
-		{ OPTION_CALLBACK, 'F', "file", &msg, N_("file"),
+		{ OPTION_CALLBACK, 'F', "file", &d, N_("file"),
 			N_("note contents in a file"), PARSE_OPT_NONEG,
 			parse_file_arg},
-		{ OPTION_CALLBACK, 'c', "reedit-message", &msg, N_("object"),
+		{ OPTION_CALLBACK, 'c', "reedit-message", &d, N_("object"),
 			N_("reuse and edit specified note object"), PARSE_OPT_NONEG,
 			parse_reedit_arg},
-		{ OPTION_CALLBACK, 'C', "reuse-message", &msg, N_("object"),
+		{ OPTION_CALLBACK, 'C', "reuse-message", &d, N_("object"),
 			N_("reuse specified note object"), PARSE_OPT_NONEG,
 			parse_reuse_arg},
 		OPT_END()
@@ -587,7 +586,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
 		usage_with_options(usage, options);
 	}
 
-	if (msg.given && edit)
+	if (d.given && edit)
 		fprintf(stderr, _("The -m/-F/-c/-C options have been deprecated "
 			"for the 'edit' subcommand.\n"
 			"Please use 'git notes add -f -m/-F/-c/-C' instead.\n"));
@@ -600,7 +599,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
 	t = init_notes_check(argv[0]);
 	note = get_note(t, object);
 
-	create_note(object, &msg, !edit, note, new_note);
+	create_note(object, &d, !edit, note, new_note);
 
 	if (is_null_sha1(new_note))
 		remove_note(t, object);
@@ -611,7 +610,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
 		 is_null_sha1(new_note) ? "removed" : "added", argv[0]);
 	commit_notes(t, logmsg);
 	free_notes(t);
-	strbuf_release(&(msg.buf));
+	strbuf_release(&d.buf);
 	return 0;
 }
 
-- 
2.1.1.392.g062cc5d

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCHv4 4/9] builtin/notes: Refactor note file path into struct note_data
  2014-11-09 12:30 [PATCHv4 0/9] Handling empty notes Johan Herland
                   ` (2 preceding siblings ...)
  2014-11-09 12:30 ` [PATCHv4 3/9] builtin/notes: Improve naming Johan Herland
@ 2014-11-09 12:30 ` Johan Herland
  2014-11-09 12:30 ` [PATCHv4 5/9] builtin/notes: Simplify early exit code in add() Johan Herland
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 17+ messages in thread
From: Johan Herland @ 2014-11-09 12:30 UTC (permalink / raw)
  To: gitster; +Cc: git, mackyle, jhf, sunshine, Johan Herland

Move the 'path' variable from create_note() and into the
note_data struct. Unify cleanup of note_data objects with
a free_note_data() function.

This might not make too much sense on its own, but it makes the
future refactoring of create_note() considerably cleaner.

Signed-off-by: Johan Herland <johan@herland.net>
---
 builtin/notes.c | 38 +++++++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 17 deletions(-)

diff --git a/builtin/notes.c b/builtin/notes.c
index 3cf22cb..1017472 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -95,9 +95,19 @@ static const char note_template[] =
 struct note_data {
 	int given;
 	int use_editor;
+	char *edit_path;
 	struct strbuf buf;
 };
 
+static void free_note_data(struct note_data *d)
+{
+	if (d->edit_path) {
+		unlink_or_warn(d->edit_path);
+		free(d->edit_path);
+	}
+	strbuf_release(&d->buf);
+}
+
 static int list_each_note(const unsigned char *object_sha1,
 		const unsigned char *note_sha1, char *note_path,
 		void *cb_data)
@@ -153,17 +163,15 @@ static void create_note(const unsigned char *object, struct note_data *d,
 			int append_only, const unsigned char *prev,
 			unsigned char *result)
 {
-	char *path = NULL;
-
 	if (d->use_editor || !d->given) {
 		int fd;
 		struct strbuf buf = STRBUF_INIT;
 
 		/* write the template message before editing: */
-		path = git_pathdup("NOTES_EDITMSG");
-		fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0600);
+		d->edit_path = git_pathdup("NOTES_EDITMSG");
+		fd = open(d->edit_path, O_CREAT | O_TRUNC | O_WRONLY, 0600);
 		if (fd < 0)
-			die_errno(_("could not create file '%s'"), path);
+			die_errno(_("could not create file '%s'"), d->edit_path);
 
 		if (d->given)
 			write_or_die(fd, d->buf.buf, d->buf.len);
@@ -181,7 +189,7 @@ static void create_note(const unsigned char *object, struct note_data *d,
 		strbuf_release(&buf);
 		strbuf_reset(&d->buf);
 
-		if (launch_editor(path, &d->buf, NULL)) {
+		if (launch_editor(d->edit_path, &d->buf, NULL)) {
 			die(_("Please supply the note contents using either -m or -F option"));
 		}
 		stripspace(&d->buf, 1);
@@ -208,17 +216,12 @@ static void create_note(const unsigned char *object, struct note_data *d,
 	} else {
 		if (write_sha1_file(d->buf.buf, d->buf.len, blob_type, result)) {
 			error(_("unable to write note object"));
-			if (path)
+			if (d->edit_path)
 				error(_("The note contents have been left in %s"),
-				      path);
+				      d->edit_path);
 			exit(128);
 		}
 	}
-
-	if (path) {
-		unlink_or_warn(path);
-		free(path);
-	}
 }
 
 static int parse_msg_arg(const struct option *opt, const char *arg, int unset)
@@ -402,7 +405,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 note_data d = { 0, 0, STRBUF_INIT };
+	struct note_data d = { 0, 0, NULL, STRBUF_INIT };
 	struct option options[] = {
 		{ OPTION_CALLBACK, 'm', "message", &d, N_("message"),
 			N_("note contents as a string"), PARSE_OPT_NONEG,
@@ -447,6 +450,7 @@ static int add(int argc, const char **argv, const char *prefix)
 				 * therefore still in argv[0-1].
 				 */
 				argv[0] = "edit";
+				free_note_data(&d);
 				free_notes(t);
 				return append_edit(argc, argv, prefix);
 			}
@@ -460,6 +464,7 @@ static int add(int argc, const char **argv, const char *prefix)
 	}
 
 	create_note(object, &d, 0, note, new_note);
+	free_note_data(&d);
 
 	if (is_null_sha1(new_note))
 		remove_note(t, object);
@@ -471,7 +476,6 @@ static int add(int argc, const char **argv, const char *prefix)
 	commit_notes(t, logmsg);
 out:
 	free_notes(t);
-	strbuf_release(&d.buf);
 	return retval;
 }
 
@@ -559,7 +563,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 note_data d = { 0, 0, STRBUF_INIT };
+	struct note_data d = { 0, 0, NULL, STRBUF_INIT };
 	struct option options[] = {
 		{ OPTION_CALLBACK, 'm', "message", &d, N_("message"),
 			N_("note contents as a string"), PARSE_OPT_NONEG,
@@ -600,6 +604,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
 	note = get_note(t, object);
 
 	create_note(object, &d, !edit, note, new_note);
+	free_note_data(&d);
 
 	if (is_null_sha1(new_note))
 		remove_note(t, object);
@@ -610,7 +615,6 @@ static int append_edit(int argc, const char **argv, const char *prefix)
 		 is_null_sha1(new_note) ? "removed" : "added", argv[0]);
 	commit_notes(t, logmsg);
 	free_notes(t);
-	strbuf_release(&d.buf);
 	return 0;
 }
 
-- 
2.1.1.392.g062cc5d

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCHv4 5/9] builtin/notes: Simplify early exit code in add()
  2014-11-09 12:30 [PATCHv4 0/9] Handling empty notes Johan Herland
                   ` (3 preceding siblings ...)
  2014-11-09 12:30 ` [PATCHv4 4/9] builtin/notes: Refactor note file path into struct note_data Johan Herland
@ 2014-11-09 12:30 ` Johan Herland
  2014-11-10 20:36   ` Junio C Hamano
  2014-11-09 12:30 ` [PATCHv4 6/9] builtin/notes: Split create_note() to clarify add vs. remove logic Johan Herland
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 17+ messages in thread
From: Johan Herland @ 2014-11-09 12:30 UTC (permalink / raw)
  To: gitster; +Cc: git, mackyle, jhf, sunshine, Johan Herland

Signed-off-by: Johan Herland <johan@herland.net>
---
 builtin/notes.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/builtin/notes.c b/builtin/notes.c
index 1017472..f1480cf 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -399,7 +399,7 @@ static int append_edit(int argc, const char **argv, const char *prefix);
 
 static int add(int argc, const char **argv, const char *prefix)
 {
-	int retval = 0, force = 0;
+	int force = 0;
 	const char *object_ref;
 	struct notes_tree *t;
 	unsigned char object[20], new_note[20];
@@ -441,6 +441,8 @@ static int add(int argc, const char **argv, const char *prefix)
 
 	if (note) {
 		if (!force) {
+			free_note_data(&d);
+			free_notes(t);
 			if (!d.given) {
 				/*
 				 * Redirect to "edit" subcommand.
@@ -450,14 +452,11 @@ static int add(int argc, const char **argv, const char *prefix)
 				 * therefore still in argv[0-1].
 				 */
 				argv[0] = "edit";
-				free_note_data(&d);
-				free_notes(t);
 				return append_edit(argc, argv, prefix);
 			}
-			retval = error(_("Cannot add notes. Found existing notes "
+			return error(_("Cannot add notes. Found existing notes "
 				       "for object %s. Use '-f' to overwrite "
 				       "existing notes"), sha1_to_hex(object));
-			goto out;
 		}
 		fprintf(stderr, _("Overwriting existing notes for object %s\n"),
 			sha1_to_hex(object));
@@ -474,9 +473,8 @@ static int add(int argc, const char **argv, const char *prefix)
 	snprintf(logmsg, sizeof(logmsg), "Notes %s by 'git notes %s'",
 		 is_null_sha1(new_note) ? "removed" : "added", "add");
 	commit_notes(t, logmsg);
-out:
 	free_notes(t);
-	return retval;
+	return 0;
 }
 
 static int copy(int argc, const char **argv, const char *prefix)
-- 
2.1.1.392.g062cc5d

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCHv4 6/9] builtin/notes: Split create_note() to clarify add vs. remove logic
  2014-11-09 12:30 [PATCHv4 0/9] Handling empty notes Johan Herland
                   ` (4 preceding siblings ...)
  2014-11-09 12:30 ` [PATCHv4 5/9] builtin/notes: Simplify early exit code in add() Johan Herland
@ 2014-11-09 12:30 ` Johan Herland
  2014-11-09 12:30 ` [PATCHv4 7/9] builtin/notes: Add --allow-empty, to allow storing empty notes Johan Herland
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 17+ messages in thread
From: Johan Herland @ 2014-11-09 12:30 UTC (permalink / raw)
  To: gitster; +Cc: git, mackyle, jhf, sunshine, Johan Herland

create_note() has a non-trivial interface, and comprises three loosely
related parts:

 1. launching the editor with the note contents, if needed
 2. appending to an existing note, if append_only was given
 3. adding or removing the resulting note, based on whether it's non-empty

Split it along those lines to make the logic clearer: The first part
goes into a new function - prepare_note_data(), with a simpler interface.
The second part is moved into append_edit(), which is the only user of
this code. Finally, the add vs. remove decision is moved into the callers
(add() and append_edit()), keeping the logic for writing the actual note
object in a separate function: write_note_data().

Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Johan Herland <johan@herland.net>
---
 builtin/notes.c | 103 +++++++++++++++++++++++++++++---------------------------
 1 file changed, 54 insertions(+), 49 deletions(-)

diff --git a/builtin/notes.c b/builtin/notes.c
index f1480cf..7017434 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -159,9 +159,8 @@ static void write_commented_object(int fd, const unsigned char *object)
 		    sha1_to_hex(object));
 }
 
-static void create_note(const unsigned char *object, struct note_data *d,
-			int append_only, const unsigned char *prev,
-			unsigned char *result)
+static void prepare_note_data(const unsigned char *object, struct note_data *d,
+		const unsigned char *old_note)
 {
 	if (d->use_editor || !d->given) {
 		int fd;
@@ -175,8 +174,8 @@ static void create_note(const unsigned char *object, struct note_data *d,
 
 		if (d->given)
 			write_or_die(fd, d->buf.buf, d->buf.len);
-		else if (prev && !append_only)
-			copy_obj_to_fd(fd, prev);
+		else if (old_note)
+			copy_obj_to_fd(fd, old_note);
 
 		strbuf_addch(&buf, '\n');
 		strbuf_add_commented_lines(&buf, note_template, strlen(note_template));
@@ -194,33 +193,16 @@ static void create_note(const unsigned char *object, struct note_data *d,
 		}
 		stripspace(&d->buf, 1);
 	}
+}
 
-	if (prev && append_only) {
-		/* Append buf to previous note contents */
-		unsigned long size;
-		enum object_type type;
-		char *prev_buf = read_sha1_file(prev, &type, &size);
-
-		strbuf_grow(&d->buf, size + 1);
-		if (d->buf.len && prev_buf && size)
-			strbuf_insert(&d->buf, 0, "\n", 1);
-		if (prev_buf && size)
-			strbuf_insert(&d->buf, 0, prev_buf, size);
-		free(prev_buf);
-	}
-
-	if (!d->buf.len) {
-		fprintf(stderr, _("Removing note for object %s\n"),
-			sha1_to_hex(object));
-		hashclr(result);
-	} else {
-		if (write_sha1_file(d->buf.buf, d->buf.len, blob_type, result)) {
-			error(_("unable to write note object"));
-			if (d->edit_path)
-				error(_("The note contents have been left in %s"),
-				      d->edit_path);
-			exit(128);
-		}
+static void write_note_data(struct note_data *d, unsigned char *sha1)
+{
+	if (write_sha1_file(d->buf.buf, d->buf.len, blob_type, sha1)) {
+		error(_("unable to write note object"));
+		if (d->edit_path)
+			error(_("The note contents have been left in %s"),
+				d->edit_path);
+		exit(128);
 	}
 }
 
@@ -403,7 +385,6 @@ static int add(int argc, const char **argv, const char *prefix)
 	const char *object_ref;
 	struct notes_tree *t;
 	unsigned char object[20], new_note[20];
-	char logmsg[100];
 	const unsigned char *note;
 	struct note_data d = { 0, 0, NULL, STRBUF_INIT };
 	struct option options[] = {
@@ -462,17 +443,20 @@ static int add(int argc, const char **argv, const char *prefix)
 			sha1_to_hex(object));
 	}
 
-	create_note(object, &d, 0, note, new_note);
-	free_note_data(&d);
-
-	if (is_null_sha1(new_note))
+	prepare_note_data(object, &d, note);
+	if (d.buf.len) {
+		write_note_data(&d, new_note);
+		if (add_note(t, object, new_note, combine_notes_overwrite))
+			die("BUG: combine_notes_overwrite failed");
+		commit_notes(t, "Notes added by 'git notes add'");
+	} else {
+		fprintf(stderr, _("Removing note for object %s\n"),
+			sha1_to_hex(object));
 		remove_note(t, object);
-	else if (add_note(t, object, new_note, combine_notes_overwrite))
-		die("BUG: combine_notes_overwrite failed");
+		commit_notes(t, "Notes removed by 'git notes add'");
+	}
 
-	snprintf(logmsg, sizeof(logmsg), "Notes %s by 'git notes %s'",
-		 is_null_sha1(new_note) ? "removed" : "added", "add");
-	commit_notes(t, logmsg);
+	free_note_data(&d);
 	free_notes(t);
 	return 0;
 }
@@ -601,17 +585,38 @@ static int append_edit(int argc, const char **argv, const char *prefix)
 	t = init_notes_check(argv[0]);
 	note = get_note(t, object);
 
-	create_note(object, &d, !edit, note, new_note);
-	free_note_data(&d);
+	prepare_note_data(object, &d, edit ? note : NULL);
 
-	if (is_null_sha1(new_note))
-		remove_note(t, object);
-	else if (add_note(t, object, new_note, combine_notes_overwrite))
-		die("BUG: combine_notes_overwrite failed");
+	if (note && !edit) {
+		/* Append buf to previous note contents */
+		unsigned long size;
+		enum object_type type;
+		char *prev_buf = read_sha1_file(note, &type, &size);
+
+		strbuf_grow(&d.buf, size + 1);
+		if (d.buf.len && prev_buf && size)
+			strbuf_insert(&d.buf, 0, "\n", 1);
+		if (prev_buf && size)
+			strbuf_insert(&d.buf, 0, prev_buf, size);
+		free(prev_buf);
+	}
 
-	snprintf(logmsg, sizeof(logmsg), "Notes %s by 'git notes %s'",
-		 is_null_sha1(new_note) ? "removed" : "added", argv[0]);
+	if (d.buf.len) {
+		write_note_data(&d, new_note);
+		if (add_note(t, object, new_note, combine_notes_overwrite))
+			die("BUG: combine_notes_overwrite failed");
+		snprintf(logmsg, sizeof(logmsg), "Notes added by 'git notes %s'",
+			argv[0]);
+	} else {
+		fprintf(stderr, _("Removing note for object %s\n"),
+			sha1_to_hex(object));
+		remove_note(t, object);
+		snprintf(logmsg, sizeof(logmsg), "Notes removed by 'git notes %s'",
+			argv[0]);
+	}
 	commit_notes(t, logmsg);
+
+	free_note_data(&d);
 	free_notes(t);
 	return 0;
 }
-- 
2.1.1.392.g062cc5d

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCHv4 7/9] builtin/notes: Add --allow-empty, to allow storing empty notes
  2014-11-09 12:30 [PATCHv4 0/9] Handling empty notes Johan Herland
                   ` (5 preceding siblings ...)
  2014-11-09 12:30 ` [PATCHv4 6/9] builtin/notes: Split create_note() to clarify add vs. remove logic Johan Herland
@ 2014-11-09 12:30 ` Johan Herland
  2014-11-09 12:30 ` [PATCHv4 8/9] notes: Empty notes should be shown by 'git log' Johan Herland
  2014-11-09 12:30 ` [PATCHv4 9/9] t3301: Modernize Johan Herland
  8 siblings, 0 replies; 17+ messages in thread
From: Johan Herland @ 2014-11-09 12:30 UTC (permalink / raw)
  To: gitster; +Cc: git, mackyle, jhf, sunshine, Johan Herland

Although the "git notes" man page advertises that we support binary-safe
notes addition (using the -C option), we currently do not support adding
the empty note (i.e. using the empty blob to annotate an object). Instead,
an empty note is always treated as an intent to remove the note
altogether.

Introduce the --allow-empty option to the add/append/edit subcommands,
to explicitly allow an empty note to be stored into the notes tree.

Also update the documentation, and add test cases for the new option.

Reported-by: James H. Fisher <jhf@trifork.com>
Improved-by: Kyle J. McKay <mackyle@gmail.com>
Improved-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Johan Herland <johan@herland.net>
---
 Documentation/git-notes.txt | 12 ++++++++----
 builtin/notes.c             | 17 +++++++++++------
 t/t3301-notes.sh            | 10 +++++++++-
 3 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 310f0a5..851518d 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -9,10 +9,10 @@ SYNOPSIS
 --------
 [verse]
 'git notes' [list [<object>]]
-'git notes' add [-f] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>]
+'git notes' add [-f] [--allow-empty] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>]
 'git notes' copy [-f] ( --stdin | <from-object> <to-object> )
-'git notes' append [-F <file> | -m <msg> | (-c | -C) <object>] [<object>]
-'git notes' edit [<object>]
+'git notes' append [--allow-empty] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>]
+'git notes' edit [--allow-empty] [<object>]
 'git notes' show [<object>]
 'git notes' merge [-v | -q] [-s <strategy> ] <notes-ref>
 'git notes' merge --commit [-v | -q]
@@ -155,6 +155,10 @@ OPTIONS
 	Like '-C', but with '-c' the editor is invoked, so that
 	the user can further edit the note message.
 
+--allow-empty::
+	Allow an empty note object to be stored. The default behavior is
+	to automatically remove empty notes.
+
 --ref <ref>::
 	Manipulate the notes tree in <ref>.  This overrides
 	'GIT_NOTES_REF' and the "core.notesRef" configuration.  The ref
@@ -287,7 +291,7 @@ arbitrary files using 'git hash-object':
 ------------
 $ cc *.c
 $ blob=$(git hash-object -w a.out)
-$ git notes --ref=built add -C "$blob" HEAD
+$ git notes --ref=built add --allow-empty -C "$blob" HEAD
 ------------
 
 (You cannot simply use `git notes --ref=built add -F a.out HEAD`
diff --git a/builtin/notes.c b/builtin/notes.c
index 7017434..4605210 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -22,10 +22,10 @@
 
 static const char * const git_notes_usage[] = {
 	N_("git notes [--ref <notes_ref>] [list [<object>]]"),
-	N_("git notes [--ref <notes_ref>] add [-f] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]"),
+	N_("git notes [--ref <notes_ref>] add [-f] [--allow-empty] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]"),
 	N_("git notes [--ref <notes_ref>] copy [-f] <from-object> <to-object>"),
-	N_("git notes [--ref <notes_ref>] append [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]"),
-	N_("git notes [--ref <notes_ref>] edit [<object>]"),
+	N_("git notes [--ref <notes_ref>] append [--allow-empty] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]"),
+	N_("git notes [--ref <notes_ref>] edit [--allow-empty] [<object>]"),
 	N_("git notes [--ref <notes_ref>] show [<object>]"),
 	N_("git notes [--ref <notes_ref>] merge [-v | -q] [-s <strategy> ] <notes_ref>"),
 	N_("git notes merge --commit [-v | -q]"),
@@ -381,7 +381,7 @@ static int append_edit(int argc, const char **argv, const char *prefix);
 
 static int add(int argc, const char **argv, const char *prefix)
 {
-	int force = 0;
+	int force = 0, allow_empty = 0;
 	const char *object_ref;
 	struct notes_tree *t;
 	unsigned char object[20], new_note[20];
@@ -400,6 +400,8 @@ static int add(int argc, const char **argv, const char *prefix)
 		{ OPTION_CALLBACK, 'C', "reuse-message", &d, N_("object"),
 			N_("reuse specified note object"), PARSE_OPT_NONEG,
 			parse_reuse_arg},
+		OPT_BOOL(0, "allow-empty", &allow_empty,
+			N_("allow storing empty note")),
 		OPT__FORCE(&force, N_("replace existing notes")),
 		OPT_END()
 	};
@@ -444,7 +446,7 @@ static int add(int argc, const char **argv, const char *prefix)
 	}
 
 	prepare_note_data(object, &d, note);
-	if (d.buf.len) {
+	if (d.buf.len || allow_empty) {
 		write_note_data(&d, new_note);
 		if (add_note(t, object, new_note, combine_notes_overwrite))
 			die("BUG: combine_notes_overwrite failed");
@@ -539,6 +541,7 @@ out:
 
 static int append_edit(int argc, const char **argv, const char *prefix)
 {
+	int allow_empty = 0;
 	const char *object_ref;
 	struct notes_tree *t;
 	unsigned char object[20], new_note[20];
@@ -559,6 +562,8 @@ static int append_edit(int argc, const char **argv, const char *prefix)
 		{ OPTION_CALLBACK, 'C', "reuse-message", &d, N_("object"),
 			N_("reuse specified note object"), PARSE_OPT_NONEG,
 			parse_reuse_arg},
+		OPT_BOOL(0, "allow-empty", &allow_empty,
+			N_("allow storing empty note")),
 		OPT_END()
 	};
 	int edit = !strcmp(argv[0], "edit");
@@ -601,7 +606,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
 		free(prev_buf);
 	}
 
-	if (d.buf.len) {
+	if (d.buf.len || allow_empty) {
 		write_note_data(&d, new_note);
 		if (add_note(t, object, new_note, combine_notes_overwrite))
 			die("BUG: combine_notes_overwrite failed");
diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index f74b3fa..70ec5c3 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -1242,7 +1242,8 @@ test_expect_success 'git notes get-ref (--ref)' '
 test_expect_success 'setup testing of empty notes' '
 	test_unconfig core.notesRef &&
 	test_commit 16th &&
-	empty_blob=$(git hash-object -w /dev/null)
+	empty_blob=$(git hash-object -w /dev/null) &&
+	echo "$empty_blob" >expect_empty
 '
 
 while read cmd
@@ -1252,6 +1253,13 @@ do
 		MSG= git notes $cmd &&
 		test_must_fail git notes list HEAD
 	"
+
+	test_expect_success "'git notes $cmd --allow-empty' stores empty note" "
+		test_might_fail git notes remove HEAD &&
+		MSG= git notes $cmd --allow-empty &&
+		git notes list HEAD >actual &&
+		test_cmp expect_empty actual
+	"
 done <<\EOF
 add
 add -F /dev/null
-- 
2.1.1.392.g062cc5d

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCHv4 8/9] notes: Empty notes should be shown by 'git log'
  2014-11-09 12:30 [PATCHv4 0/9] Handling empty notes Johan Herland
                   ` (6 preceding siblings ...)
  2014-11-09 12:30 ` [PATCHv4 7/9] builtin/notes: Add --allow-empty, to allow storing empty notes Johan Herland
@ 2014-11-09 12:30 ` Johan Herland
  2014-11-09 12:30 ` [PATCHv4 9/9] t3301: Modernize Johan Herland
  8 siblings, 0 replies; 17+ messages in thread
From: Johan Herland @ 2014-11-09 12:30 UTC (permalink / raw)
  To: gitster; +Cc: git, mackyle, jhf, sunshine, Johan Herland

If the user has gone through the trouble of explicitly adding an empty
note, then "git log" should not silently skip it (as if it didn't exist).

Signed-off-by: Johan Herland <johan@herland.net>
---
 notes.c          |  3 +--
 t/t3301-notes.sh | 12 ++++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/notes.c b/notes.c
index 5fe691d..62bc6e1 100644
--- a/notes.c
+++ b/notes.c
@@ -1218,8 +1218,7 @@ static void format_note(struct notes_tree *t, const unsigned char *object_sha1,
 	if (!sha1)
 		return;
 
-	if (!(msg = read_sha1_file(sha1, &type, &msglen)) || !msglen ||
-			type != OBJ_BLOB) {
+	if (!(msg = read_sha1_file(sha1, &type, &msglen)) || type != OBJ_BLOB) {
 		free(msg);
 		return;
 	}
diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index 70ec5c3..416ed9e 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -1274,4 +1274,16 @@ append -C "$empty_blob"
 edit
 EOF
 
+test_expect_success 'empty notes are displayed by git log' '
+	test_commit 17th &&
+	git log -1 >expect &&
+	cat >>expect <<\EOF &&
+
+Notes:
+EOF
+	git notes add -C "$empty_blob" --allow-empty &&
+	git log -1 >actual &&
+	test_cmp expect actual
+'
+
 test_done
-- 
2.1.1.392.g062cc5d

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCHv4 9/9] t3301: Modernize
  2014-11-09 12:30 [PATCHv4 0/9] Handling empty notes Johan Herland
                   ` (7 preceding siblings ...)
  2014-11-09 12:30 ` [PATCHv4 8/9] notes: Empty notes should be shown by 'git log' Johan Herland
@ 2014-11-09 12:30 ` Johan Herland
  2014-11-10 20:42   ` Junio C Hamano
  8 siblings, 1 reply; 17+ messages in thread
From: Johan Herland @ 2014-11-09 12:30 UTC (permalink / raw)
  To: gitster; +Cc: git, mackyle, jhf, sunshine, Johan Herland

Make this test script appear somewhat less old-fashioned:
 - Use test helper functions:
    - write_script
    - test_commit
    - test_write_lines
    - test_config
    - test_unconfig
    - test_path_is_missing
 - Remove whitespace between redirection operators and their targets.
 - Move preparation of "except" files into tests.
 - More consistent quoting, especially around commands that might
   expand to nothing.
 - More visibility of important whitespace with ${indent}.
 - Combine pairs of tests that unnecessarily split setup and verification.

Improved-by: Eric Sunshine <sunshine@sunshineco.com>
Improved-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Johan Herland <johan@herland.net>
---
 t/t3301-notes.sh | 1148 +++++++++++++++++++++++++-----------------------------
 1 file changed, 522 insertions(+), 626 deletions(-)

diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index 416ed9e..cd756ec 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -7,28 +7,22 @@ test_description='Test commit notes'
 
 . ./test-lib.sh
 
-cat > fake_editor.sh << \EOF
-#!/bin/sh
-echo "$MSG" > "$1"
-echo "$MSG" >& 2
+write_script fake_editor <<\EOF
+echo "$MSG" >"$1"
+echo "$MSG" >&2
 EOF
-chmod a+x fake_editor.sh
-GIT_EDITOR=./fake_editor.sh
+GIT_EDITOR=./fake_editor
 export GIT_EDITOR
 
+indent="    "
+
 test_expect_success 'cannot annotate non-existing HEAD' '
 	test_must_fail env MSG=3 git notes add
 '
 
-test_expect_success setup '
-	: > a1 &&
-	git add a1 &&
-	test_tick &&
-	git commit -m 1st &&
-	: > a2 &&
-	git add a2 &&
-	test_tick &&
-	git commit -m 2nd
+test_expect_success 'setup' '
+	test_commit 1st &&
+	test_commit 2nd
 '
 
 test_expect_success 'need valid notes ref' '
@@ -50,189 +44,163 @@ test_expect_success 'handle empty notes gracefully' '
 '
 
 test_expect_success 'show non-existent notes entry with %N' '
-	for l in A B
-	do
-		echo "$l"
-	done >expect &&
-	git show -s --format='A%n%NB' >output &&
+	test_write_lines A B >expect &&
+	git show -s --format="A%n%NB" >output &&
 	test_cmp expect output
 '
 
 test_expect_success 'create notes' '
-	git config core.notesRef refs/notes/commits &&
 	MSG=b4 git notes add &&
-	test ! -f .git/NOTES_EDITMSG &&
-	test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
-	test b4 = $(git notes show) &&
+	test_path_is_missing .git/NOTES_EDITMSG &&
+	test "1" = "$(git ls-tree refs/notes/commits | wc -l)" &&
+	test "b4" = "$(git notes show)" &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
 
 test_expect_success 'show notes entry with %N' '
-	for l in A b4 B
-	do
-		echo "$l"
-	done >expect &&
-	git show -s --format='A%n%NB' >output &&
+	test_write_lines A b4 B >expect &&
+	git show -s --format="A%n%NB" >output &&
 	test_cmp expect output
 '
 
-cat >expect <<EOF
-d423f8c refs/notes/commits@{0}: notes: Notes added by 'git notes add'
-EOF
-
 test_expect_success 'create reflog entry' '
+	cat <<-EOF >expect &&
+		a1d8fa6 refs/notes/commits@{0}: notes: Notes added by '"'"'git notes add'"'"'
+	EOF
 	git reflog show refs/notes/commits >output &&
 	test_cmp expect output
 '
 
 test_expect_success 'edit existing notes' '
 	MSG=b3 git notes edit &&
-	test ! -f .git/NOTES_EDITMSG &&
-	test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
-	test b3 = $(git notes show) &&
+	test_path_is_missing .git/NOTES_EDITMSG &&
+	test "1" = "$(git ls-tree refs/notes/commits | wc -l)" &&
+	test "b3" = "$(git notes show)" &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
 
 test_expect_success 'cannot "git notes add -m" where notes already exists' '
 	test_must_fail git notes add -m "b2" &&
-	test ! -f .git/NOTES_EDITMSG &&
-	test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
-	test b3 = $(git notes show) &&
+	test_path_is_missing .git/NOTES_EDITMSG &&
+	test "1" = "$(git ls-tree refs/notes/commits | wc -l)" &&
+	test "b3" = "$(git notes show)" &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
 
 test_expect_success 'can overwrite existing note with "git notes add -f -m"' '
 	git notes add -f -m "b1" &&
-	test ! -f .git/NOTES_EDITMSG &&
-	test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
-	test b1 = $(git notes show) &&
+	test_path_is_missing .git/NOTES_EDITMSG &&
+	test "1" = "$(git ls-tree refs/notes/commits | wc -l)" &&
+	test "b1" = "$(git notes show)" &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
 
 test_expect_success 'add w/no options on existing note morphs into edit' '
 	MSG=b2 git notes add &&
-	test ! -f .git/NOTES_EDITMSG &&
-	test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
-	test b2 = $(git notes show) &&
+	test_path_is_missing .git/NOTES_EDITMSG &&
+	test "1" = "$(git ls-tree refs/notes/commits | wc -l)" &&
+	test "b2" = "$(git notes show)" &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
 
 test_expect_success 'can overwrite existing note with "git notes add -f"' '
 	MSG=b1 git notes add -f &&
-	test ! -f .git/NOTES_EDITMSG &&
-	test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
-	test b1 = $(git notes show) &&
+	test_path_is_missing .git/NOTES_EDITMSG &&
+	test "1" = "$(git ls-tree refs/notes/commits | wc -l)" &&
+	test "b1" = "$(git notes show)" &&
 	git show HEAD^ &&
 	test_must_fail git notes show HEAD^
 '
 
-cat > expect << EOF
-commit 268048bfb8a1fb38e703baceb8ab235421bf80c5
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:14:13 2005 -0700
+test_expect_success 'show notes' '
+	cat >expect <<-EOF &&
+		commit 7a4ca6ee52a974a66cbaa78e33214535dff1d691
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:14:13 2005 -0700
 
-    2nd
+		${indent}2nd
 
-Notes:
-    b1
-EOF
-
-test_expect_success 'show notes' '
+		Notes:
+		${indent}b1
+	EOF
 	! (git cat-file commit HEAD | grep b1) &&
-	git log -1 > output &&
+	git log -1 >output &&
 	test_cmp expect output
 '
 
-test_expect_success 'create multi-line notes (setup)' '
-	: > a3 &&
-	git add a3 &&
-	test_tick &&
-	git commit -m 3rd &&
-	MSG="b3
-c3c3c3c3
-d3d3d3" git notes add
-'
-
-cat > expect-multiline << EOF
-commit 1584215f1d29c65e99c6c6848626553fdd07fd75
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:15:13 2005 -0700
-
-    3rd
-
-Notes:
-    b3
-    c3c3c3c3
-    d3d3d3
-EOF
-
-printf "\n" >> expect-multiline
-cat expect >> expect-multiline
-
 test_expect_success 'show multi-line notes' '
-	git log -2 > output &&
+	test_commit 3rd &&
+	MSG="b3${LF}c3c3c3c3${LF}d3d3d3" git notes add &&
+	cat >expect-multiline <<-EOF &&
+		commit d07d62e5208f22eb5695e7eb47667dc8b9860290
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:15:13 2005 -0700
+
+		${indent}3rd
+
+		Notes:
+		${indent}b3
+		${indent}c3c3c3c3
+		${indent}d3d3d3
+
+	EOF
+	cat expect >>expect-multiline &&
+	git log -2 >output &&
 	test_cmp expect-multiline output
 '
-test_expect_success 'create -F notes (setup)' '
-	: > a4 &&
-	git add a4 &&
-	test_tick &&
-	git commit -m 4th &&
-	echo "xyzzy" > note5 &&
-	git notes add -F note5
-'
-
-cat > expect-F << EOF
-commit 15023535574ded8b1a89052b32673f84cf9582b8
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:16:13 2005 -0700
-
-    4th
-
-Notes:
-    xyzzy
-EOF
-
-printf "\n" >> expect-F
-cat expect-multiline >> expect-F
 
 test_expect_success 'show -F notes' '
-	git log -3 > output &&
+	test_commit 4th &&
+	echo "xyzzy" >note5 &&
+	git notes add -F note5 &&
+	cat >expect-F <<-EOF &&
+		commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:16:13 2005 -0700
+
+		${indent}4th
+
+		Notes:
+		${indent}xyzzy
+
+	EOF
+	cat expect-multiline >>expect-F &&
+	git log -3 >output &&
 	test_cmp expect-F output
 '
 
 test_expect_success 'Re-adding -F notes without -f fails' '
-	echo "zyxxy" > note5 &&
+	echo "zyxxy" >note5 &&
 	test_must_fail git notes add -F note5 &&
-	git log -3 > output &&
+	git log -3 >output &&
 	test_cmp expect-F output
 '
 
-cat >expect << EOF
-commit 15023535574ded8b1a89052b32673f84cf9582b8
-tree e070e3af51011e47b183c33adf9736736a525709
-parent 1584215f1d29c65e99c6c6848626553fdd07fd75
-author A U Thor <author@example.com> 1112912173 -0700
-committer C O Mitter <committer@example.com> 1112912173 -0700
-
-    4th
-EOF
 test_expect_success 'git log --pretty=raw does not show notes' '
+	cat >expect <<-EOF &&
+		commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11
+		tree 05ac65288c4c4b3b709a020ae94b2ece2f2201ae
+		parent d07d62e5208f22eb5695e7eb47667dc8b9860290
+		author A U Thor <author@example.com> 1112912173 -0700
+		committer C O Mitter <committer@example.com> 1112912173 -0700
+
+		${indent}4th
+	EOF
 	git log -1 --pretty=raw >output &&
 	test_cmp expect output
 '
 
-cat >>expect <<EOF
-
-Notes:
-    xyzzy
-EOF
 test_expect_success 'git log --show-notes' '
+	cat >>expect <<-EOF &&
+
+	Notes:
+	${indent}xyzzy
+	EOF
 	git log -1 --pretty=raw --show-notes >output &&
 	test_cmp expect output
 '
@@ -304,128 +272,98 @@ test_expect_success 'git log --no-notes resets ref list' '
 	! grep alternate output
 '
 
-test_expect_success 'create -m notes (setup)' '
-	: > a5 &&
-	git add a5 &&
-	test_tick &&
-	git commit -m 5th &&
-	git notes add -m spam -m "foo
-bar
-baz"
-'
-
-whitespace="    "
-cat > expect-m << EOF
-commit bd1753200303d0a0344be813e504253b3d98e74d
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:17:13 2005 -0700
-
-    5th
-
-Notes:
-    spam
-$whitespace
-    foo
-    bar
-    baz
-EOF
-
-printf "\n" >> expect-m
-cat expect-F >> expect-m
-
 test_expect_success 'show -m notes' '
-	git log -4 > output &&
+	test_commit 5th &&
+	git notes add -m spam -m "foo${LF}bar${LF}baz" &&
+	cat >expect-m <<-EOF &&
+		commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:17:13 2005 -0700
+
+		${indent}5th
+
+		Notes:
+		${indent}spam
+		${indent}
+		${indent}foo
+		${indent}bar
+		${indent}baz
+
+	EOF
+	cat expect-F >>expect-m &&
+	git log -4 >output &&
 	test_cmp expect-m output
 '
 
-test_expect_success 'remove note with add -f -F /dev/null (setup)' '
-	git notes add -f -F /dev/null
-'
-
-cat > expect-rm-F << EOF
-commit bd1753200303d0a0344be813e504253b3d98e74d
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:17:13 2005 -0700
-
-    5th
-EOF
+test_expect_success 'remove note with add -f -F /dev/null' '
+	git notes add -f -F /dev/null &&
+	cat >expect-rm-F <<-EOF &&
+		commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:17:13 2005 -0700
 
-printf "\n" >> expect-rm-F
-cat expect-F >> expect-rm-F
+		${indent}5th
 
-test_expect_success 'verify note removal with -F /dev/null' '
-	git log -4 > output &&
+	EOF
+	cat expect-F >>expect-rm-F &&
+	git log -4 >output &&
 	test_cmp expect-rm-F output &&
 	test_must_fail git notes show
 '
 
-test_expect_success 'do not create empty note with -m "" (setup)' '
-	git notes add -m ""
-'
-
-test_expect_success 'verify non-creation of note with -m ""' '
-	git log -4 > output &&
+test_expect_success 'do not create empty note with -m ""' '
+	git notes add -m "" &&
+	git log -4 >output &&
 	test_cmp expect-rm-F output &&
 	test_must_fail git notes show
 '
 
-cat > expect-combine_m_and_F << EOF
-foo
-
-xyzzy
+test_expect_success 'create note with combination of -m and -F' '
+	cat >expect-combine_m_and_F <<-EOF &&
+		foo
 
-bar
+		xyzzy
 
-zyxxy
+		bar
 
-baz
-EOF
+		zyxxy
 
-test_expect_success 'create note with combination of -m and -F' '
-	echo "xyzzy" > note_a &&
-	echo "zyxxy" > note_b &&
+		baz
+	EOF
+	echo "xyzzy" >note_a &&
+	echo "zyxxy" >note_b &&
 	git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" &&
-	git notes show > output &&
+	git notes show >output &&
 	test_cmp expect-combine_m_and_F output
 '
 
-test_expect_success 'remove note with "git notes remove" (setup)' '
+test_expect_success 'remove note with "git notes remove"' '
 	git notes remove HEAD^ &&
-	git notes remove
-'
+	git notes remove &&
+	cat >expect-rm-remove <<-EOF &&
+		commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:17:13 2005 -0700
 
-cat > expect-rm-remove << EOF
-commit bd1753200303d0a0344be813e504253b3d98e74d
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:17:13 2005 -0700
+		${indent}5th
 
-    5th
-
-commit 15023535574ded8b1a89052b32673f84cf9582b8
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:16:13 2005 -0700
-
-    4th
-EOF
+		commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:16:13 2005 -0700
 
-printf "\n" >> expect-rm-remove
-cat expect-multiline >> expect-rm-remove
+		${indent}4th
 
-test_expect_success 'verify note removal with "git notes remove"' '
-	git log -4 > output &&
+	EOF
+	cat expect-multiline >>expect-rm-remove &&
+	git log -4 >output &&
 	test_cmp expect-rm-remove output &&
 	test_must_fail git notes show HEAD^
 '
 
-cat > expect << EOF
-c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75
-c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5
-EOF
-
 test_expect_success 'removing non-existing note should not create new commit' '
-	git rev-parse --verify refs/notes/commits > before_commit &&
+	git rev-parse --verify refs/notes/commits >before_commit &&
 	test_must_fail git notes remove HEAD^ &&
-	git rev-parse --verify refs/notes/commits > after_commit &&
+	git rev-parse --verify refs/notes/commits >after_commit &&
 	test_cmp before_commit after_commit
 '
 
@@ -505,69 +443,67 @@ test_expect_success 'removing with --stdin --ignore-missing' '
 '
 
 test_expect_success 'list notes with "git notes list"' '
-	git notes list > output &&
+	cat >expect <<-EOF &&
+		c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 7a4ca6ee52a974a66cbaa78e33214535dff1d691
+		c18dc024e14f08d18d14eea0d747ff692d66d6a3 d07d62e5208f22eb5695e7eb47667dc8b9860290
+	EOF
+	git notes list >output &&
 	test_cmp expect output
 '
 
 test_expect_success 'list notes with "git notes"' '
-	git notes > output &&
+	git notes >output &&
 	test_cmp expect output
 '
 
-cat > expect << EOF
-c18dc024e14f08d18d14eea0d747ff692d66d6a3
-EOF
-
 test_expect_success 'list specific note with "git notes list <object>"' '
-	git notes list HEAD^^ > output &&
+	cat >expect <<-EOF &&
+		c18dc024e14f08d18d14eea0d747ff692d66d6a3
+	EOF
+	git notes list HEAD^^ >output &&
 	test_cmp expect output
 '
 
-cat > expect << EOF
-EOF
-
 test_expect_success 'listing non-existing notes fails' '
-	test_must_fail git notes list HEAD > output &&
+	cat >expect <<-EOF &&
+	EOF
+	test_must_fail git notes list HEAD >output &&
 	test_cmp expect output
 '
 
-cat > expect << EOF
-Initial set of notes
-
-More notes appended with git notes append
-EOF
-
 test_expect_success 'append to existing note with "git notes append"' '
+	cat >expect <<-EOF &&
+		Initial set of notes
+
+		More notes appended with git notes append
+	EOF
 	git notes add -m "Initial set of notes" &&
 	git notes append -m "More notes appended with git notes append" &&
-	git notes show > output &&
+	git notes show >output &&
 	test_cmp expect output
 '
 
-cat > expect_list << EOF
-c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75
-c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5
-4b6ad22357cc8a1296720574b8d2fbc22fab0671 bd1753200303d0a0344be813e504253b3d98e74d
-EOF
-
 test_expect_success '"git notes list" does not expand to "git notes list HEAD"' '
-	git notes list > output &&
+	cat >expect_list <<-EOF &&
+		c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 7a4ca6ee52a974a66cbaa78e33214535dff1d691
+		4b6ad22357cc8a1296720574b8d2fbc22fab0671 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
+		c18dc024e14f08d18d14eea0d747ff692d66d6a3 d07d62e5208f22eb5695e7eb47667dc8b9860290
+	EOF
+	git notes list >output &&
 	test_cmp expect_list output
 '
 
 test_expect_success 'appending empty string does not change existing note' '
 	git notes append -m "" &&
-	git notes show > output &&
+	git notes show >output &&
 	test_cmp expect output
 '
 
 test_expect_success 'git notes append == add when there is no existing note' '
 	git notes remove HEAD &&
 	test_must_fail git notes list HEAD &&
-	git notes append -m "Initial set of notes
-
-More notes appended with git notes append" &&
-	git notes show > output &&
+	git notes append -m "Initial set of notes${LF}${LF}More notes appended with git notes append" &&
+	git notes show >output &&
 	test_cmp expect output
 '
 
@@ -579,229 +515,208 @@ test_expect_success 'appending empty string to non-existing note does not create
 '
 
 test_expect_success 'create other note on a different notes ref (setup)' '
-	: > a6 &&
-	git add a6 &&
-	test_tick &&
-	git commit -m 6th &&
-	GIT_NOTES_REF="refs/notes/other" git notes add -m "other note"
-'
-
-cat > expect-other << EOF
-commit 387a89921c73d7ed72cd94d179c1c7048ca47756
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:18:13 2005 -0700
+	test_commit 6th &&
+	GIT_NOTES_REF="refs/notes/other" git notes add -m "other note" &&
+	cat >expect-not-other <<-EOF &&
+		commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:18:13 2005 -0700
 
-    6th
+		${indent}6th
+	EOF
+	cp expect-not-other expect-other &&
+	cat >>expect-other <<-EOF
 
-Notes (other):
-    other note
-EOF
-
-cat > expect-not-other << EOF
-commit 387a89921c73d7ed72cd94d179c1c7048ca47756
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:18:13 2005 -0700
-
-    6th
-EOF
+		Notes (other):
+		${indent}other note
+	EOF
+'
 
 test_expect_success 'Do not show note on other ref by default' '
-	git log -1 > output &&
+	git log -1 >output &&
 	test_cmp expect-not-other output
 '
 
 test_expect_success 'Do show note when ref is given in GIT_NOTES_REF' '
-	GIT_NOTES_REF="refs/notes/other" git log -1 > output &&
+	GIT_NOTES_REF="refs/notes/other" git log -1 >output &&
 	test_cmp expect-other output
 '
 
 test_expect_success 'Do show note when ref is given in core.notesRef config' '
-	git config core.notesRef "refs/notes/other" &&
-	git log -1 > output &&
+	test_config core.notesRef "refs/notes/other" &&
+	git log -1 >output &&
 	test_cmp expect-other output
 '
 
 test_expect_success 'Do not show note when core.notesRef is overridden' '
-	GIT_NOTES_REF="refs/notes/wrong" git log -1 > output &&
+	test_config core.notesRef "refs/notes/other" &&
+	GIT_NOTES_REF="refs/notes/wrong" git log -1 >output &&
 	test_cmp expect-not-other output
 '
 
-cat > expect-both << EOF
-commit 387a89921c73d7ed72cd94d179c1c7048ca47756
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:18:13 2005 -0700
-
-    6th
+test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' '
+	cat >expect-both <<-EOF &&
+		commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:18:13 2005 -0700
 
-Notes:
-    order test
+		${indent}6th
 
-Notes (other):
-    other note
+		Notes:
+		${indent}order test
 
-commit bd1753200303d0a0344be813e504253b3d98e74d
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:17:13 2005 -0700
+		Notes (other):
+		${indent}other note
 
-    5th
+		commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:17:13 2005 -0700
 
-Notes:
-    replacement for deleted note
-EOF
+		${indent}5th
 
-test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' '
+		Notes:
+		${indent}replacement for deleted note
+	EOF
 	GIT_NOTES_REF=refs/notes/commits git notes add \
 		-m"replacement for deleted note" HEAD^ &&
 	GIT_NOTES_REF=refs/notes/commits git notes add -m"order test" &&
-	git config --unset core.notesRef &&
-	git config notes.displayRef "refs/notes/*" &&
-	git log -2 > output &&
+	test_unconfig core.notesRef &&
+	test_config notes.displayRef "refs/notes/*" &&
+	git log -2 >output &&
 	test_cmp expect-both output
 '
 
 test_expect_success 'core.notesRef is implicitly in notes.displayRef' '
-	git config core.notesRef refs/notes/commits &&
-	git config notes.displayRef refs/notes/other &&
-	git log -2 > output &&
+	test_config core.notesRef refs/notes/commits &&
+	test_config notes.displayRef refs/notes/other &&
+	git log -2 >output &&
 	test_cmp expect-both output
 '
 
 test_expect_success 'notes.displayRef can be given more than once' '
-	git config --unset core.notesRef &&
-	git config notes.displayRef refs/notes/commits &&
+	test_unconfig core.notesRef &&
+	test_config notes.displayRef refs/notes/commits &&
 	git config --add notes.displayRef refs/notes/other &&
-	git log -2 > output &&
+	git log -2 >output &&
 	test_cmp expect-both output
 '
 
-cat > expect-both-reversed << EOF
-commit 387a89921c73d7ed72cd94d179c1c7048ca47756
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:18:13 2005 -0700
-
-    6th
-
-Notes (other):
-    other note
-
-Notes:
-    order test
-EOF
-
 test_expect_success 'notes.displayRef respects order' '
-	git config core.notesRef refs/notes/other &&
-	git config --unset-all notes.displayRef &&
-	git config notes.displayRef refs/notes/commits &&
-	git log -1 > output &&
+	cat >expect-both-reversed <<-EOF &&
+		commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:18:13 2005 -0700
+
+		${indent}6th
+
+		Notes (other):
+		${indent}other note
+
+		Notes:
+		${indent}order test
+	EOF
+	test_config core.notesRef refs/notes/other &&
+	test_config notes.displayRef refs/notes/commits &&
+	git log -1 >output &&
 	test_cmp expect-both-reversed output
 '
 
 test_expect_success 'GIT_NOTES_DISPLAY_REF works' '
-	git config --unset-all core.notesRef &&
-	git config --unset-all notes.displayRef &&
 	GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \
-		git log -2 > output &&
+		git log -2 >output &&
 	test_cmp expect-both output
 '
 
-cat > expect-none << EOF
-commit 387a89921c73d7ed72cd94d179c1c7048ca47756
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:18:13 2005 -0700
+test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' '
+	cat >expect-none <<-EOF &&
+		commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:18:13 2005 -0700
 
-    6th
+		${indent}6th
 
-commit bd1753200303d0a0344be813e504253b3d98e74d
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:17:13 2005 -0700
+		commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:17:13 2005 -0700
 
-    5th
-EOF
-
-test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' '
-	git config notes.displayRef "refs/notes/*" &&
-	GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 > output &&
+		${indent}5th
+	EOF
+	test_config notes.displayRef "refs/notes/*" &&
+	GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 >output &&
 	test_cmp expect-none output
 '
 
 test_expect_success '--show-notes=* adds to GIT_NOTES_DISPLAY_REF' '
-	GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 > output &&
+	GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 >output &&
 	test_cmp expect-both output
 '
 
-cat > expect-commits << EOF
-commit 387a89921c73d7ed72cd94d179c1c7048ca47756
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:18:13 2005 -0700
-
-    6th
+test_expect_success '--no-standard-notes' '
+	cat >expect-commits <<EOF
+		commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:18:13 2005 -0700
 
-Notes:
-    order test
-EOF
+		${indent}6th
 
-test_expect_success '--no-standard-notes' '
-	git log --no-standard-notes --show-notes=commits -1 > output &&
+		Notes:
+		${indent}order test
+	EOF
+	git log --no-standard-notes --show-notes=commits -1 >output &&
 	test_cmp expect-commits output
 '
 
 test_expect_success '--standard-notes' '
+	test_config notes.displayRef "refs/notes/*" &&
 	git log --no-standard-notes --show-notes=commits \
-		--standard-notes -2 > output &&
+		--standard-notes -2 >output &&
 	test_cmp expect-both output
 '
 
 test_expect_success '--show-notes=ref accumulates' '
 	git log --show-notes=other --show-notes=commits \
-		 --no-standard-notes -1 > output &&
+		 --no-standard-notes -1 >output &&
 	test_cmp expect-both-reversed output
 '
 
 test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
-	git config core.notesRef refs/notes/other &&
-	echo "Note on a tree" > expect &&
+	test_config core.notesRef refs/notes/other &&
+	echo "Note on a tree" >expect &&
 	git notes add -m "Note on a tree" HEAD: &&
-	git notes show HEAD: > actual &&
+	git notes show HEAD: >actual &&
 	test_cmp expect actual &&
-	echo "Note on a blob" > expect &&
+	echo "Note on a blob" >expect &&
 	filename=$(git ls-tree --name-only HEAD | head -n1) &&
 	git notes add -m "Note on a blob" HEAD:$filename &&
-	git notes show HEAD:$filename > actual &&
+	git notes show HEAD:$filename >actual &&
 	test_cmp expect actual &&
-	echo "Note on a tag" > expect &&
+	echo "Note on a tag" >expect &&
 	git tag -a -m "This is an annotated tag" foobar HEAD^ &&
 	git notes add -m "Note on a tag" foobar &&
-	git notes show foobar > actual &&
+	git notes show foobar >actual &&
 	test_cmp expect actual
 '
 
-cat > expect << EOF
-commit 2ede89468182a62d0bde2583c736089bcf7d7e92
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:19:13 2005 -0700
+test_expect_success 'create note from other note with "git notes add -C"' '
+	cat >expect <<-EOF &&
+		commit fb01e0ca8c33b6cc0c6451dde747f97df567cb5c
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:19:13 2005 -0700
 
-    7th
+		${indent}7th
 
-Notes (other):
-    other note
-EOF
-
-test_expect_success 'create note from other note with "git notes add -C"' '
-	: > a7 &&
-	git add a7 &&
-	test_tick &&
-	git commit -m 7th &&
+		Notes:
+		${indent}order test
+	EOF
+	test_commit 7th &&
 	git notes add -C $(git notes list HEAD^) &&
-	git log -1 > actual &&
+	git log -1 >actual &&
 	test_cmp expect actual &&
 	test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
 '
 
 test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
-	: > a8 &&
-	git add a8 &&
-	test_tick &&
-	git commit -m 8th &&
+	test_commit 8th &&
 	test_must_fail git notes add -C deadbeef &&
 	test_must_fail git notes list HEAD
 '
@@ -814,404 +729,385 @@ test_expect_success 'create note from non-blob with "git notes add -C" fails' '
 	test_must_fail git notes list HEAD
 '
 
-cat > expect << EOF
-commit 80d796defacd5db327b7a4e50099663902fbdc5c
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:20:13 2005 -0700
+test_expect_success 'create note from blob with "git notes add -C" reuses blob id' '
+	cat >expect <<-EOF &&
+		commit 9a4c31c7f722b5d517e92c64e932dd751e1413bf
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:20:13 2005 -0700
 
-    8th
+		${indent}8th
 
-Notes (other):
-    This is a blob object
-EOF
-
-test_expect_success 'create note from blob with "git notes add -C" reuses blob id' '
+		Notes:
+		${indent}This is a blob object
+	EOF
 	blob=$(echo "This is a blob object" | git hash-object -w --stdin) &&
 	git notes add -C $blob &&
-	git log -1 > actual &&
+	git log -1 >actual &&
 	test_cmp expect actual &&
 	test "$(git notes list HEAD)" = "$blob"
 '
 
-cat > expect << EOF
-commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:21:13 2005 -0700
-
-    9th
+test_expect_success 'create note from other note with "git notes add -c"' '
+	cat >expect <<-EOF &&
+		commit 2e0db4bc649e174d667a1cde19e725cf897a5bd2
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:21:13 2005 -0700
 
-Notes (other):
-    yet another note
-EOF
+		${indent}9th
 
-test_expect_success 'create note from other note with "git notes add -c"' '
-	: > a9 &&
-	git add a9 &&
-	test_tick &&
-	git commit -m 9th &&
+		Notes:
+		${indent}yet another note
+	EOF
+	test_commit 9th &&
 	MSG="yet another note" git notes add -c $(git notes list HEAD^^) &&
-	git log -1 > actual &&
+	git log -1 >actual &&
 	test_cmp expect actual
 '
 
 test_expect_success 'create note from non-existing note with "git notes add -c" fails' '
-	: > a10 &&
-	git add a10 &&
-	test_tick &&
-	git commit -m 10th &&
+	test_commit 10th &&
 	test_must_fail env MSG="yet another note" git notes add -c deadbeef &&
 	test_must_fail git notes list HEAD
 '
 
-cat > expect << EOF
-commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:21:13 2005 -0700
-
-    9th
-
-Notes (other):
-    yet another note
-$whitespace
-    yet another note
-EOF
-
 test_expect_success 'append to note from other note with "git notes append -C"' '
+	cat >expect <<-EOF &&
+		commit 2e0db4bc649e174d667a1cde19e725cf897a5bd2
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:21:13 2005 -0700
+
+		${indent}9th
+
+		Notes:
+		${indent}yet another note
+		${indent}
+		${indent}yet another note
+	EOF
 	git notes append -C $(git notes list HEAD^) HEAD^ &&
-	git log -1 HEAD^ > actual &&
+	git log -1 HEAD^ >actual &&
 	test_cmp expect actual
 '
 
-cat > expect << EOF
-commit ffed603236bfa3891c49644257a83598afe8ae5a
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:22:13 2005 -0700
-
-    10th
+test_expect_success 'create note from other note with "git notes append -c"' '
+	cat >expect <<-EOF &&
+		commit 7c3b87ab368f81e11b1ea87b2ab99a71ccd25406
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:22:13 2005 -0700
 
-Notes (other):
-    other note
-EOF
+		${indent}10th
 
-test_expect_success 'create note from other note with "git notes append -c"' '
+		Notes:
+		${indent}other note
+	EOF
 	MSG="other note" git notes append -c $(git notes list HEAD^) &&
-	git log -1 > actual &&
+	git log -1 >actual &&
 	test_cmp expect actual
 '
 
-cat > expect << EOF
-commit ffed603236bfa3891c49644257a83598afe8ae5a
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:22:13 2005 -0700
-
-    10th
-
-Notes (other):
-    other note
-$whitespace
-    yet another note
-EOF
-
 test_expect_success 'append to note from other note with "git notes append -c"' '
+	cat >expect <<-EOF &&
+		commit 7c3b87ab368f81e11b1ea87b2ab99a71ccd25406
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:22:13 2005 -0700
+
+		${indent}10th
+
+		Notes:
+		${indent}other note
+		${indent}
+		${indent}yet another note
+	EOF
 	MSG="yet another note" git notes append -c $(git notes list HEAD) &&
-	git log -1 > actual &&
+	git log -1 >actual &&
 	test_cmp expect actual
 '
 
-cat > expect << EOF
-commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:23:13 2005 -0700
-
-    11th
-
-Notes (other):
-    other note
-$whitespace
-    yet another note
-EOF
-
 test_expect_success 'copy note with "git notes copy"' '
-	: > a11 &&
-	git add a11 &&
-	test_tick &&
-	git commit -m 11th &&
+	cat >expect <<-EOF &&
+		commit a446fff8777efdc6eb8f4b7c8a5ff699484df0d5
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:23:13 2005 -0700
+
+		${indent}11th
+
+		Notes:
+		${indent}other note
+		${indent}
+		${indent}yet another note
+	EOF
+	test_commit 11th &&
 	git notes copy HEAD^ HEAD &&
-	git log -1 > actual &&
+	git log -1 >actual &&
 	test_cmp expect actual &&
 	test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
 '
 
 test_expect_success 'prevent overwrite with "git notes copy"' '
 	test_must_fail git notes copy HEAD~2 HEAD &&
-	git log -1 > actual &&
+	git log -1 >actual &&
 	test_cmp expect actual &&
 	test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
 '
 
-cat > expect << EOF
-commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:23:13 2005 -0700
-
-    11th
-
-Notes (other):
-    yet another note
-$whitespace
-    yet another note
-EOF
-
 test_expect_success 'allow overwrite with "git notes copy -f"' '
+	cat >expect <<-EOF &&
+		commit a446fff8777efdc6eb8f4b7c8a5ff699484df0d5
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:23:13 2005 -0700
+
+		${indent}11th
+
+		Notes:
+		${indent}yet another note
+		${indent}
+		${indent}yet another note
+	EOF
 	git notes copy -f HEAD~2 HEAD &&
-	git log -1 > actual &&
+	git log -1 >actual &&
 	test_cmp expect actual &&
 	test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
 '
 
 test_expect_success 'cannot copy note from object without notes' '
-	: > a12 &&
-	git add a12 &&
-	test_tick &&
-	git commit -m 12th &&
-	: > a13 &&
-	git add a13 &&
-	test_tick &&
-	git commit -m 13th &&
+	test_commit 12th &&
+	test_commit 13th &&
 	test_must_fail git notes copy HEAD^ HEAD
 '
 
-cat > expect << EOF
-commit e5d4fb5698d564ab8c73551538ecaf2b0c666185
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:25:13 2005 -0700
-
-    13th
+test_expect_success 'git notes copy --stdin' '
+	cat >expect <<-EOF &&
+		commit e871aa61182b1d95d0a6fb75445d891722863b6b
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:25:13 2005 -0700
 
-Notes (other):
-    yet another note
-$whitespace
-    yet another note
+		${indent}13th
 
-commit 7038787dfe22a14c3867ce816dbba39845359719
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:24:13 2005 -0700
+		Notes:
+		${indent}yet another note
+		${indent}
+		${indent}yet another note
 
-    12th
+		commit 65e263ded02ae4e8839bc151095113737579dc12
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:24:13 2005 -0700
 
-Notes (other):
-    other note
-$whitespace
-    yet another note
-EOF
+		${indent}12th
 
-test_expect_success 'git notes copy --stdin' '
+		Notes:
+		${indent}other note
+		${indent}
+		${indent}yet another note
+	EOF
 	(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
 	echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
 	git notes copy --stdin &&
-	git log -2 > output &&
+	git log -2 >output &&
 	test_cmp expect output &&
 	test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" &&
 	test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)"
 '
 
-cat > expect << EOF
-commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:27:13 2005 -0700
-
-    15th
+test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
+	cat >expect <<-EOF &&
+		commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:27:13 2005 -0700
 
-commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:26:13 2005 -0700
+		${indent}15th
 
-    14th
-EOF
+		commit 07c85d77059393ed0154b8c96906547a59dfcddd
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:26:13 2005 -0700
 
-test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
+		${indent}14th
+	EOF
 	test_commit 14th &&
 	test_commit 15th &&
 	(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
 	echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
 	git notes copy --for-rewrite=foo &&
-	git log -2 > output &&
+	git log -2 >output &&
 	test_cmp expect output
 '
 
-cat > expect << EOF
-commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:27:13 2005 -0700
-
-    15th
-
-Notes (other):
-    yet another note
-$whitespace
-    yet another note
-
-commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:26:13 2005 -0700
-
-    14th
-
-Notes (other):
-    other note
-$whitespace
-    yet another note
-EOF
-
 test_expect_success 'git notes copy --for-rewrite (enabled)' '
-	git config notes.rewriteMode overwrite &&
-	git config notes.rewriteRef "refs/notes/*" &&
+	cat >expect <<-EOF &&
+		commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:27:13 2005 -0700
+
+		${indent}15th
+
+		Notes:
+		${indent}yet another note
+		${indent}
+		${indent}yet another note
+
+		commit 07c85d77059393ed0154b8c96906547a59dfcddd
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:26:13 2005 -0700
+
+		${indent}14th
+
+		Notes:
+		${indent}other note
+		${indent}
+		${indent}yet another note
+	EOF
+	test_config notes.rewriteMode overwrite &&
+	test_config notes.rewriteRef "refs/notes/*" &&
 	(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
 	echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
 	git notes copy --for-rewrite=foo &&
-	git log -2 > output &&
+	git log -2 >output &&
 	test_cmp expect output
 '
 
 test_expect_success 'git notes copy --for-rewrite (disabled)' '
-	git config notes.rewrite.bar false &&
+	test_config notes.rewrite.bar false &&
 	echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) |
 	git notes copy --for-rewrite=bar &&
-	git log -2 > output &&
+	git log -2 >output &&
 	test_cmp expect output
 '
 
-cat > expect << EOF
-commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:27:13 2005 -0700
-
-    15th
+test_expect_success 'git notes copy --for-rewrite (overwrite)' '
+	cat >expect <<-EOF &&
+		commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:27:13 2005 -0700
 
-Notes (other):
-    a fresh note
-EOF
+		${indent}15th
 
-test_expect_success 'git notes copy --for-rewrite (overwrite)' '
+		Notes:
+		${indent}a fresh note
+	EOF
 	git notes add -f -m"a fresh note" HEAD^ &&
+	test_config notes.rewriteMode overwrite &&
+	test_config notes.rewriteRef "refs/notes/*" &&
 	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
 	git notes copy --for-rewrite=foo &&
-	git log -1 > output &&
+	git log -1 >output &&
 	test_cmp expect output
 '
 
 test_expect_success 'git notes copy --for-rewrite (ignore)' '
-	git config notes.rewriteMode ignore &&
+	test_config notes.rewriteMode ignore &&
+	test_config notes.rewriteRef "refs/notes/*" &&
 	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
 	git notes copy --for-rewrite=foo &&
-	git log -1 > output &&
+	git log -1 >output &&
 	test_cmp expect output
 '
 
-cat > expect << EOF
-commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:27:13 2005 -0700
-
-    15th
-
-Notes (other):
-    a fresh note
-$whitespace
-    another fresh note
-EOF
-
 test_expect_success 'git notes copy --for-rewrite (append)' '
+	cat >expect <<-EOF &&
+		commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:27:13 2005 -0700
+
+		${indent}15th
+
+		Notes:
+		${indent}a fresh note
+		${indent}
+		${indent}another fresh note
+	EOF
 	git notes add -f -m"another fresh note" HEAD^ &&
-	git config notes.rewriteMode concatenate &&
+	test_config notes.rewriteMode concatenate &&
+	test_config notes.rewriteRef "refs/notes/*" &&
 	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
 	git notes copy --for-rewrite=foo &&
-	git log -1 > output &&
+	git log -1 >output &&
 	test_cmp expect output
 '
 
-cat > expect << EOF
-commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:27:13 2005 -0700
-
-    15th
-
-Notes (other):
-    a fresh note
-$whitespace
-    another fresh note
-$whitespace
-    append 1
-$whitespace
-    append 2
-EOF
-
 test_expect_success 'git notes copy --for-rewrite (append two to one)' '
+	cat >expect <<-EOF &&
+		commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:27:13 2005 -0700
+
+		${indent}15th
+
+		Notes:
+		${indent}a fresh note
+		${indent}
+		${indent}another fresh note
+		${indent}
+		${indent}append 1
+		${indent}
+		${indent}append 2
+	EOF
 	git notes add -f -m"append 1" HEAD^ &&
 	git notes add -f -m"append 2" HEAD^^ &&
+	test_config notes.rewriteMode concatenate &&
+	test_config notes.rewriteRef "refs/notes/*" &&
 	(echo $(git rev-parse HEAD^) $(git rev-parse HEAD);
 	echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) |
 	git notes copy --for-rewrite=foo &&
-	git log -1 > output &&
+	git log -1 >output &&
 	test_cmp expect output
 '
 
 test_expect_success 'git notes copy --for-rewrite (append empty)' '
 	git notes remove HEAD^ &&
+	test_config notes.rewriteMode concatenate &&
+	test_config notes.rewriteRef "refs/notes/*" &&
 	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
 	git notes copy --for-rewrite=foo &&
-	git log -1 > output &&
+	git log -1 >output &&
 	test_cmp expect output
 '
 
-cat > expect << EOF
-commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:27:13 2005 -0700
-
-    15th
-
-Notes (other):
-    replacement note 1
-EOF
-
 test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
+	cat >expect <<-EOF &&
+		commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:27:13 2005 -0700
+
+		${indent}15th
+
+		Notes:
+		${indent}replacement note 1
+	EOF
+	test_config notes.rewriteMode concatenate &&
+	test_config notes.rewriteRef "refs/notes/*" &&
 	git notes add -f -m"replacement note 1" HEAD^ &&
 	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
 	GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo &&
-	git log -1 > output &&
+	git log -1 >output &&
 	test_cmp expect output
 '
 
-cat > expect << EOF
-commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
-Author: A U Thor <author@example.com>
-Date:   Thu Apr 7 15:27:13 2005 -0700
-
-    15th
+test_expect_success 'GIT_NOTES_REWRITE_REF works' '
+	cat >expect <<-EOF &&
+		commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:27:13 2005 -0700
 
-Notes (other):
-    replacement note 2
-EOF
+		${indent}15th
 
-test_expect_success 'GIT_NOTES_REWRITE_REF works' '
-	git config notes.rewriteMode overwrite &&
+		Notes:
+		${indent}replacement note 2
+	EOF
 	git notes add -f -m"replacement note 2" HEAD^ &&
-	git config --unset-all notes.rewriteRef &&
+	test_config notes.rewriteMode overwrite &&
+	test_unconfig notes.rewriteRef &&
 	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
 	GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \
 		git notes copy --for-rewrite=foo &&
-	git log -1 > output &&
+	git log -1 >output &&
 	test_cmp expect output
 '
 
 test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
-	git config notes.rewriteRef refs/notes/other &&
 	git notes add -f -m"replacement note 3" HEAD^ &&
+	test_config notes.rewriteMode overwrite &&
+	test_config notes.rewriteRef refs/notes/other &&
 	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
 	GIT_NOTES_REWRITE_REF= git notes copy --for-rewrite=foo &&
-	git log -1 > output &&
+	git log -1 >output &&
 	test_cmp expect output
 '
 
@@ -1221,13 +1117,13 @@ test_expect_success 'git notes copy diagnoses too many or too few parameters' '
 '
 
 test_expect_success 'git notes get-ref (no overrides)' '
-	git config --unset core.notesRef &&
+	test_unconfig core.notesRef &&
 	sane_unset GIT_NOTES_REF &&
 	test "$(git notes get-ref)" = "refs/notes/commits"
 '
 
 test_expect_success 'git notes get-ref (core.notesRef)' '
-	git config core.notesRef refs/notes/foo &&
+	test_config core.notesRef refs/notes/foo &&
 	test "$(git notes get-ref)" = "refs/notes/foo"
 '
 
@@ -1277,10 +1173,10 @@ EOF
 test_expect_success 'empty notes are displayed by git log' '
 	test_commit 17th &&
 	git log -1 >expect &&
-	cat >>expect <<\EOF &&
+	cat >>expect <<-EOF &&
 
-Notes:
-EOF
+		Notes:
+	EOF
 	git notes add -C "$empty_blob" --allow-empty &&
 	git log -1 >actual &&
 	test_cmp expect actual
-- 
2.1.1.392.g062cc5d

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCHv4 5/9] builtin/notes: Simplify early exit code in add()
  2014-11-09 12:30 ` [PATCHv4 5/9] builtin/notes: Simplify early exit code in add() Johan Herland
@ 2014-11-10 20:36   ` Junio C Hamano
  2014-11-11  0:49     ` Johan Herland
  0 siblings, 1 reply; 17+ messages in thread
From: Junio C Hamano @ 2014-11-10 20:36 UTC (permalink / raw)
  To: Johan Herland; +Cc: git, mackyle, jhf, sunshine

Johan Herland <johan@herland.net> writes:

> Signed-off-by: Johan Herland <johan@herland.net>
> ---
>  builtin/notes.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/builtin/notes.c b/builtin/notes.c
> index 1017472..f1480cf 100644
> --- a/builtin/notes.c
> +++ b/builtin/notes.c
> @@ -399,7 +399,7 @@ static int append_edit(int argc, const char **argv, const char *prefix);
>  
>  static int add(int argc, const char **argv, const char *prefix)
>  {
> -	int retval = 0, force = 0;
> +	int force = 0;
>  	const char *object_ref;
>  	struct notes_tree *t;
>  	unsigned char object[20], new_note[20];
> @@ -441,6 +441,8 @@ static int add(int argc, const char **argv, const char *prefix)
>  
>  	if (note) {
>  		if (!force) {
> +			free_note_data(&d);
> +			free_notes(t);
>  			if (!d.given) {

It looks a bit strange to refer to d.given after calling a function
that sounds as if it is meant to clear what is recorded in and to
invalidate &d; yes, I can read the implementation to see that
d.given keeps its stale value, but that is something other people
may want to "clean up" later and this reference to d.given will get
in the way when that happens.

At this point of the code, it makes sense to free t in preparation
to either switching to append codepath or erroring out, but does &d
have anything in it already to necessitate its freeing?

>  				/*
>  				 * Redirect to "edit" subcommand.
> @@ -450,14 +452,11 @@ static int add(int argc, const char **argv, const char *prefix)
>  				 * therefore still in argv[0-1].
>  				 */
>  				argv[0] = "edit";
> -				free_note_data(&d);
> -				free_notes(t);
>  				return append_edit(argc, argv, prefix);
>  			}
> -			retval = error(_("Cannot add notes. Found existing notes "
> +			return error(_("Cannot add notes. Found existing notes "
>  				       "for object %s. Use '-f' to overwrite "
>  				       "existing notes"), sha1_to_hex(object));
> -			goto out;
>  		}
>  		fprintf(stderr, _("Overwriting existing notes for object %s\n"),
>  			sha1_to_hex(object));
> @@ -474,9 +473,8 @@ static int add(int argc, const char **argv, const char *prefix)
>  	snprintf(logmsg, sizeof(logmsg), "Notes %s by 'git notes %s'",
>  		 is_null_sha1(new_note) ? "removed" : "added", "add");
>  	commit_notes(t, logmsg);
> -out:
>  	free_notes(t);
> -	return retval;
> +	return 0;
>  }
>  
>  static int copy(int argc, const char **argv, const char *prefix)

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCHv4 9/9] t3301: Modernize
  2014-11-09 12:30 ` [PATCHv4 9/9] t3301: Modernize Johan Herland
@ 2014-11-10 20:42   ` Junio C Hamano
  2014-11-11  1:04     ` Johan Herland
  0 siblings, 1 reply; 17+ messages in thread
From: Junio C Hamano @ 2014-11-10 20:42 UTC (permalink / raw)
  To: Johan Herland; +Cc: git, mackyle, jhf, sunshine

Johan Herland <johan@herland.net> writes:

> Make this test script appear somewhat less old-fashioned:
>  - Use test helper functions:
>     - write_script
>     - test_commit
>     - test_write_lines
>     - test_config
>     - test_unconfig
>     - test_path_is_missing
>  - Remove whitespace between redirection operators and their targets.
>  - Move preparation of "except" files into tests.

expect, I think (no need to resend; I've fixed it up locally).

>  - More consistent quoting, especially around commands that might
>    expand to nothing.
>  - More visibility of important whitespace with ${indent}.
>  - Combine pairs of tests that unnecessarily split setup and verification.
>
> Improved-by: Eric Sunshine <sunshine@sunshineco.com>
> Improved-by: Junio C Hamano <gitster@pobox.com>
> Signed-off-by: Johan Herland <johan@herland.net>
> ---
>  t/t3301-notes.sh | 1148 +++++++++++++++++++++++++-----------------------------
>  1 file changed, 522 insertions(+), 626 deletions(-)
>
> diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
> index 416ed9e..cd756ec 100755
> --- a/t/t3301-notes.sh
> +++ b/t/t3301-notes.sh
> @@ -7,28 +7,22 @@ test_description='Test commit notes'
>  
>  . ./test-lib.sh
>  
> -cat > fake_editor.sh << \EOF
> -#!/bin/sh
> -echo "$MSG" > "$1"
> -echo "$MSG" >& 2
> +write_script fake_editor <<\EOF
> +echo "$MSG" >"$1"
> +echo "$MSG" >&2
>  EOF
> -chmod a+x fake_editor.sh
> -GIT_EDITOR=./fake_editor.sh
> +GIT_EDITOR=./fake_editor
>  export GIT_EDITOR
>  
> +indent="    "
> +
>  test_expect_success 'cannot annotate non-existing HEAD' '
>  	test_must_fail env MSG=3 git notes add
>  '
>  
> -test_expect_success setup '
> -	: > a1 &&
> -	git add a1 &&
> -	test_tick &&
> -	git commit -m 1st &&
> -	: > a2 &&
> -	git add a2 &&
> -	test_tick &&
> -	git commit -m 2nd
> +test_expect_success 'setup' '
> +	test_commit 1st &&
> +	test_commit 2nd
>  '
>  
>  test_expect_success 'need valid notes ref' '
> @@ -50,189 +44,163 @@ test_expect_success 'handle empty notes gracefully' '
>  '
>  
>  test_expect_success 'show non-existent notes entry with %N' '
> -	for l in A B
> -	do
> -		echo "$l"
> -	done >expect &&
> -	git show -s --format='A%n%NB' >output &&
> +	test_write_lines A B >expect &&
> +	git show -s --format="A%n%NB" >output &&
>  	test_cmp expect output
>  '
>  
>  test_expect_success 'create notes' '
> -	git config core.notesRef refs/notes/commits &&
>  	MSG=b4 git notes add &&
> -	test ! -f .git/NOTES_EDITMSG &&
> -	test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
> -	test b4 = $(git notes show) &&
> +	test_path_is_missing .git/NOTES_EDITMSG &&
> +	test "1" = "$(git ls-tree refs/notes/commits | wc -l)" &&
> +	test "b4" = "$(git notes show)" &&
>  	git show HEAD^ &&
>  	test_must_fail git notes show HEAD^
>  '
>  
>  test_expect_success 'show notes entry with %N' '
> -	for l in A b4 B
> -	do
> -		echo "$l"
> -	done >expect &&
> -	git show -s --format='A%n%NB' >output &&
> +	test_write_lines A b4 B >expect &&
> +	git show -s --format="A%n%NB" >output &&
>  	test_cmp expect output
>  '
>  
> -cat >expect <<EOF
> -d423f8c refs/notes/commits@{0}: notes: Notes added by 'git notes add'
> -EOF
> -
>  test_expect_success 'create reflog entry' '
> +	cat <<-EOF >expect &&
> +		a1d8fa6 refs/notes/commits@{0}: notes: Notes added by '"'"'git notes add'"'"'
> +	EOF
>  	git reflog show refs/notes/commits >output &&
>  	test_cmp expect output
>  '
>  
>  test_expect_success 'edit existing notes' '
>  	MSG=b3 git notes edit &&
> -	test ! -f .git/NOTES_EDITMSG &&
> -	test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
> -	test b3 = $(git notes show) &&
> +	test_path_is_missing .git/NOTES_EDITMSG &&
> +	test "1" = "$(git ls-tree refs/notes/commits | wc -l)" &&
> +	test "b3" = "$(git notes show)" &&
>  	git show HEAD^ &&
>  	test_must_fail git notes show HEAD^
>  '
>  
>  test_expect_success 'cannot "git notes add -m" where notes already exists' '
>  	test_must_fail git notes add -m "b2" &&
> -	test ! -f .git/NOTES_EDITMSG &&
> -	test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
> -	test b3 = $(git notes show) &&
> +	test_path_is_missing .git/NOTES_EDITMSG &&
> +	test "1" = "$(git ls-tree refs/notes/commits | wc -l)" &&
> +	test "b3" = "$(git notes show)" &&
>  	git show HEAD^ &&
>  	test_must_fail git notes show HEAD^
>  '
>  
>  test_expect_success 'can overwrite existing note with "git notes add -f -m"' '
>  	git notes add -f -m "b1" &&
> -	test ! -f .git/NOTES_EDITMSG &&
> -	test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
> -	test b1 = $(git notes show) &&
> +	test_path_is_missing .git/NOTES_EDITMSG &&
> +	test "1" = "$(git ls-tree refs/notes/commits | wc -l)" &&
> +	test "b1" = "$(git notes show)" &&
>  	git show HEAD^ &&
>  	test_must_fail git notes show HEAD^
>  '
>  
>  test_expect_success 'add w/no options on existing note morphs into edit' '
>  	MSG=b2 git notes add &&
> -	test ! -f .git/NOTES_EDITMSG &&
> -	test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
> -	test b2 = $(git notes show) &&
> +	test_path_is_missing .git/NOTES_EDITMSG &&
> +	test "1" = "$(git ls-tree refs/notes/commits | wc -l)" &&
> +	test "b2" = "$(git notes show)" &&
>  	git show HEAD^ &&
>  	test_must_fail git notes show HEAD^
>  '
>  
>  test_expect_success 'can overwrite existing note with "git notes add -f"' '
>  	MSG=b1 git notes add -f &&
> -	test ! -f .git/NOTES_EDITMSG &&
> -	test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
> -	test b1 = $(git notes show) &&
> +	test_path_is_missing .git/NOTES_EDITMSG &&
> +	test "1" = "$(git ls-tree refs/notes/commits | wc -l)" &&
> +	test "b1" = "$(git notes show)" &&
>  	git show HEAD^ &&
>  	test_must_fail git notes show HEAD^
>  '
>  
> -cat > expect << EOF
> -commit 268048bfb8a1fb38e703baceb8ab235421bf80c5
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:14:13 2005 -0700
> +test_expect_success 'show notes' '
> +	cat >expect <<-EOF &&
> +		commit 7a4ca6ee52a974a66cbaa78e33214535dff1d691
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:14:13 2005 -0700
>  
> -    2nd
> +		${indent}2nd
>  
> -Notes:
> -    b1
> -EOF
> -
> -test_expect_success 'show notes' '
> +		Notes:
> +		${indent}b1
> +	EOF
>  	! (git cat-file commit HEAD | grep b1) &&
> -	git log -1 > output &&
> +	git log -1 >output &&
>  	test_cmp expect output
>  '
>  
> -test_expect_success 'create multi-line notes (setup)' '
> -	: > a3 &&
> -	git add a3 &&
> -	test_tick &&
> -	git commit -m 3rd &&
> -	MSG="b3
> -c3c3c3c3
> -d3d3d3" git notes add
> -'
> -
> -cat > expect-multiline << EOF
> -commit 1584215f1d29c65e99c6c6848626553fdd07fd75
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:15:13 2005 -0700
> -
> -    3rd
> -
> -Notes:
> -    b3
> -    c3c3c3c3
> -    d3d3d3
> -EOF
> -
> -printf "\n" >> expect-multiline
> -cat expect >> expect-multiline
> -
>  test_expect_success 'show multi-line notes' '
> -	git log -2 > output &&
> +	test_commit 3rd &&
> +	MSG="b3${LF}c3c3c3c3${LF}d3d3d3" git notes add &&
> +	cat >expect-multiline <<-EOF &&
> +		commit d07d62e5208f22eb5695e7eb47667dc8b9860290
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:15:13 2005 -0700
> +
> +		${indent}3rd
> +
> +		Notes:
> +		${indent}b3
> +		${indent}c3c3c3c3
> +		${indent}d3d3d3
> +
> +	EOF
> +	cat expect >>expect-multiline &&
> +	git log -2 >output &&
>  	test_cmp expect-multiline output
>  '
> -test_expect_success 'create -F notes (setup)' '
> -	: > a4 &&
> -	git add a4 &&
> -	test_tick &&
> -	git commit -m 4th &&
> -	echo "xyzzy" > note5 &&
> -	git notes add -F note5
> -'
> -
> -cat > expect-F << EOF
> -commit 15023535574ded8b1a89052b32673f84cf9582b8
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:16:13 2005 -0700
> -
> -    4th
> -
> -Notes:
> -    xyzzy
> -EOF
> -
> -printf "\n" >> expect-F
> -cat expect-multiline >> expect-F
>  
>  test_expect_success 'show -F notes' '
> -	git log -3 > output &&
> +	test_commit 4th &&
> +	echo "xyzzy" >note5 &&
> +	git notes add -F note5 &&
> +	cat >expect-F <<-EOF &&
> +		commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:16:13 2005 -0700
> +
> +		${indent}4th
> +
> +		Notes:
> +		${indent}xyzzy
> +
> +	EOF
> +	cat expect-multiline >>expect-F &&
> +	git log -3 >output &&
>  	test_cmp expect-F output
>  '
>  
>  test_expect_success 'Re-adding -F notes without -f fails' '
> -	echo "zyxxy" > note5 &&
> +	echo "zyxxy" >note5 &&
>  	test_must_fail git notes add -F note5 &&
> -	git log -3 > output &&
> +	git log -3 >output &&
>  	test_cmp expect-F output
>  '
>  
> -cat >expect << EOF
> -commit 15023535574ded8b1a89052b32673f84cf9582b8
> -tree e070e3af51011e47b183c33adf9736736a525709
> -parent 1584215f1d29c65e99c6c6848626553fdd07fd75
> -author A U Thor <author@example.com> 1112912173 -0700
> -committer C O Mitter <committer@example.com> 1112912173 -0700
> -
> -    4th
> -EOF
>  test_expect_success 'git log --pretty=raw does not show notes' '
> +	cat >expect <<-EOF &&
> +		commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11
> +		tree 05ac65288c4c4b3b709a020ae94b2ece2f2201ae
> +		parent d07d62e5208f22eb5695e7eb47667dc8b9860290
> +		author A U Thor <author@example.com> 1112912173 -0700
> +		committer C O Mitter <committer@example.com> 1112912173 -0700
> +
> +		${indent}4th
> +	EOF
>  	git log -1 --pretty=raw >output &&
>  	test_cmp expect output
>  '
>  
> -cat >>expect <<EOF
> -
> -Notes:
> -    xyzzy
> -EOF
>  test_expect_success 'git log --show-notes' '
> +	cat >>expect <<-EOF &&
> +
> +	Notes:
> +	${indent}xyzzy
> +	EOF
>  	git log -1 --pretty=raw --show-notes >output &&
>  	test_cmp expect output
>  '
> @@ -304,128 +272,98 @@ test_expect_success 'git log --no-notes resets ref list' '
>  	! grep alternate output
>  '
>  
> -test_expect_success 'create -m notes (setup)' '
> -	: > a5 &&
> -	git add a5 &&
> -	test_tick &&
> -	git commit -m 5th &&
> -	git notes add -m spam -m "foo
> -bar
> -baz"
> -'
> -
> -whitespace="    "
> -cat > expect-m << EOF
> -commit bd1753200303d0a0344be813e504253b3d98e74d
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:17:13 2005 -0700
> -
> -    5th
> -
> -Notes:
> -    spam
> -$whitespace
> -    foo
> -    bar
> -    baz
> -EOF
> -
> -printf "\n" >> expect-m
> -cat expect-F >> expect-m
> -
>  test_expect_success 'show -m notes' '
> -	git log -4 > output &&
> +	test_commit 5th &&
> +	git notes add -m spam -m "foo${LF}bar${LF}baz" &&
> +	cat >expect-m <<-EOF &&
> +		commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:17:13 2005 -0700
> +
> +		${indent}5th
> +
> +		Notes:
> +		${indent}spam
> +		${indent}
> +		${indent}foo
> +		${indent}bar
> +		${indent}baz
> +
> +	EOF
> +	cat expect-F >>expect-m &&
> +	git log -4 >output &&
>  	test_cmp expect-m output
>  '
>  
> -test_expect_success 'remove note with add -f -F /dev/null (setup)' '
> -	git notes add -f -F /dev/null
> -'
> -
> -cat > expect-rm-F << EOF
> -commit bd1753200303d0a0344be813e504253b3d98e74d
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:17:13 2005 -0700
> -
> -    5th
> -EOF
> +test_expect_success 'remove note with add -f -F /dev/null' '
> +	git notes add -f -F /dev/null &&
> +	cat >expect-rm-F <<-EOF &&
> +		commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:17:13 2005 -0700
>  
> -printf "\n" >> expect-rm-F
> -cat expect-F >> expect-rm-F
> +		${indent}5th
>  
> -test_expect_success 'verify note removal with -F /dev/null' '
> -	git log -4 > output &&
> +	EOF
> +	cat expect-F >>expect-rm-F &&
> +	git log -4 >output &&
>  	test_cmp expect-rm-F output &&
>  	test_must_fail git notes show
>  '
>  
> -test_expect_success 'do not create empty note with -m "" (setup)' '
> -	git notes add -m ""
> -'
> -
> -test_expect_success 'verify non-creation of note with -m ""' '
> -	git log -4 > output &&
> +test_expect_success 'do not create empty note with -m ""' '
> +	git notes add -m "" &&
> +	git log -4 >output &&
>  	test_cmp expect-rm-F output &&
>  	test_must_fail git notes show
>  '
>  
> -cat > expect-combine_m_and_F << EOF
> -foo
> -
> -xyzzy
> +test_expect_success 'create note with combination of -m and -F' '
> +	cat >expect-combine_m_and_F <<-EOF &&
> +		foo
>  
> -bar
> +		xyzzy
>  
> -zyxxy
> +		bar
>  
> -baz
> -EOF
> +		zyxxy
>  
> -test_expect_success 'create note with combination of -m and -F' '
> -	echo "xyzzy" > note_a &&
> -	echo "zyxxy" > note_b &&
> +		baz
> +	EOF
> +	echo "xyzzy" >note_a &&
> +	echo "zyxxy" >note_b &&
>  	git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" &&
> -	git notes show > output &&
> +	git notes show >output &&
>  	test_cmp expect-combine_m_and_F output
>  '
>  
> -test_expect_success 'remove note with "git notes remove" (setup)' '
> +test_expect_success 'remove note with "git notes remove"' '
>  	git notes remove HEAD^ &&
> -	git notes remove
> -'
> +	git notes remove &&
> +	cat >expect-rm-remove <<-EOF &&
> +		commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:17:13 2005 -0700
>  
> -cat > expect-rm-remove << EOF
> -commit bd1753200303d0a0344be813e504253b3d98e74d
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:17:13 2005 -0700
> +		${indent}5th
>  
> -    5th
> -
> -commit 15023535574ded8b1a89052b32673f84cf9582b8
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:16:13 2005 -0700
> -
> -    4th
> -EOF
> +		commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:16:13 2005 -0700
>  
> -printf "\n" >> expect-rm-remove
> -cat expect-multiline >> expect-rm-remove
> +		${indent}4th
>  
> -test_expect_success 'verify note removal with "git notes remove"' '
> -	git log -4 > output &&
> +	EOF
> +	cat expect-multiline >>expect-rm-remove &&
> +	git log -4 >output &&
>  	test_cmp expect-rm-remove output &&
>  	test_must_fail git notes show HEAD^
>  '
>  
> -cat > expect << EOF
> -c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75
> -c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5
> -EOF
> -
>  test_expect_success 'removing non-existing note should not create new commit' '
> -	git rev-parse --verify refs/notes/commits > before_commit &&
> +	git rev-parse --verify refs/notes/commits >before_commit &&
>  	test_must_fail git notes remove HEAD^ &&
> -	git rev-parse --verify refs/notes/commits > after_commit &&
> +	git rev-parse --verify refs/notes/commits >after_commit &&
>  	test_cmp before_commit after_commit
>  '
>  
> @@ -505,69 +443,67 @@ test_expect_success 'removing with --stdin --ignore-missing' '
>  '
>  
>  test_expect_success 'list notes with "git notes list"' '
> -	git notes list > output &&
> +	cat >expect <<-EOF &&
> +		c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 7a4ca6ee52a974a66cbaa78e33214535dff1d691
> +		c18dc024e14f08d18d14eea0d747ff692d66d6a3 d07d62e5208f22eb5695e7eb47667dc8b9860290
> +	EOF
> +	git notes list >output &&
>  	test_cmp expect output
>  '
>  
>  test_expect_success 'list notes with "git notes"' '
> -	git notes > output &&
> +	git notes >output &&
>  	test_cmp expect output
>  '
>  
> -cat > expect << EOF
> -c18dc024e14f08d18d14eea0d747ff692d66d6a3
> -EOF
> -
>  test_expect_success 'list specific note with "git notes list <object>"' '
> -	git notes list HEAD^^ > output &&
> +	cat >expect <<-EOF &&
> +		c18dc024e14f08d18d14eea0d747ff692d66d6a3
> +	EOF
> +	git notes list HEAD^^ >output &&
>  	test_cmp expect output
>  '
>  
> -cat > expect << EOF
> -EOF
> -
>  test_expect_success 'listing non-existing notes fails' '
> -	test_must_fail git notes list HEAD > output &&
> +	cat >expect <<-EOF &&
> +	EOF
> +	test_must_fail git notes list HEAD >output &&
>  	test_cmp expect output
>  '
>  
> -cat > expect << EOF
> -Initial set of notes
> -
> -More notes appended with git notes append
> -EOF
> -
>  test_expect_success 'append to existing note with "git notes append"' '
> +	cat >expect <<-EOF &&
> +		Initial set of notes
> +
> +		More notes appended with git notes append
> +	EOF
>  	git notes add -m "Initial set of notes" &&
>  	git notes append -m "More notes appended with git notes append" &&
> -	git notes show > output &&
> +	git notes show >output &&
>  	test_cmp expect output
>  '
>  
> -cat > expect_list << EOF
> -c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75
> -c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5
> -4b6ad22357cc8a1296720574b8d2fbc22fab0671 bd1753200303d0a0344be813e504253b3d98e74d
> -EOF
> -
>  test_expect_success '"git notes list" does not expand to "git notes list HEAD"' '
> -	git notes list > output &&
> +	cat >expect_list <<-EOF &&
> +		c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 7a4ca6ee52a974a66cbaa78e33214535dff1d691
> +		4b6ad22357cc8a1296720574b8d2fbc22fab0671 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
> +		c18dc024e14f08d18d14eea0d747ff692d66d6a3 d07d62e5208f22eb5695e7eb47667dc8b9860290
> +	EOF
> +	git notes list >output &&
>  	test_cmp expect_list output
>  '
>  
>  test_expect_success 'appending empty string does not change existing note' '
>  	git notes append -m "" &&
> -	git notes show > output &&
> +	git notes show >output &&
>  	test_cmp expect output
>  '
>  
>  test_expect_success 'git notes append == add when there is no existing note' '
>  	git notes remove HEAD &&
>  	test_must_fail git notes list HEAD &&
> -	git notes append -m "Initial set of notes
> -
> -More notes appended with git notes append" &&
> -	git notes show > output &&
> +	git notes append -m "Initial set of notes${LF}${LF}More notes appended with git notes append" &&
> +	git notes show >output &&
>  	test_cmp expect output
>  '
>  
> @@ -579,229 +515,208 @@ test_expect_success 'appending empty string to non-existing note does not create
>  '
>  
>  test_expect_success 'create other note on a different notes ref (setup)' '
> -	: > a6 &&
> -	git add a6 &&
> -	test_tick &&
> -	git commit -m 6th &&
> -	GIT_NOTES_REF="refs/notes/other" git notes add -m "other note"
> -'
> -
> -cat > expect-other << EOF
> -commit 387a89921c73d7ed72cd94d179c1c7048ca47756
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:18:13 2005 -0700
> +	test_commit 6th &&
> +	GIT_NOTES_REF="refs/notes/other" git notes add -m "other note" &&
> +	cat >expect-not-other <<-EOF &&
> +		commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:18:13 2005 -0700
>  
> -    6th
> +		${indent}6th
> +	EOF
> +	cp expect-not-other expect-other &&
> +	cat >>expect-other <<-EOF
>  
> -Notes (other):
> -    other note
> -EOF
> -
> -cat > expect-not-other << EOF
> -commit 387a89921c73d7ed72cd94d179c1c7048ca47756
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:18:13 2005 -0700
> -
> -    6th
> -EOF
> +		Notes (other):
> +		${indent}other note
> +	EOF
> +'
>  
>  test_expect_success 'Do not show note on other ref by default' '
> -	git log -1 > output &&
> +	git log -1 >output &&
>  	test_cmp expect-not-other output
>  '
>  
>  test_expect_success 'Do show note when ref is given in GIT_NOTES_REF' '
> -	GIT_NOTES_REF="refs/notes/other" git log -1 > output &&
> +	GIT_NOTES_REF="refs/notes/other" git log -1 >output &&
>  	test_cmp expect-other output
>  '
>  
>  test_expect_success 'Do show note when ref is given in core.notesRef config' '
> -	git config core.notesRef "refs/notes/other" &&
> -	git log -1 > output &&
> +	test_config core.notesRef "refs/notes/other" &&
> +	git log -1 >output &&
>  	test_cmp expect-other output
>  '
>  
>  test_expect_success 'Do not show note when core.notesRef is overridden' '
> -	GIT_NOTES_REF="refs/notes/wrong" git log -1 > output &&
> +	test_config core.notesRef "refs/notes/other" &&
> +	GIT_NOTES_REF="refs/notes/wrong" git log -1 >output &&
>  	test_cmp expect-not-other output
>  '
>  
> -cat > expect-both << EOF
> -commit 387a89921c73d7ed72cd94d179c1c7048ca47756
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:18:13 2005 -0700
> -
> -    6th
> +test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' '
> +	cat >expect-both <<-EOF &&
> +		commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:18:13 2005 -0700
>  
> -Notes:
> -    order test
> +		${indent}6th
>  
> -Notes (other):
> -    other note
> +		Notes:
> +		${indent}order test
>  
> -commit bd1753200303d0a0344be813e504253b3d98e74d
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:17:13 2005 -0700
> +		Notes (other):
> +		${indent}other note
>  
> -    5th
> +		commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:17:13 2005 -0700
>  
> -Notes:
> -    replacement for deleted note
> -EOF
> +		${indent}5th
>  
> -test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' '
> +		Notes:
> +		${indent}replacement for deleted note
> +	EOF
>  	GIT_NOTES_REF=refs/notes/commits git notes add \
>  		-m"replacement for deleted note" HEAD^ &&
>  	GIT_NOTES_REF=refs/notes/commits git notes add -m"order test" &&
> -	git config --unset core.notesRef &&
> -	git config notes.displayRef "refs/notes/*" &&
> -	git log -2 > output &&
> +	test_unconfig core.notesRef &&
> +	test_config notes.displayRef "refs/notes/*" &&
> +	git log -2 >output &&
>  	test_cmp expect-both output
>  '
>  
>  test_expect_success 'core.notesRef is implicitly in notes.displayRef' '
> -	git config core.notesRef refs/notes/commits &&
> -	git config notes.displayRef refs/notes/other &&
> -	git log -2 > output &&
> +	test_config core.notesRef refs/notes/commits &&
> +	test_config notes.displayRef refs/notes/other &&
> +	git log -2 >output &&
>  	test_cmp expect-both output
>  '
>  
>  test_expect_success 'notes.displayRef can be given more than once' '
> -	git config --unset core.notesRef &&
> -	git config notes.displayRef refs/notes/commits &&
> +	test_unconfig core.notesRef &&
> +	test_config notes.displayRef refs/notes/commits &&
>  	git config --add notes.displayRef refs/notes/other &&
> -	git log -2 > output &&
> +	git log -2 >output &&
>  	test_cmp expect-both output
>  '
>  
> -cat > expect-both-reversed << EOF
> -commit 387a89921c73d7ed72cd94d179c1c7048ca47756
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:18:13 2005 -0700
> -
> -    6th
> -
> -Notes (other):
> -    other note
> -
> -Notes:
> -    order test
> -EOF
> -
>  test_expect_success 'notes.displayRef respects order' '
> -	git config core.notesRef refs/notes/other &&
> -	git config --unset-all notes.displayRef &&
> -	git config notes.displayRef refs/notes/commits &&
> -	git log -1 > output &&
> +	cat >expect-both-reversed <<-EOF &&
> +		commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:18:13 2005 -0700
> +
> +		${indent}6th
> +
> +		Notes (other):
> +		${indent}other note
> +
> +		Notes:
> +		${indent}order test
> +	EOF
> +	test_config core.notesRef refs/notes/other &&
> +	test_config notes.displayRef refs/notes/commits &&
> +	git log -1 >output &&
>  	test_cmp expect-both-reversed output
>  '
>  
>  test_expect_success 'GIT_NOTES_DISPLAY_REF works' '
> -	git config --unset-all core.notesRef &&
> -	git config --unset-all notes.displayRef &&
>  	GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \
> -		git log -2 > output &&
> +		git log -2 >output &&
>  	test_cmp expect-both output
>  '
>  
> -cat > expect-none << EOF
> -commit 387a89921c73d7ed72cd94d179c1c7048ca47756
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:18:13 2005 -0700
> +test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' '
> +	cat >expect-none <<-EOF &&
> +		commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:18:13 2005 -0700
>  
> -    6th
> +		${indent}6th
>  
> -commit bd1753200303d0a0344be813e504253b3d98e74d
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:17:13 2005 -0700
> +		commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:17:13 2005 -0700
>  
> -    5th
> -EOF
> -
> -test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' '
> -	git config notes.displayRef "refs/notes/*" &&
> -	GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 > output &&
> +		${indent}5th
> +	EOF
> +	test_config notes.displayRef "refs/notes/*" &&
> +	GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 >output &&
>  	test_cmp expect-none output
>  '
>  
>  test_expect_success '--show-notes=* adds to GIT_NOTES_DISPLAY_REF' '
> -	GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 > output &&
> +	GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 >output &&
>  	test_cmp expect-both output
>  '
>  
> -cat > expect-commits << EOF
> -commit 387a89921c73d7ed72cd94d179c1c7048ca47756
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:18:13 2005 -0700
> -
> -    6th
> +test_expect_success '--no-standard-notes' '
> +	cat >expect-commits <<EOF
> +		commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:18:13 2005 -0700
>  
> -Notes:
> -    order test
> -EOF
> +		${indent}6th
>  
> -test_expect_success '--no-standard-notes' '
> -	git log --no-standard-notes --show-notes=commits -1 > output &&
> +		Notes:
> +		${indent}order test
> +	EOF
> +	git log --no-standard-notes --show-notes=commits -1 >output &&
>  	test_cmp expect-commits output
>  '
>  
>  test_expect_success '--standard-notes' '
> +	test_config notes.displayRef "refs/notes/*" &&
>  	git log --no-standard-notes --show-notes=commits \
> -		--standard-notes -2 > output &&
> +		--standard-notes -2 >output &&
>  	test_cmp expect-both output
>  '
>  
>  test_expect_success '--show-notes=ref accumulates' '
>  	git log --show-notes=other --show-notes=commits \
> -		 --no-standard-notes -1 > output &&
> +		 --no-standard-notes -1 >output &&
>  	test_cmp expect-both-reversed output
>  '
>  
>  test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
> -	git config core.notesRef refs/notes/other &&
> -	echo "Note on a tree" > expect &&
> +	test_config core.notesRef refs/notes/other &&
> +	echo "Note on a tree" >expect &&
>  	git notes add -m "Note on a tree" HEAD: &&
> -	git notes show HEAD: > actual &&
> +	git notes show HEAD: >actual &&
>  	test_cmp expect actual &&
> -	echo "Note on a blob" > expect &&
> +	echo "Note on a blob" >expect &&
>  	filename=$(git ls-tree --name-only HEAD | head -n1) &&
>  	git notes add -m "Note on a blob" HEAD:$filename &&
> -	git notes show HEAD:$filename > actual &&
> +	git notes show HEAD:$filename >actual &&
>  	test_cmp expect actual &&
> -	echo "Note on a tag" > expect &&
> +	echo "Note on a tag" >expect &&
>  	git tag -a -m "This is an annotated tag" foobar HEAD^ &&
>  	git notes add -m "Note on a tag" foobar &&
> -	git notes show foobar > actual &&
> +	git notes show foobar >actual &&
>  	test_cmp expect actual
>  '
>  
> -cat > expect << EOF
> -commit 2ede89468182a62d0bde2583c736089bcf7d7e92
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:19:13 2005 -0700
> +test_expect_success 'create note from other note with "git notes add -C"' '
> +	cat >expect <<-EOF &&
> +		commit fb01e0ca8c33b6cc0c6451dde747f97df567cb5c
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:19:13 2005 -0700
>  
> -    7th
> +		${indent}7th
>  
> -Notes (other):
> -    other note
> -EOF
> -
> -test_expect_success 'create note from other note with "git notes add -C"' '
> -	: > a7 &&
> -	git add a7 &&
> -	test_tick &&
> -	git commit -m 7th &&
> +		Notes:
> +		${indent}order test
> +	EOF
> +	test_commit 7th &&
>  	git notes add -C $(git notes list HEAD^) &&
> -	git log -1 > actual &&
> +	git log -1 >actual &&
>  	test_cmp expect actual &&
>  	test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
>  '
>  
>  test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
> -	: > a8 &&
> -	git add a8 &&
> -	test_tick &&
> -	git commit -m 8th &&
> +	test_commit 8th &&
>  	test_must_fail git notes add -C deadbeef &&
>  	test_must_fail git notes list HEAD
>  '
> @@ -814,404 +729,385 @@ test_expect_success 'create note from non-blob with "git notes add -C" fails' '
>  	test_must_fail git notes list HEAD
>  '
>  
> -cat > expect << EOF
> -commit 80d796defacd5db327b7a4e50099663902fbdc5c
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:20:13 2005 -0700
> +test_expect_success 'create note from blob with "git notes add -C" reuses blob id' '
> +	cat >expect <<-EOF &&
> +		commit 9a4c31c7f722b5d517e92c64e932dd751e1413bf
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:20:13 2005 -0700
>  
> -    8th
> +		${indent}8th
>  
> -Notes (other):
> -    This is a blob object
> -EOF
> -
> -test_expect_success 'create note from blob with "git notes add -C" reuses blob id' '
> +		Notes:
> +		${indent}This is a blob object
> +	EOF
>  	blob=$(echo "This is a blob object" | git hash-object -w --stdin) &&
>  	git notes add -C $blob &&
> -	git log -1 > actual &&
> +	git log -1 >actual &&
>  	test_cmp expect actual &&
>  	test "$(git notes list HEAD)" = "$blob"
>  '
>  
> -cat > expect << EOF
> -commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:21:13 2005 -0700
> -
> -    9th
> +test_expect_success 'create note from other note with "git notes add -c"' '
> +	cat >expect <<-EOF &&
> +		commit 2e0db4bc649e174d667a1cde19e725cf897a5bd2
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:21:13 2005 -0700
>  
> -Notes (other):
> -    yet another note
> -EOF
> +		${indent}9th
>  
> -test_expect_success 'create note from other note with "git notes add -c"' '
> -	: > a9 &&
> -	git add a9 &&
> -	test_tick &&
> -	git commit -m 9th &&
> +		Notes:
> +		${indent}yet another note
> +	EOF
> +	test_commit 9th &&
>  	MSG="yet another note" git notes add -c $(git notes list HEAD^^) &&
> -	git log -1 > actual &&
> +	git log -1 >actual &&
>  	test_cmp expect actual
>  '
>  
>  test_expect_success 'create note from non-existing note with "git notes add -c" fails' '
> -	: > a10 &&
> -	git add a10 &&
> -	test_tick &&
> -	git commit -m 10th &&
> +	test_commit 10th &&
>  	test_must_fail env MSG="yet another note" git notes add -c deadbeef &&
>  	test_must_fail git notes list HEAD
>  '
>  
> -cat > expect << EOF
> -commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:21:13 2005 -0700
> -
> -    9th
> -
> -Notes (other):
> -    yet another note
> -$whitespace
> -    yet another note
> -EOF
> -
>  test_expect_success 'append to note from other note with "git notes append -C"' '
> +	cat >expect <<-EOF &&
> +		commit 2e0db4bc649e174d667a1cde19e725cf897a5bd2
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:21:13 2005 -0700
> +
> +		${indent}9th
> +
> +		Notes:
> +		${indent}yet another note
> +		${indent}
> +		${indent}yet another note
> +	EOF
>  	git notes append -C $(git notes list HEAD^) HEAD^ &&
> -	git log -1 HEAD^ > actual &&
> +	git log -1 HEAD^ >actual &&
>  	test_cmp expect actual
>  '
>  
> -cat > expect << EOF
> -commit ffed603236bfa3891c49644257a83598afe8ae5a
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:22:13 2005 -0700
> -
> -    10th
> +test_expect_success 'create note from other note with "git notes append -c"' '
> +	cat >expect <<-EOF &&
> +		commit 7c3b87ab368f81e11b1ea87b2ab99a71ccd25406
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:22:13 2005 -0700
>  
> -Notes (other):
> -    other note
> -EOF
> +		${indent}10th
>  
> -test_expect_success 'create note from other note with "git notes append -c"' '
> +		Notes:
> +		${indent}other note
> +	EOF
>  	MSG="other note" git notes append -c $(git notes list HEAD^) &&
> -	git log -1 > actual &&
> +	git log -1 >actual &&
>  	test_cmp expect actual
>  '
>  
> -cat > expect << EOF
> -commit ffed603236bfa3891c49644257a83598afe8ae5a
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:22:13 2005 -0700
> -
> -    10th
> -
> -Notes (other):
> -    other note
> -$whitespace
> -    yet another note
> -EOF
> -
>  test_expect_success 'append to note from other note with "git notes append -c"' '
> +	cat >expect <<-EOF &&
> +		commit 7c3b87ab368f81e11b1ea87b2ab99a71ccd25406
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:22:13 2005 -0700
> +
> +		${indent}10th
> +
> +		Notes:
> +		${indent}other note
> +		${indent}
> +		${indent}yet another note
> +	EOF
>  	MSG="yet another note" git notes append -c $(git notes list HEAD) &&
> -	git log -1 > actual &&
> +	git log -1 >actual &&
>  	test_cmp expect actual
>  '
>  
> -cat > expect << EOF
> -commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:23:13 2005 -0700
> -
> -    11th
> -
> -Notes (other):
> -    other note
> -$whitespace
> -    yet another note
> -EOF
> -
>  test_expect_success 'copy note with "git notes copy"' '
> -	: > a11 &&
> -	git add a11 &&
> -	test_tick &&
> -	git commit -m 11th &&
> +	cat >expect <<-EOF &&
> +		commit a446fff8777efdc6eb8f4b7c8a5ff699484df0d5
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:23:13 2005 -0700
> +
> +		${indent}11th
> +
> +		Notes:
> +		${indent}other note
> +		${indent}
> +		${indent}yet another note
> +	EOF
> +	test_commit 11th &&
>  	git notes copy HEAD^ HEAD &&
> -	git log -1 > actual &&
> +	git log -1 >actual &&
>  	test_cmp expect actual &&
>  	test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
>  '
>  
>  test_expect_success 'prevent overwrite with "git notes copy"' '
>  	test_must_fail git notes copy HEAD~2 HEAD &&
> -	git log -1 > actual &&
> +	git log -1 >actual &&
>  	test_cmp expect actual &&
>  	test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
>  '
>  
> -cat > expect << EOF
> -commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:23:13 2005 -0700
> -
> -    11th
> -
> -Notes (other):
> -    yet another note
> -$whitespace
> -    yet another note
> -EOF
> -
>  test_expect_success 'allow overwrite with "git notes copy -f"' '
> +	cat >expect <<-EOF &&
> +		commit a446fff8777efdc6eb8f4b7c8a5ff699484df0d5
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:23:13 2005 -0700
> +
> +		${indent}11th
> +
> +		Notes:
> +		${indent}yet another note
> +		${indent}
> +		${indent}yet another note
> +	EOF
>  	git notes copy -f HEAD~2 HEAD &&
> -	git log -1 > actual &&
> +	git log -1 >actual &&
>  	test_cmp expect actual &&
>  	test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
>  '
>  
>  test_expect_success 'cannot copy note from object without notes' '
> -	: > a12 &&
> -	git add a12 &&
> -	test_tick &&
> -	git commit -m 12th &&
> -	: > a13 &&
> -	git add a13 &&
> -	test_tick &&
> -	git commit -m 13th &&
> +	test_commit 12th &&
> +	test_commit 13th &&
>  	test_must_fail git notes copy HEAD^ HEAD
>  '
>  
> -cat > expect << EOF
> -commit e5d4fb5698d564ab8c73551538ecaf2b0c666185
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:25:13 2005 -0700
> -
> -    13th
> +test_expect_success 'git notes copy --stdin' '
> +	cat >expect <<-EOF &&
> +		commit e871aa61182b1d95d0a6fb75445d891722863b6b
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:25:13 2005 -0700
>  
> -Notes (other):
> -    yet another note
> -$whitespace
> -    yet another note
> +		${indent}13th
>  
> -commit 7038787dfe22a14c3867ce816dbba39845359719
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:24:13 2005 -0700
> +		Notes:
> +		${indent}yet another note
> +		${indent}
> +		${indent}yet another note
>  
> -    12th
> +		commit 65e263ded02ae4e8839bc151095113737579dc12
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:24:13 2005 -0700
>  
> -Notes (other):
> -    other note
> -$whitespace
> -    yet another note
> -EOF
> +		${indent}12th
>  
> -test_expect_success 'git notes copy --stdin' '
> +		Notes:
> +		${indent}other note
> +		${indent}
> +		${indent}yet another note
> +	EOF
>  	(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
>  	echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
>  	git notes copy --stdin &&
> -	git log -2 > output &&
> +	git log -2 >output &&
>  	test_cmp expect output &&
>  	test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" &&
>  	test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)"
>  '
>  
> -cat > expect << EOF
> -commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:27:13 2005 -0700
> -
> -    15th
> +test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
> +	cat >expect <<-EOF &&
> +		commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:27:13 2005 -0700
>  
> -commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:26:13 2005 -0700
> +		${indent}15th
>  
> -    14th
> -EOF
> +		commit 07c85d77059393ed0154b8c96906547a59dfcddd
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:26:13 2005 -0700
>  
> -test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
> +		${indent}14th
> +	EOF
>  	test_commit 14th &&
>  	test_commit 15th &&
>  	(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
>  	echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
>  	git notes copy --for-rewrite=foo &&
> -	git log -2 > output &&
> +	git log -2 >output &&
>  	test_cmp expect output
>  '
>  
> -cat > expect << EOF
> -commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:27:13 2005 -0700
> -
> -    15th
> -
> -Notes (other):
> -    yet another note
> -$whitespace
> -    yet another note
> -
> -commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:26:13 2005 -0700
> -
> -    14th
> -
> -Notes (other):
> -    other note
> -$whitespace
> -    yet another note
> -EOF
> -
>  test_expect_success 'git notes copy --for-rewrite (enabled)' '
> -	git config notes.rewriteMode overwrite &&
> -	git config notes.rewriteRef "refs/notes/*" &&
> +	cat >expect <<-EOF &&
> +		commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:27:13 2005 -0700
> +
> +		${indent}15th
> +
> +		Notes:
> +		${indent}yet another note
> +		${indent}
> +		${indent}yet another note
> +
> +		commit 07c85d77059393ed0154b8c96906547a59dfcddd
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:26:13 2005 -0700
> +
> +		${indent}14th
> +
> +		Notes:
> +		${indent}other note
> +		${indent}
> +		${indent}yet another note
> +	EOF
> +	test_config notes.rewriteMode overwrite &&
> +	test_config notes.rewriteRef "refs/notes/*" &&
>  	(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
>  	echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
>  	git notes copy --for-rewrite=foo &&
> -	git log -2 > output &&
> +	git log -2 >output &&
>  	test_cmp expect output
>  '
>  
>  test_expect_success 'git notes copy --for-rewrite (disabled)' '
> -	git config notes.rewrite.bar false &&
> +	test_config notes.rewrite.bar false &&
>  	echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) |
>  	git notes copy --for-rewrite=bar &&
> -	git log -2 > output &&
> +	git log -2 >output &&
>  	test_cmp expect output
>  '
>  
> -cat > expect << EOF
> -commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:27:13 2005 -0700
> -
> -    15th
> +test_expect_success 'git notes copy --for-rewrite (overwrite)' '
> +	cat >expect <<-EOF &&
> +		commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:27:13 2005 -0700
>  
> -Notes (other):
> -    a fresh note
> -EOF
> +		${indent}15th
>  
> -test_expect_success 'git notes copy --for-rewrite (overwrite)' '
> +		Notes:
> +		${indent}a fresh note
> +	EOF
>  	git notes add -f -m"a fresh note" HEAD^ &&
> +	test_config notes.rewriteMode overwrite &&
> +	test_config notes.rewriteRef "refs/notes/*" &&
>  	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
>  	git notes copy --for-rewrite=foo &&
> -	git log -1 > output &&
> +	git log -1 >output &&
>  	test_cmp expect output
>  '
>  
>  test_expect_success 'git notes copy --for-rewrite (ignore)' '
> -	git config notes.rewriteMode ignore &&
> +	test_config notes.rewriteMode ignore &&
> +	test_config notes.rewriteRef "refs/notes/*" &&
>  	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
>  	git notes copy --for-rewrite=foo &&
> -	git log -1 > output &&
> +	git log -1 >output &&
>  	test_cmp expect output
>  '
>  
> -cat > expect << EOF
> -commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:27:13 2005 -0700
> -
> -    15th
> -
> -Notes (other):
> -    a fresh note
> -$whitespace
> -    another fresh note
> -EOF
> -
>  test_expect_success 'git notes copy --for-rewrite (append)' '
> +	cat >expect <<-EOF &&
> +		commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:27:13 2005 -0700
> +
> +		${indent}15th
> +
> +		Notes:
> +		${indent}a fresh note
> +		${indent}
> +		${indent}another fresh note
> +	EOF
>  	git notes add -f -m"another fresh note" HEAD^ &&
> -	git config notes.rewriteMode concatenate &&
> +	test_config notes.rewriteMode concatenate &&
> +	test_config notes.rewriteRef "refs/notes/*" &&
>  	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
>  	git notes copy --for-rewrite=foo &&
> -	git log -1 > output &&
> +	git log -1 >output &&
>  	test_cmp expect output
>  '
>  
> -cat > expect << EOF
> -commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:27:13 2005 -0700
> -
> -    15th
> -
> -Notes (other):
> -    a fresh note
> -$whitespace
> -    another fresh note
> -$whitespace
> -    append 1
> -$whitespace
> -    append 2
> -EOF
> -
>  test_expect_success 'git notes copy --for-rewrite (append two to one)' '
> +	cat >expect <<-EOF &&
> +		commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:27:13 2005 -0700
> +
> +		${indent}15th
> +
> +		Notes:
> +		${indent}a fresh note
> +		${indent}
> +		${indent}another fresh note
> +		${indent}
> +		${indent}append 1
> +		${indent}
> +		${indent}append 2
> +	EOF
>  	git notes add -f -m"append 1" HEAD^ &&
>  	git notes add -f -m"append 2" HEAD^^ &&
> +	test_config notes.rewriteMode concatenate &&
> +	test_config notes.rewriteRef "refs/notes/*" &&
>  	(echo $(git rev-parse HEAD^) $(git rev-parse HEAD);
>  	echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) |
>  	git notes copy --for-rewrite=foo &&
> -	git log -1 > output &&
> +	git log -1 >output &&
>  	test_cmp expect output
>  '
>  
>  test_expect_success 'git notes copy --for-rewrite (append empty)' '
>  	git notes remove HEAD^ &&
> +	test_config notes.rewriteMode concatenate &&
> +	test_config notes.rewriteRef "refs/notes/*" &&
>  	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
>  	git notes copy --for-rewrite=foo &&
> -	git log -1 > output &&
> +	git log -1 >output &&
>  	test_cmp expect output
>  '
>  
> -cat > expect << EOF
> -commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:27:13 2005 -0700
> -
> -    15th
> -
> -Notes (other):
> -    replacement note 1
> -EOF
> -
>  test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
> +	cat >expect <<-EOF &&
> +		commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:27:13 2005 -0700
> +
> +		${indent}15th
> +
> +		Notes:
> +		${indent}replacement note 1
> +	EOF
> +	test_config notes.rewriteMode concatenate &&
> +	test_config notes.rewriteRef "refs/notes/*" &&
>  	git notes add -f -m"replacement note 1" HEAD^ &&
>  	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
>  	GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo &&
> -	git log -1 > output &&
> +	git log -1 >output &&
>  	test_cmp expect output
>  '
>  
> -cat > expect << EOF
> -commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
> -Author: A U Thor <author@example.com>
> -Date:   Thu Apr 7 15:27:13 2005 -0700
> -
> -    15th
> +test_expect_success 'GIT_NOTES_REWRITE_REF works' '
> +	cat >expect <<-EOF &&
> +		commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
> +		Author: A U Thor <author@example.com>
> +		Date:   Thu Apr 7 15:27:13 2005 -0700
>  
> -Notes (other):
> -    replacement note 2
> -EOF
> +		${indent}15th
>  
> -test_expect_success 'GIT_NOTES_REWRITE_REF works' '
> -	git config notes.rewriteMode overwrite &&
> +		Notes:
> +		${indent}replacement note 2
> +	EOF
>  	git notes add -f -m"replacement note 2" HEAD^ &&
> -	git config --unset-all notes.rewriteRef &&
> +	test_config notes.rewriteMode overwrite &&
> +	test_unconfig notes.rewriteRef &&
>  	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
>  	GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \
>  		git notes copy --for-rewrite=foo &&
> -	git log -1 > output &&
> +	git log -1 >output &&
>  	test_cmp expect output
>  '
>  
>  test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
> -	git config notes.rewriteRef refs/notes/other &&
>  	git notes add -f -m"replacement note 3" HEAD^ &&
> +	test_config notes.rewriteMode overwrite &&
> +	test_config notes.rewriteRef refs/notes/other &&
>  	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
>  	GIT_NOTES_REWRITE_REF= git notes copy --for-rewrite=foo &&
> -	git log -1 > output &&
> +	git log -1 >output &&
>  	test_cmp expect output
>  '
>  
> @@ -1221,13 +1117,13 @@ test_expect_success 'git notes copy diagnoses too many or too few parameters' '
>  '
>  
>  test_expect_success 'git notes get-ref (no overrides)' '
> -	git config --unset core.notesRef &&
> +	test_unconfig core.notesRef &&
>  	sane_unset GIT_NOTES_REF &&
>  	test "$(git notes get-ref)" = "refs/notes/commits"
>  '
>  
>  test_expect_success 'git notes get-ref (core.notesRef)' '
> -	git config core.notesRef refs/notes/foo &&
> +	test_config core.notesRef refs/notes/foo &&
>  	test "$(git notes get-ref)" = "refs/notes/foo"
>  '
>  
> @@ -1277,10 +1173,10 @@ EOF
>  test_expect_success 'empty notes are displayed by git log' '
>  	test_commit 17th &&
>  	git log -1 >expect &&
> -	cat >>expect <<\EOF &&
> +	cat >>expect <<-EOF &&
>  
> -Notes:
> -EOF
> +		Notes:
> +	EOF
>  	git notes add -C "$empty_blob" --allow-empty &&
>  	git log -1 >actual &&
>  	test_cmp expect actual

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCHv4 5/9] builtin/notes: Simplify early exit code in add()
  2014-11-10 20:36   ` Junio C Hamano
@ 2014-11-11  0:49     ` Johan Herland
  2014-11-11 15:53       ` Junio C Hamano
  0 siblings, 1 reply; 17+ messages in thread
From: Johan Herland @ 2014-11-11  0:49 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Git mailing list, Kyle J. McKay, James H. Fisher, Eric Sunshine

On Mon, Nov 10, 2014 at 9:36 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Johan Herland <johan@herland.net> writes:
>
>> Signed-off-by: Johan Herland <johan@herland.net>
>> ---
>>  builtin/notes.c | 12 +++++-------
>>  1 file changed, 5 insertions(+), 7 deletions(-)
>>
>> diff --git a/builtin/notes.c b/builtin/notes.c
>> index 1017472..f1480cf 100644
>> --- a/builtin/notes.c
>> +++ b/builtin/notes.c
>> @@ -399,7 +399,7 @@ static int append_edit(int argc, const char **argv, const char *prefix);
>>
>>  static int add(int argc, const char **argv, const char *prefix)
>>  {
>> -     int retval = 0, force = 0;
>> +     int force = 0;
>>       const char *object_ref;
>>       struct notes_tree *t;
>>       unsigned char object[20], new_note[20];
>> @@ -441,6 +441,8 @@ static int add(int argc, const char **argv, const char *prefix)
>>
>>       if (note) {
>>               if (!force) {
>> +                     free_note_data(&d);
>> +                     free_notes(t);
>>                       if (!d.given) {
>
> It looks a bit strange to refer to d.given after calling a function
> that sounds as if it is meant to clear what is recorded in and to
> invalidate &d; yes, I can read the implementation to see that
> d.given keeps its stale value, but that is something other people
> may want to "clean up" later and this reference to d.given will get
> in the way when that happens.

Yes, that was obviously an oversight on my part.

> At this point of the code, it makes sense to free t in preparation
> to either switching to append codepath or erroring out, but does &d
> have anything in it already to necessitate its freeing?

Actually, no, although verifying that required double-checking that
each of the -m/-F/-c/-C parsers which store data into &d, do in fact
set d.given.

I suggest to either move the free_note_data(&d) call below the "if
(!d.given)" block, or reorganize into this (which at the moment reads
better to me):

    if (note) {
        if (!force) {
            free_notes(t);
            if (d.given) {
                free_note_data(&d);
                return error(_("Cannot add notes. "
                    "Found existing notes for object %s. "
                    "Use '-f' to overwrite existing notes"),
                    sha1_to_hex(object));
            }
            /*
             * Redirect to "edit" subcommand.
             *
             * We only end up here if none of -m/-F/-c/-C or -f are
             * given. The original args are therefore still in
             * argv[0-1].
             */
            argv[0] = "edit";
            return append_edit(argc, argv, prefix);
        }
        fprintf(stderr, _("Overwriting existing notes for object %s\n"),
            sha1_to_hex(object));
    }

This keeps the two free_* calls close together, only separated by if
(d.given), which nicely indicates whether we need to call
free_notes_data(&d) at all.

If that looks good to you, do you want a re-roll, or is it easier to
fix up yourself?


...Johan

-- 
Johan Herland, <johan@herland.net>
www.herland.net

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCHv4 9/9] t3301: Modernize
  2014-11-10 20:42   ` Junio C Hamano
@ 2014-11-11  1:04     ` Johan Herland
  2014-11-11  1:07       ` Eric Sunshine
  0 siblings, 1 reply; 17+ messages in thread
From: Johan Herland @ 2014-11-11  1:04 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Git mailing list, Kyle J. McKay, James H. Fisher, Eric Sunshine

On Mon, Nov 10, 2014 at 9:42 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Johan Herland <johan@herland.net> writes:
>
>> Make this test script appear somewhat less old-fashioned:
>>  - Use test helper functions:
>>     - write_script
>>     - test_commit
>>     - test_write_lines
>>     - test_config
>>     - test_unconfig
>>     - test_path_is_missing
>>  - Remove whitespace between redirection operators and their targets.
>>  - Move preparation of "except" files into tests.
>
> expect, I think (no need to resend; I've fixed it up locally).

Thanks.

...Johan

-- 
Johan Herland, <johan@herland.net>
www.herland.net

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCHv4 9/9] t3301: Modernize
  2014-11-11  1:04     ` Johan Herland
@ 2014-11-11  1:07       ` Eric Sunshine
  2014-11-11  1:50         ` Johan Herland
  0 siblings, 1 reply; 17+ messages in thread
From: Eric Sunshine @ 2014-11-11  1:07 UTC (permalink / raw)
  To: Johan Herland
  Cc: Junio C Hamano, Git mailing list, Kyle J. McKay, James H. Fisher

On Mon, Nov 10, 2014 at 8:04 PM, Johan Herland <johan@herland.net> wrote:
> On Mon, Nov 10, 2014 at 9:42 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> Johan Herland <johan@herland.net> writes:
>>
>>> Make this test script appear somewhat less old-fashioned:
>>>  - Use test helper functions:
>>>     - write_script
>>>     - test_commit
>>>     - test_write_lines
>>>     - test_config
>>>     - test_unconfig
>>>     - test_path_is_missing
>>>  - Remove whitespace between redirection operators and their targets.
>>>  - Move preparation of "except" files into tests.
>>
>> expect, I think (no need to resend; I've fixed it up locally).
>
> Thanks.

One further modernization would be to use the name "actual" rather
than "output" for files holding actual contents (as opposed to the
"expect" contents).

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCHv4 9/9] t3301: Modernize
  2014-11-11  1:07       ` Eric Sunshine
@ 2014-11-11  1:50         ` Johan Herland
  0 siblings, 0 replies; 17+ messages in thread
From: Johan Herland @ 2014-11-11  1:50 UTC (permalink / raw)
  To: Eric Sunshine
  Cc: Junio C Hamano, Git mailing list, Kyle J. McKay, James H. Fisher

On Tue, Nov 11, 2014 at 2:07 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
> On Mon, Nov 10, 2014 at 8:04 PM, Johan Herland <johan@herland.net> wrote:
>> On Mon, Nov 10, 2014 at 9:42 PM, Junio C Hamano <gitster@pobox.com> wrote:
>>> Johan Herland <johan@herland.net> writes:
>>>
>>>> Make this test script appear somewhat less old-fashioned:
>>>>  - Use test helper functions:
>>>>     - write_script
>>>>     - test_commit
>>>>     - test_write_lines
>>>>     - test_config
>>>>     - test_unconfig
>>>>     - test_path_is_missing
>>>>  - Remove whitespace between redirection operators and their targets.
>>>>  - Move preparation of "except" files into tests.
>>>
>>> expect, I think (no need to resend; I've fixed it up locally).
>>
>> Thanks.
>
> One further modernization would be to use the name "actual" rather
> than "output" for files holding actual contents (as opposed to the
> "expect" contents).

Agreed. Will be fixed in the re-roll.

...Johan
-- 
Johan Herland, <johan@herland.net>
www.herland.net

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCHv4 5/9] builtin/notes: Simplify early exit code in add()
  2014-11-11  0:49     ` Johan Herland
@ 2014-11-11 15:53       ` Junio C Hamano
  0 siblings, 0 replies; 17+ messages in thread
From: Junio C Hamano @ 2014-11-11 15:53 UTC (permalink / raw)
  To: Johan Herland
  Cc: Git mailing list, Kyle J. McKay, James H. Fisher, Eric Sunshine

Johan Herland <johan@herland.net> writes:

> On Mon, Nov 10, 2014 at 9:36 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> Johan Herland <johan@herland.net> writes:
>>
>>> Signed-off-by: Johan Herland <johan@herland.net>
>>> ---
>>>  builtin/notes.c | 12 +++++-------
>>>  1 file changed, 5 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/builtin/notes.c b/builtin/notes.c
>>> index 1017472..f1480cf 100644
>>> --- a/builtin/notes.c
>>> +++ b/builtin/notes.c
>>> @@ -399,7 +399,7 @@ static int append_edit(int argc, const char **argv, const char *prefix);
>>>
>>>  static int add(int argc, const char **argv, const char *prefix)
>>>  {
>>> -     int retval = 0, force = 0;
>>> +     int force = 0;
>>>       const char *object_ref;
>>>       struct notes_tree *t;
>>>       unsigned char object[20], new_note[20];
>>> @@ -441,6 +441,8 @@ static int add(int argc, const char **argv, const char *prefix)
>>>
>>>       if (note) {
>>>               if (!force) {
>>> +                     free_note_data(&d);
>>> +                     free_notes(t);
>>>                       if (!d.given) {
>>
>> It looks a bit strange to refer to d.given after calling a function
>> that sounds as if it is meant to clear what is recorded in and to
>> invalidate &d; yes, I can read the implementation to see that
>> d.given keeps its stale value, but that is something other people
>> may want to "clean up" later and this reference to d.given will get
>> in the way when that happens.
>
> Yes, that was obviously an oversight on my part.
>
>> At this point of the code, it makes sense to free t in preparation
>> to either switching to append codepath or erroring out, but does &d
>> have anything in it already to necessitate its freeing?
>
> Actually, no, although verifying that required double-checking that
> each of the -m/-F/-c/-C parsers which store data into &d, do in fact
> set d.given.
>
> I suggest to either move the free_note_data(&d) call below the "if
> (!d.given)" block, or reorganize into this (which at the moment reads
> better to me):
>
>     if (note) {
>         if (!force) {
>             free_notes(t);
>             if (d.given) {
>                 free_note_data(&d);
>                 return error(_("Cannot add notes. "
>                     "Found existing notes for object %s. "
>                     "Use '-f' to overwrite existing notes"),
>                     sha1_to_hex(object));
>             }
>             /*
>              * Redirect to "edit" subcommand.
>              *
>              * We only end up here if none of -m/-F/-c/-C or -f are
>              * given. The original args are therefore still in
>              * argv[0-1].
>              */
>             argv[0] = "edit";
>             return append_edit(argc, argv, prefix);
>         }
>         fprintf(stderr, _("Overwriting existing notes for object %s\n"),
>             sha1_to_hex(object));
>     }
>
> This keeps the two free_* calls close together, only separated by if
> (d.given), which nicely indicates whether we need to call
> free_notes_data(&d) at all.
>
> If that looks good to you, do you want a re-roll, or is it easier to
> fix up yourself?

I strongly prefer reroll for anything bigger than single-line tweaks
to avoid mistakes.

Thans.

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2014-11-11 15:53 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-09 12:30 [PATCHv4 0/9] Handling empty notes Johan Herland
2014-11-09 12:30 ` [PATCHv4 1/9] builtin/notes: Fix premature failure when trying to add the empty blob Johan Herland
2014-11-09 12:30 ` [PATCHv4 2/9] t3301: Verify that 'git notes' removes empty notes by default Johan Herland
2014-11-09 12:30 ` [PATCHv4 3/9] builtin/notes: Improve naming Johan Herland
2014-11-09 12:30 ` [PATCHv4 4/9] builtin/notes: Refactor note file path into struct note_data Johan Herland
2014-11-09 12:30 ` [PATCHv4 5/9] builtin/notes: Simplify early exit code in add() Johan Herland
2014-11-10 20:36   ` Junio C Hamano
2014-11-11  0:49     ` Johan Herland
2014-11-11 15:53       ` Junio C Hamano
2014-11-09 12:30 ` [PATCHv4 6/9] builtin/notes: Split create_note() to clarify add vs. remove logic Johan Herland
2014-11-09 12:30 ` [PATCHv4 7/9] builtin/notes: Add --allow-empty, to allow storing empty notes Johan Herland
2014-11-09 12:30 ` [PATCHv4 8/9] notes: Empty notes should be shown by 'git log' Johan Herland
2014-11-09 12:30 ` [PATCHv4 9/9] t3301: Modernize Johan Herland
2014-11-10 20:42   ` Junio C Hamano
2014-11-11  1:04     ` Johan Herland
2014-11-11  1:07       ` Eric Sunshine
2014-11-11  1:50         ` Johan Herland

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).