X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=fast-import.c;h=1ae125a040e6dfcf83b2cdc4aeea8fa248d2ba22;hb=7943b3a94f0f862dc9d7dcec6b5639ae5bf027bd;hp=858df17f35efe2ab610c501744ec65b621a8f53d;hpb=c499d76849b09194434708376138952e2cac2e68;p=git.git diff --git a/fast-import.c b/fast-import.c index 858df17f3..1ae125a04 100644 --- a/fast-import.c +++ b/fast-import.c @@ -133,6 +133,10 @@ Format of STDIN stream: #define PACK_ID_BITS 16 #define MAX_PACK_ID ((1<data.marked[idnum]; } if (!oe) - die("mark :%ju not declared", orig_idnum); + die("mark :%" PRIuMAX " not declared", orig_idnum); return oe; } @@ -811,18 +816,21 @@ static void end_packfile(void) install_packed_git(new_p); /* Print the boundary */ - fprintf(stdout, "%s:", new_p->pack_name); - for (i = 0; i < branch_table_sz; i++) { - for (b = branch_table[i]; b; b = b->table_next_branch) { - if (b->pack_id == pack_id) - fprintf(stdout, " %s", sha1_to_hex(b->sha1)); + if (pack_edges) { + fprintf(pack_edges, "%s:", new_p->pack_name); + for (i = 0; i < branch_table_sz; i++) { + for (b = branch_table[i]; b; b = b->table_next_branch) { + if (b->pack_id == pack_id) + fprintf(pack_edges, " %s", sha1_to_hex(b->sha1)); + } } + for (t = first_tag; t; t = t->next_tag) { + if (t->pack_id == pack_id) + fprintf(pack_edges, " %s", sha1_to_hex(t->sha1)); + } + fputc('\n', pack_edges); + fflush(pack_edges); } - for (t = first_tag; t; t = t->next_tag) { - if (t->pack_id == pack_id) - fprintf(stdout, " %s", sha1_to_hex(t->sha1)); - } - fputc('\n', stdout); pack_id++; } @@ -838,7 +846,7 @@ static void end_packfile(void) last_blob.depth = 0; } -static void checkpoint(void) +static void cycle_packfile(void) { end_packfile(); start_packfile(); @@ -883,7 +891,8 @@ static int store_object( SHA_CTX c; z_stream s; - hdrlen = sprintf((char*)hdr,"%s %lu",type_names[type],datlen) + 1; + hdrlen = sprintf((char*)hdr,"%s %lu", type_names[type], + (unsigned long)datlen) + 1; SHA1_Init(&c); SHA1_Update(&c, hdr, hdrlen); SHA1_Update(&c, dat, datlen); @@ -931,7 +940,7 @@ static int store_object( /* This new object needs to *not* have the current pack_id. */ e->pack_id = pack_id + 1; - checkpoint(); + cycle_packfile(); /* We cannot carry a delta into the new pack. */ if (delta) { @@ -1356,7 +1365,7 @@ static void dump_marks_helper(FILE *f, } else { for (k = 0; k < 1024; k++) { if (m->data.marked[k]) - fprintf(f, ":%ju %s\n", base + k, + fprintf(f, ":%" PRIuMAX " %s\n", base + k, sha1_to_hex(m->data.marked[k]->sha1)); } } @@ -1367,8 +1376,12 @@ static void dump_marks(void) if (mark_file) { FILE *f = fopen(mark_file, "w"); - dump_marks_helper(f, 0, marks); - fclose(f); + if (f) { + dump_marks_helper(f, 0, marks); + fclose(f); + } else + failure |= error("Unable to write marks file %s: %s", + mark_file, strerror(errno)); } } @@ -1428,7 +1441,8 @@ static void *cmd_data (size_t *size) while (n < length) { size_t s = fread(buffer + n, 1, length - n, stdin); if (!s && feof(stdin)) - die("EOF in data (%lu bytes remaining)", length - n); + die("EOF in data (%lu bytes remaining)", + (unsigned long)(length - n)); n += s; } } @@ -1657,8 +1671,10 @@ static void cmd_from(struct branch *b) if (strncmp("from ", command_buf.buf, 5)) return; - if (b->last_commit) - die("Can't reinitailize branch %s", b->name); + if (b->branch_tree.tree) { + release_tree_content_recursive(b->branch_tree.tree); + b->branch_tree.tree = NULL; + } from = strchr(command_buf.buf, ' ') + 1; s = lookup_branch(from); @@ -1675,7 +1691,7 @@ static void cmd_from(struct branch *b) unsigned long size; char *buf; if (oe->type != OBJ_COMMIT) - die("Mark :%ju not a commit", idnum); + die("Mark :%" PRIuMAX " not a commit", idnum); hashcpy(b->sha1, oe->sha1); buf = gfi_unpack_entry(oe, &size); if (!buf || size < 46) @@ -1728,7 +1744,7 @@ static struct hash_list *cmd_merge(unsigned int *count) uintmax_t idnum = strtoumax(from + 1, NULL, 10); struct object_entry *oe = find_mark(idnum); if (oe->type != OBJ_COMMIT) - die("Mark :%ju not a commit", idnum); + die("Mark :%" PRIuMAX " not a commit", idnum); hashcpy(n->sha1, oe->sha1); } else if (get_sha1(from, n->sha1)) die("Invalid ref name or SHA1 expression: %s", from); @@ -1872,7 +1888,7 @@ static void cmd_new_tag(void) from_mark = strtoumax(from + 1, NULL, 10); oe = find_mark(from_mark); if (oe->type != OBJ_COMMIT) - die("Mark :%ju not a commit", from_mark); + die("Mark :%" PRIuMAX " not a commit", from_mark); hashcpy(sha1, oe->sha1); } else if (!get_sha1(from, sha1)) { unsigned long size; @@ -1926,7 +1942,9 @@ static void cmd_reset_branch(void) sp = strchr(command_buf.buf, ' ') + 1; b = lookup_branch(sp); if (b) { - b->last_commit = 0; + hashclr(b->sha1); + hashclr(b->branch_tree.versions[0].sha1); + hashclr(b->branch_tree.versions[1].sha1); if (b->branch_tree.tree) { release_tree_content_recursive(b->branch_tree.tree); b->branch_tree.tree = NULL; @@ -1940,8 +1958,12 @@ static void cmd_reset_branch(void) static void cmd_checkpoint(void) { - if (object_count) - checkpoint(); + if (object_count) { + cycle_packfile(); + dump_branches(); + dump_tags(); + dump_marks(); + } read_next_command(); } @@ -1978,7 +2000,13 @@ int main(int argc, const char **argv) max_active_branches = strtoul(a + 18, NULL, 0); else if (!strncmp(a, "--export-marks=", 15)) mark_file = a + 15; - else if (!strcmp(a, "--force")) + else if (!strncmp(a, "--export-pack-edges=", 20)) { + if (pack_edges) + fclose(pack_edges); + pack_edges = fopen(a + 20, "a"); + if (!pack_edges) + die("Cannot open %s: %s", a + 20, strerror(errno)); + } else if (!strcmp(a, "--force")) force_update = 1; else if (!strcmp(a, "--quiet")) show_stats = 0; @@ -2023,6 +2051,9 @@ int main(int argc, const char **argv) unkeep_all_packs(); dump_marks(); + if (pack_edges) + fclose(pack_edges); + if (show_stats) { uintmax_t total_count = 0, duplicate_count = 0; for (i = 0; i < ARRAY_SIZE(object_count_by_type); i++) @@ -2032,18 +2063,18 @@ int main(int argc, const char **argv) fprintf(stderr, "%s statistics:\n", argv[0]); fprintf(stderr, "---------------------------------------------------------------------\n"); - fprintf(stderr, "Alloc'd objects: %10ju\n", alloc_count); - fprintf(stderr, "Total objects: %10ju (%10ju duplicates )\n", total_count, duplicate_count); - fprintf(stderr, " blobs : %10ju (%10ju duplicates %10ju deltas)\n", object_count_by_type[OBJ_BLOB], duplicate_count_by_type[OBJ_BLOB], delta_count_by_type[OBJ_BLOB]); - fprintf(stderr, " trees : %10ju (%10ju duplicates %10ju deltas)\n", object_count_by_type[OBJ_TREE], duplicate_count_by_type[OBJ_TREE], delta_count_by_type[OBJ_TREE]); - fprintf(stderr, " commits: %10ju (%10ju duplicates %10ju deltas)\n", object_count_by_type[OBJ_COMMIT], duplicate_count_by_type[OBJ_COMMIT], delta_count_by_type[OBJ_COMMIT]); - fprintf(stderr, " tags : %10ju (%10ju duplicates %10ju deltas)\n", object_count_by_type[OBJ_TAG], duplicate_count_by_type[OBJ_TAG], delta_count_by_type[OBJ_TAG]); + fprintf(stderr, "Alloc'd objects: %10" PRIuMAX "\n", alloc_count); + fprintf(stderr, "Total objects: %10" PRIuMAX " (%10" PRIuMAX " duplicates )\n", total_count, duplicate_count); + fprintf(stderr, " blobs : %10" PRIuMAX " (%10" PRIuMAX " duplicates %10" PRIuMAX " deltas)\n", object_count_by_type[OBJ_BLOB], duplicate_count_by_type[OBJ_BLOB], delta_count_by_type[OBJ_BLOB]); + fprintf(stderr, " trees : %10" PRIuMAX " (%10" PRIuMAX " duplicates %10" PRIuMAX " deltas)\n", object_count_by_type[OBJ_TREE], duplicate_count_by_type[OBJ_TREE], delta_count_by_type[OBJ_TREE]); + fprintf(stderr, " commits: %10" PRIuMAX " (%10" PRIuMAX " duplicates %10" PRIuMAX " deltas)\n", object_count_by_type[OBJ_COMMIT], duplicate_count_by_type[OBJ_COMMIT], delta_count_by_type[OBJ_COMMIT]); + fprintf(stderr, " tags : %10" PRIuMAX " (%10" PRIuMAX " duplicates %10" PRIuMAX " deltas)\n", object_count_by_type[OBJ_TAG], duplicate_count_by_type[OBJ_TAG], delta_count_by_type[OBJ_TAG]); fprintf(stderr, "Total branches: %10lu (%10lu loads )\n", branch_count, branch_load_count); - fprintf(stderr, " marks: %10ju (%10ju unique )\n", (((uintmax_t)1) << marks->shift) * 1024, marks_set_count); + fprintf(stderr, " marks: %10" PRIuMAX " (%10" PRIuMAX " unique )\n", (((uintmax_t)1) << marks->shift) * 1024, marks_set_count); fprintf(stderr, " atoms: %10u\n", atom_cnt); - fprintf(stderr, "Memory total: %10ju KiB\n", (total_allocd + alloc_count*sizeof(struct object_entry))/1024); - fprintf(stderr, " pools: %10lu KiB\n", total_allocd/1024); - fprintf(stderr, " objects: %10ju KiB\n", (alloc_count*sizeof(struct object_entry))/1024); + fprintf(stderr, "Memory total: %10" PRIuMAX " KiB\n", (total_allocd + alloc_count*sizeof(struct object_entry))/1024); + fprintf(stderr, " pools: %10lu KiB\n", (unsigned long)(total_allocd/1024)); + fprintf(stderr, " objects: %10" PRIuMAX " KiB\n", (alloc_count*sizeof(struct object_entry))/1024); fprintf(stderr, "---------------------------------------------------------------------\n"); pack_report(); fprintf(stderr, "---------------------------------------------------------------------\n");