|
7 | 7 | static const char http_fetch_usage[] = "git http-fetch "
|
8 | 8 | "[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url";
|
9 | 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) |
11 | 13 | {
|
| 14 | + char *url = NULL; |
12 | 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 | +{ |
13 | 48 | int commits_on_stdin = 0;
|
14 | 49 | int commits;
|
15 | 50 | const char **write_ref = NULL;
|
16 | 51 | char **commit_id;
|
17 |
| - char *url = NULL; |
18 | 52 | int arg = 1;
|
19 |
| - int rc = 0; |
20 | 53 | int get_verbosely = 0;
|
21 | 54 | int get_recover = 0;
|
22 | 55 |
|
@@ -47,34 +80,14 @@ int cmd_main(int argc, const char **argv)
|
47 | 80 | commits = 1;
|
48 | 81 | }
|
49 | 82 |
|
50 |
| - if (argv[arg]) |
51 |
| - str_end_url_with_slash(argv[arg], &url); |
52 |
| - |
53 | 83 | setup_git_directory();
|
54 | 84 |
|
55 | 85 | git_config(git_default_config, NULL);
|
56 | 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"); |
66 | 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); |
80 | 93 | }
|
0 commit comments