Skip to content

Commit c11be92

Browse files
committed
Merge branch 'ps/odb-cleanup' into jch
Various code clean-up around odb subsystem. * ps/odb-cleanup: odb: drop unneeded headers and forward decls odb: rename `odb_has_object()` flags odb: use enum for `odb_write_object` flags odb: rename `odb_write_object()` flags treewide: use enum for `odb_for_each_object()` flags CodingGuidelines: document our style for flags
2 parents d18575c + 109bcb7 commit c11be92

28 files changed

Lines changed: 72 additions & 64 deletions

Documentation/CodingGuidelines

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,18 @@ For C programs:
668668
unsigned other_field:1;
669669
unsigned field_with_longer_name:1;
670670

671+
- When a function `F` accepts flags, those flags should be defined as `enum
672+
F_flags`. Individual flag definitions should start with `F` and be in
673+
all-uppercase letters. Flag values should be represented via bit shifts.
674+
E.g.
675+
676+
enum frobnicate_flags {
677+
FROBNICATE_FOO = (1 << 0),
678+
FROBNICATE_BAR = (1 << 1),
679+
};
680+
681+
int frobnicate(enum frobnicate_flags flags);
682+
671683
- Array names should be named in the singular form if the individual items are
672684
subject of use. E.g.:
673685

builtin/cat-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
169169

170170
case 'e':
171171
ret = !odb_has_object(the_repository->objects, &oid,
172-
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR);
172+
ODB_HAS_OBJECT_RECHECK_PACKED | ODB_HAS_OBJECT_FETCH_PROMISOR);
173173
goto cleanup;
174174

175175
case 'w':

builtin/fetch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ static int update_local_ref(struct ref *ref,
946946
int fast_forward = 0;
947947

948948
if (!odb_has_object(the_repository->objects, &ref->new_oid,
949-
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
949+
ODB_HAS_OBJECT_RECHECK_PACKED | ODB_HAS_OBJECT_FETCH_PROMISOR))
950950
die(_("object %s not found"), oid_to_hex(&ref->new_oid));
951951

952952
if (oideq(&ref->old_oid, &ref->new_oid)) {
@@ -1396,7 +1396,7 @@ static int check_exist_and_connected(struct ref *ref_map)
13961396
*/
13971397
for (r = rm; r; r = r->next) {
13981398
if (!odb_has_object(the_repository->objects, &r->old_oid,
1399-
HAS_OBJECT_RECHECK_PACKED))
1399+
ODB_HAS_OBJECT_RECHECK_PACKED))
14001400
return -1;
14011401
}
14021402

