fast-import: permit reading multiple marks files
In the future, we'll want to read marks files for submodules as well. Refactor the existing code to make it possible to read multiple marks files, each into their own marks set. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Feb 22, 2020 at 20:17 UTC
ddddf8d7e254f4af6297d0ed62ea6a5d7eabdb64
1 file changed
+18
-14
fast-import.c
+18
-14
@@ -493,9 +493,8 @@ static char *pool_strdup(const char *s)
493
return r;
494
}
495
496
-static void insert_mark(uintmax_t idnum, struct object_entry *oe)
496
+static void insert_mark(struct mark_set *s, uintmax_t idnum, struct object_entry *oe)
497
{
498
- struct mark_set *s = marks;
498
while ((idnum >> s->shift) >= 1024) {
499
s = mem_pool_calloc(&fi_mem_pool, 1, sizeof(struct mark_set));
500
s->shift = marks->shift + 10;
@@ -919,7 +918,7 @@ static int store_object(
918
919
e = insert_object(&oid);
920
if (mark)
922
- insert_mark(mark, e);
921
+ insert_mark(marks, mark, e);
922
if (e->idx.offset) {
923
duplicate_count_by_type[type]++;
924
return 1;
@@ -1117,7 +1116,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
1116
e = insert_object(&oid);
1117
1118
if (mark)
1120
- insert_mark(mark, e);
1119
+ insert_mark(marks, mark, e);
1120
1121
if (e->idx.offset) {
1122
duplicate_count_by_type[OBJ_BLOB]++;
@@ -1712,16 +1711,9 @@ static void dump_marks(void)
1711
}
1712
}
1713
1715
-static void read_marks(void)
1714
+static void read_mark_file(struct mark_set *s, FILE *f)
1715
{
1716
char line[512];
1718
- FILE *f = fopen(import_marks_file, "r");
1719
- if (f)
1720
- ;
1721
- else if (import_marks_file_ignore_missing && errno == ENOENT)
1722
- goto done; /* Marks file does not exist */
1723
- else
1724
- die_errno("cannot read '%s'", import_marks_file);
1717
while (fgets(line, sizeof(line), f)) {
1718
uintmax_t mark;
1719
char *end;
@@ -1747,8 +1739,20 @@ static void read_marks(void)
1739
e->pack_id = MAX_PACK_ID;
1740
e->idx.offset = 1; /* just not zero! */
1741
}
1750
- insert_mark(mark, e);
1742
+ insert_mark(s, mark, e);
1743
}
1744
+}
1745
+
1746
+static void read_marks(void)
1747
+{
1748
+ FILE *f = fopen(import_marks_file, "r");
1749
+ if (f)
1750
+ ;
1751
+ else if (import_marks_file_ignore_missing && errno == ENOENT)
1752
+ goto done; /* Marks file does not exist */
1753
+ else
1754
+ die_errno("cannot read '%s'", import_marks_file);
1755
+ read_mark_file(marks, f);
1756
fclose(f);
1757
done:
1758
import_marks_file_done = 1;
@@ -3130,7 +3134,7 @@ static void parse_alias(void)
3134
die(_("Expected 'to' command, got %s"), command_buf.buf);
3135
e = find_object(&b.oid);
3136
assert(e);
3133
- insert_mark(next_mark, e);
3137
+ insert_mark(marks, next_mark, e);
3138
}
3139
3140
static char* make_fast_import_path(const char *path)