Skip to content

Commit 42c8ce1

Browse files
committed
Merge branch 'bc/object-id'
Conversion from uchar[20] to struct object_id continues. * bc/object-id: (42 commits) merge-one-file: compute empty blob object ID add--interactive: compute the empty tree value Update shell scripts to compute empty tree object ID sha1_file: only expose empty object constants through git_hash_algo dir: use the_hash_algo for empty blob object ID sequencer: use the_hash_algo for empty tree object ID cache-tree: use is_empty_tree_oid sha1_file: convert cached object code to struct object_id builtin/reset: convert use of EMPTY_TREE_SHA1_BIN builtin/receive-pack: convert one use of EMPTY_TREE_SHA1_HEX wt-status: convert two uses of EMPTY_TREE_SHA1_HEX submodule: convert several uses of EMPTY_TREE_SHA1_HEX sequencer: convert one use of EMPTY_TREE_SHA1_HEX merge: convert empty tree constant to the_hash_algo builtin/merge: switch tree functions to use object_id builtin/am: convert uses of EMPTY_TREE_SHA1_BIN to the_hash_algo sha1-file: add functions for hex empty tree and blob OIDs builtin/receive-pack: avoid hard-coded constants for push certs diff: specify abbreviation size in terms of the_hash_algo upload-pack: replace use of several hard-coded constants ...
2 parents 3d24129 + 7882fa2 commit 42c8ce1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+348
-306
lines changed

Diff for: builtin/am.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
15421542
char *their_tree_name;
15431543

15441544
if (get_oid("HEAD", &our_tree) < 0)
1545-
hashcpy(our_tree.hash, EMPTY_TREE_SHA1_BIN);
1545+
oidcpy(&our_tree, the_hash_algo->empty_tree);
15461546

15471547
if (build_fake_ancestor(state, index_path))
15481548
return error("could not build fake ancestor");
@@ -2042,7 +2042,7 @@ static void am_skip(struct am_state *state)
20422042
am_rerere_clear();
20432043

20442044
if (get_oid("HEAD", &head))
2045-
hashcpy(head.hash, EMPTY_TREE_SHA1_BIN);
2045+
oidcpy(&head, the_hash_algo->empty_tree);
20462046

20472047
if (clean_index(&head, &head))
20482048
die(_("failed to clean index"));
@@ -2105,11 +2105,11 @@ static void am_abort(struct am_state *state)
21052105
curr_branch = resolve_refdup("HEAD", 0, &curr_head, NULL);
21062106
has_curr_head = curr_branch && !is_null_oid(&curr_head);
21072107
if (!has_curr_head)
2108-
hashcpy(curr_head.hash, EMPTY_TREE_SHA1_BIN);
2108+
oidcpy(&curr_head, the_hash_algo->empty_tree);
21092109

21102110
has_orig_head = !get_oid("ORIG_HEAD", &orig_head);
21112111
if (!has_orig_head)
2112-
hashcpy(orig_head.hash, EMPTY_TREE_SHA1_BIN);
2112+
oidcpy(&orig_head, the_hash_algo->empty_tree);
21132113

21142114
clean_index(&curr_head, &orig_head);
21152115

