notes-cache: convert to struct object_id

Convert as many instances of unsigned char [20] as possible. Update the callers of notes_cache_get and notes_cache_put to use the new interface. Among the functions updated are callers of lookup_commit_reference_gently, which we will soon convert. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed May 6, 2017 at 22:09 UTC 569aa376ea2bb3f27f6248543f3df91c71e612d6
3 files changed +18 -19
diff.c
+2 -2
@@ -5244,7 +5244,7 @@ size_t fill_textconv(struct userdiff_driver *driver,
5244
5245 if (driver->textconv_cache && df->oid_valid) {
5246 *outbuf = notes_cache_get(driver->textconv_cache,
5247 - df->oid.hash,
5247 + &df->oid,
5248 &size);
5249 if (*outbuf)
5250 return size;
@@ -5256,7 +5256,7 @@ size_t fill_textconv(struct userdiff_driver *driver,
5256
5257 if (driver->textconv_cache && df->oid_valid) {
5258 /* ignore errors, as we might be in a readonly repository */
5259 - notes_cache_put(driver->textconv_cache, df->oid.hash, *outbuf,
5259 + notes_cache_put(driver->textconv_cache, &df->oid, *outbuf,
5260 size);
5261 /*
5262 * we could save up changes and flush them all at the end,
notes-cache.c
+14 -15
@@ -5,16 +5,16 @@
5
6 static int notes_cache_match_validity(const char *ref, const char *validity)
7 {
8 - unsigned char sha1[20];
8 + struct object_id oid;
9 struct commit *commit;
10 struct pretty_print_context pretty_ctx;
11 struct strbuf msg = STRBUF_INIT;
12 int ret;
13
14 - if (read_ref(ref, sha1) < 0)
14 + if (read_ref(ref, oid.hash) < 0)
15 return 0;
16
17 - commit = lookup_commit_reference_gently(sha1, 1);
17 + commit = lookup_commit_reference_gently(oid.hash, 1);
18 if (!commit)
19 return 0;
20
@@ -46,8 +46,7 @@ void notes_cache_init(struct notes_cache *c, const char *name,
46
47 int notes_cache_write(struct notes_cache *c)
48 {
49 - unsigned char tree_sha1[20];
50 - unsigned char commit_sha1[20];
49 + struct object_id tree_oid, commit_oid;
50
51 if (!c || !c->tree.initialized || !c->tree.update_ref ||
52 !*c->tree.update_ref)
@@ -55,19 +54,19 @@ int notes_cache_write(struct notes_cache *c)
54 if (!c->tree.dirty)
55 return 0;
56
58 - if (write_notes_tree(&c->tree, tree_sha1))
57 + if (write_notes_tree(&c->tree, tree_oid.hash))
58 return -1;
60 - if (commit_tree(c->validity, strlen(c->validity), tree_sha1, NULL,
61 - commit_sha1, NULL, NULL) < 0)
59 + if (commit_tree(c->validity, strlen(c->validity), tree_oid.hash, NULL,
60 + commit_oid.hash, NULL, NULL) < 0)
61 return -1;
63 - if (update_ref("update notes cache", c->tree.update_ref, commit_sha1,
62 + if (update_ref("update notes cache", c->tree.update_ref, commit_oid.hash,
63 NULL, 0, UPDATE_REFS_QUIET_ON_ERR) < 0)
64 return -1;
65
66 return 0;
67 }
68
70 -char *notes_cache_get(struct notes_cache *c, unsigned char key_sha1[20],
69 +char *notes_cache_get(struct notes_cache *c, struct object_id *key_oid,
70 size_t *outsize)
71 {
72 const unsigned char *value_sha1;
@@ -75,7 +74,7 @@ char *notes_cache_get(struct notes_cache *c, unsigned char key_sha1[20],
74 char *value;
75 unsigned long size;
76
78 - value_sha1 = get_note(&c->tree, key_sha1);
77 + value_sha1 = get_note(&c->tree, key_oid->hash);
78 if (!value_sha1)
79 return NULL;
80 value = read_sha1_file(value_sha1, &type, &size);
@@ -84,12 +83,12 @@ char *notes_cache_get(struct notes_cache *c, unsigned char key_sha1[20],
83 return value;
84 }
85
87 -int notes_cache_put(struct notes_cache *c, unsigned char key_sha1[20],
86 +int notes_cache_put(struct notes_cache *c, struct object_id *key_oid,
87 const char *data, size_t size)
88 {
90 - unsigned char value_sha1[20];
89 + struct object_id value_oid;
90
92 - if (write_sha1_file(data, size, "blob", value_sha1) < 0)
91 + if (write_sha1_file(data, size, "blob", value_oid.hash) < 0)
92 return -1;
94 - return add_note(&c->tree, key_sha1, value_sha1, NULL);
93 + return add_note(&c->tree, key_oid->hash, value_oid.hash, NULL);
94 }
notes-cache.h
+2 -2
@@ -12,9 +12,9 @@ void notes_cache_init(struct notes_cache *c, const char *name,
12 const char *validity);
13 int notes_cache_write(struct notes_cache *c);
14
15 -char *notes_cache_get(struct notes_cache *c, unsigned char sha1[20], size_t
15 +char *notes_cache_get(struct notes_cache *c, struct object_id *oid, size_t
16 *outsize);
17 -int notes_cache_put(struct notes_cache *c, unsigned char sha1[20],
17 +int notes_cache_put(struct notes_cache *c, struct object_id *oid,
18 const char *data, size_t size);
19
20 #endif /* NOTES_CACHE_H */