88f7dc8845face548d973e46c9da052b057ea778
   1#include "cache.h"
   2#include "exec_cmd.h"
   3#include "walker.h"
   4
   5int main(int argc, const char **argv)
   6{
   7        const char *prefix;
   8        struct walker *walker;
   9        int commits_on_stdin = 0;
  10        int commits;
  11        const char **write_ref = NULL;
  12        char **commit_id;
  13        const char *url;
  14        char *rewritten_url = NULL;
  15        int arg = 1;
  16        int rc = 0;
  17        int get_tree = 0;
  18        int get_history = 0;
  19        int get_all = 0;
  20        int get_verbosely = 0;
  21        int get_recover = 0;
  22
  23        git_extract_argv0_path(argv[0]);
  24        prefix = setup_git_directory();
  25        git_config(git_default_config, NULL);
  26
  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++;
  41                } 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        }
  48        if (argc < arg + 2 - commits_on_stdin) {
  49                usage("git http-fetch [-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url");
  50                return 1;
  51        }
  52        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        }
  58        url = argv[arg];
  59        if (url && url[strlen(url)-1] != '/') {
  60                rewritten_url = xmalloc(strlen(url)+2);
  61                strcpy(rewritten_url, url);
  62                strcat(rewritten_url, "/");
  63                url = rewritten_url;
  64        }
  65
  66        walker = get_http_walker(url, NULL);
  67        walker->get_tree = get_tree;
  68        walker->get_history = get_history;
  69        walker->get_all = get_all;
  70        walker->get_verbosely = get_verbosely;
  71        walker->get_recover = get_recover;
  72
  73        rc = walker_fetch(walker, commits, commit_id, write_ref, url);
  74
  75        if (commits_on_stdin)
  76                walker_targets_free(commits, commit_id, write_ref);
  77
  78        if (walker->corrupt_object_found) {
  79                fprintf(stderr,
  80"Some loose object were found to be corrupt, but they might be just\n"
  81"a false '404 Not Found' error message sent with incorrect HTTP\n"
  82"status code.  Suggest running 'git fsck'.\n");
  83        }
  84
  85        walker_free(walker);
  86
  87        free(rewritten_url);
  88
  89        return rc;
  90}