Skip to content

Commit 3fc366b

Browse files
npitregitster
authored andcommitted
fast-import: start using struct pack_idx_entry
This is in preparation for using write_idx_file(). Signed-off-by: Nicolas Pitre <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e923eae commit 3fc366b

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

fast-import.c

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,11 @@ Format of STDIN stream:
164164

165165
struct object_entry
166166
{
167+
struct pack_idx_entry idx;
167168
struct object_entry *next;
168-
uint32_t offset;
169169
uint32_t type : TYPE_BITS,
170170
pack_id : PACK_ID_BITS,
171171
depth : DEPTH_BITS;
172-
unsigned char sha1[20];
173172
};
174173

175174
struct object_entry_pool
@@ -521,7 +520,7 @@ static struct object_entry *new_object(unsigned char *sha1)
521520
alloc_objects(object_entry_alloc);
522521

523522
e = blocks->next_free++;
524-
hashcpy(e->sha1, sha1);
523+
hashcpy(e->idx.sha1, sha1);
525524
return e;
526525
}
527526

@@ -530,7 +529,7 @@ static struct object_entry *find_object(unsigned char *sha1)
530529
unsigned int h = sha1[0] << 8 | sha1[1];
531530
struct object_entry *e;
532531
for (e = object_table[h]; e; e = e->next)
533-
if (!hashcmp(sha1, e->sha1))
532+
if (!hashcmp(sha1, e->idx.sha1))
534533
return e;
535534
return NULL;
536535
}
@@ -542,15 +541,15 @@ static struct object_entry *insert_object(unsigned char *sha1)
542541
struct object_entry *p = NULL;
543542

544543
while (e) {
545-
if (!hashcmp(sha1, e->sha1))
544+
if (!hashcmp(sha1, e->idx.sha1))
546545
return e;
547546
p = e;
548547
e = e->next;
549548
}
550549

551550
e = new_object(sha1);
552551
e->next = NULL;
553-
e->offset = 0;
552+
e->idx.offset = 0;
554553
if (p)
555554
p->next = e;
556555
else
@@ -857,7 +856,7 @@ static int oecmp (const void *a_, const void *b_)
857856
{
858857
struct object_entry *a = *((struct object_entry**)a_);
859858
struct object_entry *b = *((struct object_entry**)b_);
860-
return hashcmp(a->sha1, b->sha1);
859+
return hashcmp(a->idx.sha1, b->idx.sha1);
861860
}
862861

