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