git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Lars Hjemli <hjemli@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 1/5] Add platform-independent .git "symlink"
Date: Sun, 17 Feb 2008 21:43:34 -0800	[thread overview]
Message-ID: <7v7ih2u8e1.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: 1203286456-26033-2-git-send-email-hjemli@gmail.com

Lars Hjemli <hjemli@gmail.com> writes:

> 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.

Hmmmm.  I have suspected all along that these "platforms lacking
support for real symlinks" are the ones whose native line
termination convention is CRLF.  How do you envision this file
is initialized?  By users editing the file by hand?  Or some git
specific tool?  If the former, it might make sense to define the
format as "a single line, terminated with platform line
terminator" and open and read it in text mode.  If the latter,
we do not have to care, and "terminated with LF" is good enough.

I think a sane simplification is to allow the file to have
any number of optional \r or \n at the end.  We may care about
allowing arbitrary and possibly crazy filenames in the tracked
contents, but we can say "Sorry, you cannot create a directory
'ab\nc\r' and use it as the .git directory substitute."

> +const char *read_gitfile_gently(const char *path)
> +{
> +	static char buf[PATH_MAX + 9];  /* "gitdir: " + "\n" */
> +	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;

Up to this point it is fine "gently" semantics.

> +	len = read_in_full(fd, buf, sizeof(buf));
> +	close(fd);
> +	if (len != st.st_size)
> +		return NULL;
> +	if (!len || buf[len - 1] != '\n')
> +		return NULL;
> +	buf[len - 1] = '\0';
> +	if (prefixcmp(buf, "gitdir: "))
> +		return NULL;

But I am not sure about this part.  We found what claims to be
the ".git" fake symlink but it is ill-formed.  Don't we want to
diagnose the possible breakage for the user?

> +/*
> +	if (!is_git_directory(buf + 8))
> +		return NULL;
> +*/

Likewise.

  parent reply	other threads:[~2008-02-18  5:44 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-17 22:14 Intoducing the .git file (again) Lars Hjemli
2008-02-17 22:14 ` [PATCH 1/5] Add platform-independent .git "symlink" Lars Hjemli
2008-02-17 22:14   ` [PATCH 2/5] Fix setup of $GIT_DIR in git-sh-setup.sh Lars Hjemli
2008-02-17 22:14     ` [PATCH 3/5] Teach resolve_gitlink_ref() about the .git file Lars Hjemli
2008-02-17 22:14       ` [PATCH 4/5] git-submodule: prepare for the .git-file Lars Hjemli
2008-02-17 22:14         ` [PATCH 5/5] Teach GIT-VERSION-GEN about the .git file Lars Hjemli
2008-02-18  5:44     ` [PATCH 2/5] Fix setup of $GIT_DIR in git-sh-setup.sh Junio C Hamano
2008-02-18  8:41       ` Lars Hjemli
2008-02-17 22:25   ` [PATCH 1/5] Add platform-independent .git "symlink" Johannes Schindelin
2008-02-17 22:37     ` Lars Hjemli
2008-02-17 22:50       ` Lars Hjemli
2008-02-18  5:43   ` Junio C Hamano [this message]
2008-02-18  8:35     ` Lars Hjemli
2008-02-18 11:45       ` Johannes Schindelin
2008-02-17 22:20 ` Intoducing the .git file (again) Johannes Schindelin
2008-02-17 22:29   ` Lars Hjemli
2008-02-17 23:27     ` 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=7v7ih2u8e1.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=hjemli@gmail.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).