diff options
author | Stefan Beller <sbeller@google.com> | 2016-08-15 14:53:24 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-08-15 15:28:01 -0700 |
commit | 9eeea7d2bc8132cfaa1b79271c077e80317f3ae1 (patch) | |
tree | 311909d3eefff75811402fcaaa95b51549645019 /builtin/clone.c | |
parent | 5f50f33e875cc877747a40a80e8ead73db0ec8c1 (diff) | |
download | git-9eeea7d2bc8132cfaa1b79271c077e80317f3ae1.tar.gz |
clone: factor out checking for an alternate path
In a later patch we want to determine if a path is suitable as an
alternate from other commands than builtin/clone. Move the checking
functionality of `add_one_reference` to `compute_alternate_path` that is
defined in cache.h.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/clone.c')
-rw-r--r-- | builtin/clone.c | 43 |
1 files changed, 9 insertions, 34 deletions
diff --git a/builtin/clone.c b/builtin/clone.c index f044a8c27f..4cd3a6691a 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -282,44 +282,19 @@ static void strip_trailing_slashes(char *dir) static int add_one_reference(struct string_list_item *item, void *cb_data) { - char *ref_git; - const char *repo; - struct strbuf alternate = STRBUF_INIT; - - /* Beware: read_gitfile(), real_path() and mkpath() return static buffer */ - ref_git = xstrdup(real_path(item->string)); - - repo = read_gitfile(ref_git); - if (!repo) - repo = read_gitfile(mkpath("%s/.git", ref_git)); - if (repo) { - free(ref_git); - ref_git = xstrdup(repo); - } - - if (!repo && is_directory(mkpath("%s/.git/objects", ref_git))) { - char *ref_git_git = mkpathdup("%s/.git", ref_git); - free(ref_git); - ref_git = ref_git_git; - } else if (!is_directory(mkpath("%s/objects", ref_git))) { - struct strbuf sb = STRBUF_INIT; - if (get_common_dir(&sb, ref_git)) - die(_("reference repository '%s' as a linked checkout is not supported yet."), - item->string); - die(_("reference repository '%s' is not a local repository."), - item->string); - } + struct strbuf err = STRBUF_INIT; + struct strbuf sb = STRBUF_INIT; + char *ref_git = compute_alternate_path(item->string, &err); - if (!access(mkpath("%s/shallow", ref_git), F_OK)) - die(_("reference repository '%s' is shallow"), item->string); + if (!ref_git) + die("%s", err.buf); - if (!access(mkpath("%s/info/grafts", ref_git), F_OK)) - die(_("reference repository '%s' is grafted"), item->string); + strbuf_addf(&sb, "%s/objects", ref_git); + add_to_alternates_file(sb.buf); - strbuf_addf(&alternate, "%s/objects", ref_git); - add_to_alternates_file(alternate.buf); - strbuf_release(&alternate); free(ref_git); + strbuf_release(&err); + strbuf_release(&sb); return 0; } |