Skip to content

Commit f6516a5

Browse files
pks-tgitster
authored andcommitted
odb: convert object info flags into an enum
Convert the object info flags into an enum and adapt all functions that receive these flags as parameters to use the enum instead of an integer. This serves two purposes: - The function signatures become more self-documenting, as callers don't have to wonder which flags they expect. - The compiler can warn when a wrong flag type is passed. Note that the second benefit is somewhat limited. For example, when or-ing multiple enum flags together the result will be an integer, and the compiler will not warn about such use cases. But where it does help is when a single flag of the wrong type is passed, as the compiler would generate a warning in that case. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent ae77afc commit f6516a5

6 files changed

Lines changed: 30 additions & 22 deletions

File tree

object-file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,8 @@ static int parse_loose_header(const char *hdr, struct object_info *oi)
414414

415415
int odb_source_loose_read_object_info(struct odb_source *source,
416416
const struct object_id *oid,
417-
struct object_info *oi, int flags)
417+
struct object_info *oi,
418+
enum object_info_flags flags)
418419
{
419420
int ret;
420421
int fd;

object-file.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ void odb_source_loose_reprepare(struct odb_source *source);
4747

4848
int odb_source_loose_read_object_info(struct odb_source *source,
4949
const struct object_id *oid,
50-
struct object_info *oi, int flags);
50+
struct object_info *oi,
51+
enum object_info_flags flags);
5152

5253
int odb_source_loose_read_object_stream(struct odb_read_stream **out,
5354
struct odb_source *source,

odb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ static int oid_object_info_convert(struct repository *r,
842842
int odb_read_object_info_extended(struct object_database *odb,
843843
const struct object_id *oid,
844844
struct object_info *oi,
845-
unsigned flags)
845+
enum object_info_flags flags)
846846
{
847847
int ret;
848848

odb.h

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -352,23 +352,29 @@ struct object_info {
352352
*/
353353
#define OBJECT_INFO_INIT { 0 }
354354

355-
/* Invoke lookup_replace_object() on the given hash */
356-
#define OBJECT_INFO_LOOKUP_REPLACE (1 << 0)
357-
/* Do not retry packed storage after checking packed and loose storage */
358-
#define OBJECT_INFO_QUICK (1 << 1)
359-
/*
360-
* Do not attempt to fetch the object if missing (even if fetch_is_missing is
361-
* nonzero).
362-
*/
363-
#define OBJECT_INFO_SKIP_FETCH_OBJECT (1 << 2)
364-
/*
365-
* This is meant for bulk prefetching of missing blobs in a partial
366-
* clone. Implies OBJECT_INFO_SKIP_FETCH_OBJECT and OBJECT_INFO_QUICK
367-
*/
368-
#define OBJECT_INFO_FOR_PREFETCH (OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK)
355+
/* Flags that can be passed to `odb_read_object_info_extended()`. */
356+
enum object_info_flags {
357+
/* Invoke lookup_replace_object() on the given hash. */
358+
OBJECT_INFO_LOOKUP_REPLACE = (1 << 0),
359+
360+
/* Do not reprepare object sources when the first lookup has failed. */
361+
OBJECT_INFO_QUICK = (1 << 1),
362+
363+
/*
364+
* Do not attempt to fetch the object if missing (even if fetch_is_missing is
365+
* nonzero).
366+
*/
367+
OBJECT_INFO_SKIP_FETCH_OBJECT = (1 << 2),
368+
369+
/* Die if object corruption (not just an object being missing) was detected. */
370+
OBJECT_INFO_DIE_IF_CORRUPT = (1 << 3),
369371

370-
/* Die if object corruption (not just an object being missing) was detected. */
371-
#define OBJECT_INFO_DIE_IF_CORRUPT (1 << 3)
372+
/*
373+
* This is meant for bulk prefetching of missing blobs in a partial
374+
* clone. Implies OBJECT_INFO_SKIP_FETCH_OBJECT and OBJECT_INFO_QUICK.
375+
*/
376+
OBJECT_INFO_FOR_PREFETCH = (OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK),
377+
};
372378

373379
/*
374380
* Read object info from the object database and populate the `object_info`
@@ -377,7 +383,7 @@ struct object_info {
377383
int odb_read_object_info_extended(struct object_database *odb,
378384
const struct object_id *oid,
379385
struct object_info *oi,
380-
unsigned flags);
386+
enum object_info_flags flags);
381387

382388
/*
383389
* Read a subset of object info for the given object ID. Returns an `enum

packfile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2149,7 +2149,7 @@ int packfile_store_freshen_object(struct packfile_store *store,
21492149
int packfile_store_read_object_info(struct packfile_store *store,
21502150
const struct object_id *oid,
21512151
struct object_info *oi,
2152-
unsigned flags UNUSED)
2152+
enum object_info_flags flags UNUSED)
21532153
{
21542154
struct pack_entry e;
21552155
int ret;

packfile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ int packfile_store_read_object_stream(struct odb_read_stream **out,
247247
int packfile_store_read_object_info(struct packfile_store *store,
248248
const struct object_id *oid,
249249
struct object_info *oi,
250-
unsigned flags);
250+
enum object_info_flags flags);
251251

252252
/*
253253
* Open the packfile and add it to the store if it isn't yet known. Returns

0 commit comments

Comments
 (0)