Code

git-svn: get rid of Memoize for now...
[git.git] / connect.c
index b9666cc0d826890b5e84a58c7f7ed52ff56c3e79..8a8a13bb72b33f335a5a10642f0461ef673ef168 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -3,12 +3,6 @@
 #include "pkt-line.h"
 #include "quote.h"
 #include "refs.h"
-#include <sys/wait.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <signal.h>
 
 static char *server_capabilities;
 
@@ -102,7 +96,7 @@ int get_ack(int fd, unsigned char *result_sha1)
                line[--len] = 0;
        if (!strcmp(line, "NAK"))
                return 0;
-       if (!strncmp(line, "ACK ", 4)) {
+       if (!prefixcmp(line, "ACK ")) {
                if (!get_sha1_hex(line+4, result_sha1)) {
                        if (strstr(line+45, "continue"))
                                return 2;
@@ -144,6 +138,7 @@ struct refspec {
  * +A:B means overwrite remote B with local A.
  * +A is a shorthand for +A:A.
  * A is a shorthand for A:A.
+ * :B means delete remote B.
  */
 static struct refspec *parse_ref_spec(int nr_refspec, char **refspec)
 {
@@ -201,8 +196,8 @@ static int count_refspec_match(const char *pattern,
                 */
                if (namelen != patlen &&
                    patlen != namelen - 5 &&
-                   strncmp(name, "refs/heads/", 11) &&
-                   strncmp(name, "refs/tags/", 10)) {
+                   prefixcmp(name, "refs/heads/") &&
+                   prefixcmp(name, "refs/tags/")) {
                        /* We want to catch the case where only weak
                         * matches are found and there are multiple
                         * matches, and where more than one strong
@@ -240,6 +235,13 @@ static struct ref *try_explicit_object_name(const char *name)
        unsigned char sha1[20];
        struct ref *ref;
        int len;
+
+       if (!*name) {
+               ref = xcalloc(1, sizeof(*ref) + 20);
+               strcpy(ref->name, "(delete)");
+               hashclr(ref->new_sha1);
+               return ref;
+       }
        if (get_sha1(name, sha1))
                return NULL;
        len = strlen(name) + 1;
@@ -262,7 +264,8 @@ static int match_explicit_refs(struct ref *src, struct ref *dst,
                        break;
                case 0:
                        /* The source could be in the get_sha1() format
-                        * not a reference name.
+                        * not a reference name.  :refs/other is a
+                        * way to delete 'other' ref at the remote end.
                         */
                        matched_src = try_explicit_object_name(rs[i].src);
                        if (matched_src)
@@ -526,7 +529,7 @@ static void git_tcp_connect(int fd[2], char *host)
        int sockfd = git_tcp_connect_sock(host);
 
        fd[0] = sockfd;
-       fd[1] = sockfd;
+       fd[1] = dup(sockfd);
 }