@matheusbsbs / matheus-bagliano / commits / ccfd3e9962
Fork 0

[PATCH] Define relative .git/objects/info/alternates semantics.

An entry in the alternates file can name a directory relative to the object store it describes. A typical linux-2.6 maintainer repository would have "../../../torvalds/linux-2.6.git/objects" there, because the subsystem maintainer object store would live in /pub/scm/linux/kernel/git/$u/$system.git/objects/ and the object store of Linus tree is in /pub/scm/linux/kernel/git/torvalds/linux-2.6.git/objects/ This unfortunately is different from GIT_ALTERNATE_OBJECT_DIRECTORIES which is relative to the cwd of the running process, but there is no way to make it consistent with the behaviour of the environment variable. The process typically is run in $system.git/ directory for a naked repository, or one level up for a repository with a working tree, so we just define it to be relative to the objects/ directory to be different from either ;-). Later, the dumb transport could be updated to read from info/alternates and make requests for the repository the repository borrows from. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Sep 13, 2005 at 00:05 UTC ccfd3e99621f489db4ea37a03be7674adbd03f6e
1 file changed +22 -6
sha1_file.c
+22 -6
@@ -240,10 +240,12 @@ static struct alternate_object_database **alt_odb_tail;
240 * SHA1, an extra slash for the first level indirection, and the
241 * terminating NUL.
242 */
243 -static void link_alt_odb_entries(const char *alt, const char *ep, int sep)
243 +static void link_alt_odb_entries(const char *alt, const char *ep, int sep,
244 + const char *relative_base)
245 {
246 const char *cp, *last;
247 struct alternate_object_database *ent;
248 + int base_len = -1;
249
250 last = alt;
251 while (last < ep) {
@@ -261,12 +263,25 @@ static void link_alt_odb_entries(const char *alt, const char *ep, int sep)
263 int pfxlen = cp - last;
264 int entlen = pfxlen + 43;
265
266 + if (*last != '/' && relative_base) {
267 + /* Relative alt-odb */
268 + if (base_len < 0)
269 + base_len = strlen(relative_base) + 1;
270 + entlen += base_len;
271 + pfxlen += base_len;
272 + }
273 ent = xmalloc(sizeof(*ent) + entlen);
274 *alt_odb_tail = ent;
275 alt_odb_tail = &(ent->next);
276 ent->next = NULL;
268 -
269 - memcpy(ent->base, last, pfxlen);
277 + if (*last != '/' && relative_base) {
278 + memcpy(ent->base, relative_base, base_len - 1);
279 + ent->base[base_len - 1] = '/';
280 + memcpy(ent->base + base_len,
281 + last, cp - last);
282 + }
283 + else
284 + memcpy(ent->base, last, pfxlen);
285 ent->name = ent->base + pfxlen + 1;
286 ent->base[pfxlen] = ent->base[pfxlen + 3] = '/';
287 ent->base[entlen-1] = 0;
@@ -288,12 +303,12 @@ void prepare_alt_odb(void)
303 alt = getenv(ALTERNATE_DB_ENVIRONMENT);
304 if (!alt) alt = "";
305
291 - sprintf(path, "%s/info/alternates", get_object_directory());
306 if (alt_odb_tail)
307 return;
308 alt_odb_tail = &alt_odb_list;
295 - link_alt_odb_entries(alt, alt + strlen(alt), ':');
309 + link_alt_odb_entries(alt, alt + strlen(alt), ':', NULL);
310
311 + sprintf(path, "%s/info/alternates", get_object_directory());
312 fd = open(path, O_RDONLY);
313 if (fd < 0)
314 return;
@@ -306,7 +321,8 @@ void prepare_alt_odb(void)
321 if (map == MAP_FAILED)
322 return;
323
309 - link_alt_odb_entries(map, map + st.st_size, '\n');
324 + link_alt_odb_entries(map, map + st.st_size, '\n',
325 + get_object_directory());
326 munmap(map, st.st_size);
327 }
328