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 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 void copy_or_link_directory(struct strbuf *src, struct strbuf *dest) { struct dirent *de; struct stat buf; int src_len, dest_len; DIR *dir; dir = opendir(src->buf); if (!dir) die_errno("failed to open '%s'", src->buf); if (mkdir(dest->buf, 0777)) { if (errno != EEXIST) die_errno("failed to create directory '%s'", dest->buf); else if (stat(dest->buf, &buf)) die_errno("failed to stat '%s'", dest->buf); else if (!S_ISDIR(buf.st_mode)) die("%s exists and is not a directory", dest->buf); } strbuf_addch(src, '/'); src_len = src->len; strbuf_addch(dest, '/'); dest_len = dest->len; while ((de = readdir(dir)) != NULL) { strbuf_setlen(src, src_len); strbuf_addstr(src, de->d_name); strbuf_setlen(dest, dest_len); strbuf_addstr(dest, de->d_name); if (stat(src->buf, &buf)) { warning ("failed to stat %s\n", src->buf); continue; } if (S_ISDIR(buf.st_mode)) { if (de->d_name[0] != '.') copy_or_link_directory(src, dest); continue; } if (unlink(dest->buf) && errno != ENOENT) die_errno("failed to unlink '%s'", dest->buf); if (!option_no_hardlinks) { if (!link(src->buf, dest->buf)) continue; if (option_local) die_errno("failed to create link '%s'", dest->buf); option_no_hardlinks = 1; } if (copy_file_with_time(dest->buf, src->buf, 0666)) die_errno("failed to copy file to '%s'", dest->buf); } closedir(dir); }
static void copy_or_link_directory(char *src, char *dest) { struct dirent *de; struct stat buf; int src_len, dest_len; DIR *dir; dir = opendir(src); if (!dir) die("failed to open %s\n", src); if (mkdir(dest, 0777)) { if (errno != EEXIST) die("failed to create directory %s\n", dest); else if (stat(dest, &buf)) die("failed to stat %s\n", dest); else if (!S_ISDIR(buf.st_mode)) die("%s exists and is not a directory\n", dest); } src_len = strlen(src); src[src_len] = '/'; dest_len = strlen(dest); dest[dest_len] = '/'; while ((de = readdir(dir)) != NULL) { strcpy(src + src_len + 1, de->d_name); strcpy(dest + dest_len + 1, de->d_name); if (stat(src, &buf)) { warning ("failed to stat %s\n", src); continue; } if (S_ISDIR(buf.st_mode)) { if (de->d_name[0] != '.') copy_or_link_directory(src, dest); continue; } if (unlink(dest) && errno != ENOENT) die("failed to unlink %s\n", dest); if (!option_no_hardlinks) { if (!link(src, dest)) continue; if (option_local) die("failed to create link %s\n", dest); option_no_hardlinks = 1; } if (copy_file(dest, src, 0666)) die("failed to copy file to %s\n", dest); } closedir(dir); }
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 void copy_or_link_directory(struct strbuf *src, struct strbuf *dest, const char *src_repo, int src_baselen) { struct dirent *de; struct stat buf; int src_len, dest_len; DIR *dir; dir = opendir(src->buf); if (!dir) die_errno(_("failed to open '%s'"), src->buf); if (mkdir(dest->buf, 0777)) { if (errno != EEXIST) die_errno(_("failed to create directory '%s'"), dest->buf); else if (stat(dest->buf, &buf)) die_errno(_("failed to stat '%s'"), dest->buf); else if (!S_ISDIR(buf.st_mode)) die(_("%s exists and is not a directory"), dest->buf); } strbuf_addch(src, '/'); src_len = src->len; strbuf_addch(dest, '/'); dest_len = dest->len; while ((de = readdir(dir)) != NULL) { strbuf_setlen(src, src_len); strbuf_addstr(src, de->d_name); strbuf_setlen(dest, dest_len); strbuf_addstr(dest, de->d_name); if (stat(src->buf, &buf)) { warning (_("failed to stat %s\n"), src->buf); continue; } if (S_ISDIR(buf.st_mode)) { if (de->d_name[0] != '.') copy_or_link_directory(src, dest, src_repo, src_baselen); continue; } /* Files that cannot be copied bit-for-bit... */ if (!strcmp(src->buf + src_baselen, "/info/alternates")) { copy_alternates(src, dest, src_repo); continue; } if (unlink(dest->buf) && errno != ENOENT) die_errno(_("failed to unlink '%s'"), dest->buf); if (!option_no_hardlinks) { if (!link(src->buf, dest->buf)) continue; if (option_local > 0) die_errno(_("failed to create link '%s'"), dest->buf); option_no_hardlinks = 1; } if (copy_file_with_time(dest->buf, src->buf, 0666)) die_errno(_("failed to copy file to '%s'"), dest->buf); } closedir(dir); }