Skip to content

Commit 1462d1a

Browse files
rctaygitster
authored andcommitted
http-push: add trailing slash at arg-parse time, instead of later on
That way, we don't have to update repo->path and repo->path_len again after adding the trailing slash. Signed-off-by: Tay Ray Chuan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dfc2dcd commit 1462d1a

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

http-push.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,7 +1801,6 @@ int main(int argc, char **argv)
18011801
int new_refs;
18021802
struct ref *ref, *local_refs;
18031803
struct remote *remote;
1804-
char *rewritten_url = NULL;
18051804

18061805
git_extract_argv0_path(argv[0]);
18071806

@@ -1847,8 +1846,8 @@ int main(int argc, char **argv)
18471846
}
18481847
if (!repo->url) {
18491848
char *path = strstr(arg, "//");
1850-
repo->url = arg;
1851-
repo->path_len = strlen(arg);
1849+
str_end_url_with_slash(arg, &repo->url);
1850+
repo->path_len = strlen(repo->url);
18521851
if (path) {
18531852
repo->path = strchr(path+2, '/');
18541853
if (repo->path)
@@ -1884,15 +1883,6 @@ int main(int argc, char **argv)
18841883
remote->url[remote->url_nr++] = repo->url;
18851884
http_init(remote);
18861885

1887-
if (repo->url && repo->url[strlen(repo->url)-1] != '/') {
1888-
rewritten_url = xmalloc(strlen(repo->url)+2);
1889-
strcpy(rewritten_url, repo->url);
1890-
strcat(rewritten_url, "/");
1891-
repo->path = rewritten_url + (repo->path - repo->url);
1892-
repo->path_len++;
1893-
repo->url = rewritten_url;
1894-
}
1895-
18961886
#ifdef USE_CURL_MULTI
18971887
is_running_queue = 0;
18981888
#endif
@@ -2100,7 +2090,6 @@ int main(int argc, char **argv)
21002090
}
21012091

21022092
cleanup:
2103-
free(rewritten_url);
21042093
if (info_ref_lock)
21052094
unlock_remote(info_ref_lock);
21062095
free(repo);

0 commit comments

Comments
 (0)