- if (!one->sha1_valid)
- strcpy(temp->hex, sha1_to_hex(null_sha1));
- else
- strcpy(temp->hex, sha1_to_hex(one->blob_sha1));
- sprintf(temp->mode, "%06o",
- S_IFREG |ce_permissions(st.st_mode));
+ if (S_ISLNK(st.st_mode)) {
+ int ret;
+ char *buf, buf_[1024];
+ buf = ((sizeof(buf_) < st.st_size) ?
+ xmalloc(st.st_size) : buf_);
+ ret = readlink(name, buf, st.st_size);
+ if (ret < 0)
+ die("readlink(%s)", name);
+ prep_temp_blob(temp, buf, st.st_size,
+ (one->sha1_valid ?
+ one->blob_sha1 : null_sha1),
+ (one->sha1_valid ?
+ one->mode : S_IFLNK));
+ }
+ else {
+ if (!one->sha1_valid)
+ strcpy(temp->hex, sha1_to_hex(null_sha1));
+ else
+ strcpy(temp->hex, sha1_to_hex(one->blob_sha1));
+ sprintf(temp->mode, "%06o",
+ S_IFREG |ce_permissions(st.st_mode));
+ }
+ return;