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

[PATCH] pack-refs: dereference .git/packed-refs if it is a symlink

From
PBPeter Baumann <waste.manager@gmx.de>
Date
Apr 18, 2007, 10:28 UTC
Message-ID
<20070418102823.GA5586@xp.machine.xx>
In-Reply-To
<7v7isajfl1.fsf@assigned-by-dhcp.cox.net>

git-new-workdir creates a new working directory where everything necessary, including .git/packed-refs, is symlinked to your master repo. But git-pack-refs breaks the symlink, so you could accidentally loose some refs. This fixes it to first dereference .git/packed-refs if it is a symlink.

Signed-off-by: Peter Baumann <waste.manager@gmx.de>
---
 builtin-pack-refs.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/builtin-pack-refs.c b/builtin-pack-refs.c
index d080e30..afa9b5a 100644
--- a/builtin-pack-refs.c
+++ b/builtin-pack-refs.c
@@ -89,6 +89,8 @@ int cmd_pack_refs(int argc, const char **argv, const char *prefix)
 {
 	int fd, i;
 	struct pack_refs_cb_data cbdata;
+	struct stat st;
+	char *ref_file_name;
 
 	memset(&cbdata, 0, sizeof(cbdata));
 
@@ -113,7 +115,18 @@ int cmd_pack_refs(int argc, const char **argv, const char *prefix)
 	if (i != argc)
 		usage(builtin_pack_refs_usage);
 
-	fd = hold_lock_file_for_update(&packed, git_path("packed-refs"), 1);
+	ref_file_name = git_path("packed-refs");
+	if (!lstat(ref_file_name, &st) && S_ISLNK(st.st_mode)) {
+		char *buf = xmalloc(st.st_size + 1);
+		if (readlink(ref_file_name, buf, st.st_size + 1) != st.st_size) {
+			free(buf);
+			die("readlink failed\n");
+		}
+		buf[st.st_size] = '\0';
+		ref_file_name = buf;
+	}
+
+	fd = hold_lock_file_for_update(&packed, ref_file_name, 1);
 	cbdata.refs_file = fdopen(fd, "w");
 	if (!cbdata.refs_file)
 		die("unable to create ref-pack file structure (%s)",
-- 
1.5.1
Previous: Julian PhillipsNext: Linus Torvalds
Message 20 of 22 in “[BUG] git-new-workdir doesn't understand packed refs”
  1. Peter BaumannApr 17, 2007
  2. Julian PhillipsApr 17, 2007
  3. Peter BaumannApr 18, 2007
  4. Julian PhillipsApr 18, 2007
  5. Junio C HamanoApr 18, 2007
  6. Peter BaumannApr 18, 2007
  7. Julian PhillipsApr 18, 2007
  8. Junio C HamanoApr 18, 2007
  9. Peter BaumannApr 18, 2007
  10. Junio C HamanoApr 18, 2007
  11. Peter BaumannApr 18, 2007
  12. Junio C HamanoApr 18, 2007
  13. Peter BaumannApr 18, 2007
  14. Junio C HamanoApr 18, 2007
  15. Add test for symlinked .git/packed-refsPeter Baumann, Apr 19, 2007
  16. Junio C HamanoApr 19, 2007
  17. pack-refs: dereference .git/packed-refs if it is a symlinkPeter Baumann, Apr 20, 2007
  18. Junio C HamanoApr 21, 2007
  19. Julian PhillipsApr 18, 2007
  20. pack-refs: dereference .git/packed-refs if it is a symlinkPeter Baumann, Apr 18, 2007
  21. Linus TorvaldsApr 18, 2007
  22. Peter BaumannApr 18, 2007

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.