🌐 AI搜索 & 代理 主页
blob: 8c4c5d2224a2493a648e6a34257bc150f2712dd0 [file] [log] [blame]
Daniel Barkalow30ae7642007-09-11 03:02:451#include "cache.h"
Jonathan Niederf01d7492009-11-09 15:05:002#include "exec_cmd.h"
Tay Ray Chuan888692b2010-03-02 10:49:293#include "http.h"
Daniel Barkalow30ae7642007-09-11 03:02:454#include "walker.h"
5
Jonathan Nieder616f86d2009-11-09 15:04:596static const char http_fetch_usage[] = "git http-fetch "
7"[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url";
8
Linus Torvalds10882612009-08-05 05:01:599int main(int argc, const char **argv)
Daniel Barkalow30ae7642007-09-11 03:02:4510{
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 08:21:1016 char *url = NULL;
Daniel Barkalow30ae7642007-09-11 03:02:4517 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
Jonathan Niederf01d7492009-11-09 15:05:0025 git_extract_argv0_path(argv[0]);
Daniel Barkalow30ae7642007-09-11 03:02:4526
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++;
Jonathan Nieder616f86d2009-11-09 15:04:5941 } else if (argv[arg][1] == 'h') {
42 usage(http_fetch_usage);
Daniel Barkalow30ae7642007-09-11 03:02:4543 } else if (!strcmp(argv[arg], "--recover")) {
44 get_recover = 1;
45 } else if (!strcmp(argv[arg], "--stdin")) {
46 commits_on_stdin = 1;
47 }
48 arg++;
49 }
Jonathan Nieder616f86d2009-11-09 15:04:5950 if (argc != arg + 2 - commits_on_stdin)
51 usage(http_fetch_usage);
Daniel Barkalow30ae7642007-09-11 03:02:4552 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 }
Tay Ray Chuan6f5185b2010-11-25 08:21:1058
Ben Waltona6c786f2011-08-24 00:29:5159 if (get_all == 0)
60 warning("http-fetch: use without -a is deprecated.\n"
61 "In a future release, -a will become the default.");
62
Tay Ray Chuan6f5185b2010-11-25 08:21:1063 if (argv[arg])
64 str_end_url_with_slash(argv[arg], &url);
Jonathan Nieder616f86d2009-11-09 15:04:5965
Dan McGee13ee1382011-03-28 01:32:1966 setup_git_directory();
Jonathan Nieder616f86d2009-11-09 15:04:5967
68 git_config(git_default_config, NULL);
69
Tay Ray Chuan888692b2010-03-02 10:49:2970 http_init(NULL);
71 walker = get_http_walker(url);
Daniel Barkalow30ae7642007-09-11 03:02:4572 walker->get_tree = get_tree;
73 walker->get_history = get_history;
74 walker->get_all = get_all;
75 walker->get_verbosely = get_verbosely;
76 walker->get_recover = get_recover;
77
78 rc = walker_fetch(walker, commits, commit_id, write_ref, url);
79
80 if (commits_on_stdin)
81 walker_targets_free(commits, commit_id, write_ref);
82
83 if (walker->corrupt_object_found) {
84 fprintf(stderr,
85"Some loose object were found to be corrupt, but they might be just\n"
86"a false '404 Not Found' error message sent with incorrect HTTP\n"
Heikki Orsila05207a22008-09-09 10:28:3087"status code. Suggest running 'git fsck'.\n");
Daniel Barkalow30ae7642007-09-11 03:02:4588 }
89
90 walker_free(walker);
Tay Ray Chuan888692b2010-03-02 10:49:2991 http_cleanup();
Daniel Barkalow30ae7642007-09-11 03:02:4592
Tay Ray Chuan6f5185b2010-11-25 08:21:1093 free(url);
Grégoire Barbier3057ded2008-01-19 15:22:5094
Daniel Barkalow30ae7642007-09-11 03:02:4595 return rc;
96}