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