@matheusbsbs / matheus-bagliano / commits / 8e6adb69e1
Fork 0

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 <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Jun 10, 2020 at 13:57 UTC 8e6adb69e18b18de72f0114d153b47bed4560560
1 file changed +41 -28
http-fetch.c
+41 -28
@@ -7,16 +7,49 @@
7 static const char http_fetch_usage[] = "git http-fetch "
8 "[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url";
9
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)
13 {
14 + char *url = NULL;
15 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 +{
48 int commits_on_stdin = 0;
49 int commits;
50 const char **write_ref = NULL;
51 char **commit_id;
17 - char *url = NULL;
52 int arg = 1;
19 - int rc = 0;
53 int get_verbosely = 0;
54 int get_recover = 0;
55
@@ -47,34 +80,14 @@ int cmd_main(int argc, const char **argv)
80 commits = 1;
81 }
82
50 - if (argv[arg])
51 - str_end_url_with_slash(argv[arg], &url);
52 -
83 setup_git_directory();
84
85 git_config(git_default_config, NULL);
86
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");
89
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);
93 }