]> git.ipfire.org Git - thirdparty/git.git/blame - http-fetch.c
Makefile: Include subdirectories in "make cover" reports
[thirdparty/git.git] / http-fetch.c
CommitLineData
30ae764b 1#include "cache.h"
f01d7496 2#include "exec_cmd.h"
888692b7 3#include "http.h"
30ae764b
DB
4#include "walker.h"
5
616f86d7
JN
6static const char http_fetch_usage[] = "git http-fetch "
7"[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url";
8
1088261f 9int main(int argc, const char **argv)
30ae764b 10{
1088261f 11 const char *prefix;
30ae764b
DB
12 struct walker *walker;
13 int commits_on_stdin = 0;
14 int commits;
15 const char **write_ref = NULL;
16 char **commit_id;
17 const char *url;
3057ded0 18 char *rewritten_url = NULL;
30ae764b
DB
19 int arg = 1;
20 int rc = 0;
21 int get_tree = 0;
22 int get_history = 0;
23 int get_all = 0;
24 int get_verbosely = 0;
25 int get_recover = 0;
26
f01d7496 27 git_extract_argv0_path(argv[0]);
30ae764b
DB
28
29 while (arg < argc && argv[arg][0] == '-') {
30 if (argv[arg][1] == 't') {
31 get_tree = 1;
32 } else if (argv[arg][1] == 'c') {
33 get_history = 1;
34 } else if (argv[arg][1] == 'a') {
35 get_all = 1;
36 get_tree = 1;
37 get_history = 1;
38 } else if (argv[arg][1] == 'v') {
39 get_verbosely = 1;
40 } else if (argv[arg][1] == 'w') {
41 write_ref = &argv[arg + 1];
42 arg++;
616f86d7
JN
43 } else if (argv[arg][1] == 'h') {
44 usage(http_fetch_usage);
30ae764b
DB
45 } else if (!strcmp(argv[arg], "--recover")) {
46 get_recover = 1;
47 } else if (!strcmp(argv[arg], "--stdin")) {
48 commits_on_stdin = 1;
49 }
50 arg++;
51 }
616f86d7
JN
52 if (argc != arg + 2 - commits_on_stdin)
53 usage(http_fetch_usage);
30ae764b
DB
54 if (commits_on_stdin) {
55 commits = walker_targets_stdin(&commit_id, &write_ref);
56 } else {
57 commit_id = (char **) &argv[arg++];
58 commits = 1;
59 }
60 url = argv[arg];
616f86d7
JN
61
62 prefix = setup_git_directory();
63
64 git_config(git_default_config, NULL);
65
3057ded0 66 if (url && url[strlen(url)-1] != '/') {
e8eec71d 67 rewritten_url = xmalloc(strlen(url)+2);
3057ded0
GB
68 strcpy(rewritten_url, url);
69 strcat(rewritten_url, "/");
70 url = rewritten_url;
71 }
30ae764b 72
888692b7
TRC
73 http_init(NULL);
74 walker = get_http_walker(url);
30ae764b
DB
75 walker->get_tree = get_tree;
76 walker->get_history = get_history;
77 walker->get_all = get_all;
78 walker->get_verbosely = get_verbosely;
79 walker->get_recover = get_recover;
80
81 rc = walker_fetch(walker, commits, commit_id, write_ref, url);
82
83 if (commits_on_stdin)
84 walker_targets_free(commits, commit_id, write_ref);
85
86 if (walker->corrupt_object_found) {
87 fprintf(stderr,
88"Some loose object were found to be corrupt, but they might be just\n"
89"a false '404 Not Found' error message sent with incorrect HTTP\n"
05207a28 90"status code. Suggest running 'git fsck'.\n");
30ae764b
DB
91 }
92
93 walker_free(walker);
888692b7 94 http_cleanup();
30ae764b 95
8e0f7003 96 free(rewritten_url);
3057ded0 97
30ae764b
DB
98 return rc;
99}