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