| 190 | } |
| 191 | |
| 192 | static void copy_alternates(struct strbuf *src, const char *src_repo) |
| 193 | { |
| 194 | /* |
| 195 | * Read from the source objects/info/alternates file |
| 196 | * and copy the entries to corresponding file in the |
| 197 | * destination repository with add_to_alternates_file(). |
| 198 | * Both src and dst have "$path/objects/info/alternates". |
| 199 | * |
| 200 | * Instead of copying bit-for-bit from the original, |
| 201 | * we need to append to existing one so that the already |
| 202 | * created entry via "clone -s" is not lost, and also |
| 203 | * to turn entries with paths relative to the original |
| 204 | * absolute, so that they can be used in the new repository. |
| 205 | */ |
| 206 | FILE *in = xfopen(src->buf, "r"); |
| 207 | struct strbuf line = STRBUF_INIT; |
| 208 | |
| 209 | while (strbuf_getline(&line, in) != EOF) { |
| 210 | char *abs_path; |
| 211 | if (!line.len || line.buf[0] == '#') |
| 212 | continue; |
| 213 | if (is_absolute_path(line.buf)) { |
| 214 | odb_add_to_alternates_file(the_repository->objects, |
| 215 | line.buf); |
| 216 | continue; |
| 217 | } |
| 218 | abs_path = mkpathdup("%s/objects/%s", src_repo, line.buf); |
| 219 | if (!normalize_path_copy(abs_path, abs_path)) |
| 220 | odb_add_to_alternates_file(the_repository->objects, |
| 221 | abs_path); |
| 222 | else |
| 223 | warning("skipping invalid relative alternate: %s/%s", |
| 224 | src_repo, line.buf); |
| 225 | free(abs_path); |
| 226 | } |
| 227 | strbuf_release(&line); |
| 228 | fclose(in); |
| 229 | } |
| 230 | |
| 231 | static void mkdir_if_missing(const char *pathname, mode_t mode) |
| 232 | { |
no test coverage detected