Support mandatory capabilities
authorIlari Liusvaara <ilari.liusvaara@elisanet.fi>
Wed, 9 Dec 2009 15:26:28 +0000 (17:26 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 9 Dec 2009 20:40:42 +0000 (12:40 -0800)
Add support for marking capability as mandatory for hosting git version
to understand. This is useful for helpers which require various types
of assistance from main git binary.

Signed-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-remote-helpers.txt
transport-helper.c

index 5cfdc0cfc553dc01f6f1c7cb185e79449ee0b0a8..20a05fe9d890e921779fa32da15edac6bc688687 100644 (file)
@@ -25,7 +25,10 @@ Commands are given by the caller on the helper's standard input, one per line.
 
 'capabilities'::
        Lists the capabilities of the helper, one per line, ending
-       with a blank line.
+       with a blank line. Each capability may be preceeded with '*'.
+       This marks them mandatory for git version using the remote
+       helper to understand (unknown mandatory capability is fatal
+       error).
 
 'list'::
        Lists the refs, one per line, in the format "<value> <name>
index a721dc25beb31350f6fc64f7446b340f83c707c8..4b17aaa237d498dcaaac14df1730af5b67b47705 100644 (file)
@@ -93,25 +93,38 @@ static struct child_process *get_helper(struct transport *transport)
 
        data->out = xfdopen(helper->out, "r");
        while (1) {
+               const char *capname;
+               int mandatory = 0;
                recvline(data, &buf);
 
                if (!*buf.buf)
                        break;
+
+               if (*buf.buf == '*') {
+                       capname = buf.buf + 1;
+                       mandatory = 1;
+               } else
+                       capname = buf.buf;
+
                if (debug)
-                       fprintf(stderr, "Debug: Got cap %s\n", buf.buf);
-               if (!strcmp(buf.buf, "fetch"))
+                       fprintf(stderr, "Debug: Got cap %s\n", capname);
+               if (!strcmp(capname, "fetch"))
                        data->fetch = 1;
-               if (!strcmp(buf.buf, "option"))
+               else if (!strcmp(capname, "option"))
                        data->option = 1;
-               if (!strcmp(buf.buf, "push"))
+               else if (!strcmp(capname, "push"))
                        data->push = 1;
-               if (!strcmp(buf.buf, "import"))
+               else if (!strcmp(capname, "import"))
                        data->import = 1;
-               if (!data->refspecs && !prefixcmp(buf.buf, "refspec ")) {
+               else if (!data->refspecs && !prefixcmp(capname, "refspec ")) {
                        ALLOC_GROW(refspecs,
                                   refspec_nr + 1,
                                   refspec_alloc);
                        refspecs[refspec_nr++] = strdup(buf.buf + strlen("refspec "));
+               } else if (mandatory) {
+                       die("Unknown madatory capability %s. This remote "
+                           "helper probably needs newer version of Git.\n",
+                           capname);
                }
        }
        if (refspecs) {