git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Peter Baumann <waste.manager@gmx.de>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: [PATCH] pack-refs: dereference .git/packed-refs if it is a symlink
Date: Wed, 18 Apr 2007 12:28:23 +0200	[thread overview]
Message-ID: <20070418102823.GA5586@xp.machine.xx> (raw)
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

  parent reply	other threads:[~2007-04-18 10:28 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-17 16:17 [BUG] git-new-workdir doesn't understand packed refs Peter Baumann
2007-04-17 21:55 ` Julian Phillips
2007-04-18  5:52   ` Peter Baumann
2007-04-18  7:26     ` Julian Phillips
2007-04-18  7:40     ` Junio C Hamano
2007-04-18  8:11       ` Peter Baumann
2007-04-18 11:55         ` Julian Phillips
2007-04-18 16:23           ` Junio C Hamano
2007-04-18 17:43             ` Peter Baumann
2007-04-18 18:17               ` Junio C Hamano
2007-04-18 18:31                 ` Peter Baumann
2007-04-18 18:42                   ` Junio C Hamano
2007-04-18 21:08                     ` Peter Baumann
2007-04-18 21:31                       ` Junio C Hamano
2007-04-19  5:35                         ` [PATCH] Add test for symlinked .git/packed-refs Peter Baumann
2007-04-19  6:06                           ` Junio C Hamano
2007-04-20 16:52                             ` [PATCH] pack-refs: dereference .git/packed-refs if it is a symlink Peter Baumann
2007-04-21 20:05                               ` Junio C Hamano
2007-04-18 18:43                   ` [BUG] git-new-workdir doesn't understand packed refs Julian Phillips
2007-04-18 10:28       ` Peter Baumann [this message]
2007-04-18 16:09         ` [PATCH] pack-refs: dereference .git/packed-refs if it is a symlink Linus Torvalds
2007-04-18 17:47           ` Peter Baumann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070418102823.GA5586@xp.machine.xx \
    --to=waste.manager@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).