Skip to content

Commit bd99d6e

Browse files
committed
Merge branch 'ps/object-store-cleanup'
Further code clean-up in the object-store layer. * ps/object-store-cleanup: object-store: drop `repo_has_object_file()` treewide: convert users of `repo_has_object_file()` to `has_object()` object-store: allow fetching objects via `has_object()` object-store: move function declarations to their respective subsystems object-store: move and rename `odb_pack_keep()` object-store: drop `loose_object_path()` object-store: move `struct packed_git` into "packfile.h"
2 parents 38758be + 8a9e27b commit bd99d6e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+278
-289
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/count-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "parse-options.h"
1313
#include "quote.h"
1414
#include "packfile.h"
15-
#include "object-store.h"
15+
#include "object-file.h"
1616

1717
static unsigned long garbage;
1818
static off_t size_garbage;

builtin/fast-import.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,8 @@ static char *keep_pack(const char *curr_index_name)
811811
int keep_fd;
812812

813813
odb_pack_name(pack_data->repo, &name, pack_data->hash, "keep");
814-
keep_fd = odb_pack_keep(name.buf);
814+
keep_fd = safe_create_file_with_leading_directories(pack_data->repo,
815+
name.buf);
815816
if (keep_fd < 0)
816817
die_errno("cannot create keep file");
817818
write_or_die(keep_fd, keep_msg, strlen(keep_msg));

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/gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "commit.h"
2929
#include "commit-graph.h"
3030
#include "packfile.h"
31-
#include "object-store.h"
31+
#include "object-file.h"
3232
#include "pack.h"
3333
#include "pack-objects.h"
3434
#include "path.h"

builtin/index-pack.c

Lines changed: 3 additions & 4 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

@@ -1565,7 +1564,7 @@ static void write_special_file(const char *suffix, const char *msg,
15651564
else
15661565
filename = odb_pack_name(the_repository, &name_buf, hash, suffix);
15671566

1568-
fd = odb_pack_keep(filename);
1567+
fd = safe_create_file_with_leading_directories(the_repository, filename);
15691568
if (fd < 0) {
15701569
if (errno != EEXIST)
15711570
die_errno(_("cannot write %s file '%s'"),

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

0 commit comments

Comments
 (0)