MCPcopy Create free account
hub / github.com/git/git / copy_alternates

Function copy_alternates

builtin/clone.c:192–229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

190}
191
192static 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
231static void mkdir_if_missing(const char *pathname, mode_t mode)
232{

Callers 1

copy_or_link_directoryFunction · 0.85

Calls 8

xfopenFunction · 0.85
strbuf_getlineFunction · 0.85
is_absolute_pathFunction · 0.85
mkpathdupFunction · 0.85
normalize_path_copyFunction · 0.85
warningFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected