Imported Upstream version 2.13.2
[platform/upstream/git.git] / notes-cache.c
index eabe4a0..5dfc5cb 100644 (file)
@@ -32,14 +32,14 @@ void notes_cache_init(struct notes_cache *c, const char *name,
                     const char *validity)
 {
        struct strbuf ref = STRBUF_INIT;
-       int flags = 0;
+       int flags = NOTES_INIT_WRITABLE;
 
        memset(c, 0, sizeof(*c));
        c->validity = xstrdup(validity);
 
        strbuf_addf(&ref, "refs/notes/%s", name);
        if (!notes_cache_match_validity(ref.buf, validity))
-               flags = NOTES_INIT_EMPTY;
+               flags |= NOTES_INIT_EMPTY;
        init_notes(&c->tree, ref.buf, combine_notes_overwrite, flags);
        strbuf_release(&ref);
 }
@@ -48,21 +48,20 @@ int notes_cache_write(struct notes_cache *c)
 {
        unsigned char tree_sha1[20];
        unsigned char commit_sha1[20];
-       struct strbuf msg = STRBUF_INIT;
 
-       if (!c || !c->tree.initialized || !c->tree.ref || !*c->tree.ref)
+       if (!c || !c->tree.initialized || !c->tree.update_ref ||
+           !*c->tree.update_ref)
                return -1;
        if (!c->tree.dirty)
                return 0;
 
        if (write_notes_tree(&c->tree, tree_sha1))
                return -1;
-       strbuf_attach(&msg, c->validity,
-                     strlen(c->validity), strlen(c->validity) + 1);
-       if (commit_tree(&msg, tree_sha1, NULL, commit_sha1, NULL, NULL) < 0)
+       if (commit_tree(c->validity, strlen(c->validity), tree_sha1, NULL,
+                       commit_sha1, NULL, NULL) < 0)
                return -1;
-       if (update_ref("update notes cache", c->tree.ref, commit_sha1, NULL,
-                      0, QUIET_ON_ERR) < 0)
+       if (update_ref("update notes cache", c->tree.update_ref, commit_sha1,
+                      NULL, 0, UPDATE_REFS_QUIET_ON_ERR) < 0)
                return -1;
 
        return 0;