Skip to content
/ git Public
forked from git/git

Commit

Permalink
Merge branch 'nd/error-errno'
Browse files Browse the repository at this point in the history
The code for warning_errno/die_errno has been refactored and a new
error_errno() reporting helper is introduced.

* nd/error-errno: (41 commits)
  wrapper.c: use warning_errno()
  vcs-svn: use error_errno()
  upload-pack.c: use error_errno()
  unpack-trees.c: use error_errno()
  transport-helper.c: use error_errno()
  sha1_file.c: use {error,die,warning}_errno()
  server-info.c: use error_errno()
  sequencer.c: use error_errno()
  run-command.c: use error_errno()
  rerere.c: use error_errno() and warning_errno()
  reachable.c: use error_errno()
  mailmap.c: use error_errno()
  ident.c: use warning_errno()
  http.c: use error_errno() and warning_errno()
  grep.c: use error_errno()
  gpg-interface.c: use error_errno()
  fast-import.c: use error_errno()
  entry.c: use error_errno()
  editor.c: use error_errno()
  diff-no-index.c: use error_errno()
  ...
  • Loading branch information
gitster committed May 17, 2016
2 parents 8648eac + 1da045f commit 40cfc95
Show file tree
Hide file tree
Showing 44 changed files with 160 additions and 173 deletions.
7 changes: 3 additions & 4 deletions bisect.c
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,8 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
/* Create file BISECT_ANCESTORS_OK. */
fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600);
if (fd < 0)
warning("could not create file '%s': %s",
filename, strerror(errno));
warning_errno("could not create file '%s'",
filename);
else
close(fd);
done:
Expand Down Expand Up @@ -910,8 +910,7 @@ void read_bisect_terms(const char **read_bad, const char **read_good)
*read_good = "good";
return;
} else {
die("could not read file '%s': %s", filename,
strerror(errno));
die_errno("could not read file '%s'", filename);
}
} else {
strbuf_getline_lf(&str, fp);
Expand Down
11 changes: 5 additions & 6 deletions builtin/am.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,15 +769,15 @@ static int split_mail_conv(mail_conv_fn fn, struct am_state *state,
in = fopen(*paths, "r");

if (!in)
return error(_("could not open '%s' for reading: %s"),
*paths, strerror(errno));
return error_errno(_("could not open '%s' for reading"),
*paths);

mail = mkpath("%s/%0*d", state->dir, state->prec, i + 1);

out = fopen(mail, "w");
if (!out)
return error(_("could not open '%s' for writing: %s"),
mail, strerror(errno));
return error_errno(_("could not open '%s' for writing"),
mail);

ret = fn(out, in, keep_cr);

Expand Down Expand Up @@ -857,8 +857,7 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths,

fp = fopen(*paths, "r");
if (!fp)
return error(_("could not open '%s' for reading: %s"), *paths,
strerror(errno));
return error_errno(_("could not open '%s' for reading"), *paths);

while (!strbuf_getline_lf(&sb, fp)) {
if (*sb.buf == '#')
Expand Down
3 changes: 1 addition & 2 deletions builtin/branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,7 @@ static int edit_branch_description(const char *branch_name)
branch_name, comment_line_char);
if (write_file_gently(git_path(edit_description), "%s", buf.buf)) {
strbuf_release(&buf);
return error(_("could not write branch description template: %s"),
strerror(errno));
return error_errno(_("could not write branch description template"));
}
strbuf_reset(&buf);
if (launch_editor(git_path(edit_description), &buf, NULL)) {
Expand Down
4 changes: 2 additions & 2 deletions builtin/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,

fp = fopen(filename, "a");
if (!fp)
return error(_("cannot open %s: %s\n"), filename, strerror(errno));
return error_errno(_("cannot open %s"), filename);

if (raw_url)
url = transport_anonymize_url(raw_url);
Expand Down Expand Up @@ -848,7 +848,7 @@ static int truncate_fetch_head(void)
FILE *fp = fopen_for_writing(filename);

if (!fp)
return error(_("cannot open %s: %s\n"), filename, strerror(errno));
return error_errno(_("cannot open %s"), filename);
fclose(fp);
return 0;
}
Expand Down
8 changes: 4 additions & 4 deletions builtin/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static void exec_woman_emacs(const char *path, const char *page)
path = "emacsclient";
strbuf_addf(&man_page, "(woman \"%s\")", page);
execlp(path, "emacsclient", "-e", man_page.buf, (char *)NULL);
warning(_("failed to exec '%s': %s"), path, strerror(errno));
warning_errno(_("failed to exec '%s'"), path);
}
}

