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 <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Feb 22, 2020 at 20:17 UTC
abe0cc536414f2b9cfa37f208b36df5126e6356a
1 file changed
+22
-15
fast-import.c
+22
-15
@@ -131,6 +131,8 @@ struct recent_command {
131
char *buf;
132
};
133
134
+typedef void (*mark_set_inserter_t)(struct mark_set *s, struct object_id *oid, uintmax_t mark);
135
+
136
/* Configured limits on output */
137
static unsigned long max_depth = 50;
138
static off_t max_packsize;
@@ -1711,14 +1713,30 @@ static void dump_marks(void)
1713
}
1714
}
1715
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)
1734
{
1735
char line[512];
1736
while (fgets(line, sizeof(line), f)) {
1737
uintmax_t mark;
1738
char *end;
1739
struct object_id oid;
1721
- struct object_entry *e;
1740
1741
end = strchr(line, '\n');
1742
if (line[0] != ':' || !end)
@@ -1728,18 +1746,7 @@ static void read_mark_file(struct mark_set *s, FILE *f)
1746
if (!mark || end == line + 1
1747
|| *end != ' ' || get_oid_hex(end + 1, &oid))
1748
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);
1750
}
1751
}
1752
@@ -1752,7 +1759,7 @@ static void read_marks(void)
1759
goto done; /* Marks file does not exist */
1760
else
1761
die_errno("cannot read '%s'", import_marks_file);
1755
- read_mark_file(marks, f);
1762
+ read_mark_file(marks, f, insert_object_entry);
1763
fclose(f);
1764
done:
1765
import_marks_file_done = 1;