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>

brian m. carlson committed Feb 21, 2017 at 23:47 UTC 76c1d9a09624ae39fa9e3140f6581e672b9c040a
9 files changed +50 -50
builtin/cat-file.c
+4 -4
@@ -409,20 +409,20 @@ static int batch_object_cb(const unsigned char sha1[20], void *vdata)
409 return 0;
410 }
411
412 -static int batch_loose_object(const unsigned char *sha1,
412 +static int batch_loose_object(const struct object_id *oid,
413 const char *path,
414 void *data)
415 {
416 - sha1_array_append(data, sha1);
416 + sha1_array_append(data, oid->hash);
417 return 0;
418 }
419
420 -static int batch_packed_object(const unsigned char *sha1,
420 +static int batch_packed_object(const struct object_id *oid,
421 struct packed_git *pack,
422 uint32_t pos,
423 void *data)
424 {
425 - sha1_array_append(data, sha1);
425 + sha1_array_append(data, oid->hash);
426 return 0;
427 }
428
builtin/count-objects.c
+2 -2
@@ -53,7 +53,7 @@ static void loose_garbage(const char *path)
53 report_garbage(PACKDIR_FILE_GARBAGE, path);
54 }
55
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)
57 {
58 struct stat st;
59
@@ -62,7 +62,7 @@ static int count_loose(const unsigned char *sha1, const char *path, void *data)
62 else {
63 loose_size += on_disk_bytes(st);
64 loose++;
65 - if (verbose && has_sha1_pack(sha1))
65 + if (verbose && has_sha1_pack(oid->hash))
66 packed_loose++;
67 }
68 return 0;
builtin/fsck.c
+12 -12
@@ -491,7 +491,7 @@ static void get_default_heads(void)
491 }
492 }
493
494 -static struct object *parse_loose_object(const unsigned char *sha1,
494 +static struct object *parse_loose_object(const struct object_id *oid,
495 const char *path)
496 {
497 struct object *obj;
@@ -500,27 +500,27 @@ static struct object *parse_loose_object(const unsigned char *sha1,
500 unsigned long size;
501 int eaten;
502
503 - if (read_loose_object(path, sha1, &type, &size, &contents) < 0)
503 + if (read_loose_object(path, oid->hash, &type, &size, &contents) < 0)
504 return NULL;
505
506 if (!contents && type != OBJ_BLOB)
507 die("BUG: read_loose_object streamed a non-blob");
508
509 - obj = parse_object_buffer(sha1, type, size, contents, &eaten);
509 + obj = parse_object_buffer(oid->hash, type, size, contents, &eaten);
510
511 if (!eaten)
512 free(contents);
513 return obj;
514 }
515
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)
517 {
518 - struct object *obj = parse_loose_object(sha1, path);
518 + struct object *obj = parse_loose_object(oid, path);
519
520 if (!obj) {
521 errors_found |= ERROR_OBJECT;
522 error("%s: object corrupt or missing: %s",
523 - sha1_to_hex(sha1), path);
523 + oid_to_hex(oid), path);
524 return 0; /* keep checking other objects */
525 }
526
@@ -619,26 +619,26 @@ static int fsck_cache_tree(struct cache_tree *it)
619 return err;
620 }
621
622 -static void mark_object_for_connectivity(const unsigned char *sha1)
622 +static void mark_object_for_connectivity(const struct object_id *oid)
623 {
624 - struct object *obj = lookup_unknown_object(sha1);
624 + struct object *obj = lookup_unknown_object(oid->hash);
625 obj->flags |= HAS_OBJ;
626 }
627
628 -static int mark_loose_for_connectivity(const unsigned char *sha1,
628 +static int mark_loose_for_connectivity(const struct object_id *oid,
629 const char *path,
630 void *data)
631 {
632 - mark_object_for_connectivity(sha1);
632 + mark_object_for_connectivity(oid);
633 return 0;
634 }
635
636 -static int mark_packed_for_connectivity(const unsigned char *sha1,
636 +static int mark_packed_for_connectivity(const struct object_id *oid,
637 struct packed_git *pack,
638 uint32_t pos,
639 void *data)
640 {
641 - mark_object_for_connectivity(sha1);
641 + mark_object_for_connectivity(oid);
642 return 0;
643 }
644
builtin/pack-objects.c
+3 -3
@@ -2534,17 +2534,17 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
2534 free(in_pack.array);
2535 }
2536
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,
2538 void *data)
2539 {
2540 - enum object_type type = sha1_object_info(sha1, NULL);
2540 + enum object_type type = sha1_object_info(oid->hash, NULL);
2541
2542 if (type < 0) {
2543 warning("loose object at %s could not be examined", path);
2544 return 0;
2545 }
2546
2547 - add_object_entry(sha1, type, "", 0);
2547 + add_object_entry(oid->hash, type, "", 0);
2548 return 0;
2549 }
2550
builtin/prune-packed.c
+2 -2
@@ -19,12 +19,12 @@ static int prune_subdir(int nr, const char *path, void *data)
19 return 0;
20 }
21
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,
23 void *data)
24 {
25 int *opts = data;
26
27 - if (!has_sha1_pack(sha1))
27 + if (!has_sha1_pack(oid->hash))
28 return 0;
29
30 if (*opts & PRUNE_PACKED_DRY_RUN)
builtin/prune.c
+4 -4
@@ -30,7 +30,7 @@ static int prune_tmp_file(const char *fullpath)
30 return 0;
31 }
32
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,
34 void *data)
35 {
36 struct stat st;
@@ -39,7 +39,7 @@ static int prune_object(const unsigned char *sha1, const char *fullpath,
39 * Do we know about this object?
40 * It must have been reachable
41 */
42 - if (lookup_object(sha1))
42 + if (lookup_object(oid->hash))
43 return 0;
44
45 if (lstat(fullpath, &st)) {
@@ -50,8 +50,8 @@ static int prune_object(const unsigned char *sha1, const char *fullpath,
50 if (st.st_mtime > expire)
51 return 0;
52 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),
55 (type > 0) ? typename(type) : "unknown");
56 }
57 if (!show_only)
cache.h
+2 -2
@@ -1655,7 +1655,7 @@ extern int unpack_object_header(struct packed_git *, struct pack_window **, off_
1655 * scratch buffer, but restored to its original contents before
1656 * the function returns.
1657 */
1658 -typedef int each_loose_object_fn(const unsigned char *sha1,
1658 +typedef int each_loose_object_fn(const struct object_id *oid,
1659 const char *path,
1660 void *data);
1661 typedef int each_loose_cruft_fn(const char *basename,
@@ -1681,7 +1681,7 @@ int for_each_loose_file_in_objdir_buf(struct strbuf *path,
1681 * LOCAL_ONLY flag is set).
1682 */
1683 #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,
1685 struct packed_git *pack,
1686 uint32_t pos,
1687 void *data);
reachable.c
+15 -15
@@ -58,7 +58,7 @@ struct recent_data {
58 unsigned long timestamp;
59 };
60
61 -static void add_recent_object(const unsigned char *sha1,
61 +static void add_recent_object(const struct object_id *oid,
62 unsigned long mtime,
63 struct recent_data *data)
64 {
@@ -75,37 +75,37 @@ static void add_recent_object(const unsigned char *sha1,
75 * later processing, and the revision machinery expects
76 * commits and tags to have been parsed.
77 */
78 - type = sha1_object_info(sha1, NULL);
78 + type = sha1_object_info(oid->hash, NULL);
79 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));
81
82 switch (type) {
83 case OBJ_TAG:
84 case OBJ_COMMIT:
85 - obj = parse_object_or_die(sha1, NULL);
85 + obj = parse_object_or_die(oid->hash, NULL);
86 break;
87 case OBJ_TREE:
88 - obj = (struct object *)lookup_tree(sha1);
88 + obj = (struct object *)lookup_tree(oid->hash);
89 break;
90 case OBJ_BLOB:
91 - obj = (struct object *)lookup_blob(sha1);
91 + obj = (struct object *)lookup_blob(oid->hash);
92 break;
93 default:
94 die("unknown object type for %s: %s",
95 - sha1_to_hex(sha1), typename(type));
95 + oid_to_hex(oid), typename(type));
96 }
97
98 if (!obj)
99 - die("unable to lookup %s", sha1_to_hex(sha1));
99 + die("unable to lookup %s", oid_to_hex(oid));
100
101 add_pending_object(data->revs, obj, "");
102 }
103
104 -static int add_recent_loose(const unsigned char *sha1,
104 +static int add_recent_loose(const struct object_id *oid,
105 const char *path, void *data)
106 {
107 struct stat st;
108 - struct object *obj = lookup_object(sha1);
108 + struct object *obj = lookup_object(oid->hash);
109
110 if (obj && obj->flags & SEEN)
111 return 0;
@@ -119,22 +119,22 @@ static int add_recent_loose(const unsigned char *sha1,
119 */
120 if (errno == ENOENT)
121 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));
123 }
124
125 - add_recent_object(sha1, st.st_mtime, data);
125 + add_recent_object(oid, st.st_mtime, data);
126 return 0;
127 }
128
129 -static int add_recent_packed(const unsigned char *sha1,
129 +static int add_recent_packed(const struct object_id *oid,
130 struct packed_git *p, uint32_t pos,
131 void *data)
132 {
133 - struct object *obj = lookup_object(sha1);
133 + struct object *obj = lookup_object(oid->hash);
134
135 if (obj && obj->flags & SEEN)
136 return 0;
137 - add_recent_object(sha1, p->mtime, data);
137 + add_recent_object(oid, p->mtime, data);
138 return 0;
139 }
140
sha1_file.c
+6 -6
@@ -3685,15 +3685,15 @@ static int for_each_file_in_obj_subdir(int subdir_nr,
3685 strbuf_setlen(path, baselen);
3686 strbuf_addf(path, "/%s", de->d_name);
3687
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;
3691
3692 snprintf(hex, sizeof(hex), "%02x%s",
3693 subdir_nr, de->d_name);
3694 - if (!get_sha1_hex(hex, sha1)) {
3694 + if (!get_oid_hex(hex, &oid)) {
3695 if (obj_cb) {
3696 - r = obj_cb(sha1, path->buf, data);
3696 + r = obj_cb(&oid, path->buf, data);
3697 if (r)
3698 break;
3699 }
@@ -3805,7 +3805,7 @@ static int for_each_object_in_pack(struct packed_git *p, each_packed_object_fn c
3805 return error("unable to get sha1 of object %u in %s",
3806 i, p->pack_name);
3807
3808 - r = cb(oid.hash, p, i, data);
3808 + r = cb(&oid, p, i, data);
3809 if (r)
3810 break;
3811 }