Subject: [PATCH v2 18/21] refs: adjust reflog path for repos/<id>/HEAD

From: Nguyễn Thái Ngọc Duy <[email-masked]>
Date: Sat, 14 Dec 2013 17:55:04 +0700

Signed-off-by: Nguyễn Thái Ngọc Duy <[email-masked]>
---
 refs.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/refs.c b/refs.c
index 5e5a382..3691ef5 100644
--- a/refs.c
+++ b/refs.c
@@ -2676,13 +2676,24 @@ static int copy_msg(char *buf, const char *msg)
 int log_ref_setup(const char *refname, char *logfile, int bufsize)
 {
 	int logfd, oflags = O_APPEND | O_WRONLY;
+	const char *p = NULL;
 
-	git_snpath(logfile, bufsize, "logs/%s", refname);
+	/*
+	 * reflog of repos/XXX/HEAD is repos/XXX/logs/HEAD, not
+	 * refs/repos/XXX/HEAD
+	 */
+	if (!strncmp(refname, "repos/", 6) &&
+	    (p = strchr(refname + 6, '/')) != 0)
+		git_snpath(logfile, bufsize, "%.*s/logs/%s",
+			   (int)(p - refname), refname, p + 1);
+	else
+		git_snpath(logfile, bufsize, "logs/%s", refname);
 	if (log_all_ref_updates &&
 	    (!prefixcmp(refname, "refs/heads/") ||
 	     !prefixcmp(refname, "refs/remotes/") ||
 	     !prefixcmp(refname, "refs/notes/") ||
-	     !strcmp(refname, "HEAD"))) {
+	     !strcmp(refname, "HEAD") ||
+	     (p && !strcmp(p + 1, "HEAD")))) {
 		if (safe_create_leading_directories(logfile) < 0)
 			return error("unable to create directory for %s",
 				     logfile);
-- 
1.8.5.1.77.g42c48fa