summaryrefslogtreecommitdiff
path: root/http-fetch.c
diff options
context:
space:
mode:
Diffstat (limited to 'http-fetch.c')
-rw-r--r--http-fetch.c45
1 files changed, 27 insertions, 18 deletions
diff --git a/http-fetch.c b/http-fetch.c
index e8f44babd9..ba3ea10670 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -1,16 +1,19 @@
#include "cache.h"
+#include "exec_cmd.h"
+#include "http.h"
#include "walker.h"
+static const char http_fetch_usage[] = "git http-fetch "
+"[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url";
+
int main(int argc, const char **argv)
{
- const char *prefix;
struct walker *walker;
int commits_on_stdin = 0;
int commits;
const char **write_ref = NULL;
char **commit_id;
- const char *url;
- char *rewritten_url = NULL;
+ char *url = NULL;
int arg = 1;
int rc = 0;
int get_tree = 0;
@@ -19,9 +22,9 @@ int main(int argc, const char **argv)
int get_verbosely = 0;
int get_recover = 0;
- prefix = setup_git_directory();
+ git_setup_gettext();
- git_config(git_default_config, NULL);
+ git_extract_argv0_path(argv[0]);
while (arg < argc && argv[arg][0] == '-') {
if (argv[arg][1] == 't') {
@@ -37,6 +40,8 @@ int main(int argc, const char **argv)
} else if (argv[arg][1] == 'w') {
write_ref = &argv[arg + 1];
arg++;
+ } else if (argv[arg][1] == 'h') {
+ usage(http_fetch_usage);
} else if (!strcmp(argv[arg], "--recover")) {
get_recover = 1;
} else if (!strcmp(argv[arg], "--stdin")) {
@@ -44,25 +49,28 @@ int main(int argc, const char **argv)
}
arg++;
}
- if (argc < arg + 2 - commits_on_stdin) {
- usage("git http-fetch [-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url");
- return 1;
- }
+ if (argc != arg + 2 - commits_on_stdin)
+ usage(http_fetch_usage);
if (commits_on_stdin) {
commits = walker_targets_stdin(&commit_id, &write_ref);
} else {
commit_id = (char **) &argv[arg++];
commits = 1;
}
- url = argv[arg];
- if (url && url[strlen(url)-1] != '/') {
- rewritten_url = xmalloc(strlen(url)+2);
- strcpy(rewritten_url, url);
- strcat(rewritten_url, "/");
- url = rewritten_url;
- }
- walker = get_http_walker(url, NULL);
+ if (get_all == 0)
+ warning("http-fetch: use without -a is deprecated.\n"
+ "In a future release, -a will become the default.");
+
+ if (argv[arg])
+ str_end_url_with_slash(argv[arg], &url);
+
+ setup_git_directory();
+
+ git_config(git_default_config, NULL);
+
+ http_init(NULL, url, 0);
+ walker = get_http_walker(url);
walker->get_tree = get_tree;
walker->get_history = get_history;
walker->get_all = get_all;
@@ -82,8 +90,9 @@ int main(int argc, const char **argv)
}
walker_free(walker);
+ http_cleanup();
- free(rewritten_url);
+ free(url);
return rc;
}