From 2badc03f91b0dcb7f3d4d7c794c553a4afc184e6 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 78250eab08..309b02f2b6 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 6474c2a68644665cae0fafff16e953ecc3f6647f 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 673b7c214f..6856a66979 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -429,7 +429,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 ? @@ -442,6 +442,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 538c638e685b8a770db0bee54d45b3a4d3fd5ea6 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 874e0fd0b6..0641166382 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -925,7 +925,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 6856a66979..76bba32006 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -448,6 +448,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) { @@ -484,6 +497,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 @@ -892,6 +906,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 a62a9a27ffa751e92f88a34ea87fc4adbf510423 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 76bba32006..80e1ff3ced 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; @@ -529,6 +531,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; }