Skip to content

Commit 062b914

Browse files
pks-tgitster
authored andcommitted
treewide: convert users of repo_has_object_file() to has_object()
As the comment of `repo_has_object_file()` and its `_with_flags()` variant tells us, these functions are considered to be deprecated in favor of `has_object()`. There are a couple of slight benefits in favor of the replacement: - The new function has a short-and-sweet name. - More explicit defaults: `has_object()` doesn't fetch missing objects via promisor remotes, and neither does it reload packfiles if an object wasn't found by default. This ensures that it becomes immediately obvious when a simple object existence check may result in expensive actions. Most importantly though, it is confusing that we have two sets of functions that ultimately do the same thing, but with different defaults. Start sunsetting `repo_has_object_file()` and its `_with_flags()` sibling by replacing all callsites with `has_object()`: - `repo_has_object_file(...)` is equivalent to `has_object(..., HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)`. - `repo_has_object_file_with_flags(..., OBJECT_INFO_QUICK | OBJECT_INFO_SKIP_FETCH_OBJECT)` is equivalent to `has_object(..., 0)`. - `repo_has_object_file_with_flags(..., OBJECT_INFO_SKIP_FETCH_OBJECT)` is equivalent to `has_object(..., HAS_OBJECT_RECHECK_PACKED)`. - `repo_has_object_file_with_flags(..., OBJECT_INFO_QUICK)` is equivalent to `has_object(..., HAS_OBJECT_FETCH_PROMISOR)`. The replacements should be functionally equivalent. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f8fc4ca commit 062b914

23 files changed

+65
-50
lines changed

builtin/cat-file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
169169
goto cleanup;
170170

171171
case 'e':
172-
ret = !repo_has_object_file(the_repository, &oid);
172+
ret = !has_object(the_repository, &oid,
173+
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR);
173174
goto cleanup;
174175

175176
case 'w':

