Skip to content

Commit 4ebef53

Browse files
mhaggergitster
authored andcommitted
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>
1 parent 67c9b42 commit 4ebef53

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

notes.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,6 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
447447
goto handle_non_note; /* entry.path is not a SHA1 */
448448

449449
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);
454450
} else if (path_len == 2) {
455451
/* This is potentially an internal node */
456452

@@ -463,17 +459,17 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
463459
GIT_SHA1_RAWSZ - prefix_len))
464460
goto handle_non_note; /* entry.path is not a SHA1 */
465461

462+
object_oid.hash[KEY_INDEX] = (unsigned char) (prefix_len + 1);
463+
466464
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);
472465
} else {
473466
/* This can't be part of a note */
474467
goto handle_non_note;
475468
}
476469

470+
l = xcalloc(1, sizeof(*l));
471+
oidcpy(&l->key_oid, &object_oid);
472+
oidcpy(&l->val_oid, entry.oid);
477473
if (note_tree_insert(t, node, n, l, type,
478474
combine_notes_concatenate))
479475
die("Failed to load %s %s into notes tree "

0 commit comments

Comments
 (0)