attr.c: read .gitattributes from index as well.

This makes .gitattributes files to be read from the index when
they are not checked out to the work tree.  This is in line with
the way we always allowed low-level tools to operate in sparsely
checked out work tree in a reasonable way.

It swaps the order of new file creation and converting the blob
to work tree representation; otherwise when we are in the middle
of checking out .gitattributes we would notice an empty but
unwritten .gitattributes file in the work tree and will ignore
the copy in the index.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Junio C Hamano
2007-08-14 01:41:02 -07:00
parent a44131181a
commit 1a9d7e9b48
3 changed files with 150 additions and 11 deletions

19
entry.c
View File

@ -112,6 +112,16 @@ static int write_entry(struct cache_entry *ce, char *path, const struct checkout
if (!new)
return error("git-checkout-index: unable to read sha1 file of %s (%s)",
path, sha1_to_hex(ce->sha1));
/*
* Convert from git internal format to working tree format
*/
buf = convert_to_working_tree(ce->name, new, &size);
if (buf) {
free(new);
new = buf;
}
if (to_tempfile) {
strcpy(path, ".merge_file_XXXXXX");
fd = mkstemp(path);
@ -123,15 +133,6 @@ static int write_entry(struct cache_entry *ce, char *path, const struct checkout
path, strerror(errno));
}
/*
* Convert from git internal format to working tree format
*/
buf = convert_to_working_tree(ce->name, new, &size);
if (buf) {
free(new);
new = buf;
}
wrote = write_in_full(fd, new, size);
close(fd);
free(new);