sha1_file.c: use {error,die,warning}_errno()

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed May 8, 2016 at 16:47 UTC 7616c6ca9d3559a1768b7293c64c5a39e73bd365
1 file changed +13 -19
sha1_file.c
+13 -19
@@ -1107,9 +1107,8 @@ unsigned char *use_pack(struct packed_git *p,
1107 PROT_READ, MAP_PRIVATE,
1108 p->pack_fd, win->offset);
1109 if (win->base == MAP_FAILED)
1110 - die("packfile %s cannot be mapped: %s",
1111 - p->pack_name,
1112 - strerror(errno));
1110 + die_errno("packfile %s cannot be mapped",
1111 + p->pack_name);
1112 if (!win->offset && win->len == p->pack_size
1113 && !p->do_not_close)
1114 close_pack_fd(p);
@@ -1279,8 +1278,8 @@ static void prepare_packed_git_one(char *objdir, int local)
1278 dir = opendir(path.buf);
1279 if (!dir) {
1280 if (errno != ENOENT)
1282 - error("unable to open object pack directory: %s: %s",
1283 - path.buf, strerror(errno));
1281 + error_errno("unable to open object pack directory: %s",
1282 + path.buf);
1283 strbuf_release(&path);
1284 return;
1285 }
@@ -2984,7 +2983,7 @@ int finalize_object_file(const char *tmpfile, const char *filename)
2983 unlink_or_warn(tmpfile);
2984 if (ret) {
2985 if (ret != EEXIST) {
2987 - return error("unable to write sha1 filename %s: %s", filename, strerror(ret));
2986 + return error_errno("unable to write sha1 filename %s", filename);
2987 }
2988 /* FIXME!!! Collision check here ? */
2989 }
@@ -2998,7 +2997,7 @@ out:
2997 static int write_buffer(int fd, const void *buf, size_t len)
2998 {
2999 if (write_in_full(fd, buf, len) < 0)
3001 - return error("file write error (%s)", strerror(errno));
3000 + return error_errno("file write error");
3001 return 0;
3002 }
3003
@@ -3081,7 +3080,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
3080 if (errno == EACCES)
3081 return error("insufficient permission for adding an object to repository database %s", get_object_directory());
3082 else
3084 - return error("unable to create temporary file: %s", strerror(errno));
3083 + return error_errno("unable to create temporary file");
3084 }
3085
3086 /* Set it up */
@@ -3126,8 +3125,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
3125 utb.actime = mtime;
3126 utb.modtime = mtime;
3127 if (utime(tmp_file.buf, &utb) < 0)
3129 - warning("failed utime() on %s: %s",
3130 - tmp_file.buf, strerror(errno));
3128 + warning_errno("failed utime() on %s", tmp_file.buf);
3129 }
3130
3131 return finalize_object_file(tmp_file.buf, filename);
@@ -3360,7 +3358,7 @@ static int index_core(unsigned char *sha1, int fd, size_t size,
3358 if (size == read_in_full(fd, buf, size))
3359 ret = index_mem(sha1, buf, size, type, path, flags);
3360 else
3363 - ret = error("short read %s", strerror(errno));
3361 + ret = error_errno("short read");
3362 free(buf);
3363 } else {
3364 void *buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
@@ -3425,18 +3423,14 @@ int index_path(unsigned char *sha1, const char *path, struct stat *st, unsigned
3423 case S_IFREG:
3424 fd = open(path, O_RDONLY);
3425 if (fd < 0)
3428 - return error("open(\"%s\"): %s", path,
3429 - strerror(errno));
3426 + return error_errno("open(\"%s\")", path);
3427 if (index_fd(sha1, fd, st, OBJ_BLOB, path, flags) < 0)
3428 return error("%s: failed to insert into database",
3429 path);
3430 break;
3431 case S_IFLNK:
3435 - if (strbuf_readlink(&sb, path, st->st_size)) {
3436 - char *errstr = strerror(errno);
3437 - return error("readlink(\"%s\"): %s", path,
3438 - errstr);
3439 - }
3432 + if (strbuf_readlink(&sb, path, st->st_size))
3433 + return error_errno("readlink(\"%s\")", path);
3434 if (!(flags & HASH_WRITE_OBJECT))
3435 hash_sha1_file(sb.buf, sb.len, blob_type, sha1);
3436 else if (write_sha1_file(sb.buf, sb.len, blob_type, sha1))
@@ -3492,7 +3486,7 @@ static int for_each_file_in_obj_subdir(int subdir_nr,
3486 if (!dir) {
3487 if (errno == ENOENT)
3488 return 0;
3495 - return error("unable to open %s: %s", path->buf, strerror(errno));
3489 + return error_errno("unable to open %s", path->buf);
3490 }
3491
3492 while ((de = readdir(dir))) {