make it easier for people who just want to get rid of 'git gc --auto'
[git/spearce.git] / builtin-http-fetch.c
blobb1f33891c36fe38d855ace535cf9218fe9603541
1 #include "cache.h"
2 #include "walker.h"
4 int cmd_http_fetch(int argc, const char **argv, const char *prefix)
6 struct walker *walker;
7 int commits_on_stdin = 0;
8 int commits;
9 const char **write_ref = NULL;
10 char **commit_id;
11 const char *url;
12 char *rewritten_url = NULL;
13 int arg = 1;
14 int rc = 0;
15 int get_tree = 0;
16 int get_history = 0;
17 int get_all = 0;
18 int get_verbosely = 0;
19 int get_recover = 0;
21 git_config(git_default_config);
23 while (arg < argc && argv[arg][0] == '-') {
24 if (argv[arg][1] == 't') {
25 get_tree = 1;
26 } else if (argv[arg][1] == 'c') {
27 get_history = 1;
28 } else if (argv[arg][1] == 'a') {
29 get_all = 1;
30 get_tree = 1;
31 get_history = 1;
32 } else if (argv[arg][1] == 'v') {
33 get_verbosely = 1;
34 } else if (argv[arg][1] == 'w') {
35 write_ref = &argv[arg + 1];
36 arg++;
37 } else if (!strcmp(argv[arg], "--recover")) {
38 get_recover = 1;
39 } else if (!strcmp(argv[arg], "--stdin")) {
40 commits_on_stdin = 1;
42 arg++;
44 if (argc < arg + 2 - commits_on_stdin) {
45 usage("git-http-fetch [-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url");
46 return 1;
48 if (commits_on_stdin) {
49 commits = walker_targets_stdin(&commit_id, &write_ref);
50 } else {
51 commit_id = (char **) &argv[arg++];
52 commits = 1;
54 url = argv[arg];
55 if (url && url[strlen(url)-1] != '/') {
56 rewritten_url = malloc(strlen(url)+2);
57 strcpy(rewritten_url, url);
58 strcat(rewritten_url, "/");
59 url = rewritten_url;
62 walker = get_http_walker(url, NULL);
63 walker->get_tree = get_tree;
64 walker->get_history = get_history;
65 walker->get_all = get_all;
66 walker->get_verbosely = get_verbosely;
67 walker->get_recover = get_recover;
69 rc = walker_fetch(walker, commits, commit_id, write_ref, url);
71 if (commits_on_stdin)
72 walker_targets_free(commits, commit_id, write_ref);
74 if (walker->corrupt_object_found) {
75 fprintf(stderr,
76 "Some loose object were found to be corrupt, but they might be just\n"
77 "a false '404 Not Found' error message sent with incorrect HTTP\n"
78 "status code. Suggest running git-fsck.\n");
81 walker_free(walker);
83 free(rewritten_url);
85 return rc;