X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=entry.c;h=d72f811580ad10e792e38b40fe79bf4af3868846;hb=ced38ea252cb8b0315f4d2a54648b11c6c090657;hp=b2ea0efa82e1a0511fe5aa798618c23827b59bab;hpb=3fbe2d54d7d91378934df7b16d70dc5877586fae;p=git.git diff --git a/entry.c b/entry.c index b2ea0efa8..d72f81158 100644 --- a/entry.c +++ b/entry.c @@ -1,5 +1,3 @@ -#include -#include #include "cache.h" #include "blob.h" @@ -70,16 +68,19 @@ static int write_entry(struct cache_entry *ce, char *path, struct checkout *stat void *new; unsigned long size; long wrote; - char type[20]; + enum object_type type; - new = read_sha1_file(ce->sha1, type, &size); - if (!new || strcmp(type, blob_type)) { + new = read_sha1_file(ce->sha1, &type, &size); + if (!new || type != OBJ_BLOB) { if (new) free(new); return error("git-checkout-index: unable to read sha1 file of %s (%s)", path, sha1_to_hex(ce->sha1)); } switch (ntohl(ce->ce_mode) & S_IFMT) { + char *buf; + unsigned long nsize; + case S_IFREG: if (to_tempfile) { strcpy(path, ".merge_file_XXXXXX"); @@ -91,22 +92,37 @@ static int write_entry(struct cache_entry *ce, char *path, struct checkout *stat return error("git-checkout-index: unable to create file %s (%s)", path, strerror(errno)); } - wrote = write(fd, new, size); + + /* + * Convert from git internal format to working tree format + */ + buf = new; + nsize = size; + if (convert_to_working_tree(ce->name, &buf, &nsize)) { + free(new); + new = buf; + size = nsize; + } + + wrote = write_in_full(fd, new, size); close(fd); free(new); if (wrote != size) return error("git-checkout-index: unable to write file %s", path); break; case S_IFLNK: - if (to_tempfile) { - strcpy(path, ".merge_link_XXXXXX"); - fd = mkstemp(path); + if (to_tempfile || !has_symlinks) { + if (to_tempfile) { + strcpy(path, ".merge_link_XXXXXX"); + fd = mkstemp(path); + } else + fd = create_file(path, 0666); if (fd < 0) { free(new); return error("git-checkout-index: unable to create " "file %s (%s)", path, strerror(errno)); } - wrote = write(fd, new, size); + wrote = write_in_full(fd, new, size); close(fd); free(new); if (wrote != size)