[PATCH] http-fetch: don't use double-slash as directory separator in URLs

Subsystems: the rest

DORMANTno replies

2 messages, 1 author, 2016-06-15 · open the first message on its own page

[PATCH] http-fetch: don't use double-slash as directory separator in URLs

From: Gerrit Pape <hidden>
Date: 2016-06-15 22:43:02

Please see http://bugs.debian.org/409887

http-fetch expected the URL given at the command line to have a trailing
slash anyway, and then added '/objects...' when requesting objects files
from the http server.

Now it doesn't require the trailing slash in <url> anymore, and strips
trailing slashes if given nonetheless.

Signed-off-by: Gerrit Pape <redacted>
---
 git-clone.sh |    2 +-
 git-fetch.sh |    2 +-
 http-fetch.c |   21 ++++++++++++---------
 3 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/git-clone.sh b/git-clone.sh
index 6ba477d..513b574 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -60,7 +60,7 @@ Perhaps git-update-server-info needs to be run there?"
 		else
 			tname=$name
 		fi
-		git-http-fetch $v -a -w "$tname" "$name" "$1/" || exit 1
+		git-http-fetch $v -a -w "$tname" "$name" "$1" || exit 1
 	done <"$clone_tmp/refs"
 	rm -fr "$clone_tmp"
 	http_fetch "$1/HEAD" "$GIT_DIR/REMOTE_HEAD" ||
diff --git a/git-fetch.sh b/git-fetch.sh
index 9334933..fd70696 100755
--- a/git-fetch.sh
+++ b/git-fetch.sh
@@ -248,7 +248,7 @@ fetch_per_ref () {
 	  expr "z$head" : "z$_x40\$" >/dev/null ||
 		die "No such ref $remote_name at $remote"
 	  echo >&2 "Fetching $remote_name from $remote using $proto"
-	  git-http-fetch -v -a "$head" "$remote/" || exit
+	  git-http-fetch -v -a "$head" "$remote" || exit
 	  ;;
       rsync://*)
 	  test -n "$shallow_depth" &&
diff --git a/http-fetch.c b/http-fetch.c
index e6cd11d..58b77a7 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -16,7 +16,7 @@ static struct curl_slist *no_pragma_header;
 
 struct alt_base
 {
-	const char *base;
+	char *base;
 	int path_len;
 	int got_indices;
 	struct packed_git *packs;
@@ -158,12 +158,12 @@ static void start_object_request(struct object_request *obj_req)
 
 	SHA1_Init(&obj_req->c);
 
-	url = xmalloc(strlen(obj_req->repo->base) + 50);
-	obj_req->url = xmalloc(strlen(obj_req->repo->base) + 50);
+	url = xmalloc(strlen(obj_req->repo->base) + 51);
+	obj_req->url = xmalloc(strlen(obj_req->repo->base) + 51);
 	strcpy(url, obj_req->repo->base);
 	posn = url + strlen(obj_req->repo->base);
-	strcpy(posn, "objects/");
-	posn += 8;
+	strcpy(posn, "/objects/");
+	posn += 9;
 	memcpy(posn, hex, 2);
 	posn += 2;
 	*(posn++) = '/';
@@ -938,14 +938,14 @@ static char *quote_ref_url(const char *base, const char *ref)
 	int len, baselen, ch;
 
 	baselen = strlen(base);
-	len = baselen + 6; /* "refs/" + NUL */
+	len = baselen + 7; /* "/refs/" + NUL */
 	for (cp = ref; (ch = *cp) != 0; cp++, len++)
 		if (needs_quote(ch))
 			len += 2; /* extra two hex plus replacement % */
 	qref = xmalloc(len);
 	memcpy(qref, base, baselen);
-	memcpy(qref + baselen, "refs/", 5);
-	for (cp = ref, dp = qref + baselen + 5; (ch = *cp) != 0; cp++) {
+	memcpy(qref + baselen, "/refs/", 6);
+	for (cp = ref, dp = qref + baselen + 6; (ch = *cp) != 0; cp++) {
 		if (needs_quote(ch)) {
 			*dp++ = '%';
 			*dp++ = hex((ch >> 4) & 0xF);
@@ -1044,7 +1044,10 @@ int main(int argc, const char **argv)
 	no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
 
 	alt = xmalloc(sizeof(*alt));
-	alt->base = url;
+	alt->base = xmalloc(strlen(url) + 1);
+	strcpy(alt->base, url);
+	for (path = alt->base + strlen(alt->base) - 1; *path == '/'; --path)
+		*path = 0;
 	alt->got_indices = 0;
 	alt->packs = NULL;
 	alt->next = NULL;
-- 
1.5.1-rc2.GIT

[PATCH] http-fetch: remove path_len from struct alt_base, it was computed but never used

From: Gerrit Pape <hidden>
Date: 2016-06-15 22:43:02

Signed-off-by: Gerrit Pape <redacted>
---
 http-fetch.c |   20 +++-----------------
 1 files changed, 3 insertions(+), 17 deletions(-)
diff --git a/http-fetch.c b/http-fetch.c
index 58b77a7..557b403 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -17,7 +17,6 @@ static struct curl_slist *no_pragma_header;
 struct alt_base
 {
 	char *base;
-	int path_len;
 	int got_indices;
 	struct packed_git *packs;
 	struct alt_base *next;
@@ -515,7 +514,6 @@ static void process_alternates_response(void *callback_data)
 			int serverlen = 0;
 			struct alt_base *newalt;
 			char *target = NULL;
-			char *path;
 			if (data[i] == '/') {
 				/* This counts
 				 * http://git.host/pub/scm/linux.git/
@@ -583,12 +581,6 @@ static void process_alternates_response(void *callback_data)
 				newalt->base = target;
 				newalt->got_indices = 0;
 				newalt->packs = NULL;
-				path = strstr(target, "//");
-				if (path) {
-					path = strchr(path+2, '/');
-					if (path)
-						newalt->path_len = strlen(path);
-				}
 
 				while (tail->next != NULL)
 					tail = tail->next;
@@ -999,7 +991,7 @@ int main(int argc, const char **argv)
 	const char **write_ref = NULL;
 	char **commit_id;
 	const char *url;
-	char *path;
+	char *s;
 	int arg = 1;
 	int rc = 0;
 
@@ -1046,17 +1038,11 @@ int main(int argc, const char **argv)
 	alt = xmalloc(sizeof(*alt));
 	alt->base = xmalloc(strlen(url) + 1);
 	strcpy(alt->base, url);
-	for (path = alt->base + strlen(alt->base) - 1; *path == '/'; --path)
-		*path = 0;
+	for (s = alt->base + strlen(alt->base) - 1; *s == '/'; --s)
+		*s = 0;
 	alt->got_indices = 0;
 	alt->packs = NULL;
 	alt->next = NULL;
-	path = strstr(url, "//");
-	if (path) {
-		path = strchr(path+2, '/');
-		if (path)
-			alt->path_len = strlen(path);
-	}
 
 	if (pull(commits, commit_id, write_ref, url))
 		rc = 1;
-- 
1.5.1-rc2.GIT
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help