static void copy_alternates(struct strbuf *src, struct strbuf *dst, const char *src_repo) { /* * Read from the source objects/info/alternates file * and copy the entries to corresponding file in the * destination repository with add_to_alternates_file(). * Both src and dst have "$path/objects/info/alternates". * * Instead of copying bit-for-bit from the original, * we need to append to existing one so that the already * created entry via "clone -s" is not lost, and also * to turn entries with paths relative to the original * absolute, so that they can be used in the new repository. */ FILE *in = fopen(src->buf, "r"); struct strbuf line = STRBUF_INIT; while (strbuf_getline(&line, in, '\n') != EOF) { char *abs_path, abs_buf[PATH_MAX]; if (!line.len || line.buf[0] == '#') continue; if (is_absolute_path(line.buf)) { add_to_alternates_file(line.buf); continue; } abs_path = mkpath("%s/objects/%s", src_repo, line.buf); normalize_path_copy(abs_buf, abs_path); add_to_alternates_file(abs_buf); } strbuf_release(&line); fclose(in); }
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))) die(_("reference repository '%s' is not a local repository."), item->string); strbuf_addf(&alternate, "%s/objects", ref_git); add_to_alternates_file(alternate.buf); strbuf_release(&alternate); free(ref_git); return 0; }
static const struct ref *clone_local(const char *src_repo, const char *dest_repo) { const struct ref *ret; struct strbuf src = STRBUF_INIT; struct strbuf dest = STRBUF_INIT; struct remote *remote; struct transport *transport; if (option_shared) add_to_alternates_file(src_repo); else { strbuf_addf(&src, "%s/objects", src_repo); strbuf_addf(&dest, "%s/objects", dest_repo); copy_or_link_directory(&src, &dest); strbuf_release(&src); strbuf_release(&dest); } remote = remote_get(src_repo); transport = transport_get(remote, src_repo); ret = transport_get_remote_refs(transport); transport_disconnect(transport); return ret; }
static void setup_reference(const char *repo) { const char *ref_git; char *ref_git_copy; struct remote *remote; struct transport *transport; const struct ref *extra; ref_git = make_absolute_path(option_reference); if (is_directory(mkpath("%s/.git/objects", ref_git))) ref_git = mkpath("%s/.git", ref_git); else if (!is_directory(mkpath("%s/objects", ref_git))) die("reference repository '%s' is not a local directory.", option_reference); ref_git_copy = xstrdup(ref_git); add_to_alternates_file(ref_git_copy); remote = remote_get(ref_git_copy); transport = transport_get(remote, ref_git_copy); for (extra = transport_get_remote_refs(transport); extra; extra = extra->next) add_extra_ref(extra->name, extra->old_sha1, 0); transport_disconnect(transport); free(ref_git_copy); }
static const struct ref *clone_local(const char *src_repo, const char *dest_repo) { const struct ref *ret; struct remote *remote; struct transport *transport; if (option_shared) { struct strbuf alt = STRBUF_INIT; strbuf_addf(&alt, "%s/objects", src_repo); add_to_alternates_file(alt.buf); strbuf_release(&alt); } else { struct strbuf src = STRBUF_INIT; struct strbuf dest = STRBUF_INIT; strbuf_addf(&src, "%s/objects", src_repo); strbuf_addf(&dest, "%s/objects", dest_repo); copy_or_link_directory(&src, &dest, src_repo, src.len); strbuf_release(&src); strbuf_release(&dest); } remote = remote_get(src_repo); transport = transport_get(remote, src_repo); ret = transport_get_remote_refs(transport); transport_disconnect(transport); if (0 <= option_verbosity) printf(_("done.\n")); return ret; }
static int add_one_reference(struct string_list_item *item, void *cb_data) { char *ref_git; struct strbuf alternate = STRBUF_INIT; struct remote *remote; struct transport *transport; const struct ref *extra; /* Beware: real_path() and mkpath() return static buffer */ ref_git = xstrdup(real_path(item->string)); if (is_directory(mkpath("%s/.git/objects", ref_git))) { char *ref_git_git = xstrdup(mkpath("%s/.git", ref_git)); free(ref_git); ref_git = ref_git_git; } else if (!is_directory(mkpath("%s/objects", ref_git))) die(_("reference repository '%s' is not a local directory."), item->string); strbuf_addf(&alternate, "%s/objects", ref_git); add_to_alternates_file(alternate.buf); strbuf_release(&alternate); remote = remote_get(ref_git); transport = transport_get(remote, ref_git); for (extra = transport_get_remote_refs(transport); extra; extra = extra->next) add_extra_ref(extra->name, extra->old_sha1, 0); transport_disconnect(transport); free(ref_git); return 0; }
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); } if (!access(mkpath("%s/shallow", ref_git), F_OK)) die(_("reference repository '%s' is shallow"), item->string); if (!access(mkpath("%s/info/grafts", ref_git), F_OK)) die(_("reference repository '%s' is grafted"), item->string); strbuf_addf(&alternate, "%s/objects", ref_git); add_to_alternates_file(alternate.buf); strbuf_release(&alternate); free(ref_git); return 0; }
static void clone_local(const char *src_repo, const char *dest_repo) { if (option_shared) { struct strbuf alt = STRBUF_INIT; strbuf_addf(&alt, "%s/objects", src_repo); add_to_alternates_file(alt.buf); strbuf_release(&alt); } else { struct strbuf src = STRBUF_INIT; struct strbuf dest = STRBUF_INIT; strbuf_addf(&src, "%s/objects", src_repo); strbuf_addf(&dest, "%s/objects", dest_repo); copy_or_link_directory(&src, &dest, src_repo, src.len); strbuf_release(&src); strbuf_release(&dest); } if (0 <= option_verbosity) fprintf(stderr, _("done.\n")); }
static const struct ref *clone_local(const char *src_repo, const char *dest_repo) { const struct ref *ret; char src[PATH_MAX]; char dest[PATH_MAX]; struct remote *remote; struct transport *transport; if (option_shared) add_to_alternates_file(src_repo); else { snprintf(src, PATH_MAX, "%s/objects", src_repo); snprintf(dest, PATH_MAX, "%s/objects", dest_repo); copy_or_link_directory(src, dest); } remote = remote_get(src_repo); transport = transport_get(remote, src_repo); ret = transport_get_remote_refs(transport); transport_disconnect(transport); return ret; }
static int add_one_reference(struct string_list_item *item, void *cb_data) { struct strbuf err = STRBUF_INIT; int *required = cb_data; char *ref_git = compute_alternate_path(item->string, &err); if (!ref_git) { if (*required) die("%s", err.buf); else fprintf(stderr, _("info: Could not add alternate for '%s': %s\n"), item->string, err.buf); } else { struct strbuf sb = STRBUF_INIT; strbuf_addf(&sb, "%s/objects", ref_git); add_to_alternates_file(sb.buf); strbuf_release(&sb); } strbuf_release(&err); free(ref_git); return 0; }