{"thread":{"id":"20391","subject":"[PATCH 1/2] Add push by \"export\"","startedAt":"2009-08-05T05:02:29Z","lastAt":"2009-08-05T09:08:23Z","messageCount":2,"participants":["Daniel Barkalow","Bert Wesarg"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"119571","messageId":"alpine.LNX.2.00.0908050056510.2147@iabervon.org","threadId":"20391","inReplyTo":null,"subject":"[PATCH 1/2] Add push by \"export\"","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-08-05T05:02:29Z","receivedAt":"2009-08-05T05:02:29Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"---\n Documentation/git-remote-helpers.txt |   33 ++++++++++++++++++\n transport-helper.c                   |   62 ++++++++++++++++++++++++++++++++++\n 2 files changed, 95 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/git-remote-helpers.txt b/Documentation/git-remote-helpers.txt\nindex 9a3c5bc..dede2e5 100644\n--- a/Documentation/git-remote-helpers.txt\n+++ b/Documentation/git-remote-helpers.txt\n@@ -50,6 +50,17 @@ Supported if the helper has the \"fetch\" capability.\n +\n Supported if the helper has the \"import\" capability.\n \n+'export' <sha1> [<name>]::\n+\tExports the given commit to the given refname. The commit and\n+\tname (or lack of name) must be suitable for exporting,\n+\taccording to the flags that the helper has reported. Produces\n+\ta fast-import stream reimporting the exported commits to the\n+\timported version of the branch, so that the git view of the\n+\thistory matches what any other import of the history would\n+\tgive.\n++\n+Supported if the helper has the \"export\" capability.\n+\n If a fatal error occurs, the program writes the error message to\n stderr and exits. The caller should expect that a suitable error\n message has been printed if the child closes the connection without\n@@ -75,6 +86,10 @@ CAPABILITIES\n \tand --export-marks option to git-fast-import for more details)\n \tlocated at the given filename.\n \n+'export' [flags]::\n+\tThis helper supports the 'export' command. The flags specify\n+\tfeatures of the history that may be exported (see below).\n+\n REF LIST ATTRIBUTES\n -------------------\n \n@@ -82,6 +97,24 @@ REF LIST ATTRIBUTES\n \tThis ref is unchanged since the last import or fetch, although\n \tthe helper cannot necessarily determine what value that produced.\n \n+EXPORT FLAGS\n+------------\n+\n+Regardless of flags, an exported commit may only have parents which\n+have either been exported previously in this session or which were\n+produced by fast-import.\n+\n+'anonymous'::\n+\tA commit may be exported without it being immediately written\n+\tto some particular name. This is required in order to use the\n+\texport command without a name.\n+\n+'merges'::\n+\tA commit may have multiple parents.\n+\n+'branches'::\n+\tA commit may be exported to a name which did not previously exist.\n+\n Documentation\n -------------\n Documentation by Daniel Barkalow.\ndiff --git a/transport-helper.c b/transport-helper.c\nindex cc8707f..2b1450e 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -14,6 +14,7 @@ struct helper_data\n \tchar *marks_filename;\n \tunsigned fetch : 1;\n \tunsigned import : 1;\n+\tunsigned export : 1;\n };\n \n static struct child_process *get_helper(struct transport *transport)\n@@ -52,6 +53,8 @@ static struct child_process *get_helper(struct transport *transport)\n \t\t\tdata->fetch = 1;\n \t\tif (!strcmp(buf.buf, \"import\"))\n \t\t\tdata->import = 1;\n+\t\tif (!strcmp(buf.buf, \"export\"))\n+\t\t\tdata->export = 1;\n \t\tif (!prefixcmp(buf.buf, \"marks \"))\n \t\t\tdata->marks_filename = xstrdup(buf.buf + 6);\n \t}\n@@ -175,6 +178,64 @@ static int fetch(struct transport *transport,\n \treturn -1;\n }\n \n+static int push_with_export(struct transport *transport, struct ref *remote_refs, int flags) {\n+\tstruct child_process fastimport;\n+\tstruct child_process *helper = get_helper(transport);\n+\tstruct ref *ref, *has;\n+\tstruct rev_info revs;\n+\tstruct commit *commit;\n+\n+\tif (get_importer(transport, &fastimport))\n+\t\tdie(\"Couldn't run fast-import\");\n+\n+\tfor (ref = remote_refs; ref; ref = ref->next) {\n+\t\tif (!ref->peer_ref) {\n+\t\t\tref->status = REF_STATUS_NONE;\n+\t\t\tcontinue;\n+\t\t}\n+\t\tinit_revisions(&revs, NULL);\n+\t\trevs.reverse = 1;\n+\t\tfor (has = remote_refs; has; has = has->next) {\n+\t\t\tcommit = lookup_commit(has->old_sha1);\n+\t\t\tcommit->object.flags |= UNINTERESTING;\n+\t\t\tadd_pending_object(&revs, &commit->object, has->name);\n+\t\t}\n+\t\tcommit = lookup_commit(ref->peer_ref->new_sha1);\n+\t\tadd_pending_object(&revs, &commit->object, ref->name);\n+\n+\t\tif (prepare_revision_walk(&revs))\n+\t\t\tdie(\"Something wrong\");\n+\n+\t\tref->status = REF_STATUS_UPTODATE;\n+\t\twhile ((commit = get_revision(&revs))) {\n+\t\t\tref->status = REF_STATUS_EXPECTING_REPORT;\n+\t\t\twrite_in_full(helper->in, \"export \", 7);\n+\t\t\twrite_in_full(helper->in, sha1_to_hex(commit->object.sha1), 40);\n+\t\t\twrite_in_full(helper->in, \" \", 1);\n+\t\t\twrite_in_full(helper->in, ref->name, strlen(ref->name));\n+\t\t\twrite_in_full(helper->in, \"\\n\", 1);\n+\t\t}\n+\t}\n+\tdisconnect_helper(transport);\n+\tfinish_command(&fastimport);\n+\n+\tfor (ref = remote_refs; ref; ref = ref->next) {\n+\t\tread_ref(ref->name, ref->new_sha1);\n+\t\tif (ref->status == REF_STATUS_EXPECTING_REPORT)\n+\t\t\tref->status = REF_STATUS_OK;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int push(struct transport *transport, struct ref *remote_refs, int flags) {\n+\tstruct helper_data *data = transport->data;\n+\tif (data->export)\n+\t\treturn push_with_export(transport, remote_refs, flags);\n+\n+\treturn -1;\n+}\n+\n static struct ref *get_refs_list(struct transport *transport, int for_push)\n {\n \tstruct child_process *helper;\n@@ -241,6 +302,7 @@ int transport_helper_init(struct transport *transport)\n \ttransport->data = data;\n \ttransport->get_refs_list = get_refs_list;\n \ttransport->fetch = fetch;\n+\ttransport->push_refs = push;\n \ttransport->disconnect = disconnect_helper;\n \treturn 0;\n }\n-- \n1.6.4.rc3.27.g95032.dirty\n"},{"id":"119585","messageId":"36ca99e90908050208m52a9705focc86ca579780a55b@mail.gmail.com","threadId":"20391","inReplyTo":"alpine.LNX.2.00.0908050056510.2147@iabervon.org","subject":"Re: [PATCH 1/2] Add push by \"export\"","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2009-08-05T09:08:23Z","receivedAt":"2009-08-05T09:08:23Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"On Wed, Aug 5, 2009 at 07:02, Daniel Barkalow<barkalow@iabervon.org> wrote:\n> ---\n>  Documentation/git-remote-helpers.txt |   33 ++++++++++++++++++\n>  transport-helper.c                   |   62 ++++++++++++++++++++++++++++++++++\n>  2 files changed, 95 insertions(+), 0 deletions(-)\n>\n> diff --git a/Documentation/git-remote-helpers.txt b/Documentation/git-remote-helpers.txt\n> index 9a3c5bc..dede2e5 100644\n> --- a/Documentation/git-remote-helpers.txt\n> +++ b/Documentation/git-remote-helpers.txt\n> @@ -75,6 +86,10 @@ CAPABILITIES\n>        and --export-marks option to git-fast-import for more details)\n>        located at the given filename.\n>\n> +'export' [flags]::\n> +       This helper supports the 'export' command. The flags specify\n> +       features of the history that may be exported (see below).\n> +\nI can't find any code or usage of these flags in the patch!\n\nBert\n"}]}