Diff for: builtin/count-objects.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static int count_loose(const struct object_id *oid, const char *path, void *data
6666
else {
6767
loose_size += on_disk_bytes(st);
6868
loose++;
69-
if (verbose && has_sha1_pack(oid->hash))
69+
if (verbose && has_object_pack(oid))
7070
packed_loose++;
7171
}
7272
return 0;

Diff for: builtin/fsck.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ static void check_reachable_object(struct object *obj)
228228
if (!(obj->flags & HAS_OBJ)) {
229229
if (is_promisor_object(&obj->oid))
230230
return;
231-
if (has_sha1_pack(obj->oid.hash))
231+
if (has_object_pack(&obj->oid))
232232
return; /* it is in pack - forget about it */
233233
printf("missing %s %s\n", printable_type(obj),
234234
describe_object(obj));

Diff for: builtin/index-pack.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1549,12 +1549,13 @@ static void read_v2_anomalous_offsets(struct packed_git *p,
15491549
{
15501550
const uint32_t *idx1, *idx2;
15511551
uint32_t i;
1552+
const uint32_t hashwords = the_hash_algo->rawsz / sizeof(uint32_t);
15521553

15531554
/* The address of the 4-byte offset table */
15541555
idx1 = (((const uint32_t *)p->index_data)
15551556
+ 2 /* 8-byte header */
15561557
+ 256 /* fan out */
1557-
+ 5 * p->num_objects /* 20-byte SHA-1 table */
1558+
+ hashwords * p->num_objects /* object ID table */
15581559
+ p->num_objects /* CRC32 table */
15591560
);
15601561

Diff for: builtin/merge.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ static int save_state(struct object_id *stash)
280280
return rc;
281281
}
282282

283-
static void read_empty(unsigned const char *sha1, int verbose)
283+
static void read_empty(const struct object_id *oid, int verbose)
284284
{
285285
int i = 0;
286286
const char *args[7];
@@ -290,15 +290,15 @@ static void read_empty(unsigned const char *sha1, int verbose)
290290
args[i++] = "-v";
291291
args[i++] = "-m";
292292
args[i++] = "-u";
293-
args[i++] = EMPTY_TREE_SHA1_HEX;
294-
args[i++] = sha1_to_hex(sha1);
293+
args[i++] = empty_tree_oid_hex();
294+
args[i++] = oid_to_hex(oid);
295295
args[i] = NULL;
296296

297297
if (run_command_v_opt(args, RUN_GIT_CMD))
298298
die(_("read-tree failed"));
299299
}
300300

301-
static void reset_hard(unsigned const char *sha1, int verbose)
301+
static void reset_hard(const struct object_id *oid, int verbose)
302302
{
303303
int i = 0;
304304
const char *args[6];
@@ -308,7 +308,7 @@ static void reset_hard(unsigned const char *sha1, int verbose)
308308
args[i++] = "-v";
309309
args[i++] = "--reset";
310310
args[i++] = "-u";
311-
args[i++] = sha1_to_hex(sha1);
311+
args[i++] = oid_to_hex(oid);
312312
args[i] = NULL;
313313

314314
if (run_command_v_opt(args, RUN_GIT_CMD))
@@ -324,7 +324,7 @@ static void restore_state(const struct object_id *head,
324324
if (is_null_oid(stash))
325325
return;
326326

327-
reset_hard(head->hash, 1);
327+
reset_hard(head, 1);
328328

329329
args[2] = oid_to_hex(stash);
330330

@@ -1297,7 +1297,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
12971297
if (remoteheads->next)
12981298
die(_("Can merge only exactly one commit into empty head"));
12991299
remote_head_oid = &remoteheads->item->object.oid;
1300-
read_empty(remote_head_oid->hash, 0);
1300+
read_empty(remote_head_oid, 0);
13011301
update_ref("initial pull", "HEAD", remote_head_oid, NULL, 0,
13021302
UPDATE_REFS_DIE_ON_ERR);
13031303
goto done;

Diff for: builtin/pack-objects.c

+17-15
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
279279
enum object_type type;
280280
void *buf;
281281
struct git_istream *st = NULL;
282+
const unsigned hashsz = the_hash_algo->rawsz;
282283

283284
if (!usable_delta) {
284285
if (oe_type(entry) == OBJ_BLOB &&
@@ -335,7 +336,7 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
335336
dheader[pos] = ofs & 127;
336337
while (ofs >>= 7)
337338
dheader[--pos] = 128 | (--ofs & 127);
338-
if (limit && hdrlen + sizeof(dheader) - pos + datalen + 20 >= limit) {
339+
if (limit && hdrlen + sizeof(dheader) - pos + datalen + hashsz >= limit) {
339340
if (st)
340341
close_istream(st);
341342
free(buf);
@@ -347,19 +348,19 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
347348
} else if (type == OBJ_REF_DELTA) {
348349
/*
349350
* Deltas with a base reference contain
350-
* an additional 20 bytes for the base sha1.
351+
* additional bytes for the base object ID.
351352
*/
352-
if (limit && hdrlen + 20 + datalen + 20 >= limit) {
353+
if (limit && hdrlen + hashsz + datalen + hashsz >= limit) {
353354
if (st)
354355
close_istream(st);
355356
free(buf);
356357
return 0;
357358
}
358359
hashwrite(f, header, hdrlen);
359-
hashwrite(f, DELTA(entry)->idx.oid.hash, 20);
360-
hdrlen += 20;
360+
hashwrite(f, DELTA(entry)->idx.oid.hash, hashsz);
361+
hdrlen += hashsz;
361362
} else {
362-
if (limit && hdrlen + datalen + 20 >= limit) {
363+
if (limit && hdrlen + datalen + hashsz >= limit) {
363364
if (st)
364365
close_istream(st);
365366
free(buf);
@@ -391,6 +392,7 @@ static off_t write_reuse_object(struct hashfile *f, struct object_entry *entry,
391392
unsigned char header[MAX_PACK_OBJECT_HEADER],
392393
dheader[MAX_PACK_OBJECT_HEADER];
393394
unsigned hdrlen;
395+
const unsigned hashsz = the_hash_algo->rawsz;
394396
unsigned long entry_size = SIZE(entry);
395397

396398
if (DELTA(entry))
@@ -427,7 +429,7 @@ static off_t write_reuse_object(struct hashfile *f, struct object_entry *entry,
427429
dheader[pos] = ofs & 127;
428430
while (ofs >>= 7)
429431
dheader[--pos] = 128 | (--ofs & 127);
430-
if (limit && hdrlen + sizeof(dheader) - pos + datalen + 20 >= limit) {
432+
if (limit && hdrlen + sizeof(dheader) - pos + datalen + hashsz >= limit) {
431433
unuse_pack(&w_curs);
432434
return 0;
433435
}
@@ -436,16 +438,16 @@ static off_t write_reuse_object(struct hashfile *f, struct object_entry *entry,
436438
hdrlen += sizeof(dheader) - pos;
437439
reused_delta++;
438440
} else if (type == OBJ_REF_DELTA) {
439-
if (limit && hdrlen + 20 + datalen + 20 >= limit) {
441+
if (limit && hdrlen + hashsz + datalen + hashsz >= limit) {
440442
unuse_pack(&w_curs);
441443
return 0;
442444
}
443445
hashwrite(f, header, hdrlen);
444-
hashwrite(f, DELTA(entry)->idx.oid.hash, 20);
445-
hdrlen += 20;
446+
hashwrite(f, DELTA(entry)->idx.oid.hash, hashsz);
447+
hdrlen += hashsz;
446448
reused_delta++;
447449
} else {
448-
if (limit && hdrlen + datalen + 20 >= limit) {
450+
if (limit && hdrlen + datalen + hashsz >= limit) {
449451
unuse_pack(&w_curs);
450452
return 0;
451453
}
@@ -769,7 +771,7 @@ static off_t write_reused_pack(struct hashfile *f)
769771
die_errno("unable to seek in reused packfile");
770772

771773
if (reuse_packfile_offset < 0)
772-
reuse_packfile_offset = reuse_packfile->pack_size - 20;
774+
reuse_packfile_offset = reuse_packfile->pack_size - the_hash_algo->rawsz;
773775

774776
total = to_write = reuse_packfile_offset - sizeof(struct pack_header);
775777

@@ -1033,7 +1035,7 @@ static int want_object_in_pack(const struct object_id *oid,
10331035
int want;
10341036
struct list_head *pos;
10351037

1036-
if (!exclude && local && has_loose_object_nonlocal(oid->hash))
1038+
if (!exclude && local && has_loose_object_nonlocal(oid))
10371039
return 0;
10381040

10391041
/*
@@ -1467,7 +1469,7 @@ static void check_object(struct object_entry *entry)
14671469
if (reuse_delta && !entry->preferred_base)
14681470
base_ref = use_pack(p, &w_curs,
14691471
entry->in_pack_offset + used, NULL);
1470-
entry->in_pack_header_size = used + 20;
1472+
entry->in_pack_header_size = used + the_hash_algo->rawsz;
14711473
break;
14721474
case OBJ_OFS_DELTA:
14731475
buf = use_pack(p, &w_curs,
@@ -1949,7 +1951,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
19491951
/* Now some size filtering heuristics. */
19501952
trg_size = SIZE(trg_entry);
19511953
if (!DELTA(trg_entry)) {
1952-
max_size = trg_size/2 - 20;
1954+
max_size = trg_size/2 - the_hash_algo->rawsz;
19531955
ref_depth = 1;
19541956
} else {
19551957
max_size = DELTA_SIZE(trg_entry);

0 commit comments

Comments
 (0)