@matheusbsbs / matheus-bagliano / commits / 851c2b3791
Fork 0

Teach notes code to properly preserve non-notes in the notes tree

The note tree structure allows for non-note entries to coexist with note entries in a notes tree. Although we certainly expect there to be very few non-notes in a notes tree, we should still support them to a certain degree. This patch teaches the notes code to preserve non-notes when updating the notes tree with write_notes_tree(). Non-notes are not affected by fanout restructuring. For non-notes to be handled correctly, we can no longer allow subtree entries that do not match the fanout structure produced by the notes code itself. This means that fanouts like 4/36, 6/34, 8/32, 4/4/32, etc. are no longer recognized as note subtrees; only 2-based fanouts are allowed (2/38, 2/2/36, 2/2/2/34, etc.). Since the notes code has never at any point _produced_ non-2-based fanouts, it is highly unlikely that this change will cause problems for anyone. The patch also adds some tests verifying the correct handling of non-notes in a notes tree. Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johan Herland committed Feb 13, 2010 at 22:28 UTC 851c2b3791f24e319c23331887d4b8150ca4d9ba
4 files changed +233 -51
notes.c
+180 -39
@@ -37,6 +37,21 @@ struct leaf_node {
37 unsigned char val_sha1[20];
38 };
39
40 +/*
41 + * A notes tree may contain entries that are not notes, and that do not follow
42 + * the naming conventions of notes. There are typically none/few of these, but
43 + * we still need to keep track of them. Keep a simple linked list sorted alpha-
44 + * betically on the non-note path. The list is populated when parsing tree
45 + * objects in load_subtree(), and the non-notes are correctly written back into
46 + * the tree objects produced by write_notes_tree().
47 + */
48 +struct non_note {
49 + struct non_note *next; /* grounded (last->next == NULL) */
50 + char *path;
51 + unsigned int mode;
52 + unsigned char sha1[20];
53 +};
54 +
55 #define PTR_TYPE_NULL 0
56 #define PTR_TYPE_INTERNAL 1
57 #define PTR_TYPE_NOTE 2
@@ -53,8 +68,8 @@ struct leaf_node {
68
69 struct notes_tree default_notes_tree;
70
56 -static void load_subtree(struct leaf_node *subtree, struct int_node *node,
57 - unsigned int n);
71 +static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
72 + struct int_node *node, unsigned int n);
73
74 /*
75 * Search the tree until the appropriate location for the given key is found:
@@ -71,7 +86,7 @@ static void load_subtree(struct leaf_node *subtree, struct int_node *node,
86 * - an unused leaf node (NULL)
87 * In any case, set *tree and *n, and return pointer to the tree location.
88 */
74 -static void **note_tree_search(struct int_node **tree,
89 +static void **note_tree_search(struct notes_tree *t, struct int_node **tree,
90 unsigned char *n, const unsigned char *key_sha1)
91 {
92 struct leaf_node *l;
@@ -83,9 +98,9 @@ static void **note_tree_search(struct int_node **tree,
98 if (!SUBTREE_SHA1_PREFIXCMP(key_sha1, l->key_sha1)) {
99 /* unpack tree and resume search */
100 (*tree)->a[0] = NULL;
86 - load_subtree(l, *tree, *n);
101 + load_subtree(t, l, *tree, *n);
102 free(l);
88 - return note_tree_search(tree, n, key_sha1);
103 + return note_tree_search(t, tree, n, key_sha1);
104 }
105 }
106
@@ -95,15 +110,15 @@ static void **note_tree_search(struct int_node **tree,
110 case PTR_TYPE_INTERNAL:
111 *tree = CLR_PTR_TYPE(p);
112 (*n)++;
98 - return note_tree_search(tree, n, key_sha1);
113 + return note_tree_search(t, tree, n, key_sha1);
114 case PTR_TYPE_SUBTREE:
115 l = (struct leaf_node *) CLR_PTR_TYPE(p);
116 if (!SUBTREE_SHA1_PREFIXCMP(key_sha1, l->key_sha1)) {
117 /* unpack tree and resume search */
118 (*tree)->a[i] = NULL;
104 - load_subtree(l, *tree, *n);
119 + load_subtree(t, l, *tree, *n);
120 free(l);
106 - return note_tree_search(tree, n, key_sha1);
121 + return note_tree_search(t, tree, n, key_sha1);
122 }
123 /* fall through */
124 default:
@@ -116,10 +131,11 @@ static void **note_tree_search(struct int_node **tree,
131 * Search to the tree location appropriate for the given key:
132 * If a note entry with matching key, return the note entry, else return NULL.
133 */
119 -static struct leaf_node *note_tree_find(struct int_node *tree, unsigned char n,
134 +static struct leaf_node *note_tree_find(struct notes_tree *t,
135 + struct int_node *tree, unsigned char n,
136 const unsigned char *key_sha1)
137 {
122 - void **p = note_tree_search(&tree, &n, key_sha1);
138 + void **p = note_tree_search(t, &tree, &n, key_sha1);
139 if (GET_PTR_TYPE(*p) == PTR_TYPE_NOTE) {
140 struct leaf_node *l = (struct leaf_node *) CLR_PTR_TYPE(*p);
141 if (!hashcmp(key_sha1, l->key_sha1))
@@ -141,13 +157,13 @@ static struct leaf_node *note_tree_find(struct int_node *tree, unsigned char n,
157 * - Else, create a new int_node, holding both the node-at-location and the
158 * node-to-be-inserted, and store the new int_node into the location.
159 */
144 -static void note_tree_insert(struct int_node *tree, unsigned char n,
145 - struct leaf_node *entry, unsigned char type,
160 +static void note_tree_insert(struct notes_tree *t, struct int_node *tree,
161 + unsigned char n, struct leaf_node *entry, unsigned char type,
162 combine_notes_fn combine_notes)
163 {
164 struct int_node *new_node;
165 struct leaf_node *l;
150 - void **p = note_tree_search(&tree, &n, entry->key_sha1);
166 + void **p = note_tree_search(t, &tree, &n, entry->key_sha1);
167
168 assert(GET_PTR_TYPE(entry) == 0); /* no type bits set */
169 l = (struct leaf_node *) CLR_PTR_TYPE(*p);
@@ -178,7 +194,7 @@ static void note_tree_insert(struct int_node *tree, unsigned char n,
194 if (!SUBTREE_SHA1_PREFIXCMP(l->key_sha1,
195 entry->key_sha1)) {
196 /* unpack 'entry' */
181 - load_subtree(entry, tree, n);
197 + load_subtree(t, entry, tree, n);
198 free(entry);
199 return;
200 }
@@ -189,9 +205,10 @@ static void note_tree_insert(struct int_node *tree, unsigned char n,
205 if (!SUBTREE_SHA1_PREFIXCMP(entry->key_sha1, l->key_sha1)) {
206 /* unpack 'l' and restart insert */
207 *p = NULL;
192 - load_subtree(l, tree, n);
208 + load_subtree(t, l, tree, n);
209 free(l);
194 - note_tree_insert(tree, n, entry, type, combine_notes);
210 + note_tree_insert(t, tree, n, entry, type,
211 + combine_notes);
212 return;
213 }
214 break;
@@ -201,9 +218,10 @@ static void note_tree_insert(struct int_node *tree, unsigned char n,
218 assert(GET_PTR_TYPE(*p) == PTR_TYPE_NOTE ||
219 GET_PTR_TYPE(*p) == PTR_TYPE_SUBTREE);
220 new_node = (struct int_node *) xcalloc(sizeof(struct int_node), 1);
204 - note_tree_insert(new_node, n + 1, l, GET_PTR_TYPE(*p), combine_notes);
221 + note_tree_insert(t, new_node, n + 1, l, GET_PTR_TYPE(*p),
222 + combine_notes);
223 *p = SET_PTR_TYPE(new_node, PTR_TYPE_INTERNAL);
206 - note_tree_insert(new_node, n + 1, entry, type, combine_notes);
224 + note_tree_insert(t, new_node, n + 1, entry, type, combine_notes);
225 }
226
227 /*
@@ -249,7 +267,7 @@ static void note_tree_remove(struct notes_tree *t, struct int_node *tree,
267 struct leaf_node *l;
268 struct int_node *parent_stack[20];
269 unsigned char i, j;
252 - void **p = note_tree_search(&tree, &n, entry->key_sha1);
270 + void **p = note_tree_search(t, &tree, &n, entry->key_sha1);
271
272 assert(GET_PTR_TYPE(entry) == 0); /* no type bits set */
273 if (GET_PTR_TYPE(*p) != PTR_TYPE_NOTE)
@@ -324,14 +342,67 @@ static int get_sha1_hex_segment(const char *hex, unsigned int hex_len,
342 return len;
343 }
344
327 -static void load_subtree(struct leaf_node *subtree, struct int_node *node,
328 - unsigned int n)
345 +static int non_note_cmp(const struct non_note *a, const struct non_note *b)
346 +{
347 + return strcmp(a->path, b->path);
348 +}
349 +
350 +static void add_non_note(struct notes_tree *t, const char *path,
351 + unsigned int mode, const unsigned char *sha1)
352 +{
353 + struct non_note *p = t->prev_non_note, *n;
354 + n = (struct non_note *) xmalloc(sizeof(struct non_note));
355 + n->next = NULL;
356 + n->path = xstrdup(path);
357 + n->mode = mode;
358 + hashcpy(n->sha1, sha1);
359 + t->prev_non_note = n;
360 +
361 + if (!t->first_non_note) {
362 + t->first_non_note = n;
363 + return;
364 + }
365 +
366 + if (non_note_cmp(p, n) < 0)
367 + ; /* do nothing */
368 + else if (non_note_cmp(t->first_non_note, n) <= 0)
369 + p = t->first_non_note;
370 + else {
371 + /* n sorts before t->first_non_note */
372 + n->next = t->first_non_note;
373 + t->first_non_note = n;
374 + return;
375 + }
376 +
377 + /* n sorts equal or after p */
378 + while (p->next && non_note_cmp(p->next, n) <= 0)
379 + p = p->next;
380 +
381 + if (non_note_cmp(p, n) == 0) { /* n ~= p; overwrite p with n */
382 + assert(strcmp(p->path, n->path) == 0);
383 + p->mode = n->mode;
384 + hashcpy(p->sha1, n->sha1);
385 + free(n);
386 + t->prev_non_note = p;
387 + return;
388 + }
389 +
390 + /* n sorts between p and p->next */
391 + n->next = p->next;
392 + p->next = n;
393 +}
394 +
395 +static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
396 + struct int_node *node, unsigned int n)
397 {
398 unsigned char object_sha1[20];
399 unsigned int prefix_len;
400 void *buf;
401 struct tree_desc desc;
402 struct name_entry entry;
403 + int len, path_len;
404 + unsigned char type;
405 + struct leaf_node *l;
406
407 buf = fill_tree_descriptor(&desc, subtree->val_sha1);
408 if (!buf)
@@ -342,31 +413,68 @@ static void load_subtree(struct leaf_node *subtree, struct int_node *node,
413 assert(prefix_len * 2 >= n);
414 memcpy(object_sha1, subtree->key_sha1, prefix_len);
415 while (tree_entry(&desc, &entry)) {
345 - int len = get_sha1_hex_segment(entry.path, strlen(entry.path),
416 + path_len = strlen(entry.path);
417 + len = get_sha1_hex_segment(entry.path, path_len,
418 object_sha1 + prefix_len, 20 - prefix_len);
419 if (len < 0)
348 - continue; /* entry.path is not a SHA1 sum. Skip */
420 + goto handle_non_note; /* entry.path is not a SHA1 */
421 len += prefix_len;
422
423 /*
424 * If object SHA1 is complete (len == 20), assume note object
353 - * If object SHA1 is incomplete (len < 20), assume note subtree
425 + * If object SHA1 is incomplete (len < 20), and current
426 + * component consists of 2 hex chars, assume note subtree
427 */
428 if (len <= 20) {
356 - unsigned char type = PTR_TYPE_NOTE;
357 - struct leaf_node *l = (struct leaf_node *)
429 + type = PTR_TYPE_NOTE;
430 + l = (struct leaf_node *)
431 xcalloc(sizeof(struct leaf_node), 1);
432 hashcpy(l->key_sha1, object_sha1);
433 hashcpy(l->val_sha1, entry.sha1);
434 if (len < 20) {
362 - if (!S_ISDIR(entry.mode))
363 - continue; /* entry cannot be subtree */
435 + if (!S_ISDIR(entry.mode) || path_len != 2)
436 + goto handle_non_note; /* not subtree */
437 l->key_sha1[19] = (unsigned char) len;
438 type = PTR_TYPE_SUBTREE;
439 }
367 - note_tree_insert(node, n, l, type,
440 + note_tree_insert(t, node, n, l, type,
441 combine_notes_concatenate);
442 }
443 + continue;
444 +
445 +handle_non_note:
446 + /*
447 + * Determine full path for this non-note entry:
448 + * The filename is already found in entry.path, but the
449 + * directory part of the path must be deduced from the subtree
450 + * containing this entry. We assume here that the overall notes
451 + * tree follows a strict byte-based progressive fanout
452 + * structure (i.e. using 2/38, 2/2/36, etc. fanouts, and not
453 + * e.g. 4/36 fanout). This means that if a non-note is found at
454 + * path "dead/beef", the following code will register it as
455 + * being found on "de/ad/beef".
456 + * On the other hand, if you use such non-obvious non-note
457 + * paths in the middle of a notes tree, you deserve what's
458 + * coming to you ;). Note that for non-notes that are not
459 + * SHA1-like at the top level, there will be no problems.
460 + *
461 + * To conclude, it is strongly advised to make sure non-notes
462 + * have at least one non-hex character in the top-level path
463 + * component.
464 + */
465 + {
466 + char non_note_path[PATH_MAX];
467 + char *p = non_note_path;
468 + const char *q = sha1_to_hex(subtree->key_sha1);
469 + int i;
470 + for (i = 0; i < prefix_len; i++) {
471 + *p++ = *q++;
472 + *p++ = *q++;
473 + *p++ = '/';
474 + }
475 + strcpy(p, entry.path);
476 + add_non_note(t, non_note_path, entry.mode, entry.sha1);
477 + }
478 }
479 free(buf);
480 }
@@ -426,9 +534,9 @@ static void construct_path_with_fanout(const unsigned char *sha1,
534 strcpy(path + i, hex_sha1 + j);
535 }
536
429 -static int for_each_note_helper(struct int_node *tree, unsigned char n,
430 - unsigned char fanout, int flags, each_note_fn fn,
431 - void *cb_data)
537 +static int for_each_note_helper(struct notes_tree *t, struct int_node *tree,
538 + unsigned char n, unsigned char fanout, int flags,
539 + each_note_fn fn, void *cb_data)
540 {
541 unsigned int i;
542 void *p;
@@ -443,7 +551,7 @@ redo:
551 switch (GET_PTR_TYPE(p)) {
552 case PTR_TYPE_INTERNAL:
553 /* recurse into int_node */
446 - ret = for_each_note_helper(CLR_PTR_TYPE(p), n + 1,
554 + ret = for_each_note_helper(t, CLR_PTR_TYPE(p), n + 1,
555 fanout, flags, fn, cb_data);
556 break;
557 case PTR_TYPE_SUBTREE:
@@ -481,7 +589,7 @@ redo:
589 !(flags & FOR_EACH_NOTE_DONT_UNPACK_SUBTREES)) {
590 /* unpack subtree and resume traversal */
591 tree->a[i] = NULL;
484 - load_subtree(l, tree, n);
592 + load_subtree(t, l, tree, n);
593 free(l);
594 goto redo;
595 }
@@ -596,8 +704,29 @@ static int write_each_note_helper(struct tree_write_stack *tws,
704
705 struct write_each_note_data {
706 struct tree_write_stack *root;
707 + struct non_note *next_non_note;
708 };
709
710 +static int write_each_non_note_until(const char *note_path,
711 + struct write_each_note_data *d)
712 +{
713 + struct non_note *n = d->next_non_note;
714 + int cmp, ret;
715 + while (n && (!note_path || (cmp = strcmp(n->path, note_path)) <= 0)) {
716 + if (note_path && cmp == 0)
717 + ; /* do nothing, prefer note to non-note */
718 + else {
719 + ret = write_each_note_helper(d->root, n->path, n->mode,
720 + n->sha1);
721 + if (ret)
722 + return ret;
723 + }
724 + n = n->next;
725 + }
726 + d->next_non_note = n;
727 + return 0;
728 +}
729 +
730 static int write_each_note(const unsigned char *object_sha1,
731 const unsigned char *note_sha1, char *note_path,
732 void *cb_data)
@@ -615,7 +744,9 @@ static int write_each_note(const unsigned char *object_sha1,
744 }
745 assert(note_path_len <= 40 + 19);
746
618 - return write_each_note_helper(d->root, note_path, mode, note_sha1);
747 + /* Weave non-note entries into note entries */
748 + return write_each_non_note_until(note_path, d) ||
749 + write_each_note_helper(d->root, note_path, mode, note_sha1);
750 }
751
752 int combine_notes_concatenate(unsigned char *cur_sha1,
@@ -696,6 +827,8 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
827 combine_notes = combine_notes_concatenate;
828
829 t->root = (struct int_node *) xcalloc(sizeof(struct int_node), 1);
830 + t->first_non_note = NULL;
831 + t->prev_non_note = NULL;
832 t->ref = notes_ref ? xstrdup(notes_ref) : NULL;
833 t->combine_notes = combine_notes;
834 t->initialized = 1;
@@ -709,7 +842,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
842
843 hashclr(root_tree.key_sha1);
844 hashcpy(root_tree.val_sha1, sha1);
712 - load_subtree(&root_tree, t->root, 0);
845 + load_subtree(t, &root_tree, t->root, 0);
846 }
847
848 void add_note(struct notes_tree *t, const unsigned char *object_sha1,
@@ -725,7 +858,7 @@ void add_note(struct notes_tree *t, const unsigned char *object_sha1,
858 l = (struct leaf_node *) xmalloc(sizeof(struct leaf_node));
859 hashcpy(l->key_sha1, object_sha1);
860 hashcpy(l->val_sha1, note_sha1);
728 - note_tree_insert(t->root, 0, l, PTR_TYPE_NOTE, combine_notes);
861 + note_tree_insert(t, t->root, 0, l, PTR_TYPE_NOTE, combine_notes);
862 }
863
864 void remove_note(struct notes_tree *t, const unsigned char *object_sha1)
@@ -748,7 +881,7 @@ const unsigned char *get_note(struct notes_tree *t,
881 if (!t)
882 t = &default_notes_tree;
883 assert(t->initialized);
751 - found = note_tree_find(t->root, 0, object_sha1);
884 + found = note_tree_find(t, t->root, 0, object_sha1);
885 return found ? found->val_sha1 : NULL;
886 }
887
@@ -758,7 +891,7 @@ int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,
891 if (!t)
892 t = &default_notes_tree;
893 assert(t->initialized);
761 - return for_each_note_helper(t->root, 0, 0, flags, fn, cb_data);
894 + return for_each_note_helper(t, t->root, 0, 0, flags, fn, cb_data);
895 }
896
897 int write_notes_tree(struct notes_tree *t, unsigned char *result)
@@ -776,11 +909,13 @@ int write_notes_tree(struct notes_tree *t, unsigned char *result)
909 strbuf_init(&root.buf, 256 * (32 + 40)); /* assume 256 entries */
910 root.path[0] = root.path[1] = '\0';
911 cb_data.root = &root;
912 + cb_data.next_non_note = t->first_non_note;
913
914 /* Write tree objects representing current notes tree */
915 ret = for_each_note(t, FOR_EACH_NOTE_DONT_UNPACK_SUBTREES |
916 FOR_EACH_NOTE_YIELD_SUBTREES,
917 write_each_note, &cb_data) ||
918 + write_each_non_note_until(NULL, &cb_data) ||
919 tree_write_stack_finish_subtree(&root) ||
920 write_sha1_file(root.buf.buf, root.buf.len, tree_type, result);
921 strbuf_release(&root.buf);
@@ -794,6 +929,12 @@ void free_notes(struct notes_tree *t)
929 if (t->root)
930 note_tree_free(t->root);
931 free(t->root);
932 + while (t->first_non_note) {
933 + t->prev_non_note = t->first_non_note->next;
934 + free(t->first_non_note->path);
935 + free(t->first_non_note);
936 + t->first_non_note = t->prev_non_note;
937 + }
938 free(t->ref);
939 memset(t, 0, sizeof(struct notes_tree));
940 }
notes.h
+1
@@ -36,6 +36,7 @@ int combine_notes_ignore(unsigned char *cur_sha1, const unsigned char *new_sha1)
36 */
37 extern struct notes_tree {
38 struct int_node *root;
39 + struct non_note *first_non_note, *prev_non_note;
40 char *ref;
41 combine_notes_fn *combine_notes;
42 int initialized;
t/t3303-notes-subtrees.sh
+17 -11
@@ -95,12 +95,12 @@ INPUT_END
95 test_expect_success 'test notes in 2/38-fanout' 'test_sha1_based "s|^..|&/|"'
96 test_expect_success 'verify notes in 2/38-fanout' 'verify_notes'
97
98 -test_expect_success 'test notes in 4/36-fanout' 'test_sha1_based "s|^....|&/|"'
99 -test_expect_success 'verify notes in 4/36-fanout' 'verify_notes'
100 -
98 test_expect_success 'test notes in 2/2/36-fanout' 'test_sha1_based "s|^\(..\)\(..\)|\1/\2/|"'
99 test_expect_success 'verify notes in 2/2/36-fanout' 'verify_notes'
100
101 +test_expect_success 'test notes in 2/2/2/34-fanout' 'test_sha1_based "s|^\(..\)\(..\)\(..\)|\1/\2/\3/|"'
102 +test_expect_success 'verify notes in 2/2/2/34-fanout' 'verify_notes'
103 +
104 test_same_notes () {
105 (
106 start_note_commit &&
@@ -128,14 +128,17 @@ INPUT_END
128 git fast-import --quiet
129 }
130
131 -test_expect_success 'test same notes in 4/36-fanout and 2/38-fanout' 'test_same_notes "s|^..|&/|" "s|^....|&/|"'
132 -test_expect_success 'verify same notes in 4/36-fanout and 2/38-fanout' 'verify_notes'
131 +test_expect_success 'test same notes in no fanout and 2/38-fanout' 'test_same_notes "s|^..|&/|" ""'
132 +test_expect_success 'verify same notes in no fanout and 2/38-fanout' 'verify_notes'
133 +
134 +test_expect_success 'test same notes in no fanout and 2/2/36-fanout' 'test_same_notes "s|^\(..\)\(..\)|\1/\2/|" ""'
135 +test_expect_success 'verify same notes in no fanout and 2/2/36-fanout' 'verify_notes'
136
137 test_expect_success 'test same notes in 2/38-fanout and 2/2/36-fanout' 'test_same_notes "s|^\(..\)\(..\)|\1/\2/|" "s|^..|&/|"'
138 test_expect_success 'verify same notes in 2/38-fanout and 2/2/36-fanout' 'verify_notes'
139
137 -test_expect_success 'test same notes in 4/36-fanout and 2/2/36-fanout' 'test_same_notes "s|^\(..\)\(..\)|\1/\2/|" "s|^....|&/|"'
138 -test_expect_success 'verify same notes in 4/36-fanout and 2/2/36-fanout' 'verify_notes'
140 +test_expect_success 'test same notes in 2/2/2/34-fanout and 2/2/36-fanout' 'test_same_notes "s|^\(..\)\(..\)|\1/\2/|" "s|^\(..\)\(..\)\(..\)|\1/\2/\3/|"'
141 +test_expect_success 'verify same notes in 2/2/2/34-fanout and 2/2/36-fanout' 'verify_notes'
142
143 test_concatenated_notes () {
144 (
@@ -176,13 +179,16 @@ verify_concatenated_notes () {
179 test_cmp expect output
180 }
181
179 -test_expect_success 'test notes in 4/36-fanout concatenated with 2/38-fanout' 'test_concatenated_notes "s|^..|&/|" "s|^....|&/|"'
180 -test_expect_success 'verify notes in 4/36-fanout concatenated with 2/38-fanout' 'verify_concatenated_notes'
182 +test_expect_success 'test notes in no fanout concatenated with 2/38-fanout' 'test_concatenated_notes "s|^..|&/|" ""'
183 +test_expect_success 'verify notes in no fanout concatenated with 2/38-fanout' 'verify_concatenated_notes'
184 +
185 +test_expect_success 'test notes in no fanout concatenated with 2/2/36-fanout' 'test_concatenated_notes "s|^\(..\)\(..\)|\1/\2/|" ""'
186 +test_expect_success 'verify notes in no fanout concatenated with 2/2/36-fanout' 'verify_concatenated_notes'
187
188 test_expect_success 'test notes in 2/38-fanout concatenated with 2/2/36-fanout' 'test_concatenated_notes "s|^\(..\)\(..\)|\1/\2/|" "s|^..|&/|"'
189 test_expect_success 'verify notes in 2/38-fanout concatenated with 2/2/36-fanout' 'verify_concatenated_notes'
190
185 -test_expect_success 'test notes in 4/36-fanout concatenated with 2/2/36-fanout' 'test_concatenated_notes "s|^\(..\)\(..\)|\1/\2/|" "s|^....|&/|"'
186 -test_expect_success 'verify notes in 4/36-fanout concatenated with 2/2/36-fanout' 'verify_concatenated_notes'
191 +test_expect_success 'test notes in 2/2/36-fanout concatenated with 2/2/2/34-fanout' 'test_concatenated_notes "s|^\(..\)\(..\)\(..\)|\1/\2/\3/|" "s|^\(..\)\(..\)|\1/\2/|"'
192 +test_expect_success 'verify notes in 2/2/36-fanout concatenated with 2/2/2/34-fanout' 'verify_concatenated_notes'
193
194 test_done
t/t3304-notes-mixed.sh
+35 -1
@@ -131,6 +131,17 @@ data <<EOF
131 another non-note with SHA1-like name
132 EOF
133
134 +M 644 inline de/adbeefdeadbeefdeadbeefdeadbeefdeadbeef
135 +data <<EOF
136 +This is actually a valid note, albeit to a non-existing object.
137 +It is needed in order to trigger the "mishandling" of the dead/beef non-note.
138 +EOF
139 +
140 +M 644 inline dead/beef
141 +data <<EOF
142 +yet another non-note with SHA1-like name
143 +EOF
144 +
145 INPUT_END
146 git fast-import --quiet <input &&
147 git config core.notesRef refs/notes/commits
@@ -158,6 +169,9 @@ EXPECT_END
169 cat >expect_nn3 <<EXPECT_END
170 another non-note with SHA1-like name
171 EXPECT_END
172 +cat >expect_nn4 <<EXPECT_END
173 +yet another non-note with SHA1-like name
174 +EXPECT_END
175
176 test_expect_success "verify contents of non-notes" '
177
@@ -166,7 +180,27 @@ test_expect_success "verify contents of non-notes" '
180 git cat-file -p refs/notes/commits:deadbeef > actual_nn2 &&
181 test_cmp expect_nn2 actual_nn2 &&
182 git cat-file -p refs/notes/commits:de/adbeef > actual_nn3 &&
169 - test_cmp expect_nn3 actual_nn3
183 + test_cmp expect_nn3 actual_nn3 &&
184 + git cat-file -p refs/notes/commits:dead/beef > actual_nn4 &&
185 + test_cmp expect_nn4 actual_nn4
186 +'
187 +
188 +test_expect_success "git-notes preserves non-notes" '
189 +
190 + test_tick &&
191 + git notes edit -m "foo bar"
192 +'
193 +
194 +test_expect_success "verify contents of non-notes after git-notes" '
195 +
196 + git cat-file -p refs/notes/commits:foobar/non-note.txt > actual_nn1 &&
197 + test_cmp expect_nn1 actual_nn1 &&
198 + git cat-file -p refs/notes/commits:deadbeef > actual_nn2 &&
199 + test_cmp expect_nn2 actual_nn2 &&
200 + git cat-file -p refs/notes/commits:de/adbeef > actual_nn3 &&
201 + test_cmp expect_nn3 actual_nn3 &&
202 + git cat-file -p refs/notes/commits:dead/beef > actual_nn4 &&
203 + test_cmp expect_nn4 actual_nn4
204 '
205
206 test_done