Skip to content

Commit

Permalink
builtin-blame.c: use strbuf_readlink()
Browse files Browse the repository at this point in the history
When faking a commit out of the work tree contents, use strbuf_readlink()
to read the contents of symbolic links.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Junio C Hamano committed Dec 17, 2008
1 parent 737e31a commit edfd45d
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions builtin-blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -1996,7 +1996,6 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
if (!contents_from || strcmp("-", contents_from)) {
struct stat st;
const char *read_from;
unsigned long fin_size;

if (contents_from) {
if (stat(contents_from, &st) < 0)
Expand All @@ -2008,17 +2007,15 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
die("Cannot lstat %s", path);
read_from = path;
}
fin_size = xsize_t(st.st_size);
mode = canon_mode(st.st_mode);
switch (st.st_mode & S_IFMT) {
case S_IFREG:
if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size)
die("cannot open or read %s", read_from);
break;
case S_IFLNK:
if (readlink(read_from, buf.buf, buf.alloc) != fin_size)
if (strbuf_readlink(&buf, read_from, st.st_size) < 0)
die("cannot readlink %s", read_from);
buf.len = fin_size;
break;
default:
die("unsupported file type %s", read_from);
Expand Down

0 comments on commit edfd45d

Please sign in to comment.