builtin/clone.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,7 @@ static void write_followtags(const struct ref *refs, const char *msg)
504504
continue;
505505
if (ends_with(ref->name, "^{}"))
506506
continue;
507-
if (!repo_has_object_file_with_flags(the_repository, &ref->old_oid,
508-
OBJECT_INFO_QUICK |
509-
OBJECT_INFO_SKIP_FETCH_OBJECT))
507+
if (!has_object(the_repository, &ref->old_oid, 0))
510508
continue;
511509
refs_update_ref(get_main_ref_store(the_repository), msg,
512510
ref->name, &ref->old_oid, NULL, 0,

builtin/fetch.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ static void find_non_local_tags(const struct ref *refs,
337337
struct string_list_item *remote_ref_item;
338338
const struct ref *ref;
339339
struct refname_hash_entry *item = NULL;
340-
const int quick_flags = OBJECT_INFO_QUICK | OBJECT_INFO_SKIP_FETCH_OBJECT;
341340

342341
refname_hash_init(&existing_refs);
343342
refname_hash_init(&remote_refs);
@@ -367,9 +366,9 @@ static void find_non_local_tags(const struct ref *refs,
367366
*/
368367
if (ends_with(ref->name, "^{}")) {
369368
if (item &&
370-
!repo_has_object_file_with_flags(the_repository, &ref->old_oid, quick_flags) &&
369+
!has_object(the_repository, &ref->old_oid, 0) &&
371370
!oidset_contains(&fetch_oids, &ref->old_oid) &&
372-
!repo_has_object_file_with_flags(the_repository, &item->oid, quick_flags) &&
371+
!has_object(the_repository, &item->oid, 0) &&
373372
!oidset_contains(&fetch_oids, &item->oid))
374373
clear_item(item);
375374
item = NULL;
@@ -383,7 +382,7 @@ static void find_non_local_tags(const struct ref *refs,
383382
* fetch.
384383
*/
385384
if (item &&
386-
!repo_has_object_file_with_flags(the_repository, &item->oid, quick_flags) &&
385+
!has_object(the_repository, &item->oid, 0) &&
387386
!oidset_contains(&fetch_oids, &item->oid))
388387
clear_item(item);
389388

@@ -404,7 +403,7 @@ static void find_non_local_tags(const struct ref *refs,
404403
* checked to see if it needs fetching.
405404
*/
406405
if (item &&
407-
!repo_has_object_file_with_flags(the_repository, &item->oid, quick_flags) &&
406+
!has_object(the_repository, &item->oid, 0) &&
408407
!oidset_contains(&fetch_oids, &item->oid))
409408
clear_item(item);
410409

@@ -911,7 +910,8 @@ static int update_local_ref(struct ref *ref,
911910
struct commit *current = NULL, *updated;
912911
int fast_forward = 0;
913912

914-
if (!repo_has_object_file(the_repository, &ref->new_oid))
913+
if (!has_object(the_repository, &ref->new_oid,
914+
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
915915
die(_("object %s not found"), oid_to_hex(&ref->new_oid));
916916

917917
if (oideq(&ref->old_oid, &ref->new_oid)) {
@@ -1330,8 +1330,7 @@ static int check_exist_and_connected(struct ref *ref_map)
13301330
* we need all direct targets to exist.
13311331
*/
13321332
for (r = rm; r; r = r->next) {
1333-
if (!repo_has_object_file_with_flags(the_repository, &r->old_oid,
1334-
OBJECT_INFO_SKIP_FETCH_OBJECT))
1333+
if (!has_object(the_repository, &r->old_oid, HAS_OBJECT_RECHECK_PACKED))
13351334
return -1;
13361335
}
13371336

builtin/index-pack.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -892,9 +892,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
892892

893893
if (startup_info->have_repository) {
894894
read_lock();
895-
collision_test_needed =
896-
repo_has_object_file_with_flags(the_repository, oid,
897-
OBJECT_INFO_QUICK);
895+
collision_test_needed = has_object(the_repository, oid,
896+
HAS_OBJECT_FETCH_PROMISOR);
898897
read_unlock();
899898
}
900899

builtin/receive-pack.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,9 @@ static const char *update(struct command *cmd, struct shallow_info *si)
15061506
}
15071507
}
15081508

1509-
if (!is_null_oid(new_oid) && !repo_has_object_file(the_repository, new_oid)) {
1509+
if (!is_null_oid(new_oid) &&
1510+
!has_object(the_repository, new_oid,
1511+
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
15101512
error("unpack should have generated %s, "
15111513
"but I can't find it!", oid_to_hex(new_oid));
15121514
ret = "bad pack";

builtin/remote.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,8 @@ static int get_push_ref_states(const struct ref *remote_refs,
454454
info->status = PUSH_STATUS_UPTODATE;
455455
else if (is_null_oid(&ref->old_oid))
456456
info->status = PUSH_STATUS_CREATE;
457-
else if (repo_has_object_file(the_repository, &ref->old_oid) &&
457+
else if (has_object(the_repository, &ref->old_oid,
458+
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
458459
ref_newer(&ref->new_oid, &ref->old_oid))
459460
info->status = PUSH_STATUS_FASTFORWARD;
460461
else

builtin/show-ref.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ static void show_one(const struct show_one_options *opts,
3535
const char *hex;
3636
struct object_id peeled;
3737

38-
if (!repo_has_object_file(the_repository, oid))
38+
if (!has_object(the_repository, oid,
39+
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
3940
die("git show-ref: bad ref %s (%s)", refname,
4041
oid_to_hex(oid));
4142

builtin/unpack-objects.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
449449
delta_data = get_data(delta_size);
450450
if (!delta_data)
451451
return;
452-
if (repo_has_object_file(the_repository, &base_oid))
452+
if (has_object(the_repository, &base_oid,
453+
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
453454
; /* Ok we have this one */
454455
else if (resolve_against_held(nr, &base_oid,
455456
delta_data, delta_size))

bulk-checkin.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ static void flush_batch_fsync(void)
130130
static int already_written(struct bulk_checkin_packfile *state, struct object_id *oid)
131131
{
132132
/* The object may already exist in the repository */
133-
if (repo_has_object_file(the_repository, oid))
133+
if (has_object(the_repository, oid,
134+
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
134135
return 1;
135136

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

cache-tree.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,9 @@ int cache_tree_fully_valid(struct cache_tree *it)
238238
int i;
239239
if (!it)
240240
return 0;
241-
if (it->entry_count < 0 || !repo_has_object_file(the_repository, &it->oid))
241+
if (it->entry_count < 0 ||
242+
has_object(the_repository, &it->oid,
243+
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
242244
return 0;
243245
for (i = 0; i < it->subtree_nr; i++) {
244246
if (!cache_tree_fully_valid(it->down[i]->cache_tree))
@@ -289,7 +291,9 @@ static int update_one(struct cache_tree *it,
289291
}
290292
}
291293

292-
if (0 <= it->entry_count && repo_has_object_file(the_repository, &it->oid))
294+
if (0 <= it->entry_count &&
295+
has_object(the_repository, &it->oid,
296+
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
293297
return it->entry_count;
294298

295299
/*
@@ -395,7 +399,8 @@ static int update_one(struct cache_tree *it,
395399
ce_missing_ok = mode == S_IFGITLINK || missing_ok ||
396400
!must_check_existence(ce);
397401
if (is_null_oid(oid) ||
398-
(!ce_missing_ok && !repo_has_object_file(the_repository, oid))) {
402+
(!ce_missing_ok && !has_object(the_repository, oid,
403+
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))) {
399404
strbuf_release(&buffer);
400405
if (expected_missing)
401406
return -1;
@@ -443,7 +448,7 @@ static int update_one(struct cache_tree *it,
443448
struct object_id oid;
444449
hash_object_file(the_hash_algo, buffer.buf, buffer.len,
445450
OBJ_TREE, &oid);
446-
if (repo_has_object_file_with_flags(the_repository, &oid, OBJECT_INFO_SKIP_FETCH_OBJECT))
451+
if (has_object(the_repository, &oid, HAS_OBJECT_RECHECK_PACKED))
447452
oidcpy(&it->oid, &oid);
448453
else
449454
to_invalidate = 1;

0 commit comments

Comments
 (0)