From: Junio C Hamano Date: Fri, 11 Aug 2017 20:26:56 +0000 (-0700) Subject: Merge branch 'bw/object-id' X-Git-Tag: v2.15.0-rc0~212 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/c7528f4d8a2b8e4bf843b3eb95d2b7899a38c1fa?hp=-c Merge branch 'bw/object-id' Conversion from uchar[20] to struct object_id continues. * bw/object-id: receive-pack: don't access hash of NULL object_id pointer notes: don't access hash of NULL object_id pointer tree-diff: don't access hash of NULL object_id pointer --- c7528f4d8a2b8e4bf843b3eb95d2b7899a38c1fa diff --combined builtin/notes.c index 77573cf1ea,3d9dbc97a1..4303848e04 --- a/builtin/notes.c +++ b/builtin/notes.c @@@ -8,7 -8,6 +8,7 @@@ */ #include "cache.h" +#include "config.h" #include "builtin.h" #include "notes.h" #include "blob.h" @@@ -341,10 -340,8 +341,10 @@@ static struct notes_tree *init_notes_ch ref = (flags & NOTES_INIT_WRITABLE) ? t->update_ref : t->ref; if (!starts_with(ref, "refs/notes/")) - /* TRANSLATORS: the first %s will be replaced by a - git notes command: 'add', 'merge', 'remove', etc.*/ + /* + * TRANSLATORS: the first %s will be replaced by a git + * notes command: 'add', 'merge', 'remove', etc. + */ die(_("refusing to %s notes in %s (outside of refs/notes/)"), subcommand, ref); return t; @@@ -456,7 -453,7 +456,7 @@@ static int add(int argc, const char **a oid_to_hex(&object)); } - prepare_note_data(&object, &d, note->hash); + prepare_note_data(&object, &d, note ? note->hash : NULL); if (d.buf.len || allow_empty) { write_note_data(&d, new_note.hash); if (add_note(t, &object, &new_note, combine_notes_overwrite)) diff --combined builtin/receive-pack.c index 136c44def7,f589e8aebf..14b6e09b42 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@@ -1,5 -1,4 +1,5 @@@ #include "builtin.h" +#include "config.h" #include "lockfile.h" #include "pack.h" #include "refs.h" @@@ -919,9 -918,9 +919,9 @@@ static int update_shallow_ref(struct co */ static int head_has_history(void) { - unsigned char sha1[20]; + struct object_id oid; - return !get_sha1("HEAD", sha1); + return !get_oid("HEAD", &oid); } static const char *push_to_deploy(unsigned char *sha1, @@@ -1138,7 -1137,7 +1138,7 @@@ static const char *update(struct comman } if (ref_transaction_delete(transaction, namespaced_name, - old_oid->hash, + old_oid ? old_oid->hash : NULL, 0, "push", &err)) { rp_error("%s", err.buf); strbuf_release(&err); @@@ -1806,7 -1805,7 +1806,7 @@@ static const char *unpack_with_sideband static void prepare_shallow_update(struct command *commands, struct shallow_info *si) { - int i, j, k, bitmap_size = (si->ref->nr + 31) / 32; + int i, j, k, bitmap_size = DIV_ROUND_UP(si->ref->nr, 32); ALLOC_ARRAY(si->used_shallow, si->shallow->nr); assign_shallow_commits_to_refs(si, si->used_shallow, NULL); diff --combined tree-diff.c index bd6d65a409,7f7ddda4ea..2357f72899 --- a/tree-diff.c +++ b/tree-diff.c @@@ -141,7 -141,8 +141,7 @@@ static struct combine_diff_path *path_a /* if last->next is !NULL - it is a pre-allocated memory, we can reuse */ p = last->next; if (p && (alloclen > (intptr_t)p->next)) { - free(p); - p = NULL; + FREE_AND_NULL(p); } if (!p) { @@@ -421,8 -422,9 +421,9 @@@ static struct combine_diff_path *ll_dif * diff_tree_oid(parent, commit) ) */ for (i = 0; i < nparent; ++i) - tptree[i] = fill_tree_descriptor(&tp[i], parents_oid[i]->hash); - ttree = fill_tree_descriptor(&t, oid->hash); + tptree[i] = fill_tree_descriptor(&tp[i], + parents_oid[i] ? parents_oid[i]->hash : NULL); + ttree = fill_tree_descriptor(&t, oid ? oid->hash : NULL); /* Enable recursion indefinitely */ opt->pathspec.recursive = DIFF_OPT_TST(opt, RECURSIVE); @@@ -558,7 -560,8 +559,7 @@@ struct combine_diff_path *diff_tree_pat * (see path_appendnew() for details about why) */ if (p->next) { - free(p->next); - p->next = NULL; + FREE_AND_NULL(p->next); } return p;