863862
static char *create_index(void)
@@ -887,7 +886,7 @@ static char *create_index(void)
887886
for (i = 0; i < 256; i++) {
888887
struct object_entry **next = c;
889888
while (next < last) {
890-
if ((*next)->sha1[0] != i)
889+
if ((*next)->idx.sha1[0] != i)
891890
break;
892891
next++;
893892
}
@@ -901,10 +900,10 @@ static char *create_index(void)
901900
sha1write(f, array, 256 * sizeof(int));
902901
git_SHA1_Init(&ctx);
903902
for (c = idx; c != last; c++) {
904-
uint32_t offset = htonl((*c)->offset);
903+
uint32_t offset = htonl((*c)->idx.offset);
905904
sha1write(f, &offset, 4);
906-
sha1write(f, (*c)->sha1, sizeof((*c)->sha1));
907-
git_SHA1_Update(&ctx, (*c)->sha1, 20);
905+
sha1write(f, (*c)->idx.sha1, sizeof((*c)->idx.sha1));
906+
git_SHA1_Update(&ctx, (*c)->idx.sha1, 20);
908907
}
909908
sha1write(f, pack_data->sha1, sizeof(pack_data->sha1));
910909
sha1close(f, NULL, CSUM_FSYNC);
@@ -1063,13 +1062,13 @@ static int store_object(
10631062
e = insert_object(sha1);
10641063
if (mark)
10651064
insert_mark(mark, e);
1066-
if (e->offset) {
1065+
if (e->idx.offset) {
10671066
duplicate_count_by_type[type]++;
10681067
return 1;
10691068
} else if (find_sha1_pack(sha1, packed_git)) {
10701069
e->type = type;
10711070
e->pack_id = MAX_PACK_ID;
1072-
e->offset = 1; /* just not zero! */
1071+
e->idx.offset = 1; /* just not zero! */
10731072
duplicate_count_by_type[type]++;
10741073
return 1;
10751074
}
@@ -1127,12 +1126,12 @@ static int store_object(
11271126

11281127
e->type = type;
11291128
e->pack_id = pack_id;
1130-
e->offset = pack_size;
1129+
e->idx.offset = pack_size;
11311130
object_count++;
11321131
object_count_by_type[type]++;
11331132

11341133
if (delta) {
1135-
unsigned long ofs = e->offset - last->offset;
1134+
unsigned long ofs = e->idx.offset - last->offset;
11361135
unsigned pos = sizeof(hdr) - 1;
11371136

11381137
delta_count_by_type[type]++;
@@ -1165,7 +1164,7 @@ static int store_object(
11651164
} else {
11661165
strbuf_swap(&last->data, dat);
11671166
}
1168-
last->offset = e->offset;
1167+
last->offset = e->idx.offset;
11691168
last->depth = e->depth;
11701169
}
11711170
return 0;
@@ -1259,22 +1258,22 @@ static void stream_blob(uintmax_t len, unsigned char *sha1out, uintmax_t mark)
12591258
if (mark)
12601259
insert_mark(mark, e);
12611260

1262-
if (e->offset) {
1261+
if (e->idx.offset) {
12631262
duplicate_count_by_type[OBJ_BLOB]++;
12641263
truncate_pack(offset);
12651264

12661265
} else if (find_sha1_pack(sha1, packed_git)) {
12671266
e->type = OBJ_BLOB;
12681267
e->pack_id = MAX_PACK_ID;
1269-
e->offset = 1; /* just not zero! */
1268+
e->idx.offset = 1; /* just not zero! */
12701269
duplicate_count_by_type[OBJ_BLOB]++;
12711270
truncate_pack(offset);
12721271

12731272
} else {
12741273
e->depth = 0;
12751274
e->type = OBJ_BLOB;
12761275
e->pack_id = pack_id;
1277-
e->offset = offset;
1276+
e->idx.offset = offset;
12781277
object_count++;
12791278
object_count_by_type[OBJ_BLOB]++;
12801279
}
@@ -1326,7 +1325,7 @@ static void *gfi_unpack_entry(
13261325
*/
13271326
p->pack_size = pack_size + 20;
13281327
}
1329-
return unpack_entry(p, oe->offset, &type, sizep);
1328+
return unpack_entry(p, oe->idx.offset, &type, sizep);
13301329
}
13311330

13321331
static const char *get_mode(const char *str, uint16_t *modep)
@@ -1457,7 +1456,7 @@ static void store_tree(struct tree_entry *root)
14571456
if (S_ISDIR(root->versions[0].mode) && le && le->pack_id == pack_id) {
14581457
mktree(t, 0, &old_tree);
14591458
lo.data = old_tree;
1460-
lo.offset = le->offset;
1459+
lo.offset = le->idx.offset;
14611460
lo.depth = t->delta_depth;
14621461
}
14631462

@@ -1715,7 +1714,7 @@ static void dump_marks_helper(FILE *f,
17151714
for (k = 0; k < 1024; k++) {
17161715
if (m->data.marked[k])
17171716
fprintf(f, ":%" PRIuMAX " %s\n", base + k,
1718-
sha1_to_hex(m->data.marked[k]->sha1));
1717+
sha1_to_hex(m->data.marked[k]->idx.sha1));
17191718
}
17201719
}
17211720
}
@@ -1798,7 +1797,7 @@ static void read_marks(void)
17981797
e = insert_object(sha1);
17991798
e->type = type;
18001799
e->pack_id = MAX_PACK_ID;
1801-
e->offset = 1; /* just not zero! */
1800+
e->idx.offset = 1; /* just not zero! */
18021801
}
18031802
insert_mark(mark, e);
18041803
}
@@ -2183,7 +2182,7 @@ static void file_change_m(struct branch *b)
21832182
if (*p == ':') {
21842183
char *x;
21852184
oe = find_mark(strtoumax(p + 1, &x, 10));
2186-
hashcpy(sha1, oe->sha1);
2185+
hashcpy(sha1, oe->idx.sha1);
21872186
p = x;
21882187
} else if (!prefixcmp(p, "inline")) {
21892188
inline_data = 1;
@@ -2316,7 +2315,7 @@ static void note_change_n(struct branch *b, unsigned char old_fanout)
23162315
if (*p == ':') {
23172316
char *x;
23182317
oe = find_mark(strtoumax(p + 1, &x, 10));
2319-
hashcpy(sha1, oe->sha1);
2318+
hashcpy(sha1, oe->idx.sha1);
23202319
p = x;
23212320
} else if (!prefixcmp(p, "inline")) {
23222321
inline_data = 1;
@@ -2339,7 +2338,7 @@ static void note_change_n(struct branch *b, unsigned char old_fanout)
23392338
struct object_entry *commit_oe = find_mark(commit_mark);
23402339
if (commit_oe->type != OBJ_COMMIT)
23412340
die("Mark :%" PRIuMAX " not a commit", commit_mark);
2342-
hashcpy(commit_sha1, commit_oe->sha1);
2341+
hashcpy(commit_sha1, commit_oe->idx.sha1);
23432342
} else if (!get_sha1(p, commit_sha1)) {
23442343
unsigned long size;
23452344
char *buf = read_object_with_reference(commit_sha1,
@@ -2446,7 +2445,7 @@ static int parse_from(struct branch *b)
24462445
struct object_entry *oe = find_mark(idnum);
24472446
if (oe->type != OBJ_COMMIT)
24482447
die("Mark :%" PRIuMAX " not a commit", idnum);
2449-
hashcpy(b->sha1, oe->sha1);
2448+
hashcpy(b->sha1, oe->idx.sha1);
24502449
if (oe->pack_id != MAX_PACK_ID) {
24512450
unsigned long size;
24522451
char *buf = gfi_unpack_entry(oe, &size);
@@ -2481,7 +2480,7 @@ static struct hash_list *parse_merge(unsigned int *count)
24812480
struct object_entry *oe = find_mark(idnum);
24822481
if (oe->type != OBJ_COMMIT)
24832482
die("Mark :%" PRIuMAX " not a commit", idnum);
2484-
hashcpy(n->sha1, oe->sha1);
2483+
hashcpy(n->sha1, oe->idx.sha1);
24852484
} else if (!get_sha1(from, n->sha1)) {
24862485
unsigned long size;
24872486
char *buf = read_object_with_reference(n->sha1,
@@ -2639,7 +2638,7 @@ static void parse_new_tag(void)
26392638
from_mark = strtoumax(from + 1, NULL, 10);
26402639
oe = find_mark(from_mark);
26412640
type = oe->type;
2642-
hashcpy(sha1, oe->sha1);
2641+
hashcpy(sha1, oe->idx.sha1);
26432642
} else if (!get_sha1(from, sha1)) {
26442643
unsigned long size;
26452644
char *buf;

0 commit comments

Comments
 (0)