Skip to content

Commit abe0cc5

Browse files
bk2204gitster
authored andcommitted
fast-import: add helper function for inserting mark object entries
Currently, everything we want to insert into a mark set is an object entry. However, in the future, we will want to insert objects of other types. Teach read_mark_file to take a function pointer which helps us insert the object we want into our mark set. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ddddf8d commit abe0cc5

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

fast-import.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ struct recent_command {
131131
char *buf;
132132
};
133133

134+
typedef void (*mark_set_inserter_t)(struct mark_set *s, struct object_id *oid, uintmax_t mark);
135+
134136
/* Configured limits on output */
135137
static unsigned long max_depth = 50;
136138
static off_t max_packsize;
@@ -1711,14 +1713,30 @@ static void dump_marks(void)
17111713
}
17121714
}
17131715

1714-
static void read_mark_file(struct mark_set *s, FILE *f)
1716+
static void insert_object_entry(struct mark_set *s, struct object_id *oid, uintmax_t mark)
1717+
{
1718+
struct object_entry *e;
1719+
e = find_object(oid);
1720+
if (!e) {
1721+
enum object_type type = oid_object_info(the_repository,
1722+
oid, NULL);
1723+
if (type < 0)
1724+
die("object not found: %s", oid_to_hex(oid));
1725+
e = insert_object(oid);
1726+
e->type = type;
1727+
e->pack_id = MAX_PACK_ID;
1728+
e->idx.offset = 1; /* just not zero! */
1729+
}
1730+
insert_mark(s, mark, e);
1731+
}
1732+
1733+
static void read_mark_file(struct mark_set *s, FILE *f, mark_set_inserter_t inserter)
17151734
{
17161735
char line[512];
17171736
while (fgets(line, sizeof(line), f)) {
17181737
uintmax_t mark;
17191738
char *end;
17201739
struct object_id oid;
1721-
struct object_entry *e;
17221740

17231741
end = strchr(line, '\n');
17241742
if (line[0] != ':' || !end)
@@ -1728,18 +1746,7 @@ static void read_mark_file(struct mark_set *s, FILE *f)
17281746
if (!mark || end == line + 1
17291747
|| *end != ' ' || get_oid_hex(end + 1, &oid))
17301748
die("corrupt mark line: %s", line);
1731-
e = find_object(&oid);
1732-
if (!e) {
1733-
enum object_type type = oid_object_info(the_repository,
1734-
&oid, NULL);
1735-
if (type < 0)
1736-
die("object not found: %s", oid_to_hex(&oid));
1737-
e = insert_object(&oid);
1738-
e->type = type;
1739-
e->pack_id = MAX_PACK_ID;
1740-
e->idx.offset = 1; /* just not zero! */
1741-
}
1742-
insert_mark(s, mark, e);
1749+
inserter(s, &oid, mark);
17431750
}
17441751
}
17451752

@@ -1752,7 +1759,7 @@ static void read_marks(void)
17521759
goto done; /* Marks file does not exist */
17531760
else
17541761
die_errno("cannot read '%s'", import_marks_file);
1755-
read_mark_file(marks, f);
1762+
read_mark_file(marks, f, insert_object_entry);
17561763
fclose(f);
17571764
done:
17581765
import_marks_file_done = 1;

0 commit comments

Comments
 (0)