{"thread":{"id":"20392","subject":"[PATCH 08/13] Add support for \"import\" helper command","startedAt":"2009-08-05T05:02:12Z","lastAt":"2009-08-05T21:50:07Z","messageCount":5,"participants":["Daniel Barkalow","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":13},"messages":[{"id":"119572","messageId":"alpine.LNX.2.00.0908050055550.2147@iabervon.org","threadId":"20392","inReplyTo":null,"subject":"[PATCH 08/13] Add support for \"import\" helper command","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-08-05T05:02:12Z","receivedAt":"2009-08-05T05:02:12Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"This command, supported if the \"import\" capability is advertized,\nallows a helper to support fetching by outputting a git-fast-import\nstream.\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\n---\n Documentation/git-remote-helpers.txt |   10 ++++++\n transport-helper.c                   |   51 ++++++++++++++++++++++++++++++++++\n 2 files changed, 61 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/git-remote-helpers.txt b/Documentation/git-remote-helpers.txt\nindex 173ee23..e9aa67e 100644\n--- a/Documentation/git-remote-helpers.txt\n+++ b/Documentation/git-remote-helpers.txt\n@@ -43,6 +43,13 @@ Commands are given by the caller on the helper's standard input, one per line.\n +\n Supported if the helper has the \"fetch\" capability.\n \n+'import' <name>::\n+\tProduces a fast-import stream which imports the current value\n+\tof the named ref. It may additionally import other refs as\n+\tneeded to construct the history efficiently.\n++\n+Supported if the helper has the \"import\" 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@@ -57,6 +64,9 @@ CAPABILITIES\n 'fetch'::\n \tThis helper supports the 'fetch' command.\n \n+'import'::\n+\tThis helper supports the 'import' command.\n+\n REF LIST ATTRIBUTES\n -------------------\n \ndiff --git a/transport-helper.c b/transport-helper.c\nindex dccf400..6eee0da 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -11,6 +11,7 @@ struct helper_data\n \tconst char *name;\n \tstruct child_process *helper;\n \tunsigned fetch : 1;\n+\tunsigned import : 1;\n };\n \n static struct child_process *get_helper(struct transport *transport)\n@@ -47,6 +48,8 @@ static struct child_process *get_helper(struct transport *transport)\n \t\t\tbreak;\n \t\tif (!strcmp(buf.buf, \"fetch\"))\n \t\t\tdata->fetch = 1;\n+\t\tif (!strcmp(buf.buf, \"import\"))\n+\t\t\tdata->import = 1;\n \t}\n \treturn data->helper;\n }\n@@ -89,6 +92,51 @@ static int fetch_with_fetch(struct transport *transport,\n \treturn 0;\n }\n \n+static int get_importer(struct transport *transport, struct child_process *fastimport)\n+{\n+\tstruct helper_data *data = transport->data;\n+\tstruct child_process *helper = get_helper(transport);\n+\tmemset(fastimport, 0, sizeof(*fastimport));\n+\tfastimport->in = helper->out;\n+\tfastimport->argv = xcalloc(5, sizeof(*fastimport->argv));\n+\tfastimport->argv[0] = \"fast-import\";\n+\tfastimport->argv[1] = \"--quiet\";\n+\n+\tfastimport->git_cmd = 1;\n+\treturn start_command(fastimport);\n+}\n+\n+static int fetch_with_import(struct transport *transport,\n+\t\t\t     int nr_heads, struct ref **to_fetch)\n+{\n+\tstruct child_process fastimport;\n+\tstruct child_process *helper = get_helper(transport);\n+\tint i;\n+\tstruct ref *posn;\n+\n+\tif (get_importer(transport, &fastimport))\n+\t\tdie(\"Couldn't run fast-import\");\n+\n+\tfor (i = 0; i < nr_heads; i++) {\n+\t\tposn = to_fetch[i];\n+\t\tif (posn->status & REF_STATUS_UPTODATE)\n+\t\t\tcontinue;\n+\t\twrite_in_full(helper->in, \"import \", 7);\n+\t\twrite_in_full(helper->in, posn->name, strlen(posn->name));\n+\t\twrite_in_full(helper->in, \"\\n\", 1);\n+\t}\n+\tdisconnect_helper(transport);\n+\tfinish_command(&fastimport);\n+\n+\tfor (i = 0; i < nr_heads; i++) {\n+\t\tposn = to_fetch[i];\n+\t\tif (posn->status & REF_STATUS_UPTODATE)\n+\t\t\tcontinue;\n+\t\tread_ref(posn->name, posn->old_sha1);\n+\t}\n+\treturn 0;\n+}\n+\n static int fetch(struct transport *transport,\n \t\t int nr_heads, struct ref **to_fetch)\n {\n@@ -106,6 +154,9 @@ static int fetch(struct transport *transport,\n \tif (data->fetch)\n \t\treturn fetch_with_fetch(transport, nr_heads, to_fetch);\n \n+\tif (data->import)\n+\t\treturn fetch_with_import(transport, nr_heads, to_fetch);\n+\n \treturn -1;\n }\n \n-- \n1.6.4.rc3.27.g95032.dirty\n"},{"id":"119688","messageId":"alpine.DEB.1.00.0908052254570.8306@pacific.mpi-cbg.de","threadId":"20392","inReplyTo":"alpine.LNX.2.00.0908050055550.2147@iabervon.org","subject":"Re: [PATCH 08/13] Add support for \"import\" helper command","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-08-05T20:56:57Z","receivedAt":"2009-08-05T20:56:57Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 5 Aug 2009, Daniel Barkalow wrote:\n\n> This command, supported if the \"import\" capability is advertized,\n> allows a helper to support fetching by outputting a git-fast-import\n> stream.\n\n  If both the \"import\" and the \"fetch\" capability are advertised, the \n  \"import\" capability is ignored.\n\n> diff --git a/Documentation/git-remote-helpers.txt b/Documentation/git-remote-helpers.txt\n> index 173ee23..e9aa67e 100644\n> --- a/Documentation/git-remote-helpers.txt\n> +++ b/Documentation/git-remote-helpers.txt\n> @@ -43,6 +43,13 @@ Commands are given by the caller on the helper's standard input, one per line.\n>  +\n>  Supported if the helper has the \"fetch\" capability.\n>  \n> +'import' <name>::\n> +\tProduces a fast-import stream which imports the current value\n> +\tof the named ref. It may additionally import other refs as\n> +\tneeded to construct the history efficiently.\n> ++\n> +Supported if the helper has the \"import\" capability.\n\n                                                      , but ignored if the \n+helper offers the \"fetch\" capability.\n\nCiao,\nDscho\n\n--\nSent from my EeePC\n"},{"id":"119697","messageId":"alpine.LNX.2.00.0908051708060.2147@iabervon.org","threadId":"20392","inReplyTo":"alpine.DEB.1.00.0908052254570.8306@pacific.mpi-cbg.de","subject":"Re: [PATCH 08/13] Add support for \"import\" helper command","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-08-05T21:17:32Z","receivedAt":"2009-08-05T21:17:32Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Wed, 5 Aug 2009, Johannes Schindelin wrote:\n\n> Hi,\n> \n> On Wed, 5 Aug 2009, Daniel Barkalow wrote:\n> \n> > This command, supported if the \"import\" capability is advertized,\n> > allows a helper to support fetching by outputting a git-fast-import\n> > stream.\n> \n>   If both the \"import\" and the \"fetch\" capability are advertised, the \n>   \"import\" capability is ignored.\n\nThe transport code notices that both are supported; it just doesn't use \nthe less convenient one. It would be wrong for helpers to advertize both \nand depend on only \"fetch\" being used. (For example, there's no reason \nthat hg couldn't use one of these helpers and use the \"import\" capability \ndespite the \"fetch\" capability also being advertized, because \"import\" \nproduces results which are portable across local vcses.)\n\n\t-Daniel\n*This .sig left intentionally blank*\n"},{"id":"119700","messageId":"alpine.DEB.1.00.0908052321580.8306@pacific.mpi-cbg.de","threadId":"20392","inReplyTo":"alpine.LNX.2.00.0908051708060.2147@iabervon.org","subject":"Re: [PATCH 08/13] Add support for \"import\" helper command","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-08-05T21:23:09Z","receivedAt":"2009-08-05T21:23:09Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 5 Aug 2009, Daniel Barkalow wrote:\n\n> On Wed, 5 Aug 2009, Johannes Schindelin wrote:\n> \n> > Hi,\n> > \n> > On Wed, 5 Aug 2009, Daniel Barkalow wrote:\n> > \n> > > This command, supported if the \"import\" capability is advertized,\n> > > allows a helper to support fetching by outputting a git-fast-import\n> > > stream.\n> > \n> >   If both the \"import\" and the \"fetch\" capability are advertised, the \n> >   \"import\" capability is ignored.\n> \n> The transport code notices that both are supported; it just doesn't use \n> the less convenient one. It would be wrong for helpers to advertize both \n> and depend on only \"fetch\" being used. (For example, there's no reason \n> that hg couldn't use one of these helpers and use the \"import\" capability \n> despite the \"fetch\" capability also being advertized, because \"import\" \n> produces results which are portable across local vcses.)\n\nMy point was not to criticize the decision.  My point was to criticize the \nabsence of the comment from both commit message and documentation.\n\nCiao,\nDscho\n"},{"id":"119709","messageId":"alpine.LNX.2.00.0908051747020.2147@iabervon.org","threadId":"20392","inReplyTo":"alpine.DEB.1.00.0908052321580.8306@pacific.mpi-cbg.de","subject":"Re: [PATCH 08/13] Add support for \"import\" helper command","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-08-05T21:50:07Z","receivedAt":"2009-08-05T21:50:07Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Wed, 5 Aug 2009, Johannes Schindelin wrote:\n\n> Hi,\n> \n> On Wed, 5 Aug 2009, Daniel Barkalow wrote:\n> \n> > On Wed, 5 Aug 2009, Johannes Schindelin wrote:\n> > \n> > > Hi,\n> > > \n> > > On Wed, 5 Aug 2009, Daniel Barkalow wrote:\n> > > \n> > > > This command, supported if the \"import\" capability is advertized,\n> > > > allows a helper to support fetching by outputting a git-fast-import\n> > > > stream.\n> > > \n> > >   If both the \"import\" and the \"fetch\" capability are advertised, the \n> > >   \"import\" capability is ignored.\n> > \n> > The transport code notices that both are supported; it just doesn't use \n> > the less convenient one. It would be wrong for helpers to advertize both \n> > and depend on only \"fetch\" being used. (For example, there's no reason \n> > that hg couldn't use one of these helpers and use the \"import\" capability \n> > despite the \"fetch\" capability also being advertized, because \"import\" \n> > produces results which are portable across local vcses.)\n> \n> My point was not to criticize the decision.  My point was to criticize the \n> absence of the comment from both commit message and documentation.\n\nBut it would be wrong for that documentation to say that \"import\" is \nignored if \"fetch\" is available, because it's not necessarily true. I'll \nmake the commit message say that git will prefer \"fetch\".\n\n\t-Daniel\n*This .sig left intentionally blank*\n"}]}