Skip to content

Commit 76c1d9a

Browse files
bk2204gitster
authored andcommitted
Convert object iteration callbacks to struct object_id
Convert each_loose_object_fn and each_packed_object_fn to take a pointer to struct object_id. Update the various callbacks. Convert several 40-based constants to use GIT_SHA1_HEXSZ. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 068f85e commit 76c1d9a

9 files changed

Lines changed: 50 additions & 50 deletions

File tree

builtin/cat-file.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,20 +409,20 @@ static int batch_object_cb(const unsigned char sha1[20], void *vdata)
409409
return 0;
410410
}
411411

412-
static int batch_loose_object(const unsigned char *sha1,
412+
static int batch_loose_object(const struct object_id *oid,
413413
const char *path,
414414
void *data)
415415
{
416-
sha1_array_append(data, sha1);
416+
sha1_array_append(data, oid->hash);
417417
return 0;
418418
}
419419

420-
static int batch_packed_object(const unsigned char *sha1,
420+
static int batch_packed_object(const struct object_id *oid,
421421
struct packed_git *pack,
422422
uint32_t pos,
423423
void *data)
424424
{
425-
sha1_array_append(data, sha1);
425+
sha1_array_append(data, oid->hash);
426426
return 0;
427427
}
428428

builtin/count-objects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static void loose_garbage(const char *path)
5353
report_garbage(PACKDIR_FILE_GARBAGE, path);
5454
}
5555

56-
static int count_loose(const unsigned char *sha1, const char *path, void *data)
56+
static int count_loose(const struct object_id *oid, const char *path, void *data)
5757
{
5858
struct stat st;
5959

@@ -62,7 +62,7 @@ static int count_loose(const unsigned char *sha1, const char *path, void *data)
6262
else {
6363
loose_size += on_disk_bytes(st);
6464
loose++;
65-
if (verbose && has_sha1_pack(sha1))
65+
if (verbose && has_sha1_pack(oid->hash))
6666
packed_loose++;
6767
}
6868
return 0;

builtin/fsck.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ static void get_default_heads(void)
491491
}
492492
}
493493