Expand All @@ -148,7 +148,7 @@ static void exec_man_konqueror(const char *path, const char *page)
path = "kfmclient";
strbuf_addf(&man_page, "man:%s(1)", page);
execlp(path, filename, "newTab", man_page.buf, (char *)NULL);
warning(_("failed to exec '%s': %s"), path, strerror(errno));
warning_errno(_("failed to exec '%s'"), path);
}
}

Expand All @@ -157,15 +157,15 @@ static void exec_man_man(const char *path, const char *page)
if (!path)
path = "man";
execlp(path, "man", page, (char *)NULL);
warning(_("failed to exec '%s': %s"), path, strerror(errno));
warning_errno(_("failed to exec '%s'"), path);
}

static void exec_man_cmd(const char *cmd, const char *page)
{
struct strbuf shell_cmd = STRBUF_INIT;
strbuf_addf(&shell_cmd, "%s %s", cmd, page);
execl(SHELL_PATH, SHELL_PATH, "-c", shell_cmd.buf, (char *)NULL);
warning(_("failed to exec '%s': %s"), cmd, strerror(errno));
warning(_("failed to exec '%s'"), cmd);
}

static void add_man_viewer(const char *name)
Expand Down
10 changes: 5 additions & 5 deletions builtin/mailsplit.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static int populate_maildir_list(struct string_list *list, const char *path)
if ((dir = opendir(name)) == NULL) {
if (errno == ENOENT)
continue;
error("cannot opendir %s (%s)", name, strerror(errno));
error_errno("cannot opendir %s", name);
goto out;
}

Expand Down Expand Up @@ -174,12 +174,12 @@ static int split_maildir(const char *maildir, const char *dir,

f = fopen(file, "r");
if (!f) {
error("cannot open mail %s (%s)", file, strerror(errno));
error_errno("cannot open mail %s", file);
goto out;
}

if (strbuf_getwholeline(&buf, f, '\n')) {
error("cannot read mail %s (%s)", file, strerror(errno));
error_errno("cannot read mail %s", file);
goto out;
}

Expand Down Expand Up @@ -210,7 +210,7 @@ static int split_mbox(const char *file, const char *dir, int allow_bare,
int file_done = 0;

if (!f) {
error("cannot open mbox %s", file);
error_errno("cannot open mbox %s", file);
goto out;
}

Expand Down Expand Up @@ -318,7 +318,7 @@ int cmd_mailsplit(int argc, const char **argv, const char *prefix)
}

if (stat(arg, &argstat) == -1) {
error("cannot stat %s (%s)", arg, strerror(errno));
error_errno("cannot stat %s", arg);
return 1;
}

Expand Down
10 changes: 5 additions & 5 deletions builtin/merge-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
usage_with_options(merge_file_usage, options);
if (quiet) {
if (!freopen("/dev/null", "w", stderr))
return error("failed to redirect stderr to /dev/null: "
"%s", strerror(errno));
return error_errno("failed to redirect stderr to /dev/null");
}

if (prefix)
Expand Down Expand Up @@ -95,12 +94,13 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
FILE *f = to_stdout ? stdout : fopen(fpath, "wb");

if (!f)
ret = error("Could not open %s for writing", filename);
ret = error_errno("Could not open %s for writing",
filename);
else if (result.size &&
fwrite(result.ptr, result.size, 1, f) != 1)
ret = error("Could not write to %s", filename);
ret = error_errno("Could not write to %s", filename);
else if (fclose(f))
ret = error("Could not close %s", filename);
ret = error_errno("Could not close %s", filename);
free(result.ptr);
}

