summaryrefslogtreecommitdiff
path: root/csum-file.c
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2021-05-17 12:24:49 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-05-17 21:32:35 (GMT)
commit68142e117c080b7a563d681dc34c7df2ab945df5 (patch)
treeb11798c268e0a540e553acabb1219b99cb0773cc /csum-file.c
parentbf949ade81106fbda068c1fdb2c6fd1cb1babe7e (diff)
downloadgit-68142e117c080b7a563d681dc34c7df2ab945df5.zip
git-68142e117c080b7a563d681dc34c7df2ab945df5.tar.gz
git-68142e117c080b7a563d681dc34c7df2ab945df5.tar.bz2
hashfile: use write_in_full()
The flush() logic in csum-file.c was introduced originally by c38138c (git-pack-objects: write the pack files with a SHA1 csum, 2005-06-26) and a portion of the logic performs similar utility to write_in_full() in wrapper.c. The history of write_in_full() is full of moves and renames, but was originally introduced by 7230e6d (Add write_or_die(), a helper function, 2006-08-21). The point of these sections of code are to flush a write buffer using xwrite() and report errors in the case of disk space issues or other generic input/output errors. The logic in flush() can interpret the output of write_in_full() to provide the correct error messages to users. The logic in the hashfile API has an additional set of logic to augment the progress indicator between calls to xwrite(). This was introduced by 2a128d6 (add throughput display to git-push, 2007-10-30). It seems that since the hashfile's buffer is only 8KB, these additional progress indicators might not be incredibly necessary. Instead, update the progress only when write_in_full() complete. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'csum-file.c')
-rw-r--r--csum-file.c17
1 files changed, 5 insertions, 12 deletions
diff --git a/csum-file.c b/csum-file.c
index 7510950..3c26389 100644
--- a/csum-file.c
+++ b/csum-file.c
@@ -25,21 +25,14 @@ static void flush(struct hashfile *f, const void *buf, unsigned int count)
die("sha1 file '%s' validation error", f->name);
}
- for (;;) {
- int ret = xwrite(f->fd, buf, count);
- if (ret > 0) {
- f->total += ret;
- display_throughput(f->tp, f->total);
- buf = (char *) buf + ret;
- count -= ret;
- if (count)
- continue;
- return;
- }
- if (!ret)
+ if (write_in_full(f->fd, buf, count) < 0) {
+ if (errno == ENOSPC)
die("sha1 file '%s' write error. Out of diskspace", f->name);
die_errno("sha1 file '%s' write error", f->name);
}
+
+ f->total += count;
+ display_throughput(f->tp, f->total);
}
void hashflush(struct hashfile *f)