Skip to content

Commit 7616c6c

Browse files
pcloudsgitster
authored andcommitted
sha1_file.c: use {error,die,warning}_errno()
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 02382f5 commit 7616c6c

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

sha1_file.c

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,9 +1107,8 @@ unsigned char *use_pack(struct packed_git *p,
11071107
PROT_READ, MAP_PRIVATE,
11081108
p->pack_fd, win->offset);
11091109
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);
11131112
if (!win->offset && win->len == p->pack_size
11141113
&& !p->do_not_close)
11151114
close_pack_fd(p);
@@ -1279,8 +1278,8 @@ static void prepare_packed_git_one(char *objdir, int local)
12791278
dir = opendir(path.buf);
12801279
if (!dir) {
12811280
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);
12841283
strbuf_release(&path);
12851284
return;
12861285
}
@@ -2984,7 +2983,7 @@ int finalize_object_file(const char *tmpfile, const char *filename)
29842983
unlink_or_warn(tmpfile);
29852984
if (ret) {
29862985
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);
29882987
}
29892988
/* FIXME!!! Collision check here ? */
29902989
}
@@ -2998,7 +2997,7 @@ int finalize_object_file(const char *tmpfile, const char *filename)
29982997
static int write_buffer(int fd, const void *buf, size_t len)
29992998
{
30002999
if (write_in_full(fd, buf, len) < 0)
3001-
return error("file write error (%s)", strerror(errno));
3000+
return error_errno("file write error");
30023001
return 0;
30033002
}
30043003

@@ -3081,7 +3080,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
30813080
if (errno == EACCES)
30823081
return error("insufficient permission for adding an object to repository database %s", get_object_directory());
30833082
else
3084-
return error("unable to create temporary file: %s", strerror(errno));
3083+
return error_errno("unable to create temporary file");
30853084
}
30863085

30873086
/* Set it up */
@@ -3126,8 +3125,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
31263125
utb.actime = mtime;
31273126
utb.modtime = mtime;
31283127
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);
31313129
}
31323130

31333131
return finalize_object_file(tmp_file.buf, filename);
@@ -3360,7 +3358,7 @@ static int index_core(unsigned char *sha1, int fd, size_t size,
33603358
if (size == read_in_full(fd, buf, size))
33613359
ret = index_mem(sha1, buf, size, type, path, flags);
33623360
else
3363-
ret = error("short read %s", strerror(errno));
3361+
ret = error_errno("short read");
33643362
free(buf);
33653363
} else {
33663364
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
34253423
case S_IFREG:
34263424
fd = open(path, O_RDONLY);
34273425
if (fd < 0)
3428-
return error("open(\"%s\"): %s", path,
3429-
strerror(errno));
3426+
return error_errno("open(\"%s\")", path);
34303427
if (index_fd(sha1, fd, st, OBJ_BLOB, path, flags) < 0)
34313428
return error("%s: failed to insert into database",
34323429
path);
34333430
break;
34343431
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);
34403434
if (!(flags & HASH_WRITE_OBJECT))
34413435
hash_sha1_file(sb.buf, sb.len, blob_type, sha1);
34423436
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,
34923486
if (!dir) {
34933487
if (errno == ENOENT)
34943488
return 0;
3495-
return error("unable to open %s: %s", path->buf, strerror(errno));
3489+
return error_errno("unable to open %s", path->buf);
34963490
}
34973491

34983492
while ((de = readdir(dir))) {

0 commit comments

Comments
 (0)