Skip to content

Commit 8e6adb6

Browse files
jonathantanmygitster
authored andcommitted
http-fetch: refactor into function
cmd_main() in http-fetch.c will grow in a future patch, so refactor the HTTP walking part into its own function. Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent eb05349 commit 8e6adb6

File tree

1 file changed

+41
-28
lines changed

1 file changed

+41
-28
lines changed

http-fetch.c

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,49 @@
77
static const char http_fetch_usage[] = "git http-fetch "
88
"[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url";
99

10-
int cmd_main(int argc, const char **argv)
10+
static int fetch_using_walker(const char *raw_url, int get_verbosely,
11+
int get_recover, int commits, char **commit_id,
12+
const char **write_ref, int commits_on_stdin)
1113
{
14+
char *url = NULL;
1215
struct walker *walker;
16+
int rc;
17+
18+
str_end_url_with_slash(raw_url, &url);
19+
20+
http_init(NULL, url, 0);
21+
22+
walker = get_http_walker(url);
23+
walker->get_verbosely = get_verbosely;
24+
walker->get_recover = get_recover;
25+
walker->get_progress = 0;
26+
27+
rc = walker_fetch(walker, commits, commit_id, write_ref, url);
28+
29+
if (commits_on_stdin)
30+
walker_targets_free(commits, commit_id, write_ref);
31+
32+
if (walker->corrupt_object_found) {
33+
fprintf(stderr,
34+
"Some loose object were found to be corrupt, but they might be just\n"
35+
"a false '404 Not Found' error message sent with incorrect HTTP\n"
36+
"status code. Suggest running 'git fsck'.\n");
37+
}
38+
39+
walker_free(walker);
40+
http_cleanup();
41+
free(url);
42+
43+
return rc;
44+
}
45+
46+
int cmd_main(int argc, const char **argv)
47+
{
1348
int commits_on_stdin = 0;
1449
int commits;
1550
const char **write_ref = NULL;
1651
char **commit_id;
17-
char *url = NULL;
1852
int arg = 1;
19-
int rc = 0;
2053
int get_verbosely = 0;
2154
int get_recover = 0;
2255

@@ -47,34 +80,14 @@ int cmd_main(int argc, const char **argv)
4780
commits = 1;
4881
}
4982

50-
if (argv[arg])
51-
str_end_url_with_slash(argv[arg], &url);
52-
5383
setup_git_directory();
5484

5585
git_config(git_default_config, NULL);
5686

57-
http_init(NULL, url, 0);
58-
walker = get_http_walker(url);
59-
walker->get_verbosely = get_verbosely;
60-
walker->get_recover = get_recover;
61-
62-
rc = walker_fetch(walker, commits, commit_id, write_ref, url);
63-
64-
if (commits_on_stdin)
65-
walker_targets_free(commits, commit_id, write_ref);
87+
if (!argv[arg])
88+
BUG("must have one arg remaining");
6689

67-
if (walker->corrupt_object_found) {
68-
fprintf(stderr,
69-
"Some loose object were found to be corrupt, but they might be just\n"
70-
"a false '404 Not Found' error message sent with incorrect HTTP\n"
71-
"status code. Suggest running 'git fsck'.\n");
72-
}
73-
74-
walker_free(walker);
75-
http_cleanup();
76-
77-
free(url);
78-
79-
return rc;
90+
return fetch_using_walker(argv[arg], get_verbosely, get_recover,
91+
commits, commit_id, write_ref,
92+
commits_on_stdin);
8093
}

0 commit comments

Comments
 (0)