Expand Down
6 changes: 2 additions & 4 deletions builtin/pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,17 +835,15 @@ static void write_pack_file(void)
* to preserve this property.
*/
if (stat(pack_tmp_name, &st) < 0) {
warning("failed to stat %s: %s",
pack_tmp_name, strerror(errno));
warning_errno("failed to stat %s", pack_tmp_name);
} else if (!last_mtime) {
last_mtime = st.st_mtime;
} else {
struct utimbuf utb;
utb.actime = st.st_atime;
utb.modtime = --last_mtime;
if (utime(pack_tmp_name, &utb) < 0)
warning("failed utime() on %s: %s",
pack_tmp_name, strerror(errno));
warning_errno("failed utime() on %s", pack_tmp_name);
}

strbuf_addf(&tmpname, "%s-", base_name);
Expand Down
2 changes: 1 addition & 1 deletion builtin/rm.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static int check_local_mod(unsigned char *head, int index_only)

if (lstat(ce->name, &st) < 0) {
if (errno != ENOENT && errno != ENOTDIR)
warning("'%s': %s", ce->name, strerror(errno));
warning_errno(_("failed to stat '%s'"), ce->name);
/* It already vanished from the working tree */
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion builtin/update-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ static int process_lstat_error(const char *path, int err)
{
if (err == ENOENT || err == ENOTDIR)
return remove_one_path(path);
return error("lstat(\"%s\"): %s", path, strerror(errno));
return error("lstat(\"%s\"): %s", path, strerror(err));
}

static int add_one_path(const struct cache_entry *old, const char *path, int len, struct stat *st)
Expand Down
3 changes: 1 addition & 2 deletions builtin/upload-archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
pfd[1].events = POLLIN;
if (poll(pfd, 2, -1) < 0) {
if (errno != EINTR) {
error("poll failed resuming: %s",
strerror(errno));
error_errno("poll failed resuming");
sleep(1);
}
continue;
Expand Down
2 changes: 1 addition & 1 deletion builtin/worktree.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static void prune_worktrees(void)
if (ret < 0 && errno == ENOTDIR)
ret = unlink(path.buf);
if (ret)
error(_("failed to remove: %s"), strerror(errno));
error_errno(_("failed to remove '%s'"), path.buf);
}
closedir(dir);
if (!show_only)
Expand Down
2 changes: 1 addition & 1 deletion check-racy.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ int main(int ac, char **av)
struct stat st;

if (lstat(ce->name, &st)) {
error("lstat(%s): %s", ce->name, strerror(errno));
error_errno("lstat(%s)", ce->name);
continue;
}

Expand Down
3 changes: 1 addition & 2 deletions combine-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -1005,8 +1005,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
struct strbuf buf = STRBUF_INIT;

if (strbuf_readlink(&buf, elem->path, st.st_size) < 0) {
error("readlink(%s): %s", elem->path,
strerror(errno));
error_errno("readlink(%s)", elem->path);
return;
}
result_size = buf.len;
Expand Down
6 changes: 3 additions & 3 deletions compat/win32/syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ void syslog(int priority, const char *fmt, ...)
va_end(ap);

if (str_len < 0) {
warning("vsnprintf failed: '%s'", strerror(errno));
warning_errno("vsnprintf failed");
return;
}

str = malloc(st_add(str_len, 1));
if (!str) {
warning("malloc failed: '%s'", strerror(errno));
warning_errno("malloc failed");
return;
}

Expand All @@ -45,7 +45,7 @@ void syslog(int priority, const char *fmt, ...)
while ((pos = strstr(str, "%1")) != NULL) {
str = realloc(str, st_add(++str_len, 1));
if (!str) {
warning("realloc failed: '%s'", strerror(errno));
warning_errno("realloc failed");
return;
}
memmove(pos + 2, pos + 1, strlen(pos));
Expand Down
22 changes: 9 additions & 13 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2012,7 +2012,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
lock = xcalloc(1, sizeof(struct lock_file));
fd = hold_lock_file_for_update(lock, config_filename, 0);
if (fd < 0) {
error("could not lock config file %s: %s", config_filename, strerror(errno));
error_errno("could not lock config file %s", config_filename);
free(store.key);
ret = CONFIG_NO_LOCK;
goto out_free;
Expand All @@ -2026,8 +2026,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
free(store.key);

if ( ENOENT != errno ) {
error("opening %s: %s", config_filename,
strerror(errno));
error_errno("opening %s", config_filename);
ret = CONFIG_INVALID_FILE; /* same as "invalid config file" */
goto out_free;
}
Expand Down Expand Up @@ -2111,8 +2110,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
if (contents == MAP_FAILED) {
if (errno == ENODEV && S_ISDIR(st.st_mode))
errno = EISDIR;
error("unable to mmap '%s': %s",
config_filename, strerror(errno));
error_errno("unable to mmap '%s'", config_filename);
ret = CONFIG_INVALID_FILE;
contents = NULL;
goto out_free;
Expand All @@ -2121,8 +2119,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
in_fd = -1;

if (chmod(get_lock_file_path(lock), st.st_mode & 07777) < 0) {
error("chmod on %s failed: %s",
get_lock_file_path(lock), strerror(errno));
error_errno("chmod on %s failed", get_lock_file_path(lock));
ret = CONFIG_NO_WRITE;
goto out_free;
}
Expand Down Expand Up @@ -2178,8 +2175,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
}

if (commit_lock_file(lock) < 0) {
error("could not write config file %s: %s", config_filename,
strerror(errno));
error_errno("could not write config file %s", config_filename);
ret = CONFIG_NO_WRITE;
lock = NULL;
goto out_free;
Expand Down Expand Up @@ -2330,8 +2326,8 @@ int git_config_rename_section_in_file(const char *config_filename,
fstat(fileno(config_file), &st);

if (chmod(get_lock_file_path(lock), st.st_mode & 07777) < 0) {
ret = error("chmod on %s failed: %s",
get_lock_file_path(lock), strerror(errno));
ret = error_errno("chmod on %s failed",
get_lock_file_path(lock));
goto out;
}

Expand Down Expand Up @@ -2385,8 +2381,8 @@ int git_config_rename_section_in_file(const char *config_filename,
fclose(config_file);
unlock_and_out:
if (commit_lock_file(lock) < 0)
ret = error("could not write config file %s: %s",
config_filename, strerror(errno));
ret = error_errno("could not write config file %s",
config_filename);
out:
free(filename_buf);
return ret;
Expand Down
9 changes: 3 additions & 6 deletions connected.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,14 @@ static int check_everything_connected_real(sha1_iterate_fn fn,
memcpy(commit, sha1_to_hex(sha1), 40);
if (write_in_full(rev_list.in, commit, 41) < 0) {
if (errno != EPIPE && errno != EINVAL)
error(_("failed write to rev-list: %s"),
strerror(errno));
error_errno(_("failed write to rev-list"));
err = -1;
break;
}
} while (!fn(cb_data, sha1));

if (close(rev_list.in)) {
error(_("failed to close rev-list's stdin: %s"), strerror(errno));
err = -1;
}
if (close(rev_list.in))
err = error_errno(_("failed to close rev-list's stdin"));

sigchain_pop(SIGPIPE);
return finish_command(&rev_list) || err;
Expand Down
6 changes: 3 additions & 3 deletions copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ int copy_file(const char *dst, const char *src, int mode)
status = copy_fd(fdi, fdo);
switch (status) {
case COPY_READ_ERROR:
error("copy-fd: read returned %s", strerror(errno));
error_errno("copy-fd: read returned");
break;
case COPY_WRITE_ERROR:
error("copy-fd: write returned %s", strerror(errno));
error_errno("copy-fd: write returned");
break;
}
close(fdi);
if (close(fdo) != 0)
return error("%s: close error: %s", dst, strerror(errno));
return error_errno("%s: close error", dst);

if (!status && adjust_shared_perm(dst))
return -1;
Expand Down
Loading

0 comments on commit 40cfc95

Please sign in to comment.