git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 9/9] http-fetch: rework url handling

From
Tay Ray Chuan <rctay89@gmail.com>
Date
Nov 25, 2010, 08:21 UTC
Message-ID
<1290673270-4284-10-git-send-email-rctay89@gmail.com>
In-Reply-To
<1290673270-4284-9-git-send-email-rctay89@gmail.com>

Do away with a second url variable, rewritten_url, and make url non-const. This is safe because the functions called with url (ie. get_http_walker() and walker_fetch()) do not modify it (ie. marked with const char *).

Also, replace code that adds a trailing slash with a call to str_end_url_with_slash().

Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
---
New in v3.
 http-fetch.c |   16 +++++-----------
 1 files changed, 5 insertions(+), 11 deletions(-)
diff --git a/http-fetch.c b/http-fetch.c
index 762c750..923904f 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -14,8 +14,7 @@ int main(int argc, const char **argv)
 	int commits;
 	const char **write_ref = NULL;
 	char **commit_id;
-	const char *url;
-	char *rewritten_url = NULL;
+	char *url = NULL;
 	int arg = 1;
 	int rc = 0;
 	int get_tree = 0;
@@ -57,19 +56,14 @@ int main(int argc, const char **argv)
 		commit_id = (char **) &argv[arg++];
 		commits = 1;
 	}
-	url = argv[arg];
+
+	if (argv[arg])
+		str_end_url_with_slash(argv[arg], &url);
 
 	prefix = setup_git_directory();
 
 	git_config(git_default_config, NULL);
 
-	if (url && url[strlen(url)-1] != '/') {
-		rewritten_url = xmalloc(strlen(url)+2);
-		strcpy(rewritten_url, url);
-		strcat(rewritten_url, "/");
-		url = rewritten_url;
-	}
-
 	http_init(NULL);
 	walker = get_http_walker(url);
 	walker->get_tree = get_tree;
@@ -93,7 +87,7 @@ int main(int argc, const char **argv)
 	walker_free(walker);
 	http_cleanup();
 
-	free(rewritten_url);
+	free(url);
 
 	return rc;
 }
-- 
1.7.3.2.495.gc7b3f
Previous: Tay Ray Chuan
Message 12 of 12 in “Re: [PATCH v2 3/7] url: add str wrapper for end_url_with_slash()”
  1. Jonathan NiederNov 22, 2010
  2. Tay Ray ChuanNov 22, 2010
  3. 0/9 http: end urls with slashTay Ray Chuan, Nov 25, 2010
  4. 1/9 t5550-http-fetch: add missing '&&'Tay Ray Chuan, Nov 25, 2010
  5. 2/9 t5550-http-fetch: add test for http-fetchTay Ray Chuan, Nov 25, 2010
  6. 3/9 shift end_url_with_slash() from http.[ch] to url.[ch]Tay Ray Chuan, Nov 25, 2010
  7. 4/9 url: add str wrapper for end_url_with_slash()Tay Ray Chuan, Nov 25, 2010
  8. 5/9 http-backend: use end_url_with_slash()Tay Ray Chuan, Nov 25, 2010
  9. 6/9 http-push: Normalise directory names when pushing to some WebDAV serversTay Ray Chuan, Nov 25, 2010
  10. 7/9 http-push: check path length before using itTay Ray Chuan, Nov 25, 2010
  11. 8/9 http-push: add trailing slash at arg-parse time, instead of later onTay Ray Chuan, Nov 25, 2010
  12. 9/9 http-fetch: rework url handlingTay Ray Chuan, Nov 25, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.