list-objects: pass full pathname to callbacks
[gitweb.git] / builtin / remote-ext.c
index 1f773171cbdde76cc105e37928cc5f2ecb2ed93f..3b8c22cc75ed04eaf450f9d5a1e9e71b914339eb 100644 (file)
@@ -1,4 +1,4 @@
-#include "git-compat-util.h"
+#include "builtin.h"
 #include "transport.h"
 #include "run-command.h"
 
@@ -30,20 +30,14 @@ static char *strip_escapes(const char *str, const char *service,
        size_t rpos = 0;
        int escape = 0;
        char special = 0;
-       size_t pslen = 0;
-       size_t pSlen = 0;
-       size_t psoff = 0;
+       const char *service_noprefix = service;
        struct strbuf ret = STRBUF_INIT;
 
-       /* Calculate prefix length for \s and lengths for \s and \S */
-       if (!strncmp(service, "git-", 4))
-               psoff = 4;
-       pSlen = strlen(service);
-       pslen = pSlen - psoff;
+       skip_prefix(service_noprefix, "git-", &service_noprefix);
 
        /* Pass the service to command. */
        setenv("GIT_EXT_SERVICE", service, 1);
-       setenv("GIT_EXT_SERVICE_NOPREFIX", service + psoff, 1);
+       setenv("GIT_EXT_SERVICE_NOPREFIX", service_noprefix, 1);
 
        /* Scan the length of argument. */
        while (str[rpos] && (escape || str[rpos] != ' ')) {
@@ -89,7 +83,7 @@ static char *strip_escapes(const char *str, const char *service,
                                strbuf_addch(&ret, str[rpos]);
                                break;
                        case 's':
-                               strbuf_addstr(&ret, service + psoff);
+                               strbuf_addstr(&ret, service_noprefix);
                                break;
                        case 'S':
                                strbuf_addstr(&ret, service);
@@ -183,9 +177,8 @@ static void send_git_request(int stdin_fd, const char *serv, const char *repo,
 static int run_child(const char *arg, const char *service)
 {
        int r;
-       struct child_process child;
+       struct child_process child = CHILD_PROCESS_INIT;
 
-       memset(&child, 0, sizeof(child));
        child.in = -1;
        child.out = -1;
        child.err = 0;
@@ -212,16 +205,16 @@ static int command_loop(const char *child)
        char buffer[MAXCOMMAND];
 
        while (1) {
-               size_t length;
+               size_t i;
                if (!fgets(buffer, MAXCOMMAND - 1, stdin)) {
                        if (ferror(stdin))
                                die("Comammand input error");
                        exit(0);
                }
                /* Strip end of line characters. */
-               length = strlen(buffer);
-               while (isspace((unsigned char)buffer[length - 1]))
-                       buffer[--length] = 0;
+               i = strlen(buffer);
+               while (i > 0 && isspace(buffer[i - 1]))
+                       buffer[--i] = 0;
 
                if (!strcmp(buffer, "capabilities")) {
                        printf("*connect\n\n");