From 1888bd7f48ba9a7c139fbe725e78e528189c7788 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 23 Jul 2011 15:55:26 +0200 Subject: [PATCH 1/4] fast-export: do not refer to non-existing marks When calling `git fast-export a..a b` when a and b refer to the same commit, nothing would be exported, and an incorrect reset line would be printed for b ('from :0'). Signed-off-by: Johannes Schindelin Signed-off-by: Sverre Rabbelier --- builtin/fast-export.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/builtin/fast-export.c b/builtin/fast-export.c index b8d8a3aaf9..0b96a27ab4 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -556,9 +556,20 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info) } } +static void handle_reset(const char *name, struct object *object) +{ + int mark = get_object_mark(object); + + if (mark) + printf("reset %s\nfrom :%d\n\n", name, + get_object_mark(object)); + else + printf("reset %s\nfrom %s\n\n", name, + sha1_to_hex(object->sha1)); +} + static void handle_tags_and_duplicates(void) { - struct commit *commit; int i; for (i = extra_refs.nr - 1; i >= 0; i--) { @@ -570,9 +581,7 @@ static void handle_tags_and_duplicates(void) break; case OBJ_COMMIT: /* create refs pointing to already seen commits */ - commit = (struct commit *)object; - printf("reset %s\nfrom :%d\n\n", name, - get_object_mark(&commit->object)); + handle_reset(name, object); show_progress(); break; } From e1b8d093eb47a6592532fa6f2bacf9dd70248b67 Mon Sep 17 00:00:00 2001 From: Sverre Rabbelier Date: Sat, 28 Aug 2010 20:49:01 -0500 Subject: [PATCH 2/4] transport-helper: add trailing -- [PT: ensure we add an additional element to the argv array] --- transport-helper.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/transport-helper.c b/transport-helper.c index ad72fbd53c..f0214d3800 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -435,7 +435,7 @@ static int get_exporter(struct transport *transport, /* we need to duplicate helper->in because we want to use it after * fastexport is done with it. */ fastexport->out = dup(helper->in); - fastexport->argv = xcalloc(6 + revlist_args->nr, sizeof(*fastexport->argv)); + fastexport->argv = xcalloc(7 + revlist_args->nr, sizeof(*fastexport->argv)); fastexport->argv[argc++] = "fast-export"; fastexport->argv[argc++] = "--use-done-feature"; fastexport->argv[argc++] = data->signed_tags ? @@ -448,6 +448,8 @@ static int get_exporter(struct transport *transport, for (i = 0; i < revlist_args->nr; i++) fastexport->argv[argc++] = revlist_args->items[i].string; + fastexport->argv[argc++] = "--"; + fastexport->git_cmd = 1; return start_command(fastexport); } From 9e54e5234a4065ec2254e133f5f9b234d28313f2 Mon Sep 17 00:00:00 2001 From: Sverre Rabbelier Date: Sun, 24 Jul 2011 00:06:00 +0200 Subject: [PATCH 3/4] remote-helper: check helper status after import/export Signed-off-by: Johannes Schindelin Signed-off-by: Sverre Rabbelier --- builtin/clone.c | 4 +++- transport-helper.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/builtin/clone.c b/builtin/clone.c index 9b3c04d914..e56b0c096d 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -943,7 +943,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix) } if (!is_local && !complete_refs_before_fetch) - transport_fetch_refs(transport, mapped_refs); + if (transport_fetch_refs(transport, mapped_refs)) + die(_("could not fetch refs from %s"), + transport->url); remote_head = find_ref_by_name(refs, "HEAD"); remote_head_points_at = diff --git a/transport-helper.c b/transport-helper.c index f0214d3800..fe17383481 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -454,6 +454,19 @@ static int get_exporter(struct transport *transport, return start_command(fastexport); } +static void check_helper_status(struct helper_data *data) +{ + int pid, status; + + pid = waitpid(data->helper->pid, &status, WNOHANG); + if (pid < 0) + die("Could not retrieve status of remote helper '%s'", + data->name); + if (pid > 0 && WIFEXITED(status)) + die("Remote helper '%s' died with %d", + data->name, WEXITSTATUS(status)); +} + static int fetch_with_import(struct transport *transport, int nr_heads, struct ref **to_fetch) { @@ -490,6 +503,7 @@ static int fetch_with_import(struct transport *transport, if (finish_command(&fastimport)) die("Error while running fast-import"); argv_array_free_detached(fastimport.argv); + check_helper_status(data); /* * The fast-import stream of a remote helper that advertises @@ -898,6 +912,7 @@ static int push_refs_with_export(struct transport *transport, if (finish_command(&exporter)) die("Error while running fast-export"); + check_helper_status(data); push_update_refs_status(data, remote_refs); return 0; } From a77f04ddf615bb9f5d71eb9e94e3e732eb59be68 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 9 Apr 2012 13:04:35 -0500 Subject: [PATCH 4/4] Always auto-gc after calling a fast-import transport After importing anything with fast-import, we should always let the garbage collector do its job, since the objects are written to disk inefficiently. This brings down an initial import of http://selenic.com/hg from about 230 megabytes to about 14. In the future, we may want to make this configurable on a per-remote basis, or maybe teach fast-import about it in the first place. Signed-off-by: Johannes Schindelin --- transport-helper.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/transport-helper.c b/transport-helper.c index fe17383481..ece3f3c1e8 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -14,6 +14,8 @@ #include "refs.h" static int debug; +/* TODO: put somewhere sensible, e.g. git_transport_options? */ +static int auto_gc = 1; struct helper_data { const char *name; @@ -535,6 +537,12 @@ static int fetch_with_import(struct transport *transport, } } strbuf_release(&buf); + if (auto_gc) { + const char *argv_gc_auto[] = { + "gc", "--auto", "--quiet", NULL, + }; + run_command_v_opt(argv_gc_auto, RUN_GIT_CMD); + } return 0; }