@matheusbsbs / matheus-bagliano / commits / 3fc366bdbb
Fork 0

fast-import: start using struct pack_idx_entry

This is in preparation for using write_idx_file(). Signed-off-by: Nicolas Pitre <nico@fluxnic.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nicolas Pitre committed Feb 17, 2010 at 14:05 UTC 3fc366bdbbcafa36ac4e35e3124959beb94c7fce
1 file changed +28 -29
fast-import.c
+28 -29
@@ -164,12 +164,11 @@ Format of STDIN stream:
164
165 struct object_entry
166 {
167 + struct pack_idx_entry idx;
168 struct object_entry *next;
168 - uint32_t offset;
169 uint32_t type : TYPE_BITS,
170 pack_id : PACK_ID_BITS,
171 depth : DEPTH_BITS;
172 - unsigned char sha1[20];
172 };
173
174 struct object_entry_pool
@@ -521,7 +520,7 @@ static struct object_entry *new_object(unsigned char *sha1)
520 alloc_objects(object_entry_alloc);
521
522 e = blocks->next_free++;
524 - hashcpy(e->sha1, sha1);
523 + hashcpy(e->idx.sha1, sha1);
524 return e;
525 }
526
@@ -530,7 +529,7 @@ static struct object_entry *find_object(unsigned char *sha1)
529 unsigned int h = sha1[0] << 8 | sha1[1];
530 struct object_entry *e;
531 for (e = object_table[h]; e; e = e->next)
533 - if (!hashcmp(sha1, e->sha1))
532 + if (!hashcmp(sha1, e->idx.sha1))
533 return e;
534 return NULL;
535 }
@@ -542,7 +541,7 @@ static struct object_entry *insert_object(unsigned char *sha1)
541 struct object_entry *p = NULL;
542
543 while (e) {
545 - if (!hashcmp(sha1, e->sha1))
544 + if (!hashcmp(sha1, e->idx.sha1))
545 return e;
546 p = e;
547 e = e->next;
@@ -550,7 +549,7 @@ static struct object_entry *insert_object(unsigned char *sha1)
549
550 e = new_object(sha1);
551 e->next = NULL;
553 - e->offset = 0;
552 + e->idx.offset = 0;
553 if (p)
554 p->next = e;
555 else
@@ -857,7 +856,7 @@ static int oecmp (const void *a_, const void *b_)
856 {
857 struct object_entry *a = *((struct object_entry**)a_);
858 struct object_entry *b = *((struct object_entry**)b_);
860 - return hashcmp(a->sha1, b->sha1);
859 + return hashcmp(a->idx.sha1, b->idx.sha1);
860 }
861
862 static char *create_index(void)
@@ -887,7 +886,7 @@ static char *create_index(void)
886 for (i = 0; i < 256; i++) {
887 struct object_entry **next = c;
888 while (next < last) {
890 - if ((*next)->sha1[0] != i)
889 + if ((*next)->idx.sha1[0] != i)
890 break;
891 next++;
892 }
@@ -901,10 +900,10 @@ static char *create_index(void)
900 sha1write(f, array, 256 * sizeof(int));
901 git_SHA1_Init(&ctx);
902 for (c = idx; c != last; c++) {
904 - uint32_t offset = htonl((*c)->offset);
903 + uint32_t offset = htonl((*c)->idx.offset);
904 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);
907 }
908 sha1write(f, pack_data->sha1, sizeof(pack_data->sha1));
909 sha1close(f, NULL, CSUM_FSYNC);
@@ -1063,13 +1062,13 @@ static int store_object(
1062 e = insert_object(sha1);
1063 if (mark)
1064 insert_mark(mark, e);
1066 - if (e->offset) {
1065 + if (e->idx.offset) {
1066 duplicate_count_by_type[type]++;
1067 return 1;
1068 } else if (find_sha1_pack(sha1, packed_git)) {
1069 e->type = type;
1070 e->pack_id = MAX_PACK_ID;
1072 - e->offset = 1; /* just not zero! */
1071 + e->idx.offset = 1; /* just not zero! */
1072 duplicate_count_by_type[type]++;
1073 return 1;
1074 }
@@ -1127,12 +1126,12 @@ static int store_object(
1126
1127 e->type = type;
1128 e->pack_id = pack_id;
1130 - e->offset = pack_size;
1129 + e->idx.offset = pack_size;
1130 object_count++;
1131 object_count_by_type[type]++;
1132
1133 if (delta) {
1135 - unsigned long ofs = e->offset - last->offset;
1134 + unsigned long ofs = e->idx.offset - last->offset;
1135 unsigned pos = sizeof(hdr) - 1;
1136
1137 delta_count_by_type[type]++;
@@ -1165,7 +1164,7 @@ static int store_object(
1164 } else {
1165 strbuf_swap(&last->data, dat);
1166 }
1168 - last->offset = e->offset;
1167 + last->offset = e->idx.offset;
1168 last->depth = e->depth;
1169 }
1170 return 0;
@@ -1259,14 +1258,14 @@ static void stream_blob(uintmax_t len, unsigned char *sha1out, uintmax_t mark)
1258 if (mark)
1259 insert_mark(mark, e);
1260
1262 - if (e->offset) {
1261 + if (e->idx.offset) {
1262 duplicate_count_by_type[OBJ_BLOB]++;
1263 truncate_pack(offset);
1264
1265 } else if (find_sha1_pack(sha1, packed_git)) {
1266 e->type = OBJ_BLOB;
1267 e->pack_id = MAX_PACK_ID;
1269 - e->offset = 1; /* just not zero! */
1268 + e->idx.offset = 1; /* just not zero! */
1269 duplicate_count_by_type[OBJ_BLOB]++;
1270 truncate_pack(offset);
1271
@@ -1274,7 +1273,7 @@ static void stream_blob(uintmax_t len, unsigned char *sha1out, uintmax_t mark)
1273 e->depth = 0;
1274 e->type = OBJ_BLOB;
1275 e->pack_id = pack_id;
1277 - e->offset = offset;
1276 + e->idx.offset = offset;
1277 object_count++;
1278 object_count_by_type[OBJ_BLOB]++;
1279 }
@@ -1326,7 +1325,7 @@ static void *gfi_unpack_entry(
1325 */
1326 p->pack_size = pack_size + 20;
1327 }
1329 - return unpack_entry(p, oe->offset, &type, sizep);
1328 + return unpack_entry(p, oe->idx.offset, &type, sizep);
1329 }
1330
1331 static const char *get_mode(const char *str, uint16_t *modep)
@@ -1457,7 +1456,7 @@ static void store_tree(struct tree_entry *root)
1456 if (S_ISDIR(root->versions[0].mode) && le && le->pack_id == pack_id) {
1457 mktree(t, 0, &old_tree);
1458 lo.data = old_tree;
1460 - lo.offset = le->offset;
1459 + lo.offset = le->idx.offset;
1460 lo.depth = t->delta_depth;
1461 }
1462
@@ -1715,7 +1714,7 @@ static void dump_marks_helper(FILE *f,
1714 for (k = 0; k < 1024; k++) {
1715 if (m->data.marked[k])
1716 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));
1718 }
1719 }
1720 }
@@ -1798,7 +1797,7 @@ static void read_marks(void)
1797 e = insert_object(sha1);
1798 e->type = type;
1799 e->pack_id = MAX_PACK_ID;
1801 - e->offset = 1; /* just not zero! */
1800 + e->idx.offset = 1; /* just not zero! */
1801 }
1802 insert_mark(mark, e);
1803 }
@@ -2183,7 +2182,7 @@ static void file_change_m(struct branch *b)
2182 if (*p == ':') {
2183 char *x;
2184 oe = find_mark(strtoumax(p + 1, &x, 10));
2186 - hashcpy(sha1, oe->sha1);
2185 + hashcpy(sha1, oe->idx.sha1);
2186 p = x;
2187 } else if (!prefixcmp(p, "inline")) {
2188 inline_data = 1;
@@ -2316,7 +2315,7 @@ static void note_change_n(struct branch *b, unsigned char old_fanout)
2315 if (*p == ':') {
2316 char *x;
2317 oe = find_mark(strtoumax(p + 1, &x, 10));
2319 - hashcpy(sha1, oe->sha1);
2318 + hashcpy(sha1, oe->idx.sha1);
2319 p = x;
2320 } else if (!prefixcmp(p, "inline")) {
2321 inline_data = 1;
@@ -2339,7 +2338,7 @@ static void note_change_n(struct branch *b, unsigned char old_fanout)
2338 struct object_entry *commit_oe = find_mark(commit_mark);
2339 if (commit_oe->type != OBJ_COMMIT)
2340 die("Mark :%" PRIuMAX " not a commit", commit_mark);
2342 - hashcpy(commit_sha1, commit_oe->sha1);
2341 + hashcpy(commit_sha1, commit_oe->idx.sha1);
2342 } else if (!get_sha1(p, commit_sha1)) {
2343 unsigned long size;
2344 char *buf = read_object_with_reference(commit_sha1,
@@ -2446,7 +2445,7 @@ static int parse_from(struct branch *b)
2445 struct object_entry *oe = find_mark(idnum);
2446 if (oe->type != OBJ_COMMIT)
2447 die("Mark :%" PRIuMAX " not a commit", idnum);
2449 - hashcpy(b->sha1, oe->sha1);
2448 + hashcpy(b->sha1, oe->idx.sha1);
2449 if (oe->pack_id != MAX_PACK_ID) {
2450 unsigned long size;
2451 char *buf = gfi_unpack_entry(oe, &size);
@@ -2481,7 +2480,7 @@ static struct hash_list *parse_merge(unsigned int *count)
2480 struct object_entry *oe = find_mark(idnum);
2481 if (oe->type != OBJ_COMMIT)
2482 die("Mark :%" PRIuMAX " not a commit", idnum);
2484 - hashcpy(n->sha1, oe->sha1);
2483 + hashcpy(n->sha1, oe->idx.sha1);
2484 } else if (!get_sha1(from, n->sha1)) {
2485 unsigned long size;
2486 char *buf = read_object_with_reference(n->sha1,
@@ -2639,7 +2638,7 @@ static void parse_new_tag(void)
2638 from_mark = strtoumax(from + 1, NULL, 10);
2639 oe = find_mark(from_mark);
2640 type = oe->type;
2642 - hashcpy(sha1, oe->sha1);
2641 + hashcpy(sha1, oe->idx.sha1);
2642 } else if (!get_sha1(from, sha1)) {
2643 unsigned long size;
2644 char *buf;