builtin/fsck.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static int mark_object(struct object *obj, enum object_type type,
162162

163163
if (!(obj->flags & HAS_OBJ)) {
164164
if (parent && !odb_has_object(options->repo->objects, &obj->oid,
165-
HAS_OBJECT_RECHECK_PACKED)) {
165+
ODB_HAS_OBJECT_RECHECK_PACKED)) {
166166
printf_ln(_("broken link from %7s %s\n"
167167
" to %7s %s"),
168168
printable_type(options->repo, &parent->oid, parent->type),

builtin/index-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
891891
if (startup_info->have_repository) {
892892
read_lock();
893893
collision_test_needed = odb_has_object(the_repository->objects, oid,
894-
HAS_OBJECT_FETCH_PROMISOR);
894+
ODB_HAS_OBJECT_FETCH_PROMISOR);
895895
read_unlock();
896896
}
897897

builtin/receive-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
15421542

15431543
if (!is_null_oid(new_oid) &&
15441544
!odb_has_object(the_repository->objects, new_oid,
1545-
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
1545+
ODB_HAS_OBJECT_RECHECK_PACKED | ODB_HAS_OBJECT_FETCH_PROMISOR)) {
15461546
error("unpack should have generated %s, "
15471547
"but I can't find it!", oid_to_hex(new_oid));
15481548
ret = "bad pack";

builtin/remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ static int get_push_ref_states(const struct ref *remote_refs,
473473
else if (is_null_oid(&ref->old_oid))
474474
info->status = PUSH_STATUS_CREATE;
475475
else if (odb_has_object(the_repository->objects, &ref->old_oid,
476-
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
476+
ODB_HAS_OBJECT_RECHECK_PACKED | ODB_HAS_OBJECT_FETCH_PROMISOR) &&
477477
ref_newer(&ref->new_oid, &ref->old_oid))
478478
info->status = PUSH_STATUS_FASTFORWARD;
479479
else

builtin/show-ref.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static void show_one(const struct show_one_options *opts,
3737
struct object_id peeled;
3838

3939
if (!odb_has_object(the_repository->objects, ref->oid,
40-
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
40+
ODB_HAS_OBJECT_RECHECK_PACKED | ODB_HAS_OBJECT_FETCH_PROMISOR))
4141
die("git show-ref: bad ref %s (%s)", ref->name,
4242
oid_to_hex(ref->oid));
4343

builtin/unpack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
449449
if (!delta_data)
450450
return;
451451
if (odb_has_object(the_repository->objects, &base_oid,
452-
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
452+
ODB_HAS_OBJECT_RECHECK_PACKED | ODB_HAS_OBJECT_FETCH_PROMISOR))
453453
; /* Ok we have this one */
454454
else if (resolve_against_held(nr, &base_oid,
455455
delta_data, delta_size))

cache-tree.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ int cache_tree_fully_valid(struct cache_tree *it)
239239
return 0;
240240
if (it->entry_count < 0 ||
241241
odb_has_object(the_repository->objects, &it->oid,
242-
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
242+
ODB_HAS_OBJECT_RECHECK_PACKED | ODB_HAS_OBJECT_FETCH_PROMISOR))
243243
return 0;
244244
for (i = 0; i < it->subtree_nr; i++) {
245245
if (!cache_tree_fully_valid(it->down[i]->cache_tree))
@@ -292,7 +292,7 @@ static int update_one(struct cache_tree *it,
292292

293293
if (0 <= it->entry_count &&
294294
odb_has_object(the_repository->objects, &it->oid,
295-
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
295+
ODB_HAS_OBJECT_RECHECK_PACKED | ODB_HAS_OBJECT_FETCH_PROMISOR))
296296
return it->entry_count;
297297

298298
/*
@@ -400,7 +400,7 @@ static int update_one(struct cache_tree *it,
400400
if (is_null_oid(oid) ||
401401
(!ce_missing_ok &&
402402
!odb_has_object(the_repository->objects, oid,
403-
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))) {
403+
ODB_HAS_OBJECT_RECHECK_PACKED | ODB_HAS_OBJECT_FETCH_PROMISOR))) {
404404
strbuf_release(&buffer);
405405
if (expected_missing)
406406
return -1;
@@ -448,15 +448,15 @@ static int update_one(struct cache_tree *it,
448448
struct object_id oid;
449449
hash_object_file(the_hash_algo, buffer.buf, buffer.len,
450450
OBJ_TREE, &oid);
451-
if (odb_has_object(the_repository->objects, &oid, HAS_OBJECT_RECHECK_PACKED))
451+
if (odb_has_object(the_repository->objects, &oid, ODB_HAS_OBJECT_RECHECK_PACKED))
452452
oidcpy(&it->oid, &oid);
453453
else
454454
to_invalidate = 1;
455455
} else if (dryrun) {
456456
hash_object_file(the_hash_algo, buffer.buf, buffer.len,
457457
OBJ_TREE, &it->oid);
458458
} else if (odb_write_object_ext(the_repository->objects, buffer.buf, buffer.len, OBJ_TREE,
459-
&it->oid, NULL, flags & WRITE_TREE_SILENT ? WRITE_OBJECT_SILENT : 0)) {
459+
&it->oid, NULL, flags & WRITE_TREE_SILENT ? ODB_WRITE_OBJECT_SILENT : 0)) {
460460
strbuf_release(&buffer);
461461
return -1;
462462
}

0 commit comments

Comments
 (0)