Commits

Anonymous committed 9b143c6

Teach update-ref about a symbolic ref stored in a textfile.

A symbolic ref is a regular file whose contents is "ref:", followed by
optional leading whitespaces, followed by a GIT_DIR relative pathname,
followed by optional trailing whitespaces (the optional whitespaces
are unconditionally removed, so you cannot have leading nor trailing
whitespaces). This can be used in place of a traditional symbolic
link .git/HEAD that usually points at "refs/heads/master". You can
instead have a regular file .git/HEAD whose contents is
"ref: refs/heads/master".

[jc: currently the code does not enforce the symbolic ref to begin with
refs/, unlike the symbolic link case. It may be worthwhile to require
either case to begin with refs/ and not have any /./ nor /../ in them.]

Signed-off-by: Junio C Hamano <junkio@cox.net>

Comments (0)

Files changed (1)

 
 	for (;;) {
 		struct stat st;
+		char *buf;
 		int fd;
 
 		if (--depth < 0)
 			return NULL;
 		len = read(fd, buffer, sizeof(buffer)-1);
 		close(fd);
-		break;
+
+		/*
+		 * Is it a symbolic ref?
+		 */
+		if (len < 4 || memcmp("ref:", buffer, 4))
+			break;
+		buf = buffer + 4;
+		len -= 4;
+		while (len && isspace(*buf))
+			buf++, len--;
+		while (len && isspace(buf[len-1]))
+			buf[--len] = 0;
+		path = git_path("%.*s", len, buf);
 	}
 	if (len < 40 || get_sha1_hex(buffer, sha1))
 		return NULL;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.