494-
static struct object *parse_loose_object(const unsigned char *sha1,
494+
static struct object *parse_loose_object(const struct object_id *oid,
495495
const char *path)
496496
{
497497
struct object *obj;
@@ -500,27 +500,27 @@ static struct object *parse_loose_object(const unsigned char *sha1,
500500
unsigned long size;
501501
int eaten;
502502

503-
if (read_loose_object(path, sha1, &type, &size, &contents) < 0)
503+
if (read_loose_object(path, oid->hash, &type, &size, &contents) < 0)
504504
return NULL;
505505

506506
if (!contents && type != OBJ_BLOB)
507507
die("BUG: read_loose_object streamed a non-blob");
508508

509-
obj = parse_object_buffer(sha1, type, size, contents, &eaten);
509+
obj = parse_object_buffer(oid->hash, type, size, contents, &eaten);
510510

511511
if (!eaten)
512512
free(contents);
513513
return obj;
514514
}
515515

516-
static int fsck_loose(const unsigned char *sha1, const char *path, void *data)
516+
static int fsck_loose(const struct object_id *oid, const char *path, void *data)
517517
{
518-
struct object *obj = parse_loose_object(sha1, path);
518+
struct object *obj = parse_loose_object(oid, path);
519519

520520
if (!obj) {
521521
errors_found |= ERROR_OBJECT;
522522
error("%s: object corrupt or missing: %s",
523-
sha1_to_hex(sha1), path);
523+
oid_to_hex(oid), path);
524524
return 0; /* keep checking other objects */
525525
}
526526

@@ -619,26 +619,26 @@ static int fsck_cache_tree(struct cache_tree *it)
619619
return err;
620620
}
621621

622-
static void mark_object_for_connectivity(const unsigned char *sha1)
622+
static void mark_object_for_connectivity(const struct object_id *oid)
623623
{
624-
struct object *obj = lookup_unknown_object(sha1);
624+
struct object *obj = lookup_unknown_object(oid->hash);
625625
obj->flags |= HAS_OBJ;
626626
}
627627

628-
static int mark_loose_for_connectivity(const unsigned char *sha1,
628+
static int mark_loose_for_connectivity(const struct object_id *oid,
629629
const char *path,
630630
void *data)
631631
{
632-
mark_object_for_connectivity(sha1);
632+
mark_object_for_connectivity(oid);
633633
return 0;
634634
}
635635

636-
static int mark_packed_for_connectivity(const unsigned char *sha1,
636+
static int mark_packed_for_connectivity(const struct object_id *oid,
637637
struct packed_git *pack,
638638
uint32_t pos,
639639
void *data)
640640
{
641-
mark_object_for_connectivity(sha1);
641+
mark_object_for_connectivity(oid);
642642
return 0;
643643
}
644644

builtin/pack-objects.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,17 +2534,17 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
25342534
free(in_pack.array);
25352535
}
25362536

2537-
static int add_loose_object(const unsigned char *sha1, const char *path,
2537+
static int add_loose_object(const struct object_id *oid, const char *path,
25382538
void *data)
25392539
{
2540-
enum object_type type = sha1_object_info(sha1, NULL);
2540+
enum object_type type = sha1_object_info(oid->hash, NULL);
25412541

25422542
if (type < 0) {
25432543
warning("loose object at %s could not be examined", path);
25442544
return 0;
25452545
}
25462546

2547-
add_object_entry(sha1, type, "", 0);
2547+
add_object_entry(oid->hash, type, "", 0);
25482548
return 0;
25492549
}
25502550

builtin/prune-packed.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ static int prune_subdir(int nr, const char *path, void *data)
1919
return 0;
2020
}
2121

22-
static int prune_object(const unsigned char *sha1, const char *path,
22+
static int prune_object(const struct object_id *oid, const char *path,
2323
void *data)
2424
{
2525
int *opts = data;
2626

27-
if (!has_sha1_pack(sha1))
27+
if (!has_sha1_pack(oid->hash))
2828
return 0;
2929

3030
if (*opts & PRUNE_PACKED_DRY_RUN)

builtin/prune.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static int prune_tmp_file(const char *fullpath)
3030
return 0;
3131
}
3232

33-
static int prune_object(const unsigned char *sha1, const char *fullpath,
33+
static int prune_object(const struct object_id *oid, const char *fullpath,
3434
void *data)
3535
{
3636
struct stat st;
@@ -39,7 +39,7 @@ static int prune_object(const unsigned char *sha1, const char *fullpath,
3939
* Do we know about this object?
4040
* It must have been reachable
4141
*/
42-
if (lookup_object(sha1))
42+
if (lookup_object(oid->hash))
4343
return 0;
4444

4545
if (lstat(fullpath, &st)) {
@@ -50,8 +50,8 @@ static int prune_object(const unsigned char *sha1, const char *fullpath,
5050
if (st.st_mtime > expire)
5151
return 0;
5252
if (show_only || verbose) {
53-
enum object_type type = sha1_object_info(sha1, NULL);
54-
printf("%s %s\n", sha1_to_hex(sha1),
53+
enum object_type type = sha1_object_info(oid->hash, NULL);
54+
printf("%s %s\n", oid_to_hex(oid),
5555
(type > 0) ? typename(type) : "unknown");
5656
}
5757
if (!show_only)

cache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,7 @@ extern int unpack_object_header(struct packed_git *, struct pack_window **, off_
16551655
* scratch buffer, but restored to its original contents before
16561656
* the function returns.
16571657
*/
1658-
typedef int each_loose_object_fn(const unsigned char *sha1,
1658+
typedef int each_loose_object_fn(const struct object_id *oid,
16591659
const char *path,
16601660
void *data);
16611661
typedef int each_loose_cruft_fn(const char *basename,
@@ -1681,7 +1681,7 @@ int for_each_loose_file_in_objdir_buf(struct strbuf *path,
16811681
* LOCAL_ONLY flag is set).
16821682
*/
16831683
#define FOR_EACH_OBJECT_LOCAL_ONLY 0x1
1684-
typedef int each_packed_object_fn(const unsigned char *sha1,
1684+
typedef int each_packed_object_fn(const struct object_id *oid,
16851685
struct packed_git *pack,
16861686
uint32_t pos,
16871687
void *data);

reachable.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct recent_data {
5858
unsigned long timestamp;
5959
};
6060

61-
static void add_recent_object(const unsigned char *sha1,
61+
static void add_recent_object(const struct object_id *oid,
6262
unsigned long mtime,
6363
struct recent_data *data)
6464
{
@@ -75,37 +75,37 @@ static void add_recent_object(const unsigned char *sha1,
7575
* later processing, and the revision machinery expects
7676
* commits and tags to have been parsed.
7777
*/
78-
type = sha1_object_info(sha1, NULL);
78+
type = sha1_object_info(oid->hash, NULL);
7979
if (type < 0)
80-
die("unable to get object info for %s", sha1_to_hex(sha1));
80+
die("unable to get object info for %s", oid_to_hex(oid));
8181

8282
switch (type) {
8383
case OBJ_TAG:
8484
case OBJ_COMMIT:
85-
obj = parse_object_or_die(sha1, NULL);
85+
obj = parse_object_or_die(oid->hash, NULL);
8686
break;
8787
case OBJ_TREE:
88-
obj = (struct object *)lookup_tree(sha1);
88+
obj = (struct object *)lookup_tree(oid->hash);
8989
break;
9090
case OBJ_BLOB:
91-
obj = (struct object *)lookup_blob(sha1);
91+
obj = (struct object *)lookup_blob(oid->hash);
9292
break;
9393
default:
9494
die("unknown object type for %s: %s",
95-
sha1_to_hex(sha1), typename(type));
95+
oid_to_hex(oid), typename(type));
9696
}
9797

9898
if (!obj)
99-
die("unable to lookup %s", sha1_to_hex(sha1));
99+
die("unable to lookup %s", oid_to_hex(oid));
100100

101101
add_pending_object(data->revs, obj, "");
102102
}
103103

104-
static int add_recent_loose(const unsigned char *sha1,
104+
static int add_recent_loose(const struct object_id *oid,
105105
const char *path, void *data)
106106
{
107107
struct stat st;
108-
struct object *obj = lookup_object(sha1);
108+
struct object *obj = lookup_object(oid->hash);
109109

110110
if (obj && obj->flags & SEEN)
111111
return 0;
@@ -119,22 +119,22 @@ static int add_recent_loose(const unsigned char *sha1,
119119
*/
120120
if (errno == ENOENT)
121121
return 0;
122-
return error_errno("unable to stat %s", sha1_to_hex(sha1));
122+
return error_errno("unable to stat %s", oid_to_hex(oid));
123123
}
124124

125-
add_recent_object(sha1, st.st_mtime, data);
125+
add_recent_object(oid, st.st_mtime, data);
126126
return 0;
127127
}
128128

129-
static int add_recent_packed(const unsigned char *sha1,
129+
static int add_recent_packed(const struct object_id *oid,
130130
struct packed_git *p, uint32_t pos,
131131
void *data)
132132
{
133-
struct object *obj = lookup_object(sha1);
133+
struct object *obj = lookup_object(oid->hash);
134134

135135
if (obj && obj->flags & SEEN)
136136
return 0;
137-
add_recent_object(sha1, p->mtime, data);
137+
add_recent_object(oid, p->mtime, data);
138138
return 0;
139139
}
140140

sha1_file.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3685,15 +3685,15 @@ static int for_each_file_in_obj_subdir(int subdir_nr,
36853685
strbuf_setlen(path, baselen);
36863686
strbuf_addf(path, "/%s", de->d_name);
36873687

3688-
if (strlen(de->d_name) == 38) {
3689-
char hex[41];
3690-
unsigned char sha1[20];
3688+
if (strlen(de->d_name) == GIT_SHA1_HEXSZ - 2) {
3689+
char hex[GIT_SHA1_HEXSZ+1];
3690+
struct object_id oid;
36913691

36923692
snprintf(hex, sizeof(hex), "%02x%s",
36933693
subdir_nr, de->d_name);
3694-
if (!get_sha1_hex(hex, sha1)) {
3694+
if (!get_oid_hex(hex, &oid)) {
36953695
if (obj_cb) {
3696-
r = obj_cb(sha1, path->buf, data);
3696+
r = obj_cb(&oid, path->buf, data);
36973697
if (r)
36983698
break;
36993699
}
@@ -3805,7 +3805,7 @@ static int for_each_object_in_pack(struct packed_git *p, each_packed_object_fn c
38053805
return error("unable to get sha1 of object %u in %s",
38063806
i, p->pack_name);
38073807

3808-
r = cb(oid.hash, p, i, data);
3808+
r = cb(&oid, p, i, data);
38093809
if (r)
38103810
break;
38113811
}

0 commit comments

Comments
 (0)