Move git_pkt_{gen_proto,send_request} to transport_git.c This is where they really belong. Remvoe the prefix and make them static. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
diff --git a/include/git2/pkt.h b/include/git2/pkt.h
index bcd5c81..59826da 100644
--- a/include/git2/pkt.h
+++ b/include/git2/pkt.h
@@ -51,10 +51,5 @@ struct git_pkt_ref {
char *capabilities;
};
-/**
- * Create a git protocol request.
- */
-int git_pkt_gen_proto(char **out, int *outlen, const char *cmd, const char *url);
-int git_pkt_send_request(int socket, const char *cmd, const char *url);
int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_t len);
void git_pkt_free(git_pkt *pkt);
diff --git a/src/pkt.c b/src/pkt.c
index 403850b..eb51fe9 100644
--- a/src/pkt.c
+++ b/src/pkt.c
@@ -201,64 +201,6 @@ void git_pkt_free(git_pkt *pkt)
free(pkt);
}
-/*
- * Create a git procol request.
- *
- * For example: 0035git-upload-pack /libgit2/libgit2\0host=github.com\0
- *
- * TODO: the command should not be hard-coded
- */
-int git_pkt_gen_proto(char **out, int *outlen, const char *cmd, const char *url)
-{
- char *delim, *repo, *ptr;
- char default_command[] = "git-upload-pack";
- char host[] = "host=";
- int len;
-
- delim = strchr(url, '/');
- if (delim == NULL)
- return git__throw(GIT_EOBJCORRUPTED, "Failed to create proto-request: malformed URL");
-
- repo = delim;
-
- delim = strchr(url, ':');
- if (delim == NULL)
- delim = strchr(url, '/');
-
- if (cmd == NULL)
- cmd = default_command;
-
- len = 4 + strlen(cmd) + 1 + strlen(repo) + 1 + STRLEN(host) + (delim - url) + 2;
-
- *out = git__malloc(len);
- if (*out == NULL)
- return GIT_ENOMEM;
-
- *outlen = len - 1;
- ptr = *out;
- memset(ptr, 0x0, len);
- /* We expect the return value to be > len - 1 so don't bother checking it */
- snprintf(ptr, len -1, "%04x%s %s%c%s%s", len - 1, cmd, repo, 0, host, url);
-
- return GIT_SUCCESS;
-}
-
-int git_pkt_send_request(int s, const char *cmd, const char *url)
-{
- int error, len;
- char *msg = NULL;
-
- error = git_pkt_gen_proto(&msg, &len, cmd, url);
- if (error < GIT_SUCCESS)
- goto cleanup;
-
- error = gitno_send(s, msg, len, 0);
-
-cleanup:
- free(msg);
- return error;
-}
-
int git_pkt_send_flush(int s)
{
char flush[] = "0000";
diff --git a/src/transport_git.c b/src/transport_git.c
index 2441edf..eb5f708 100644
--- a/src/transport_git.c
+++ b/src/transport_git.c
@@ -49,6 +49,61 @@ typedef struct {
git_vector refs;
git_remote_head **heads;
} git_priv;
+/*
+ * Create a git procol request.
+ *
+ * For example: 0035git-upload-pack /libgit2/libgit2\0host=github.com\0
+ */
+static int gen_proto(char **out, int *outlen, const char *cmd, const char *url)
+{
+ char *delim, *repo, *ptr;
+ char default_command[] = "git-upload-pack";
+ char host[] = "host=";
+ int len;
+
+ delim = strchr(url, '/');
+ if (delim == NULL)
+ return git__throw(GIT_EOBJCORRUPTED, "Failed to create proto-request: malformed URL");
+
+ repo = delim;
+
+ delim = strchr(url, ':');
+ if (delim == NULL)
+ delim = strchr(url, '/');
+
+ if (cmd == NULL)
+ cmd = default_command;
+
+ len = 4 + strlen(cmd) + 1 + strlen(repo) + 1 + STRLEN(host) + (delim - url) + 2;
+
+ *out = git__malloc(len);
+ if (*out == NULL)
+ return GIT_ENOMEM;
+
+ *outlen = len - 1;
+ ptr = *out;
+ memset(ptr, 0x0, len);
+ /* We expect the return value to be > len - 1 so don't bother checking it */
+ snprintf(ptr, len -1, "%04x%s %s%c%s%s", len - 1, cmd, repo, 0, host, url);
+
+ return GIT_SUCCESS;
+}
+
+static int send_request(int s, const char *cmd, const char *url)
+{
+ int error, len;
+ char *msg = NULL;
+
+ error = gen_proto(&msg, &len, cmd, url);
+ if (error < GIT_SUCCESS)
+ goto cleanup;
+
+ error = gitno_send(s, msg, len, 0);
+
+cleanup:
+ free(msg);
+ return error;
+}
/* The URL should already have been stripped of the protocol */
static int extract_host_and_port(char **host, char **port, const char *url)
@@ -99,7 +154,7 @@ static int do_connect(git_priv *priv, const char *url)
error = extract_host_and_port(&host, &port, url);
s = gitno_connect(host, port);
connected = 1;
- error = git_pkt_send_request(s, NULL, url);
+ error = send_request(s, NULL, url);
priv->socket = s;
free(host);