From: Lars Hjemli <hjemli@gmail.com>
To: Junio C Hamano <gitster@pobox.com>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: git@vger.kernel.org
Subject: [PATCH] Add platform-independent .git "symlink"
Date: Sat, 2 Feb 2008 19:09:17 +0100 [thread overview]
Message-ID: <1201975757-13771-1-git-send-email-hjemli@gmail.com> (raw)
In-Reply-To: <8c5c35580802020959v613b9e32v321e97f93f2af761@mail.gmail.com>
This patch allows .git to be a regular textfile containing the path of
the real git directory (formatted like "GITDIR: <path>\n"), which is
useful on platforms lacking support for real symlinks.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
setup.c | 38 ++++++++++++++++++++++++++++++++++++++
1 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/setup.c b/setup.c
index adede16..45a78c4 100644
--- a/setup.c
+++ b/setup.c
@@ -239,6 +239,38 @@ static int check_repository_format_gently(int *nongit_ok)
}
/*
+ * Try to read the location of the git directory from the .git file,
+ * return path to git directory if found.
+ * Format of the .git file is
+ * GITDIR: <path>\n
+ */
+static const char *read_gitfile_gently(const char *path)
+{
+ static char buf[PATH_MAX + 10]; /* "GITDIR: " + "\n" + "\0" */
+ struct stat st;
+ int fd;
+ size_t len;
+
+ if (stat(path, &st))
+ return NULL;
+ if (!S_ISREG(st.st_mode) || st.st_size >= sizeof(buf))
+ return NULL;
+ fd = open(path, O_RDONLY);
+ if (fd < 0)
+ return NULL;
+ len = read_in_full(fd, buf, sizeof(buf));
+ close(fd);
+ if (len != st.st_size)
+ return NULL;
+ if (len < 10 || buf[len - 1] != '\n' || strncmp(buf, "GITDIR: ", 8))
+ return NULL;
+ buf[len - 1] = '\0';
+ if (!is_git_directory(buf + 8))
+ return NULL;
+ return make_absolute_path(buf + 8);
+}
+
+/*
* We cannot decide in this function whether we are in the work tree or
* not, since the config can only be read _after_ this function was called.
*/
@@ -247,6 +279,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
const char *work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT);
static char cwd[PATH_MAX+1];
const char *gitdirenv;
+ const char *gitfile_dir;
int len, offset;
/*
@@ -302,6 +335,11 @@ const char *setup_git_directory_gently(int *nongit_ok)
*/
offset = len = strlen(cwd);
for (;;) {
+ gitfile_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
+ if (gitfile_dir) {
+ setenv(GIT_DIR_ENVIRONMENT, gitfile_dir, 1);
+ break;
+ }
if (is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT))
break;
if (is_git_directory(".")) {
--
1.5.4.4.gd2e29
next prev parent reply other threads:[~2008-02-02 18:11 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-02 10:36 [PATCH] Add platform-independent .git "symlink" Lars Hjemli
2008-02-02 15:02 ` [PATCH] Add tests for .git file Lars Hjemli
2008-02-02 15:56 ` [PATCH] Add platform-independent .git "symlink" Johannes Schindelin
2008-02-02 17:59 ` Lars Hjemli
2008-02-02 18:09 ` Lars Hjemli [this message]
2008-02-02 18:19 ` Johannes Schindelin
2008-02-02 18:34 ` Johannes Schindelin
2008-02-04 1:57 ` Shawn O. Pearce
2008-02-04 3:05 ` Junio C Hamano
2008-02-04 14:34 ` Johannes Schindelin
2008-02-04 21:17 ` Brandon Casey
2008-02-04 21:31 ` Johannes Schindelin
2008-02-04 22:08 ` Brandon Casey
2008-02-04 22:19 ` Johannes Schindelin
2008-02-04 22:44 ` Brandon Casey
2008-02-04 22:56 ` Brandon Casey
2008-02-05 0:51 ` Johannes Schindelin
2008-02-05 0:49 ` Johannes Schindelin
2008-02-05 2:42 ` Brandon Casey
2008-02-05 12:57 ` Johannes Schindelin
2008-02-02 18:47 ` Lars Hjemli
2008-02-03 1:55 ` Johannes Schindelin
2008-02-04 0:07 ` Junio C Hamano
2008-02-04 0:24 ` Johannes Schindelin
2008-02-04 1:35 ` Shawn O. Pearce
2008-02-04 1:45 ` Junio C Hamano
2008-02-04 2:00 ` Shawn O. Pearce
2008-02-04 11:59 ` Lars Hjemli
2008-02-04 14:36 ` Johannes Schindelin
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1201975757-13771-1-git-send-email-hjemli@gmail.com \
--to=hjemli@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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.
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 NNTP newsgroup(s).