@matheusbsbs / matheus-bagliano / commits / d4990c4b2f
Fork 0

notes.c: Use two newlines (instead of one) when concatenating notes

When using combine_notes_concatenate() to concatenate notes, it currently ensures exactly one newline character between the given notes. However, when using builtin/notes.c:create_note() to concatenate notes (e.g. by 'git notes append'), it adds a newline character to the trailing newline of the preceding notes object, thus resulting in _two_ newlines (aka. a blank line) separating contents of the two notes. This patch brings combine_notes_concatenate() into consistency with builtin/notes.c:create_note(), by ensuring exactly _two_ newline characters between concatenated notes. The patch also changes a few notes-related selftests accordingly. Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johan Herland committed Nov 9, 2010 at 22:49 UTC d4990c4b2f5f7066853fea4df775b3f506c79431
5 files changed +15 -3
notes.c
+4 -3
@@ -812,16 +812,17 @@ int combine_notes_concatenate(unsigned char *cur_sha1,
812 return 0;
813 }
814
815 - /* we will separate the notes by a newline anyway */
815 + /* we will separate the notes by two newlines anyway */
816 if (cur_msg[cur_len - 1] == '\n')
817 cur_len--;
818
819 /* concatenate cur_msg and new_msg into buf */
820 - buf_len = cur_len + 1 + new_len;
820 + buf_len = cur_len + 2 + new_len;
821 buf = (char *) xmalloc(buf_len);
822 memcpy(buf, cur_msg, cur_len);
823 buf[cur_len] = '\n';
824 - memcpy(buf + cur_len + 1, new_msg, new_len);
824 + buf[cur_len + 1] = '\n';
825 + memcpy(buf + cur_len + 2, new_msg, new_len);
826 free(cur_msg);
827 free(new_msg);
828
t/t3301-notes.sh
+4
@@ -955,6 +955,7 @@ Date: Thu Apr 7 15:27:13 2005 -0700
955
956 Notes (other):
957 a fresh note
958 +$whitespace
959 another fresh note
960 EOF
961
@@ -976,8 +977,11 @@ Date: Thu Apr 7 15:27:13 2005 -0700
977
978 Notes (other):
979 a fresh note
980 +$whitespace
981 another fresh note
982 +$whitespace
983 append 1
984 +$whitespace
985 append 2
986 EOF
987
t/t3303-notes-subtrees.sh
+1
@@ -173,6 +173,7 @@ verify_concatenated_notes () {
173 while [ $i -gt 0 ]; do
174 echo " commit #$i" &&
175 echo " first note for commit #$i" &&
176 + echo " " &&
177 echo " second note for commit #$i" &&
178 i=$(($i-1));
179 done > expect &&
t/t3404-rebase-interactive.sh
+1
@@ -593,6 +593,7 @@ test_expect_success 'rebase -i can copy notes' '
593
594 cat >expect <<EOF
595 an earlier note
596 +
597 a note
598 EOF
599
t/t9301-fast-import-notes.sh
+5
@@ -255,13 +255,18 @@ EOF
255
256 INPUT_END
257
258 +whitespace=" "
259 +
260 cat >expect <<EXPECT_END
261 fourth commit
262 pre-prefix of note for fourth commit
263 +$whitespace
264 prefix of note for fourth commit
265 +$whitespace
266 third note for fourth commit
267 third commit
268 prefix of note for third commit
269 +$whitespace
270 third note for third commit
271 second commit
272 third note for second commit