Re: [PATCH 3/4] Teach transport about the gitfile mechanism
- From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
- Date
- Oct 4, 2011, 21:46 UTC
- Message-ID
- <CACsJy8AtUWbuXVQxA7jT7rQmAzPpd72trqcSH_6X=P0FBU1vwQ@mail.gmail.com>
- In-Reply-To
- <CABURp0qkVcpNRyEg8gcNPjv2KbRbdHYk1XsqCjkp8Yrf7T_Lkw@mail.gmail.com>
On Wed, Oct 5, 2011 at 7:08 AM, Phil Hord <phil.hord@gmail.com> wrote:
Show 22 quoted lines
> +static int is_gitfile(const char *url)
> +{
> + struct stat st;
> + char buf[9];
> + int fd, len;
> + if (stat(url, &st))
> + return 0;
> + if (!S_ISREG(st.st_mode))
> + return 0;
> + if (st.st_size < 10 || st.st_size > PATH_MAX)
> + return 1;
> +
> + fd = open(url, O_RDONLY);
> + if (fd < 0)
> + die_errno("Error opening '%s'", url);
> + len = read_in_full(fd, buf, sizeof(buf));
> + close(fd);
> + if (len != sizeof(buf))
> + die("Error reading %s", url);
> + return !prefixcmp(buf, "gitdir: ");
> +}
> +There's similar code in get_repo_path(), builtin/clone.c, added in commit 9b0ebc7 (clone: allow to clone from .git file). Perhaps you can reuse this function there and remove duplicate code.
-- Duy