Skip to content

Commit 98374a0

Browse files
peffgitster
authored andcommitted
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>
1 parent d7a2457 commit 98374a0

12 files changed

Lines changed: 47 additions & 16 deletions

File tree

apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3183,7 +3183,7 @@ static int apply_binary(struct apply_state *state,
31833183
return 0; /* deletion patch */
31843184
}
31853185

3186-
if (has_sha1_file(oid.hash)) {
3186+
if (has_object_file(&oid)) {
31873187
/* We already have the postimage */
31883188
enum object_type type;
31893189
unsigned long size;

builtin/fetch.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,7 @@ static void find_non_local_tags(const struct ref *refs,
317317
!has_object_file_with_flags(&ref->old_oid,
318318
OBJECT_INFO_QUICK) &&
319319
!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) &&
322321
!will_fetch(head, item->oid.hash))
323322
oidclr(&item->oid);
324323
item = NULL;
@@ -332,7 +331,7 @@ static void find_non_local_tags(const struct ref *refs,
332331
* fetch.
333332
*/
334333
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) &&
336335
!will_fetch(head, item->oid.hash))
337336
oidclr(&item->oid);
338337

@@ -353,7 +352,7 @@ static void find_non_local_tags(const struct ref *refs,
353352
* checked to see if it needs fetching.
354353
*/
355354
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) &&
357356
!will_fetch(head, item->oid.hash))
358357
oidclr(&item->oid);
359358

builtin/index-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
772772
if (startup_info->have_repository) {
773773
read_lock();
774774
collision_test_needed =
775-
has_sha1_file_with_flags(oid->hash, OBJECT_INFO_QUICK);
775+
has_object_file_with_flags(oid, OBJECT_INFO_QUICK);
776776
read_unlock();
777777
}
778778

builtin/reflog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static int tree_is_complete(const struct object_id *oid)
9494
init_tree_desc(&desc, tree->buffer, tree->size);
9595
complete = 1;
9696
while (tree_entry(&desc, &entry)) {
97-
if (!has_sha1_file(entry.oid->hash) ||
97+
if (!has_object_file(entry.oid) ||
9898
(S_ISDIR(entry.mode) && !tree_is_complete(entry.oid))) {
9999
tree->object.flags |= INCOMPLETE;
100100
complete = 0;

builtin/show-ref.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static void show_one(const char *refname, const struct object_id *oid)
2323
const char *hex;
2424
struct object_id peeled;
2525

26-
if (!has_sha1_file(oid->hash))
26+
if (!has_object_file(oid))
2727
die("git show-ref: bad ref %s (%s)", refname,
2828
oid_to_hex(oid));
2929

bulk-checkin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static int already_written(struct bulk_checkin_state *state, struct object_id *o
6767
int i;
6868

6969
/* The object may already exist in the repository */
70-
if (has_sha1_file(oid->hash))
70+
if (has_object_file(oid))
7171
return 1;
7272

7373
/* Might want to keep the list sorted */

cache-tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ int cache_tree_fully_valid(struct cache_tree *it)
225225
int i;
226226
if (!it)
227227
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))
229229
return 0;
230230
for (i = 0; i < it->subtree_nr; i++) {
231231
if (!cache_tree_fully_valid(it->down[i]->cache_tree))
@@ -253,7 +253,7 @@ static int update_one(struct cache_tree *it,
253253

254254
*skip_count = 0;
255255

256-
if (0 <= it->entry_count && has_sha1_file(it->oid.hash))
256+
if (0 <= it->entry_count && has_object_file(&it->oid))
257257
return it->entry_count;
258258

259259
/*

contrib/coccinelle/object_id.cocci

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,35 @@ expression E1, E2;
147147
- hashcmp(E1, E2) != 0
148148
+ !hasheq(E1, E2)
149149
...>}
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static int fill_active_slot(struct walker *walker)
131131
list_for_each_safe(pos, tmp, head) {
132132
obj_req = list_entry(pos, struct object_request, node);
133133
if (obj_req->state == WAITING) {
134-
if (has_sha1_file(obj_req->oid.hash))
134+
if (has_object_file(&obj_req->oid))
135135
obj_req->state = COMPLETE;
136136
else {
137137
start_object_request(walker, obj_req);
@@ -489,7 +489,7 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)
489489
if (obj_req == NULL)
490490
return error("Couldn't find request for %s in the queue", hex);
491491

492-
if (has_sha1_file(obj_req->oid.hash)) {
492+
if (has_object_file(&obj_req->oid)) {
493493
if (obj_req->req != NULL)
494494
abort_http_object_request(obj_req->req);
495495
abort_object_request(obj_req);

refs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ int ref_resolves_to_object(const char *refname,
188188
{
189189
if (flags & REF_ISBROKEN)
190190
return 0;
191-
if (!has_sha1_file(oid->hash)) {
191+
if (!has_object_file(oid)) {
192192
error(_("%s does not point to a valid object!"), refname);
193193
return 0;
194194
}

0 commit comments

Comments
 (0)