blob: 3b556d66196277b2730f7e3d366a28a9d5ad1c56 [file] [log] [blame]
Daniel Barkalow30ae7642007-09-10 23:02:45 -04001#include "cache.h"
Jonathan Niederf01d7492009-11-09 09:05:00 -06002#include "exec_cmd.h"
Tay Ray Chuan888692b2010-03-02 18:49:29 +08003#include "http.h"
Daniel Barkalow30ae7642007-09-10 23:02:45 -04004#include "walker.h"
5
Jonathan Nieder616f86d2009-11-09 09:04:59 -06006static const char http_fetch_usage[] = "git http-fetch "
7"[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url";
8
Jeff King3f2e2292016-07-01 01:58:58 -04009int cmd_main(int argc, const char **argv)
Daniel Barkalow30ae7642007-09-10 23:02:45 -040010{
11 struct walker *walker;
12 int commits_on_stdin = 0;
13 int commits;
14 const char **write_ref = NULL;
15 char **commit_id;
Tay Ray Chuan6f5185b2010-11-25 16:21:10 +080016 char *url = NULL;
Daniel Barkalow30ae7642007-09-10 23:02:45 -040017 int arg = 1;
18 int rc = 0;
19 int get_tree = 0;
20 int get_history = 0;
21 int get_all = 0;
22 int get_verbosely = 0;
23 int get_recover = 0;
24
Daniel Barkalow30ae7642007-09-10 23:02:45 -040025 while (arg < argc && argv[arg][0] == '-') {
26 if (argv[arg][1] == 't') {
27 get_tree = 1;
28 } else if (argv[arg][1] == 'c') {
29 get_history = 1;
30 } else if (argv[arg][1] == 'a') {
31 get_all = 1;
32 get_tree = 1;
33 get_history = 1;
34 } else if (argv[arg][1] == 'v') {
35 get_verbosely = 1;
36 } else if (argv[arg][1] == 'w') {
37 write_ref = &argv[arg + 1];
38 arg++;
Jonathan Nieder616f86d2009-11-09 09:04:59 -060039 } else if (argv[arg][1] == 'h') {
40 usage(http_fetch_usage);
Daniel Barkalow30ae7642007-09-10 23:02:45 -040041 } 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 }
Jonathan Nieder616f86d2009-11-09 09:04:59 -060048 if (argc != arg + 2 - commits_on_stdin)
49 usage(http_fetch_usage);
Daniel Barkalow30ae7642007-09-10 23:02:45 -040050 if (commits_on_stdin) {
51 commits = walker_targets_stdin(&commit_id, &write_ref);
52 } else {
53 commit_id = (char **) &argv[arg++];
54 commits = 1;
55 }
Tay Ray Chuan6f5185b2010-11-25 16:21:10 +080056
Ben Waltona6c786f2011-08-23 20:29:51 -040057 if (get_all == 0)
58 warning("http-fetch: use without -a is deprecated.\n"
59 "In a future release, -a will become the default.");
60
Tay Ray Chuan6f5185b2010-11-25 16:21:10 +080061 if (argv[arg])
62 str_end_url_with_slash(argv[arg], &url);
Jonathan Nieder616f86d2009-11-09 09:04:59 -060063
Dan McGee13ee1382011-03-27 20:32:19 -050064 setup_git_directory();
Jonathan Nieder616f86d2009-11-09 09:04:59 -060065
66 git_config(git_default_config, NULL);
67
Jeff Kinga4ddbc32011-12-13 19:11:56 -050068 http_init(NULL, url, 0);
Tay Ray Chuan888692b2010-03-02 18:49:29 +080069 walker = get_http_walker(url);
Daniel Barkalow30ae7642007-09-10 23:02:45 -040070 walker->get_tree = get_tree;
71 walker->get_history = get_history;
72 walker->get_all = get_all;
73 walker->get_verbosely = get_verbosely;
74 walker->get_recover = get_recover;
75
76 rc = walker_fetch(walker, commits, commit_id, write_ref, url);
77
78 if (commits_on_stdin)
79 walker_targets_free(commits, commit_id, write_ref);
80
81 if (walker->corrupt_object_found) {
82 fprintf(stderr,
83"Some loose object were found to be corrupt, but they might be just\n"
84"a false '404 Not Found' error message sent with incorrect HTTP\n"
Heikki Orsila05207a22008-09-09 13:28:30 +030085"status code. Suggest running 'git fsck'.\n");
Daniel Barkalow30ae7642007-09-10 23:02:45 -040086 }
87
88 walker_free(walker);
Tay Ray Chuan888692b2010-03-02 18:49:29 +080089 http_cleanup();
Daniel Barkalow30ae7642007-09-10 23:02:45 -040090
Tay Ray Chuan6f5185b2010-11-25 16:21:10 +080091 free(url);
Grégoire Barbier3057ded2008-01-19 16:22:50 +010092
Daniel Barkalow30ae7642007-09-10 23:02:45 -040093 return rc;
94}