blob: 8af380050ce6a43a6764ad871f0de141c316421a [file] [log] [blame]
Daniel Barkalow30ae7642007-09-10 23:02:45 -04001#include "cache.h"
Brandon Williamsb2141fc2017-06-14 11:07:36 -07002#include "config.h"
Jonathan Niederf01d7492009-11-09 09:05:00 -06003#include "exec_cmd.h"
Tay Ray Chuan888692b2010-03-02 18:49:29 +08004#include "http.h"
Daniel Barkalow30ae7642007-09-10 23:02:45 -04005#include "walker.h"
6
Jonathan Nieder616f86d2009-11-09 09:04:59 -06007static const char http_fetch_usage[] = "git http-fetch "
8"[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url";
9
Jeff King3f2e2292016-07-01 01:58:58 -040010int cmd_main(int argc, const char **argv)
Daniel Barkalow30ae7642007-09-10 23:02:45 -040011{
12 struct walker *walker;
13 int commits_on_stdin = 0;
14 int commits;
15 const char **write_ref = NULL;
16 char **commit_id;
Tay Ray Chuan6f5185b2010-11-25 16:21:10 +080017 char *url = NULL;
Daniel Barkalow30ae7642007-09-10 23:02:45 -040018 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
Daniel Barkalow30ae7642007-09-10 23:02:45 -040026 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++;
Jonathan Nieder616f86d2009-11-09 09:04:59 -060040 } else if (argv[arg][1] == 'h') {
41 usage(http_fetch_usage);
Daniel Barkalow30ae7642007-09-10 23:02:45 -040042 } else if (!strcmp(argv[arg], "--recover")) {
43 get_recover = 1;
44 } else if (!strcmp(argv[arg], "--stdin")) {
45 commits_on_stdin = 1;
46 }
47 arg++;
48 }
Jonathan Nieder616f86d2009-11-09 09:04:59 -060049 if (argc != arg + 2 - commits_on_stdin)
50 usage(http_fetch_usage);
Daniel Barkalow30ae7642007-09-10 23:02:45 -040051 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 }
Tay Ray Chuan6f5185b2010-11-25 16:21:10 +080057
Ben Waltona6c786f2011-08-23 20:29:51 -040058 if (get_all == 0)
59 warning("http-fetch: use without -a is deprecated.\n"
60 "In a future release, -a will become the default.");
61
Tay Ray Chuan6f5185b2010-11-25 16:21:10 +080062 if (argv[arg])
63 str_end_url_with_slash(argv[arg], &url);
Jonathan Nieder616f86d2009-11-09 09:04:59 -060064
Dan McGee13ee1382011-03-27 20:32:19 -050065 setup_git_directory();
Jonathan Nieder616f86d2009-11-09 09:04:59 -060066
67 git_config(git_default_config, NULL);
68
Jeff Kinga4ddbc32011-12-13 19:11:56 -050069 http_init(NULL, url, 0);
Tay Ray Chuan888692b2010-03-02 18:49:29 +080070 walker = get_http_walker(url);
Daniel Barkalow30ae7642007-09-10 23:02:45 -040071 walker->get_tree = get_tree;
72 walker->get_history = get_history;
73 walker->get_all = get_all;
74 walker->get_verbosely = get_verbosely;
75 walker->get_recover = get_recover;
76
77 rc = walker_fetch(walker, commits, commit_id, write_ref, url);
78
79 if (commits_on_stdin)
80 walker_targets_free(commits, commit_id, write_ref);
81
82 if (walker->corrupt_object_found) {
83 fprintf(stderr,
84"Some loose object were found to be corrupt, but they might be just\n"
85"a false '404 Not Found' error message sent with incorrect HTTP\n"
Heikki Orsila05207a22008-09-09 13:28:30 +030086"status code. Suggest running 'git fsck'.\n");
Daniel Barkalow30ae7642007-09-10 23:02:45 -040087 }
88
89 walker_free(walker);
Tay Ray Chuan888692b2010-03-02 18:49:29 +080090 http_cleanup();
Daniel Barkalow30ae7642007-09-10 23:02:45 -040091
Tay Ray Chuan6f5185b2010-11-25 16:21:10 +080092 free(url);
Grégoire Barbier3057ded2008-01-19 16:22:50 +010093
Daniel Barkalow30ae7642007-09-10 23:02:45 -040094 return rc;
95}