]> git.ipfire.org Git - thirdparty/git.git/blame - http-fetch.c
sha1_file.c: move find_cached_object up so sha1_object_info can use it
[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;
6f5185bd 17 char *url = NULL;
30ae764b
DB
18 int arg = 1;
19 int rc = 0;
20 int get_tree = 0;
21 int get_history = 0;
22 int get_all = 0;
23 int get_verbosely = 0;
24 int get_recover = 0;
25
f01d7496 26 git_extract_argv0_path(argv[0]);
30ae764b
DB
27
28 while (arg < argc && argv[arg][0] == '-') {
29 if (argv[arg][1] == 't') {
30 get_tree = 1;
31 } else if (argv[arg][1] == 'c') {
32 get_history = 1;
33 } else if (argv[arg][1] == 'a') {
34 get_all = 1;
35 get_tree = 1;
36 get_history = 1;
37 } else if (argv[arg][1] == 'v') {
38 get_verbosely = 1;
39 } else if (argv[arg][1] == 'w') {
40 write_ref = &argv[arg + 1];
41 arg++;
616f86d7
JN
42 } else if (argv[arg][1] == 'h') {
43 usage(http_fetch_usage);
30ae764b
DB
44 } else if (!strcmp(argv[arg], "--recover")) {
45 get_recover = 1;
46 } else if (!strcmp(argv[arg], "--stdin")) {
47 commits_on_stdin = 1;
48 }
49 arg++;
50 }
616f86d7
JN
51 if (argc != arg + 2 - commits_on_stdin)
52 usage(http_fetch_usage);
30ae764b
DB
53 if (commits_on_stdin) {
54 commits = walker_targets_stdin(&commit_id, &write_ref);
55 } else {
56 commit_id = (char **) &argv[arg++];
57 commits = 1;
58 }
6f5185bd
TRC
59
60 if (argv[arg])
61 str_end_url_with_slash(argv[arg], &url);
616f86d7
JN
62
63 prefix = setup_git_directory();
64
65 git_config(git_default_config, NULL);
66
888692b7
TRC
67 http_init(NULL);
68 walker = get_http_walker(url);
30ae764b
DB
69 walker->get_tree = get_tree;
70 walker->get_history = get_history;
71 walker->get_all = get_all;
72 walker->get_verbosely = get_verbosely;
73 walker->get_recover = get_recover;
74
75 rc = walker_fetch(walker, commits, commit_id, write_ref, url);
76
77 if (commits_on_stdin)
78 walker_targets_free(commits, commit_id, write_ref);
79
80 if (walker->corrupt_object_found) {
81 fprintf(stderr,
82"Some loose object were found to be corrupt, but they might be just\n"
83"a false '404 Not Found' error message sent with incorrect HTTP\n"
05207a28 84"status code. Suggest running 'git fsck'.\n");
30ae764b
DB
85 }
86
87 walker_free(walker);
888692b7 88 http_cleanup();
30ae764b 89
6f5185bd 90 free(url);
3057ded0 91
30ae764b
DB
92 return rc;
93}