summaryrefslogtreecommitdiff
path: root/notes-cache.c
diff options
context:
space:
mode:
authorMike Hommey <mh@glandium.org>2015-10-08 02:54:43 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-01-12 23:10:01 (GMT)
commitee76f92fe883305c1260952f5b325b0503311fc9 (patch)
tree6cea77bd1955070b9f56832d803ac0b70448f59f /notes-cache.c
parent754884255bb580df159e58defa81cdd30b5c430c (diff)
downloadgit-ee76f92fe883305c1260952f5b325b0503311fc9.zip
git-ee76f92fe883305c1260952f5b325b0503311fc9.tar.gz
git-ee76f92fe883305c1260952f5b325b0503311fc9.tar.bz2
notes: allow treeish expressions as notes ref
init_notes() is the main point of entry to the notes API. It ensures that the input can be used as ref, because it needs a ref to update to store notes tree after modifying it. There however are many use cases where notes tree is only read, e.g. "git log --notes=...". Any notes-shaped treeish could be used for such purpose, but it is not allowed due to existing restriction. Allow treeish expressions to be used in the case the notes tree is going to be used without write "permissions". Add a flag to distinguish whether the notes tree is intended to be used read-only, or will be updated. With this change, operations that use notes read-only can be fed any notes-shaped tree-ish can be used, e.g. git log --notes=notes@{1}. Signed-off-by: Mike Hommey <mh@glandium.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'notes-cache.c')
-rw-r--r--notes-cache.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/notes-cache.c b/notes-cache.c
index c4e9bb7..5dfc5cb 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -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);
}
@@ -49,7 +49,8 @@ int notes_cache_write(struct notes_cache *c)
unsigned char tree_sha1[20];
unsigned char commit_sha1[20];
- 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;
@@ -59,8 +60,8 @@ int notes_cache_write(struct notes_cache *c)
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, UPDATE_REFS_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;