]> git.ipfire.org Git - thirdparty/git.git/blame - http-fetch.c
Merge branch 'js/update-index-ignore-removal-for-skip-worktree'
[thirdparty/git.git] / http-fetch.c
CommitLineData
30ae764b 1#include "cache.h"
b2141fc1 2#include "config.h"
d807c4a0 3#include "exec-cmd.h"
888692b7 4#include "http.h"
30ae764b
DB
5#include "walker.h"
6
616f86d7
JN
7static const char http_fetch_usage[] = "git http-fetch "
8"[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url";
9
3f2e2297 10int cmd_main(int argc, const char **argv)
30ae764b
DB
11{
12 struct walker *walker;
13 int commits_on_stdin = 0;
14 int commits;
15 const char **write_ref = NULL;
16 char **commit_id;
6f5185bd 17 char *url = NULL;
30ae764b
DB
18 int arg = 1;
19 int rc = 0;
30ae764b
DB
20 int get_verbosely = 0;
21 int get_recover = 0;
22
30ae764b
DB
23 while (arg < argc && argv[arg][0] == '-') {
24 if (argv[arg][1] == 't') {
30ae764b 25 } else if (argv[arg][1] == 'c') {
30ae764b 26 } else if (argv[arg][1] == 'a') {
30ae764b
DB
27 } else if (argv[arg][1] == 'v') {
28 get_verbosely = 1;
29 } else if (argv[arg][1] == 'w') {
30 write_ref = &argv[arg + 1];
31 arg++;
616f86d7
JN
32 } else if (argv[arg][1] == 'h') {
33 usage(http_fetch_usage);
30ae764b
DB
34 } else if (!strcmp(argv[arg], "--recover")) {
35 get_recover = 1;
36 } else if (!strcmp(argv[arg], "--stdin")) {
37 commits_on_stdin = 1;
38 }
39 arg++;
40 }
616f86d7
JN
41 if (argc != arg + 2 - commits_on_stdin)
42 usage(http_fetch_usage);
30ae764b
DB
43 if (commits_on_stdin) {
44 commits = walker_targets_stdin(&commit_id, &write_ref);
45 } else {
46 commit_id = (char **) &argv[arg++];
47 commits = 1;
48 }
6f5185bd
TRC
49
50 if (argv[arg])
51 str_end_url_with_slash(argv[arg], &url);
616f86d7 52
13ee1384 53 setup_git_directory();
616f86d7
JN
54
55 git_config(git_default_config, NULL);
56
a4ddbc33 57 http_init(NULL, url, 0);
888692b7 58 walker = get_http_walker(url);
30ae764b
DB
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);
66
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"
05207a28 71"status code. Suggest running 'git fsck'.\n");
30ae764b
DB
72 }
73
74 walker_free(walker);
888692b7 75 http_cleanup();
30ae764b 76
6f5185bd 77 free(url);
3057ded0 78
30ae764b
DB
79 return rc;
80}