blob: ffd0ad7e295d7341776bb7b6407602cdb2997ef3 [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"
Daniel Barkalow30ae7642007-09-10 23:02:45 -04003#include "walker.h"
4
Jonathan Nieder616f86d2009-11-09 09:04:59 -06005static const char http_fetch_usage[] = "git http-fetch "
6"[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url";
7
Linus Torvalds10882612009-08-05 01:01:59 -04008int main(int argc, const char **argv)
Daniel Barkalow30ae7642007-09-10 23:02:45 -04009{
Linus Torvalds10882612009-08-05 01:01:59 -040010 const char *prefix;
Daniel Barkalow30ae7642007-09-10 23:02:45 -040011 struct walker *walker;
12 int commits_on_stdin = 0;
13 int commits;
14 const char **write_ref = NULL;
15 char **commit_id;
16 const char *url;
Grégoire Barbier3057ded2008-01-19 16:22:50 +010017 char *rewritten_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
Jonathan Niederf01d7492009-11-09 09:05:00 -060026 git_extract_argv0_path(argv[0]);
Daniel Barkalow30ae7642007-09-10 23:02:45 -040027
28 while (arg < argc && argv[arg][0] == '-') {
29 if (argv[arg][1] == 't') {
30 get_tree = 1;
31 } else if (argv[arg][1] == 'c') {
32 get_history = 1;
33 } else if (argv[arg][1] == 'a') {
34 get_all = 1;
35 get_tree = 1;
36 get_history = 1;
37 } else if (argv[arg][1] == 'v') {
38 get_verbosely = 1;
39 } else if (argv[arg][1] == 'w') {
40 write_ref = &argv[arg + 1];
41 arg++;
Jonathan Nieder616f86d2009-11-09 09:04:59 -060042 } else if (argv[arg][1] == 'h') {
43 usage(http_fetch_usage);
Daniel Barkalow30ae7642007-09-10 23:02:45 -040044 } else if (!strcmp(argv[arg], "--recover")) {
45 get_recover = 1;
46 } else if (!strcmp(argv[arg], "--stdin")) {
47 commits_on_stdin = 1;
48 }
49 arg++;
50 }
Jonathan Nieder616f86d2009-11-09 09:04:59 -060051 if (argc != arg + 2 - commits_on_stdin)
52 usage(http_fetch_usage);
Daniel Barkalow30ae7642007-09-10 23:02:45 -040053 if (commits_on_stdin) {
54 commits = walker_targets_stdin(&commit_id, &write_ref);
55 } else {
56 commit_id = (char **) &argv[arg++];
57 commits = 1;
58 }
59 url = argv[arg];
Jonathan Nieder616f86d2009-11-09 09:04:59 -060060
61 prefix = setup_git_directory();
62
63 git_config(git_default_config, NULL);
64
Grégoire Barbier3057ded2008-01-19 16:22:50 +010065 if (url && url[strlen(url)-1] != '/') {
Dotan Barake8eec712008-09-09 21:57:10 +030066 rewritten_url = xmalloc(strlen(url)+2);
Grégoire Barbier3057ded2008-01-19 16:22:50 +010067 strcpy(rewritten_url, url);
68 strcat(rewritten_url, "/");
69 url = rewritten_url;
70 }
Daniel Barkalow30ae7642007-09-10 23:02:45 -040071
Mike Hommey9fc64402008-02-27 21:35:50 +010072 walker = get_http_walker(url, NULL);
Daniel Barkalow30ae7642007-09-10 23:02:45 -040073 walker->get_tree = get_tree;
74 walker->get_history = get_history;
75 walker->get_all = get_all;
76 walker->get_verbosely = get_verbosely;
77 walker->get_recover = get_recover;
78
79 rc = walker_fetch(walker, commits, commit_id, write_ref, url);
80
81 if (commits_on_stdin)
82 walker_targets_free(commits, commit_id, write_ref);
83
84 if (walker->corrupt_object_found) {
85 fprintf(stderr,
86"Some loose object were found to be corrupt, but they might be just\n"
87"a false '404 Not Found' error message sent with incorrect HTTP\n"
Heikki Orsila05207a22008-09-09 13:28:30 +030088"status code. Suggest running 'git fsck'.\n");
Daniel Barkalow30ae7642007-09-10 23:02:45 -040089 }
90
91 walker_free(walker);
92
Jim Meyering8e0f7002008-01-31 18:26:32 +010093 free(rewritten_url);
Grégoire Barbier3057ded2008-01-19 16:22:50 +010094
Daniel Barkalow30ae7642007-09-10 23:02:45 -040095 return rc;
96}