builtin/pack-objects: convert to struct object_id
This is one of the last unconverted callers to peel_ref. While we're fixing that, convert the rest of the file, since it will need to be converted at some point anyway. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Oct 15, 2017 at 22:07 UTC
188960b4d68e0b77e31481592b86306a9ce37632
1 file changed
+68
-67
builtin/pack-objects.c
+68
-67
@@ -151,7 +151,7 @@ static unsigned long do_compress(void **pptr, unsigned long size)
151
}
152
153
static unsigned long write_large_blob_data(struct git_istream *st, struct sha1file *f,
154
- const unsigned char *sha1)
154
+ const struct object_id *oid)
155
{
156
git_zstream stream;
157
unsigned char ibuf[1024 * 16];
@@ -165,7 +165,7 @@ static unsigned long write_large_blob_data(struct git_istream *st, struct sha1fi
165
int zret = Z_OK;
166
readlen = read_istream(st, ibuf, sizeof(ibuf));
167
if (readlen == -1)
168
- die(_("unable to read %s"), sha1_to_hex(sha1));
168
+ die(_("unable to read %s"), oid_to_hex(oid));
169
170
stream.next_in = ibuf;
171
stream.avail_in = readlen;
@@ -339,7 +339,7 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent
339
sha1write(f, header, hdrlen);
340
}
341
if (st) {
342
- datalen = write_large_blob_data(st, f, entry->idx.oid.hash);
342
+ datalen = write_large_blob_data(st, f, &entry->idx.oid);
343
close_istream(st);
344
} else {
345
sha1write(f, buf, datalen);
@@ -557,13 +557,13 @@ static enum write_one_status write_one(struct sha1file *f,
557
static int mark_tagged(const char *path, const struct object_id *oid, int flag,
558
void *cb_data)
559
{
560
- unsigned char peeled[20];
560
+ struct object_id peeled;
561
struct object_entry *entry = packlist_find(&to_pack, oid->hash, NULL);
562
563
if (entry)
564
entry->tagged = 1;
565
- if (!peel_ref(path, peeled)) {
566
- entry = packlist_find(&to_pack, peeled, NULL);
565
+ if (!peel_ref(path, peeled.hash)) {
566
+ entry = packlist_find(&to_pack, peeled.hash, NULL);
567
if (entry)
568
entry->tagged = 1;
569
}
@@ -792,7 +792,7 @@ static void write_pack_file(void)
792
write_order = compute_write_order();
793
794
do {
795
- unsigned char sha1[20];
795
+ struct object_id oid;
796
char *pack_tmp_name = NULL;
797
798
if (pack_to_stdout)
@@ -823,13 +823,13 @@ static void write_pack_file(void)
823
* If so, rewrite it like in fast-import
824
*/
825
if (pack_to_stdout) {
826
- sha1close(f, sha1, CSUM_CLOSE);
826
+ sha1close(f, oid.hash, CSUM_CLOSE);
827
} else if (nr_written == nr_remaining) {
828
- sha1close(f, sha1, CSUM_FSYNC);
828
+ sha1close(f, oid.hash, CSUM_FSYNC);
829
} else {
830
- int fd = sha1close(f, sha1, 0);
831
- fixup_pack_header_footer(fd, sha1, pack_tmp_name,
832
- nr_written, sha1, offset);
830
+ int fd = sha1close(f, oid.hash, 0);
831
+ fixup_pack_header_footer(fd, oid.hash, pack_tmp_name,
832
+ nr_written, oid.hash, offset);
833
close(fd);
834
if (write_bitmap_index) {
835
warning(_(no_split_warning));
@@ -863,16 +863,16 @@ static void write_pack_file(void)
863
strbuf_addf(&tmpname, "%s-", base_name);
864
865
if (write_bitmap_index) {
866
- bitmap_writer_set_checksum(sha1);
866
+ bitmap_writer_set_checksum(oid.hash);
867
bitmap_writer_build_type_index(written_list, nr_written);
868
}
869
870
finish_tmp_packfile(&tmpname, pack_tmp_name,
871
written_list, nr_written,
872
- &pack_idx_opts, sha1);
872
+ &pack_idx_opts, oid.hash);
873
874
if (write_bitmap_index) {
875
- strbuf_addf(&tmpname, "%s.bitmap", sha1_to_hex(sha1));
875
+ strbuf_addf(&tmpname, "%s.bitmap", oid_to_hex(&oid));
876
877
stop_progress(&progress_state);
878
@@ -887,7 +887,7 @@ static void write_pack_file(void)
887
888
strbuf_release(&tmpname);
889
free(pack_tmp_name);
890
- puts(sha1_to_hex(sha1));
890
+ puts(oid_to_hex(&oid));
891
}
892
893
/* mark written objects as written to previous pack */
@@ -928,13 +928,13 @@ static int no_try_delta(const char *path)
928
* found the item, since that saves us from having to look it up again a
929
* few lines later when we want to add the new entry.
930
*/
931
-static int have_duplicate_entry(const unsigned char *sha1,
931
+static int have_duplicate_entry(const struct object_id *oid,
932
int exclude,
933
uint32_t *index_pos)
934
{
935
struct object_entry *entry;
936
937
- entry = packlist_find(&to_pack, sha1, index_pos);
937
+ entry = packlist_find(&to_pack, oid->hash, index_pos);
938
if (!entry)
939
return 0;
940
@@ -990,7 +990,7 @@ static int want_found_object(int exclude, struct packed_git *p)
990
* function finds if there is any pack that has the object and returns the pack
991
* and its offset in these variables.
992
*/
993
-static int want_object_in_pack(const unsigned char *sha1,
993
+static int want_object_in_pack(const struct object_id *oid,
994
int exclude,
995
struct packed_git **found_pack,
996
off_t *found_offset)
@@ -998,7 +998,7 @@ static int want_object_in_pack(const unsigned char *sha1,
998
struct mru_entry *entry;
999
int want;
1000
1001
- if (!exclude && local && has_loose_object_nonlocal(sha1))
1001
+ if (!exclude && local && has_loose_object_nonlocal(oid->hash))
1002
return 0;
1003
1004
/*
@@ -1019,7 +1019,7 @@ static int want_object_in_pack(const unsigned char *sha1,
1019
if (p == *found_pack)
1020
offset = *found_offset;
1021
else
1022
- offset = find_pack_entry_one(sha1, p);
1022
+ offset = find_pack_entry_one(oid->hash, p);
1023
1024
if (offset) {
1025
if (!*found_pack) {
@@ -1039,7 +1039,7 @@ static int want_object_in_pack(const unsigned char *sha1,
1039
return 1;
1040
}
1041
1042
-static void create_object_entry(const unsigned char *sha1,
1042
+static void create_object_entry(const struct object_id *oid,
1043
enum object_type type,
1044
uint32_t hash,
1045
int exclude,
@@ -1050,7 +1050,7 @@ static void create_object_entry(const unsigned char *sha1,
1050
{
1051
struct object_entry *entry;
1052
1053
- entry = packlist_alloc(&to_pack, sha1, index_pos);
1053
+ entry = packlist_alloc(&to_pack, oid->hash, index_pos);
1054
entry->hash = hash;
1055
if (type)
1056
entry->type = type;
@@ -1070,17 +1070,17 @@ static const char no_closure_warning[] = N_(
1070
"disabling bitmap writing, as some objects are not being packed"
1071
);
1072
1073
-static int add_object_entry(const unsigned char *sha1, enum object_type type,
1073
+static int add_object_entry(const struct object_id *oid, enum object_type type,
1074
const char *name, int exclude)
1075
{
1076
struct packed_git *found_pack = NULL;
1077
off_t found_offset = 0;
1078
uint32_t index_pos;
1079
1080
- if (have_duplicate_entry(sha1, exclude, &index_pos))
1080
+ if (have_duplicate_entry(oid, exclude, &index_pos))
1081
return 0;
1082
1083
- if (!want_object_in_pack(sha1, exclude, &found_pack, &found_offset)) {
1083
+ if (!want_object_in_pack(oid, exclude, &found_pack, &found_offset)) {
1084
/* The pack is missing an object, so it will not have closure */
1085
if (write_bitmap_index) {
1086
warning(_(no_closure_warning));
@@ -1089,7 +1089,7 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type,
1089
return 0;
1090
}
1091
1092
- create_object_entry(sha1, type, pack_name_hash(name),
1092
+ create_object_entry(oid, type, pack_name_hash(name),
1093
exclude, name && no_try_delta(name),
1094
index_pos, found_pack, found_offset);
1095
@@ -1104,20 +1104,20 @@ static int add_object_entry_from_bitmap(const struct object_id *oid,
1104
{
1105
uint32_t index_pos;
1106
1107
- if (have_duplicate_entry(oid->hash, 0, &index_pos))
1107
+ if (have_duplicate_entry(oid, 0, &index_pos))
1108
return 0;
1109
1110
- if (!want_object_in_pack(oid->hash, 0, &pack, &offset))
1110
+ if (!want_object_in_pack(oid, 0, &pack, &offset))
1111
return 0;
1112
1113
- create_object_entry(oid->hash, type, name_hash, 0, 0, index_pos, pack, offset);
1113
+ create_object_entry(oid, type, name_hash, 0, 0, index_pos, pack, offset);
1114
1115
display_progress(progress_state, nr_result);
1116
return 1;
1117
}
1118
1119
struct pbase_tree_cache {
1120
- unsigned char sha1[20];
1120
+ struct object_id oid;
1121
int ref;
1122
int temporary;
1123
void *tree_data;
@@ -1125,9 +1125,9 @@ struct pbase_tree_cache {
1125
};
1126
1127
static struct pbase_tree_cache *(pbase_tree_cache[256]);
1128
-static int pbase_tree_cache_ix(const unsigned char *sha1)
1128
+static int pbase_tree_cache_ix(const struct object_id *oid)
1129
{
1130
- return sha1[0] % ARRAY_SIZE(pbase_tree_cache);
1130
+ return oid->hash[0] % ARRAY_SIZE(pbase_tree_cache);
1131
}
1132
static int pbase_tree_cache_ix_incr(int ix)
1133
{
@@ -1144,14 +1144,14 @@ static struct pbase_tree {
1144
struct pbase_tree_cache pcache;
1145
} *pbase_tree;
1146
1147
-static struct pbase_tree_cache *pbase_tree_get(const unsigned char *sha1)
1147
+static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid)
1148
{
1149
struct pbase_tree_cache *ent, *nent;
1150
void *data;
1151
unsigned long size;
1152
enum object_type type;
1153
int neigh;
1154
- int my_ix = pbase_tree_cache_ix(sha1);
1154
+ int my_ix = pbase_tree_cache_ix(oid);
1155
int available_ix = -1;
1156
1157
/* pbase-tree-cache acts as a limited hashtable.
@@ -1160,7 +1160,7 @@ static struct pbase_tree_cache *pbase_tree_get(const unsigned char *sha1)
1160
*/
1161
for (neigh = 0; neigh < 8; neigh++) {
1162
ent = pbase_tree_cache[my_ix];
1163
- if (ent && !hashcmp(ent->sha1, sha1)) {
1163
+ if (ent && !oidcmp(&ent->oid, oid)) {
1164
ent->ref++;
1165
return ent;
1166
}
@@ -1176,7 +1176,7 @@ static struct pbase_tree_cache *pbase_tree_get(const unsigned char *sha1)
1176
/* Did not find one. Either we got a bogus request or
1177
* we need to read and perhaps cache.
1178
*/
1179
- data = read_sha1_file(sha1, &type, &size);
1179
+ data = read_sha1_file(oid->hash, &type, &size);
1180
if (!data)
1181
return NULL;
1182
if (type != OBJ_TREE) {
@@ -1202,7 +1202,7 @@ static struct pbase_tree_cache *pbase_tree_get(const unsigned char *sha1)
1202
free(ent->tree_data);
1203
nent = ent;
1204
}
1205
- hashcpy(nent->sha1, sha1);
1205
+ oidcpy(&nent->oid, oid);
1206
nent->tree_data = data;
1207
nent->tree_size = size;
1208
nent->ref = 1;
@@ -1247,7 +1247,7 @@ static void add_pbase_object(struct tree_desc *tree,
1247
if (cmp < 0)
1248
return;
1249
if (name[cmplen] != '/') {
1250
- add_object_entry(entry.oid->hash,
1250
+ add_object_entry(entry.oid,
1251
object_type(entry.mode),
1252
fullname, 1);
1253
return;
@@ -1258,7 +1258,7 @@ static void add_pbase_object(struct tree_desc *tree,
1258
const char *down = name+cmplen+1;
1259
int downlen = name_cmp_len(down);
1260
1261
- tree = pbase_tree_get(entry.oid->hash);
1261
+ tree = pbase_tree_get(entry.oid);
1262
if (!tree)
1263
return;
1264
init_tree_desc(&sub, tree->tree_data, tree->tree_size);
@@ -1317,7 +1317,7 @@ static void add_preferred_base_object(const char *name)
1317
cmplen = name_cmp_len(name);
1318
for (it = pbase_tree; it; it = it->next) {
1319
if (cmplen == 0) {
1320
- add_object_entry(it->pcache.sha1, OBJ_TREE, NULL, 1);
1320
+ add_object_entry(&it->pcache.oid, OBJ_TREE, NULL, 1);
1321
}
1322
else {
1323
struct tree_desc tree;
@@ -1327,22 +1327,22 @@ static void add_preferred_base_object(const char *name)
1327
}
1328
}
1329
1330
-static void add_preferred_base(unsigned char *sha1)
1330
+static void add_preferred_base(struct object_id *oid)
1331
{
1332
struct pbase_tree *it;
1333
void *data;
1334
unsigned long size;
1335
- unsigned char tree_sha1[20];
1335
+ struct object_id tree_oid;
1336
1337
if (window <= num_preferred_base++)
1338
return;
1339
1340
- data = read_object_with_reference(sha1, tree_type, &size, tree_sha1);
1340
+ data = read_object_with_reference(oid->hash, tree_type, &size, tree_oid.hash);
1341
if (!data)
1342
return;
1343
1344
for (it = pbase_tree; it; it = it->next) {
1345
- if (!hashcmp(it->pcache.sha1, tree_sha1)) {
1345
+ if (!oidcmp(&it->pcache.oid, &tree_oid)) {
1346
free(data);
1347
return;
1348
}
@@ -1352,7 +1352,7 @@ static void add_preferred_base(unsigned char *sha1)
1352
it->next = pbase_tree;
1353
pbase_tree = it;
1354
1355
- hashcpy(it->pcache.sha1, tree_sha1);
1355
+ oidcpy(&it->pcache.oid, &tree_oid);
1356
it->pcache.tree_data = data;
1357
it->pcache.tree_size = size;
1358
}
@@ -2357,7 +2357,7 @@ static void add_tag_chain(const struct object_id *oid)
2357
die("unable to pack objects reachable from tag %s",
2358
oid_to_hex(oid));
2359
2360
- add_object_entry(tag->object.oid.hash, OBJ_TAG, NULL, 0);
2360
+ add_object_entry(&tag->object.oid, OBJ_TAG, NULL, 0);
2361
2362
if (tag->tagged->type != OBJ_TAG)
2363
return;
@@ -2505,8 +2505,9 @@ static int git_pack_config(const char *k, const char *v, void *cb)
2505
2506
static void read_object_list_from_stdin(void)
2507
{
2508
- char line[40 + 1 + PATH_MAX + 2];
2509
- unsigned char sha1[20];
2508
+ char line[GIT_MAX_HEXSZ + 1 + PATH_MAX + 2];
2509
+ struct object_id oid;
2510
+ const char *p;
2511
2512
for (;;) {
2513
if (!fgets(line, sizeof(line), stdin)) {
@@ -2520,17 +2521,17 @@ static void read_object_list_from_stdin(void)
2521
continue;
2522
}
2523
if (line[0] == '-') {
2523
- if (get_sha1_hex(line+1, sha1))
2524
- die("expected edge sha1, got garbage:\n %s",
2524
+ if (get_oid_hex(line+1, &oid))
2525
+ die("expected edge object ID, got garbage:\n %s",
2526
line);
2526
- add_preferred_base(sha1);
2527
+ add_preferred_base(&oid);
2528
continue;
2529
}
2529
- if (get_sha1_hex(line, sha1))
2530
- die("expected sha1, got garbage:\n %s", line);
2530
+ if (parse_oid_hex(line, &oid, &p))
2531
+ die("expected object ID, got garbage:\n %s", line);
2532
2532
- add_preferred_base_object(line+41);
2533
- add_object_entry(sha1, 0, line+41, 0);
2533
+ add_preferred_base_object(p + 1);
2534
+ add_object_entry(&oid, 0, p + 1, 0);
2535
}
2536
}
2537
@@ -2538,7 +2539,7 @@ static void read_object_list_from_stdin(void)
2539
2540
static void show_commit(struct commit *commit, void *data)
2541
{
2541
- add_object_entry(commit->object.oid.hash, OBJ_COMMIT, NULL, 0);
2542
+ add_object_entry(&commit->object.oid, OBJ_COMMIT, NULL, 0);
2543
commit->object.flags |= OBJECT_ADDED;
2544
2545
if (write_bitmap_index)
@@ -2548,13 +2549,13 @@ static void show_commit(struct commit *commit, void *data)
2549
static void show_object(struct object *obj, const char *name, void *data)
2550
{
2551
add_preferred_base_object(name);
2551
- add_object_entry(obj->oid.hash, obj->type, name, 0);
2552
+ add_object_entry(&obj->oid, obj->type, name, 0);
2553
obj->flags |= OBJECT_ADDED;
2554
}
2555
2556
static void show_edge(struct commit *commit)
2557
{
2557
- add_preferred_base(commit->object.oid.hash);
2558
+ add_preferred_base(&commit->object.oid);
2559
}
2560
2561
struct in_pack_object {
@@ -2601,7 +2602,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
2602
memset(&in_pack, 0, sizeof(in_pack));
2603
2604
for (p = packed_git; p; p = p->next) {
2604
- const unsigned char *sha1;
2605
+ struct object_id oid;
2606
struct object *o;
2607
2608
if (!p->pack_local || p->pack_keep)
@@ -2614,8 +2615,8 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
2615
in_pack.alloc);
2616
2617
for (i = 0; i < p->num_objects; i++) {
2617
- sha1 = nth_packed_object_sha1(p, i);
2618
- o = lookup_unknown_object(sha1);
2618
+ nth_packed_object_oid(&oid, p, i);
2619
+ o = lookup_unknown_object(oid.hash);
2620
if (!(o->flags & OBJECT_ADDED))
2621
mark_in_pack_object(o, p, &in_pack);
2622
o->flags |= OBJECT_ADDED;
@@ -2626,7 +2627,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
2627
QSORT(in_pack.array, in_pack.nr, ofscmp);
2628
for (i = 0; i < in_pack.nr; i++) {
2629
struct object *o = in_pack.array[i].object;
2629
- add_object_entry(o->oid.hash, o->type, "", 0);
2630
+ add_object_entry(&o->oid, o->type, "", 0);
2631
}
2632
}
2633
free(in_pack.array);
@@ -2642,7 +2643,7 @@ static int add_loose_object(const struct object_id *oid, const char *path,
2643
return 0;
2644
}
2645
2645
- add_object_entry(oid->hash, type, "", 0);
2646
+ add_object_entry(oid, type, "", 0);
2647
return 0;
2648
}
2649
@@ -2658,7 +2659,7 @@ static void add_unreachable_loose_objects(void)
2659
NULL, NULL, NULL);
2660
}
2661
2661
-static int has_sha1_pack_kept_or_nonlocal(const unsigned char *sha1)
2662
+static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
2663
{
2664
static struct packed_git *last_found = (void *)1;
2665
struct packed_git *p;
@@ -2667,7 +2668,7 @@ static int has_sha1_pack_kept_or_nonlocal(const unsigned char *sha1)
2668
2669
while (p) {
2670
if ((!p->pack_local || p->pack_keep) &&
2670
- find_pack_entry_one(sha1, p)) {
2671
+ find_pack_entry_one(oid->hash, p)) {
2672
last_found = p;
2673
return 1;
2674
}
@@ -2718,7 +2719,7 @@ static void loosen_unused_packed_objects(struct rev_info *revs)
2719
for (i = 0; i < p->num_objects; i++) {
2720
nth_packed_object_oid(&oid, p, i);
2721
if (!packlist_find(&to_pack, oid.hash, NULL) &&
2721
- !has_sha1_pack_kept_or_nonlocal(oid.hash) &&
2722
+ !has_sha1_pack_kept_or_nonlocal(&oid) &&
2723
!loosened_object_can_be_discarded(&oid, p->mtime))
2724
if (force_object_loose(oid.hash, p->mtime))
2725
die("unable to force loose object");