summaryrefslogtreecommitdiff
path: root/src/fileops.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2012-09-11 12:03:33 -0700
committerRussell Belfer <rb@github.com>2012-09-11 12:03:33 -0700
commit1f35e89dbf6e0be8952cc4324a45fd600be5ca05 (patch)
tree0489cf363f6bb7484c5de0f998b1acf3f831881b /src/fileops.c
parentc6ac28fdc57d04a9a5eba129cfd267c7adde43b3 (diff)
downloadlibgit2-1f35e89dbf6e0be8952cc4324a45fd600be5ca05.tar.gz
Fix diff binary file detection
In the process of adding tests for the max file size threshold (which treats files over a certain size as binary) there seem to be a number of problems in the new code with detecting binaries. This should fix those up, as well as add a test for the file size threshold stuff. Also, this un-deprecates `GIT_DIFF_LINE_ADD_EOFNL`, since I finally found a legitimate situation where it would be returned.
Diffstat (limited to 'src/fileops.c')
-rw-r--r--src/fileops.c32
1 files changed, 9 insertions, 23 deletions
diff --git a/src/fileops.c b/src/fileops.c
index d4def1a9a..cbe3d4782 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -115,40 +115,26 @@ mode_t git_futils_canonical_mode(mode_t raw_mode)
return 0;
}
-#define MAX_READ_STALLS 10
-
int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len)
{
- int stalls = MAX_READ_STALLS;
+ ssize_t read_size;
git_buf_clear(buf);
if (git_buf_grow(buf, len + 1) < 0)
return -1;
- buf->ptr[len] = '\0';
-
- while (len > 0) {
- ssize_t read_size = p_read(fd, buf->ptr + buf->size, len);
-
- if (read_size < 0) {
- giterr_set(GITERR_OS, "Failed to read descriptor");
- return -1;
- }
-
- if (read_size == 0) {
- stalls--;
+ /* p_read loops internally to read len bytes */
+ read_size = p_read(fd, buf->ptr, len);
- if (!stalls) {
- giterr_set(GITERR_OS, "Too many stalls reading descriptor");
- return -1;
- }
- }
-
- len -= read_size;
- buf->size += read_size;
+ if (read_size < 0) {
+ giterr_set(GITERR_OS, "Failed to read descriptor");
+ return -1;
}
+ buf->ptr[read_size] = '\0';
+ buf->size = read_size;
+
return 0;
}