Skip to content

Commit 1237304

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9bf55b8 commit 1237304

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

fast-import.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,8 @@ static char *pool_strdup(const char *s)
493493
return r;
494494
}
495495

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)
497497
{
498-
struct mark_set *s = marks;
499498
while ((idnum >> s->shift) >= 1024) {
500499
s = mem_pool_calloc(&fi_mem_pool, 1, sizeof(struct mark_set));
501500
s->shift = marks->shift + 10;
@@ -919,7 +918,7 @@ static int store_object(
919918

920919
e = insert_object(&oid);
921920
if (mark)
922-
insert_mark(mark, e);
921+
insert_mark(marks, mark, e);
923922
if (e->idx.offset) {
924923
duplicate_count_by_type[type]++;
925924
return 1;
@@ -1117,7 +1116,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
11171116
e = insert_object(&oid);
11181117

11191118
if (mark)
1120-
insert_mark(mark, e);
1119+
insert_mark(marks, mark, e);
11211120

11221121
if (e->idx.offset) {
11231122
duplicate_count_by_type[OBJ_BLOB]++;
@@ -1712,16 +1711,9 @@ static void dump_marks(void)
17121711
}
17131712
}
17141713

1715-
static void read_marks(void)
1714+
static void read_mark_file(struct mark_set *s, FILE *f)
17161715
{
17171716
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);
17251717
while (fgets(line, sizeof(line), f)) {
17261718
uintmax_t mark;
17271719
char *end;
@@ -1747,8 +1739,20 @@ static void read_marks(void)
17471739
e->pack_id = MAX_PACK_ID;
17481740
e->idx.offset = 1; /* just not zero! */
17491741
}
1750-
insert_mark(mark, e);
1742+
insert_mark(s, mark, e);
17511743
}
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);
17521756
fclose(f);
17531757
done:
17541758
import_marks_file_done = 1;
@@ -3130,7 +3134,7 @@ static void parse_alias(void)
31303134
die(_("Expected 'to' command, got %s"), command_buf.buf);
31313135
e = find_object(&b.oid);
31323136
assert(e);
3133-
insert_mark(next_mark, e);
3137+
insert_mark(marks, next_mark, e);
31343138
}
31353139

31363140
static char* make_fast_import_path(const char *path)

0 commit comments

Comments
 (0)