load_subtree(): combine some common code
Write the length into `object_oid` (before copying) rather than `l->key_oid` (after copying). Then combine some code from the two `if` blocks. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Aug 26, 2017 at 10:28 UTC
4ebef533d75a197f660b38d615489ad8a233bba1
1 file changed
+5
-9
notes.c
+5
-9
@@ -447,10 +447,6 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
447
goto handle_non_note; /* entry.path is not a SHA1 */
448
449
type = PTR_TYPE_NOTE;
450
- l = (struct leaf_node *)
451
- xcalloc(1, sizeof(struct leaf_node));
452
- oidcpy(&l->key_oid, &object_oid);
453
- oidcpy(&l->val_oid, entry.oid);
450
} else if (path_len == 2) {
451
/* This is potentially an internal node */
452
@@ -463,17 +459,17 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
459
GIT_SHA1_RAWSZ - prefix_len))
460
goto handle_non_note; /* entry.path is not a SHA1 */
461
462
+ object_oid.hash[KEY_INDEX] = (unsigned char) (prefix_len + 1);
463
+
464
type = PTR_TYPE_SUBTREE;
467
- l = (struct leaf_node *)
468
- xcalloc(1, sizeof(struct leaf_node));
469
- oidcpy(&l->key_oid, &object_oid);
470
- oidcpy(&l->val_oid, entry.oid);
471
- l->key_oid.hash[KEY_INDEX] = (unsigned char) (prefix_len + 1);
465
} else {
466
/* This can't be part of a note */
467
goto handle_non_note;
468
}
469
470
+ l = xcalloc(1, sizeof(*l));
471
+ oidcpy(&l->key_oid, &object_oid);
472
+ oidcpy(&l->val_oid, entry.oid);
473
if (note_tree_insert(t, node, n, l, type,
474
combine_notes_concatenate))
475
die("Failed to load %s %s into notes tree "