link_alt_odb_entry: refactor string handling
[gitweb.git] / connect.c
index 067cf409a8360b374f587d47aa87fa7d44b7614a..d99d6435fd01754e3b0f23537d7e1b385a26f262 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -46,11 +46,11 @@ int check_ref_type(const struct ref *ref, int flags)
 static void die_initial_contact(int unexpected)
 {
        if (unexpected)
-               die("The remote end hung up upon initial contact");
+               die(_("The remote end hung up upon initial contact"));
        else
-               die("Could not read from remote repository.\n\n"
-                   "Please make sure you have the correct access rights\n"
-                   "and the repository exists.");
+               die(_("Could not read from remote repository.\n\n"
+                     "Please make sure you have the correct access rights\n"
+                     "and the repository exists."));
 }
 
 static void parse_one_symref_info(struct string_list *symref, const char *val, int len)
@@ -123,6 +123,7 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
         * response does not necessarily mean an ACL problem, though.
         */
        int saw_response;
+       int got_dummy_ref_with_capabilities_declaration = 0;
 
        *list = NULL;
        for (saw_response = 0; ; saw_response = 1) {
@@ -172,8 +173,21 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
                        continue;
                }
 
+               if (!strcmp(name, "capabilities^{}")) {
+                       if (saw_response)
+                               die("protocol error: unexpected capabilities^{}");
+                       if (got_dummy_ref_with_capabilities_declaration)
+                               die("protocol error: multiple capabilities^{}");
+                       got_dummy_ref_with_capabilities_declaration = 1;
+                       continue;
+               }
+
                if (!check_ref(name, flags))
                        continue;
+
+               if (got_dummy_ref_with_capabilities_declaration)
+                       die("protocol error: unexpected ref after capabilities^{}");
+
                ref = alloc_ref(buffer + GIT_SHA1_HEXSZ + 1);
                oidcpy(&ref->old_oid, &old_oid);
                *list = ref;
@@ -664,6 +678,19 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,
 
 static struct child_process no_fork = CHILD_PROCESS_INIT;
 
+static const char *get_ssh_command(void)
+{
+       const char *ssh;
+
+       if ((ssh = getenv("GIT_SSH_COMMAND")))
+               return ssh;
+
+       if (!git_config_get_string_const("core.sshcommand", &ssh))
+               return ssh;
+
+       return NULL;
+}
+
 /*
  * This returns a dummy child_process if the transport protocol does not
  * need fork(2), or a struct child_process object if it does.  Once done,
@@ -764,7 +791,7 @@ struct child_process *git_connect(int fd[2], const char *url,
                                return NULL;
                        }
 
-                       ssh = getenv("GIT_SSH_COMMAND");
+                       ssh = get_ssh_command();
                        if (!ssh) {
                                const char *base;
                                char *ssh_dup;