git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <junkio@cox.net>
Date
Sep 13, 2005, 07:05 UTC
Message-ID
<7vk6hl4fd9.fsf_-_@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.58.0509112038020.3242@g5.osdl.org>
Linus Torvalds <torvalds@osdl.org> writes:
Show 9 quoted lines
> Yes. We should probably have some well-defined meaning for relative paths
> in there regardless (eg just define that they are always relative to the
> main GIT_OBJECT_DIRECTORY or something).
>
> That would also allow mirrors to mirror the git archives in different 
> places, without upsetting the result (as long as they are mirrored 
> together).
>
> 		Linus

This patch is request-for-comments. I have experimented it and have a feeling that it may be more intuitive to make it relative to $project.git/ directory, instead of $project.git/objects as you originally suggested, in which case a maintainer tree would have "../../torvalds/linux-2.6.git/objects" instead (one less dotdot), and if nobody objects that is probably what I'll end up doing.

------------ 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>
---
 sha1_file.c |   28 ++++++++++++++++++++++------
 1 files changed, 22 insertions(+), 6 deletions(-)
e2e8a0ba5fc80368bf46c615276e406dd373729c
diff --git a/sha1_file.c b/sha1_file.c
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -240,10 +240,12 @@ static struct alternate_object_database 
  * SHA1, an extra slash for the first level indirection, and the
  * terminating NUL.
  */
-static void link_alt_odb_entries(const char *alt, const char *ep, int sep)
+static void link_alt_odb_entries(const char *alt, const char *ep, int sep,
+				 const char *relative_base)
 {
 	const char *cp, *last;
 	struct alternate_object_database *ent;
+	int base_len = -1;
 
 	last = alt;
 	while (last < ep) {
@@ -261,12 +263,25 @@ static void link_alt_odb_entries(const c
 			int pfxlen = cp - last;
 			int entlen = pfxlen + 43;
 
+			if (*last != '/' && relative_base) {
+				/* Relative alt-odb */
+				if (base_len < 0)
+					base_len = strlen(relative_base) + 1;
+				entlen += base_len;
+				pfxlen += base_len;
+			}
 			ent = xmalloc(sizeof(*ent) + entlen);
 			*alt_odb_tail = ent;
 			alt_odb_tail = &(ent->next);
 			ent->next = NULL;
-
-			memcpy(ent->base, last, pfxlen);
+			if (*last != '/' && relative_base) {
+				memcpy(ent->base, relative_base, base_len - 1);
+				ent->base[base_len - 1] = '/';
+				memcpy(ent->base + base_len,
+				       last, cp - last);
+			}
+			else
+				memcpy(ent->base, last, pfxlen);
 			ent->name = ent->base + pfxlen + 1;
 			ent->base[pfxlen] = ent->base[pfxlen + 3] = '/';
 			ent->base[entlen-1] = 0;
@@ -288,12 +303,12 @@ void prepare_alt_odb(void)
 	alt = getenv(ALTERNATE_DB_ENVIRONMENT);
 	if (!alt) alt = "";
 
-	sprintf(path, "%s/info/alternates", get_object_directory());
 	if (alt_odb_tail)
 		return;
 	alt_odb_tail = &alt_odb_list;
-	link_alt_odb_entries(alt, alt + strlen(alt), ':');
+	link_alt_odb_entries(alt, alt + strlen(alt), ':', NULL);
 
+	sprintf(path, "%s/info/alternates", get_object_directory());
 	fd = open(path, O_RDONLY);
 	if (fd < 0)
 		return;
@@ -306,7 +321,8 @@ void prepare_alt_odb(void)
 	if (map == MAP_FAILED)
 		return;
 
-	link_alt_odb_entries(map, map + st.st_size, '\n');
+	link_alt_odb_entries(map, map + st.st_size, '\n',
+			     get_object_directory());
 	munmap(map, st.st_size);
 }
 
Previous: Linus TorvaldsNext: Linus Torvalds
Message 11 of 18 in “Re: What's up with the GIT archive on www.kernel.org?”
  1. Linus TorvaldsSep 11, 2005
  2. Sam RavnborgSep 11, 2005
  3. Linus TorvaldsSep 11, 2005
  4. Roland DreierSep 11, 2005
  5. Linus TorvaldsSep 11, 2005
  6. Linus TorvaldsSep 11, 2005
  7. Junio C HamanoSep 12, 2005
  8. Dmitry TorokhovSep 12, 2005
  9. Ryan AndersonSep 12, 2005
  10. Linus TorvaldsSep 12, 2005
  11. Define relative .git/objects/info/alternates semantics.Junio C Hamano, Sep 13, 2005
  12. Linus TorvaldsSep 13, 2005
  13. Junio C HamanoSep 13, 2005
  14. Daniel BarkalowSep 13, 2005
  15. H. Peter AnvinSep 12, 2005
  16. Tony LuckSep 12, 2005
  17. Linus TorvaldsSep 12, 2005
  18. Junio C HamanoSep 11, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.