Skip to content

Commit 40cfc95

Browse files
committed
Merge branch 'nd/error-errno'
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() ...
2 parents 8648eac + 1da045f commit 40cfc95

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+160
-173
lines changed

bisect.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -860,8 +860,8 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
860860
/* Create file BISECT_ANCESTORS_OK. */
861861
fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600);
862862
if (fd < 0)
863-
warning("could not create file '%s': %s",
864-
filename, strerror(errno));
863+
warning_errno("could not create file '%s'",
864+
filename);
865865
else
866866
close(fd);
867867
done:
@@ -910,8 +910,7 @@ void read_bisect_terms(const char **read_bad, const char **read_good)
910910
*read_good = "good";
911911
return;
912912
} else {
913-
die("could not read file '%s': %s", filename,
914-
strerror(errno));
913+
die_errno("could not read file '%s'", filename);
915914
}
916915
} else {
917916
strbuf_getline_lf(&str, fp);

builtin/am.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -769,15 +769,15 @@ static int split_mail_conv(mail_conv_fn fn, struct am_state *state,
769769
in = fopen(*paths, "r");
770770

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

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

777777
out = fopen(mail, "w");
778778
if (!out)
779-
return error(_("could not open '%s' for writing: %s"),
780-
mail, strerror(errno));
779+
return error_errno(_("could not open '%s' for writing"),
780+
mail);
781781

782782
ret = fn(out, in, keep_cr);
783783

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

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

863862
while (!strbuf_getline_lf(&sb, fp)) {
864863
if (*sb.buf == '#')

builtin/branch.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,7 @@ static int edit_branch_description(const char *branch_name)
595595
branch_name, comment_line_char);
596596
if (write_file_gently(git_path(edit_description), "%s", buf.buf)) {
597597
strbuf_release(&buf);
598-
return error(_("could not write branch description template: %s"),
599-
strerror(errno));
598+
return error_errno(_("could not write branch description template"));
600599
}
601600
strbuf_reset(&buf);
602601
if (launch_editor(git_path(edit_description), &buf, NULL)) {

builtin/fetch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
607607

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

612612
if (raw_url)
613613
url = transport_anonymize_url(raw_url);
@@ -848,7 +848,7 @@ static int truncate_fetch_head(void)
848848
FILE *fp = fopen_for_writing(filename);
849849

850850
if (!fp)
851-
return error(_("cannot open %s: %s\n"), filename, strerror(errno));
851+
return error_errno(_("cannot open %s"), filename);
852852
fclose(fp);
853853
return 0;
854854
}

builtin/help.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static void exec_woman_emacs(const char *path, const char *page)
127127
path = "emacsclient";
128128
strbuf_addf(&man_page, "(woman \"%s\")", page);
129129
execlp(path, "emacsclient", "-e", man_page.buf, (char *)NULL);
130-
warning(_("failed to exec '%s': %s"), path, strerror(errno));
130+
warning_errno(_("failed to exec '%s'"), path);
131131
}
132132
}
133133

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

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

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

171171
static void add_man_viewer(const char *name)

builtin/mailsplit.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static int populate_maildir_list(struct string_list *list, const char *path)
109109
if ((dir = opendir(name)) == NULL) {
110110
if (errno == ENOENT)
111111
continue;
112-
error("cannot opendir %s (%s)", name, strerror(errno));
112+
error_errno("cannot opendir %s", name);
113113
goto out;
114114
}
115115

@@ -174,12 +174,12 @@ static int split_maildir(const char *maildir, const char *dir,
174174

175175
f = fopen(file, "r");
176176
if (!f) {
177-
error("cannot open mail %s (%s)", file, strerror(errno));
177+
error_errno("cannot open mail %s", file);
178178
goto out;
179179
}
180180

181181
if (strbuf_getwholeline(&buf, f, '\n')) {
182-
error("cannot read mail %s (%s)", file, strerror(errno));
182+
error_errno("cannot read mail %s", file);
183183
goto out;
184184
}
185185

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

212212
if (!f) {
213-
error("cannot open mbox %s", file);
213+
error_errno("cannot open mbox %s", file);
214214
goto out;
215215
}
216216

@@ -318,7 +318,7 @@ int cmd_mailsplit(int argc, const char **argv, const char *prefix)
318318
}
319319

320320
if (stat(arg, &argstat) == -1) {
321-
error("cannot stat %s (%s)", arg, strerror(errno));
321+
error_errno("cannot stat %s", arg);
322322
return 1;
323323
}
324324

builtin/merge-file.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
6262
usage_with_options(merge_file_usage, options);
6363
if (quiet) {
6464
if (!freopen("/dev/null", "w", stderr))
65-
return error("failed to redirect stderr to /dev/null: "
66-
"%s", strerror(errno));
65+
return error_errno("failed to redirect stderr to /dev/null");
6766
}
6867

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

9796
if (!f)
98-
ret = error("Could not open %s for writing", filename);
97+
ret = error_errno("Could not open %s for writing",
98+
filename);
9999
else if (result.size &&
100100
fwrite(result.ptr, result.size, 1, f) != 1)
101-
ret = error("Could not write to %s", filename);
101+
ret = error_errno("Could not write to %s", filename);
102102
else if (fclose(f))
103-
ret = error("Could not close %s", filename);
103+
ret = error_errno("Could not close %s", filename);
104104
free(result.ptr);
105105
}
106106

builtin/pack-objects.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -835,17 +835,15 @@ static void write_pack_file(void)
835835
* to preserve this property.
836836
*/
837837
if (stat(pack_tmp_name, &st) < 0) {
838-
warning("failed to stat %s: %s",
839-
pack_tmp_name, strerror(errno));
838+
warning_errno("failed to stat %s", pack_tmp_name);
840839
} else if (!last_mtime) {
841840
last_mtime = st.st_mtime;
842841
} else {
843842
struct utimbuf utb;
844843
utb.actime = st.st_atime;
845844
utb.modtime = --last_mtime;
846845
if (utime(pack_tmp_name, &utb) < 0)
847-
warning("failed utime() on %s: %s",
848-
pack_tmp_name, strerror(errno));
846+
warning_errno("failed utime() on %s", pack_tmp_name);
849847
}
850848

851849
strbuf_addf(&tmpname, "%s-", base_name);

builtin/rm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static int check_local_mod(unsigned char *head, int index_only)
152152

153153
if (lstat(ce->name, &st) < 0) {
154154
if (errno != ENOENT && errno != ENOTDIR)
155-
warning("'%s': %s", ce->name, strerror(errno));
155+
warning_errno(_("failed to stat '%s'"), ce->name);
156156
/* It already vanished from the working tree */
157157
continue;
158158
}

builtin/update-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ static int process_lstat_error(const char *path, int err)
255255
{
256256
if (err == ENOENT || err == ENOTDIR)
257257
return remove_one_path(path);
258-
return error("lstat(\"%s\"): %s", path, strerror(errno));
258+
return error("lstat(\"%s\"): %s", path, strerror(err));
259259
}
260260

261261
static int add_one_path(const struct cache_entry *old, const char *path, int len, struct stat *st)

0 commit comments

Comments
 (0)