convert has_sha1_file() callers to has_object_file()

The only remaining callers of has_sha1_file() actually have an object_id already. They can use the "object" variant, rather than dereferencing the hash themselves. The code changes here were completely generated by the included coccinelle patch. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jan 7, 2019 at 03:37 UTC 98374a07c98d1acc200c423b87495365a59cce0b
12 files changed +47 -16
apply.c
+1 -1
@@ -3183,7 +3183,7 @@ static int apply_binary(struct apply_state *state,
3183 return 0; /* deletion patch */
3184 }
3185
3186 - if (has_sha1_file(oid.hash)) {
3186 + if (has_object_file(&oid)) {
3187 /* We already have the postimage */
3188 enum object_type type;
3189 unsigned long size;
builtin/fetch.c
+3 -4
@@ -317,8 +317,7 @@ static void find_non_local_tags(const struct ref *refs,
317 !has_object_file_with_flags(&ref->old_oid,
318 OBJECT_INFO_QUICK) &&
319 !will_fetch(head, ref->old_oid.hash) &&
320 - !has_sha1_file_with_flags(item->oid.hash,
321 - OBJECT_INFO_QUICK) &&
320 + !has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) &&
321 !will_fetch(head, item->oid.hash))
322 oidclr(&item->oid);
323 item = NULL;
@@ -332,7 +331,7 @@ static void find_non_local_tags(const struct ref *refs,
331 * fetch.
332 */
333 if (item &&
335 - !has_sha1_file_with_flags(item->oid.hash, OBJECT_INFO_QUICK) &&
334 + !has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) &&
335 !will_fetch(head, item->oid.hash))
336 oidclr(&item->oid);
337
@@ -353,7 +352,7 @@ static void find_non_local_tags(const struct ref *refs,
352 * checked to see if it needs fetching.
353 */
354 if (item &&
356 - !has_sha1_file_with_flags(item->oid.hash, OBJECT_INFO_QUICK) &&
355 + !has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) &&
356 !will_fetch(head, item->oid.hash))
357 oidclr(&item->oid);
358
builtin/index-pack.c
+1 -1
@@ -772,7 +772,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
772 if (startup_info->have_repository) {
773 read_lock();
774 collision_test_needed =
775 - has_sha1_file_with_flags(oid->hash, OBJECT_INFO_QUICK);
775 + has_object_file_with_flags(oid, OBJECT_INFO_QUICK);
776 read_unlock();
777 }
778
builtin/reflog.c
+1 -1
@@ -94,7 +94,7 @@ static int tree_is_complete(const struct object_id *oid)
94 init_tree_desc(&desc, tree->buffer, tree->size);
95 complete = 1;
96 while (tree_entry(&desc, &entry)) {
97 - if (!has_sha1_file(entry.oid->hash) ||
97 + if (!has_object_file(entry.oid) ||
98 (S_ISDIR(entry.mode) && !tree_is_complete(entry.oid))) {
99 tree->object.flags |= INCOMPLETE;
100 complete = 0;
builtin/show-ref.c
+1 -1
@@ -23,7 +23,7 @@ static void show_one(const char *refname, const struct object_id *oid)
23 const char *hex;
24 struct object_id peeled;
25
26 - if (!has_sha1_file(oid->hash))
26 + if (!has_object_file(oid))
27 die("git show-ref: bad ref %s (%s)", refname,
28 oid_to_hex(oid));
29
bulk-checkin.c
+1 -1
@@ -67,7 +67,7 @@ static int already_written(struct bulk_checkin_state *state, struct object_id *o
67 int i;
68
69 /* The object may already exist in the repository */
70 - if (has_sha1_file(oid->hash))
70 + if (has_object_file(oid))
71 return 1;
72
73 /* Might want to keep the list sorted */
cache-tree.c
+2 -2
@@ -225,7 +225,7 @@ int cache_tree_fully_valid(struct cache_tree *it)
225 int i;
226 if (!it)
227 return 0;
228 - if (it->entry_count < 0 || !has_sha1_file(it->oid.hash))
228 + if (it->entry_count < 0 || !has_object_file(&it->oid))
229 return 0;
230 for (i = 0; i < it->subtree_nr; i++) {
231 if (!cache_tree_fully_valid(it->down[i]->cache_tree))
@@ -253,7 +253,7 @@ static int update_one(struct cache_tree *it,
253
254 *skip_count = 0;
255
256 - if (0 <= it->entry_count && has_sha1_file(it->oid.hash))
256 + if (0 <= it->entry_count && has_object_file(&it->oid))
257 return it->entry_count;
258
259 /*
contrib/coccinelle/object_id.cocci
+32
@@ -147,3 +147,35 @@ expression E1, E2;
147 - hashcmp(E1, E2) != 0
148 + !hasheq(E1, E2)
149 ...>}
150 +
151 +@@
152 +struct object_id OID;
153 +@@
154 +- has_sha1_file(OID.hash)
155 ++ has_object_file(&OID)
156 +
157 +@@
158 +identifier f != has_object_file;
159 +struct object_id *OIDPTR;
160 +@@
161 + f(...) {<...
162 +- has_sha1_file(OIDPTR->hash)
163 ++ has_object_file(OIDPTR)
164 + ...>}
165 +
166 +@@
167 +struct object_id OID;
168 +expression E;
169 +@@
170 +- has_sha1_file_with_flags(OID.hash, E)
171 ++ has_object_file_with_flags(&OID, E)
172 +
173 +@@
174 +identifier f != has_object_file_with_flags;
175 +struct object_id *OIDPTR;
176 +expression E;
177 +@@
178 + f(...) {<...
179 +- has_sha1_file_with_flags(OIDPTR->hash, E)
180 ++ has_object_file_with_flags(OIDPTR, E)
181 + ...>}
http-walker.c
+2 -2
@@ -131,7 +131,7 @@ static int fill_active_slot(struct walker *walker)
131 list_for_each_safe(pos, tmp, head) {
132 obj_req = list_entry(pos, struct object_request, node);
133 if (obj_req->state == WAITING) {
134 - if (has_sha1_file(obj_req->oid.hash))
134 + if (has_object_file(&obj_req->oid))
135 obj_req->state = COMPLETE;
136 else {
137 start_object_request(walker, obj_req);
@@ -489,7 +489,7 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)
489 if (obj_req == NULL)
490 return error("Couldn't find request for %s in the queue", hex);
491
492 - if (has_sha1_file(obj_req->oid.hash)) {
492 + if (has_object_file(&obj_req->oid)) {
493 if (obj_req->req != NULL)
494 abort_http_object_request(obj_req->req);
495 abort_object_request(obj_req);
refs.c
+1 -1
@@ -188,7 +188,7 @@ int ref_resolves_to_object(const char *refname,
188 {
189 if (flags & REF_ISBROKEN)
190 return 0;
191 - if (!has_sha1_file(oid->hash)) {
191 + if (!has_object_file(oid)) {
192 error(_("%s does not point to a valid object!"), refname);
193 return 0;
194 }
send-pack.c
+1 -1
@@ -40,7 +40,7 @@ int option_parse_push_signed(const struct option *opt,
40
41 static void feed_object(const struct object_id *oid, FILE *fh, int negative)
42 {
43 - if (negative && !has_sha1_file(oid->hash))
43 + if (negative && !has_object_file(oid))
44 return;
45
46 if (negative)
sha1-file.c
+1 -1
@@ -1372,7 +1372,7 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type,
1372 struct cached_object *co;
1373
1374 hash_object_file(buf, len, type_name(type), oid);
1375 - if (has_sha1_file(oid->hash) || find_cached_object(oid))
1375 + if (has_object_file(oid) || find_cached_object(oid))
1376 return 0;
1377 ALLOC_GROW(cached_objects, cached_object_nr + 1, cached_object_alloc);
1378 co = &cached_objects[cached_object_nr++];