Skip to content

Commit 6f5185b

Browse files
rctaygitster
authored andcommitted
http-fetch: rework url handling
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1462d1a commit 6f5185b

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

http-fetch.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ int main(int argc, const char **argv)
1414
int commits;
1515
const char **write_ref = NULL;
1616
char **commit_id;
17-
const char *url;
18-
char *rewritten_url = NULL;
17+
char *url = NULL;
1918
int arg = 1;
2019
int rc = 0;
2120
int get_tree = 0;
@@ -57,19 +56,14 @@ int main(int argc, const char **argv)
5756
commit_id = (char **) &argv[arg++];
5857
commits = 1;
5958
}
60-
url = argv[arg];
59+
60+
if (argv[arg])
61+
str_end_url_with_slash(argv[arg], &url);
6162

6263
prefix = setup_git_directory();
6364

6465
git_config(git_default_config, NULL);
6566

66-
if (url && url[strlen(url)-1] != '/') {
67-
rewritten_url = xmalloc(strlen(url)+2);
68-
strcpy(rewritten_url, url);
69-
strcat(rewritten_url, "/");
70-
url = rewritten_url;
71-
}
72-
7367
http_init(NULL);
7468
walker = get_http_walker(url);
7569
walker->get_tree = get_tree;
@@ -93,7 +87,7 @@ int main(int argc, const char **argv)
9387
walker_free(walker);
9488
http_cleanup();
9589

96-
free(rewritten_url);
90+
free(url);
9791

9892
return rc;
9993
}

0 commit comments

Comments
 (0)