Merge branch 'bw/object-id'
authorJunio C Hamano <gitster@pobox.com>
Fri, 11 Aug 2017 20:26:56 +0000 (13:26 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 11 Aug 2017 20:26:56 +0000 (13:26 -0700)
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

1  2 
builtin/notes.c
builtin/receive-pack.c
tree-diff.c
diff --combined builtin/notes.c
index 77573cf1ea8cb4d998597e265263487e22fde592,3d9dbc97a1dd53c8baa20c39bcdb06e43b1c9e32..4303848e044c9f9c6a12236d887a521316b4fc05
@@@ -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 136c44def778fa64a4a79074413d08aeedcb7991,f589e8aebfd4066b789f2c50864cef831115260a..14b6e09b42f1d423307c98275f5b203078b82445
@@@ -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 bd6d65a40920a547b9f27512e31341231273fa75,7f7ddda4ea51e32f67ded46d73f5c0b1c8adb6d6..2357f72899f8f47e497ffd1bb66a0d76d7dbe012
@@@ -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;