X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-clone.c;h=e086a40b41810c30a4f5228daa4e38857dae84d5;hb=39702431500b76425f047209c9e9b2aae7e92b00;hp=f13845fb7f0c4b3759a3055fdfe216f83d18f957;hpb=c0f5c69c680395a45294184dcf0923cea530b9af;p=git.git diff --git a/builtin-clone.c b/builtin-clone.c index f13845fb7..e086a40b4 100644 --- a/builtin-clone.c +++ b/builtin-clone.c @@ -29,7 +29,7 @@ * */ static const char * const builtin_clone_usage[] = { - "git-clone [options] [--] []", + "git clone [options] [--] []", NULL }; @@ -95,35 +95,38 @@ static char *get_repo_path(const char *repo, int *is_bundle) static char *guess_dir_name(const char *repo, int is_bundle) { - const char *p, *start, *end, *limit; - int after_slash_or_colon; - - /* Guess dir name from repository: strip trailing '/', - * strip trailing '[:/]*.{git,bundle}', strip leading '.*[/:]'. */ - - after_slash_or_colon = 1; - limit = repo + strlen(repo); - start = repo; - end = limit; - for (p = repo; p < limit; p++) { - const char *prefix = is_bundle ? ".bundle" : ".git"; - if (!prefixcmp(p, prefix)) { - if (!after_slash_or_colon) - end = p; - p += strlen(prefix) - 1; - } else if (!prefixcmp(p, ".bundle")) { - if (!after_slash_or_colon) - end = p; - p += 7; - } else if (*p == '/' || *p == ':') { - if (end == limit) - end = p; - after_slash_or_colon = 1; - } else if (after_slash_or_colon) { - start = p; - end = limit; - after_slash_or_colon = 0; - } + const char *end = repo + strlen(repo), *start; + + /* + * Strip trailing slashes and /.git + */ + while (repo < end && is_dir_sep(end[-1])) + end--; + if (end - repo > 5 && is_dir_sep(end[-5]) && + !strncmp(end - 4, ".git", 4)) { + end -= 5; + while (repo < end && is_dir_sep(end[-1])) + end--; + } + + /* + * Find last component, but be prepared that repo could have + * the form "remote.example.com:foo.git", i.e. no slash + * in the directory part. + */ + start = end; + while (repo < start && !is_dir_sep(start[-1]) && start[-1] != ':') + start--; + + /* + * Strip .{bundle,git}. + */ + if (is_bundle) { + if (end - start > 7 && !strncmp(end - 7, ".bundle", 7)) + end -= 7; + } else { + if (end - start > 4 && !strncmp(end - 4, ".git", 4)) + end -= 4; } return xstrndup(start, end - start); @@ -341,6 +344,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) const struct ref *refs, *head_points_at, *remote_head, *mapped_refs; char branch_top[256], key[256], value[256]; struct strbuf reflog_msg; + struct transport *transport = NULL; struct refspec refspec; @@ -421,9 +425,15 @@ int cmd_clone(int argc, const char **argv, const char *prefix) die("could not create leading directories of '%s'", git_dir); set_git_dir(make_absolute_path(git_dir)); - fprintf(stderr, "Initialize %s\n", git_dir); init_db(option_template, option_quiet ? INIT_DB_QUIET : 0); + /* + * At this point, the config exists, so we do not need the + * environment variable. We actually need to unset it, too, to + * re-enable parsing of the global configs. + */ + unsetenv(CONFIG_ENVIRONMENT); + if (option_reference) setup_reference(git_dir); @@ -456,7 +466,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) refs = clone_local(path, git_dir); else { struct remote *remote = remote_get(argv[0]); - struct transport *transport = transport_get(remote, argv[0]); + transport = transport_get(remote, remote->url[0]); if (!transport->get_refs_list || !transport->fetch) die("Don't know how to clone %s", transport->url); @@ -470,6 +480,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix) if (option_quiet) transport->verbose = -1; + if (option_upload_pack) + transport_set_option(transport, TRANS_OPT_UPLOADPACK, + option_upload_pack); + refs = transport_get_remote_refs(transport); transport_fetch_refs(transport, refs); } @@ -526,6 +540,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix) option_no_checkout = 1; } + if (transport) + transport_unlock_pack(transport); + if (!option_no_checkout) { struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file)); struct unpack_trees_options opts;