aboutsummaryrefslogtreecommitdiff
path: root/fast-import.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2007-03-07 23:10:05 -0800
committerJunio C Hamano <junkio@cox.net>2007-03-07 23:10:05 -0800
commitf45fa2a073da591f3ac0b63900e07afa2dccee44 (patch)
tree9d1a9d84921d63c61fabbaa4e5e6d1e4aef50d70 /fast-import.c
parent05ef58ec1f2fb69d6e7ae7fca84163f75bd95050 (diff)
parente8438420bb7d368bec3647b90c557b9931582267 (diff)
downloadgit-f45fa2a073da591f3ac0b63900e07afa2dccee44.tar.gz
git-f45fa2a073da591f3ac0b63900e07afa2dccee44.tar.xz
Merge branch 'master' of git://repo.or.cz/git/fastimport
* 'master' of git://repo.or.cz/git/fastimport: Allow fast-import frontends to reload the marks table Use atomic updates to the fast-import mark file Preallocate memory earlier in fast-import
Diffstat (limited to 'fast-import.c')
-rw-r--r--fast-import.c85
1 files changed, 68 insertions, 17 deletions
diff --git a/fast-import.c b/fast-import.c
index fda50188e..726f5ba7d 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1371,16 +1371,33 @@ static void dump_marks_helper(FILE *f,
static void dump_marks(void)
{
- if (mark_file)
- {
- FILE *f = fopen(mark_file, "w");
- if (f) {
- dump_marks_helper(f, 0, marks);
- fclose(f);
- } else
- failure |= error("Unable to write marks file %s: %s",
- mark_file, strerror(errno));
+ static struct lock_file mark_lock;
+ int mark_fd;
+ FILE *f;
+
+ if (!mark_file)
+ return;
+
+ mark_fd = hold_lock_file_for_update(&mark_lock, mark_file, 0);
+ if (mark_fd < 0) {
+ failure |= error("Unable to write marks file %s: %s",
+ mark_file, strerror(errno));
+ return;
+ }
+
+ f = fdopen(mark_fd, "w");
+ if (!f) {
+ rollback_lock_file(&mark_lock);
+ failure |= error("Unable to write marks file %s: %s",
+ mark_file, strerror(errno));
+ return;
}
+
+ dump_marks_helper(f, 0, marks);
+ fclose(f);
+ if (commit_lock_file(&mark_lock))
+ failure |= error("Unable to write marks file %s: %s",
+ mark_file, strerror(errno));
}
static void read_next_command(void)
@@ -1976,6 +1993,40 @@ static void cmd_checkpoint(void)
read_next_command();
}
+static void import_marks(const char *input_file)
+{
+ char line[512];
+ FILE *f = fopen(input_file, "r");
+ if (!f)
+ die("cannot read %s: %s", input_file, strerror(errno));
+ while (fgets(line, sizeof(line), f)) {
+ uintmax_t mark;
+ char *end;
+ unsigned char sha1[20];
+ struct object_entry *e;
+
+ end = strchr(line, '\n');
+ if (line[0] != ':' || !end)
+ die("corrupt mark line: %s", line);
+ *end = 0;
+ mark = strtoumax(line + 1, &end, 10);
+ if (!mark || end == line + 1
+ || *end != ' ' || get_sha1(end + 1, sha1))
+ die("corrupt mark line: %s", line);
+ e = find_object(sha1);
+ if (!e) {
+ enum object_type type = sha1_object_info(sha1, NULL);
+ if (type < 0)
+ die("object not found: %s", sha1_to_hex(sha1));
+ e = insert_object(sha1);
+ e->type = type;
+ e->pack_id = MAX_PACK_ID;
+ }
+ insert_mark(mark, e);
+ }
+ fclose(f);
+}
+
static const char fast_import_usage[] =
"git-fast-import [--date-format=f] [--max-pack-size=n] [--depth=n] [--active-branches=n] [--export-marks=marks.file]";
@@ -1984,6 +2035,12 @@ int main(int argc, const char **argv)
int i, show_stats = 1;
git_config(git_default_config);
+ alloc_objects(object_entry_alloc);
+ strbuf_init(&command_buf);
+ atom_table = xcalloc(atom_table_sz, sizeof(struct atom_str*));
+ branch_table = xcalloc(branch_table_sz, sizeof(struct branch*));
+ avail_tree_table = xcalloc(avail_tree_table_sz, sizeof(struct avail_tree_content*));
+ marks = pool_calloc(1, sizeof(struct mark_set));
for (i = 1; i < argc; i++) {
const char *a = argv[i];
@@ -2007,6 +2064,8 @@ int main(int argc, const char **argv)
max_depth = strtoul(a + 8, NULL, 0);
else if (!prefixcmp(a, "--active-branches="))
max_active_branches = strtoul(a + 18, NULL, 0);
+ else if (!prefixcmp(a, "--import-marks="))
+ import_marks(a + 15);
else if (!prefixcmp(a, "--export-marks="))
mark_file = a + 15;
else if (!prefixcmp(a, "--export-pack-edges=")) {
@@ -2027,14 +2086,6 @@ int main(int argc, const char **argv)
if (i != argc)
usage(fast_import_usage);
- alloc_objects(object_entry_alloc);
- strbuf_init(&command_buf);
-
- atom_table = xcalloc(atom_table_sz, sizeof(struct atom_str*));
- branch_table = xcalloc(branch_table_sz, sizeof(struct branch*));
- avail_tree_table = xcalloc(avail_tree_table_sz, sizeof(struct avail_tree_content*));
- marks = pool_calloc(1, sizeof(struct mark_set));
-
start_packfile();
for (;;) {
read_next_command();