Skip to content

Commit

Permalink
Teach transport about the gitfile mechanism
Browse files Browse the repository at this point in the history
The transport_get() function assumes that a regular file is a
bundle rather than a local git directory. Look inside the file
for the telltale "gitlink: " header to see if it is actually a
gitfile.  If so, do not try to process it as a bundle, but
treat it as a local repository instead.

Signed-off-by: Phil Hord <hordp@cisco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Phil Hord authored and Junio C Hamano committed Oct 4, 2011
1 parent 0310676 commit 7ab8777
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,28 @@ static int is_local(const char *url)
has_dos_drive_prefix(url);
}

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: ");
}

static int is_file(const char *url)
{
struct stat buf;
Expand Down Expand Up @@ -914,7 +936,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
ret->fetch = fetch_objs_via_rsync;
ret->push = rsync_transport_push;
ret->smart_options = NULL;
} else if (is_local(url) && is_file(url)) {
} else if (is_local(url) && is_file(url) && !is_gitfile(url)) {
struct bundle_transport_data *data = xcalloc(1, sizeof(*data));
ret->data = data;
ret->get_refs_list = get_refs_from_bundle;
Expand Down

0 comments on commit 7ab8777

Please sign in to comment.