Browse Source

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>
maint
Nguyễn Thái Ngọc Duy 9 years ago committed by Junio C Hamano
parent
commit
7616c6ca9d
  1. 32
      sha1_file.c

32
sha1_file.c

@ -1107,9 +1107,8 @@ unsigned char *use_pack(struct packed_git *p,
PROT_READ, MAP_PRIVATE, PROT_READ, MAP_PRIVATE,
p->pack_fd, win->offset); p->pack_fd, win->offset);
if (win->base == MAP_FAILED) if (win->base == MAP_FAILED)
die("packfile %s cannot be mapped: %s", die_errno("packfile %s cannot be mapped",
p->pack_name, p->pack_name);
strerror(errno));
if (!win->offset && win->len == p->pack_size if (!win->offset && win->len == p->pack_size
&& !p->do_not_close) && !p->do_not_close)
close_pack_fd(p); close_pack_fd(p);
@ -1279,8 +1278,8 @@ static void prepare_packed_git_one(char *objdir, int local)
dir = opendir(path.buf); dir = opendir(path.buf);
if (!dir) { if (!dir) {
if (errno != ENOENT) if (errno != ENOENT)
error("unable to open object pack directory: %s: %s", error_errno("unable to open object pack directory: %s",
path.buf, strerror(errno)); path.buf);
strbuf_release(&path); strbuf_release(&path);
return; return;
} }
@ -2984,7 +2983,7 @@ int finalize_object_file(const char *tmpfile, const char *filename)
unlink_or_warn(tmpfile); unlink_or_warn(tmpfile);
if (ret) { if (ret) {
if (ret != EEXIST) { if (ret != EEXIST) {
return error("unable to write sha1 filename %s: %s", filename, strerror(ret)); return error_errno("unable to write sha1 filename %s", filename);
} }
/* FIXME!!! Collision check here ? */ /* FIXME!!! Collision check here ? */
} }
@ -2998,7 +2997,7 @@ out:
static int write_buffer(int fd, const void *buf, size_t len) static int write_buffer(int fd, const void *buf, size_t len)
{ {
if (write_in_full(fd, buf, len) < 0) if (write_in_full(fd, buf, len) < 0)
return error("file write error (%s)", strerror(errno)); return error_errno("file write error");
return 0; return 0;
} }


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


/* Set it up */ /* Set it up */
@ -3126,8 +3125,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
utb.actime = mtime; utb.actime = mtime;
utb.modtime = mtime; utb.modtime = mtime;
if (utime(tmp_file.buf, &utb) < 0) if (utime(tmp_file.buf, &utb) < 0)
warning("failed utime() on %s: %s", warning_errno("failed utime() on %s", tmp_file.buf);
tmp_file.buf, strerror(errno));
} }


return finalize_object_file(tmp_file.buf, filename); return finalize_object_file(tmp_file.buf, filename);
@ -3360,7 +3358,7 @@ static int index_core(unsigned char *sha1, int fd, size_t size,
if (size == read_in_full(fd, buf, size)) if (size == read_in_full(fd, buf, size))
ret = index_mem(sha1, buf, size, type, path, flags); ret = index_mem(sha1, buf, size, type, path, flags);
else else
ret = error("short read %s", strerror(errno)); ret = error_errno("short read");
free(buf); free(buf);
} else { } else {
void *buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); 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
case S_IFREG: case S_IFREG:
fd = open(path, O_RDONLY); fd = open(path, O_RDONLY);
if (fd < 0) if (fd < 0)
return error("open(\"%s\"): %s", path, return error_errno("open(\"%s\")", path);
strerror(errno));
if (index_fd(sha1, fd, st, OBJ_BLOB, path, flags) < 0) if (index_fd(sha1, fd, st, OBJ_BLOB, path, flags) < 0)
return error("%s: failed to insert into database", return error("%s: failed to insert into database",
path); path);
break; break;
case S_IFLNK: case S_IFLNK:
if (strbuf_readlink(&sb, path, st->st_size)) { if (strbuf_readlink(&sb, path, st->st_size))
char *errstr = strerror(errno); return error_errno("readlink(\"%s\")", path);
return error("readlink(\"%s\"): %s", path,
errstr);
}
if (!(flags & HASH_WRITE_OBJECT)) if (!(flags & HASH_WRITE_OBJECT))
hash_sha1_file(sb.buf, sb.len, blob_type, sha1); hash_sha1_file(sb.buf, sb.len, blob_type, sha1);
else if (write_sha1_file(sb.buf, sb.len, blob_type, sha1)) 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,
if (!dir) { if (!dir) {
if (errno == ENOENT) if (errno == ENOENT)
return 0; return 0;
return error("unable to open %s: %s", path->buf, strerror(errno)); return error_errno("unable to open %s", path->buf);
} }


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

Loading…
Cancel
Save