Skip to content
This repository was archived by the owner on Mar 1, 2019. It is now read-only.

Commit d824cbb

Browse files
trastgitster
authored andcommitted
Convert existing die(..., strerror(errno)) to die_errno()
Change calls to die(..., strerror(errno)) to use the new die_errno(). In the process, also make slight style adjustments: at least state _something_ about the function that failed (instead of just printing the pathname), and put paths in single quotes. Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f8b5a8e commit d824cbb

Some content is hidden

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

42 files changed

+117
-133
lines changed

bisect.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ void read_bisect_paths(struct argv_array *array)
461461
FILE *fp = fopen(filename, "r");
462462

463463
if (!fp)
464-
die("Could not open file '%s': %s", filename, strerror(errno));
464+
die_errno("Could not open file '%s'", filename);
465465

466466
while (strbuf_getline(&str, fp, '\n') != EOF) {
467467
char *quoted;
@@ -632,8 +632,7 @@ static void mark_expected_rev(char *bisect_rev_hex)
632632
int fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600);
633633

634634
if (fd < 0)
635-
die("could not create file '%s': %s",
636-
filename, strerror(errno));
635+
die_errno("could not create file '%s'", filename);
637636

638637
bisect_rev_hex[len] = '\n';
639638
write_or_die(fd, bisect_rev_hex, len + 1);

branch.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ void create_branch(const char *head,
172172

173173
lock = lock_any_ref_for_update(ref.buf, NULL, 0);
174174
if (!lock)
175-
die("Failed to lock ref for update: %s.", strerror(errno));
175+
die_errno("Failed to lock ref for update");
176176

177177
if (reflog)
178178
log_all_ref_updates = 1;
@@ -188,7 +188,7 @@ void create_branch(const char *head,
188188
setup_tracking(name, real_ref, track);
189189

190190
if (write_ref_sha1(lock, sha1, msg) < 0)
191-
die("Failed to write ref: %s.", strerror(errno));
191+
die_errno("Failed to write ref");
192192

193193
strbuf_release(&ref);
194194
free(real_ref);

builtin-apply.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ static void say_patch_name(FILE *output, const char *pre,
280280
static void read_patch_file(struct strbuf *sb, int fd)
281281
{
282282
if (strbuf_read(sb, fd, 0) < 0)
283-
die("git apply: read returned %s", strerror(errno));
283+
die_errno("git apply: failed to read");
284284

285285
/*
286286
* Make sure that we have some slop in the buffer
@@ -2864,7 +2864,7 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,
28642864
strbuf_release(&nbuf);
28652865

28662866
if (close(fd) < 0)
2867-
die("closing file %s: %s", path, strerror(errno));
2867+
die_errno("closing file '%s'", path);
28682868
return 0;
28692869
}
28702870

@@ -3354,7 +3354,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
33543354

33553355
fd = open(arg, O_RDONLY);
33563356
if (fd < 0)
3357-
die("can't open patch '%s': %s", arg, strerror(errno));
3357+
die_errno("can't open patch '%s'", arg);
33583358
read_stdin = 0;
33593359
set_default_whitespace_mode(whitespace_option);
33603360
errs |= apply_patch(fd, arg, options);

builtin-blame.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -2035,7 +2035,7 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
20352035
contents_from = "standard input";
20362036
mode = 0;
20372037
if (strbuf_read(&buf, 0, 0) < 0)
2038-
die("read error %s from stdin", strerror(errno));
2038+
die_errno("failed to read from stdin");
20392039
}
20402040
convert_to_git(path, buf.buf, buf.len, &buf, 0);
20412041
origin->file.ptr = buf.buf;
@@ -2261,8 +2261,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
22612261
argc = parse_options_end(&ctx);
22622262

22632263
if (revs_file && read_ancestry(revs_file))
2264-
die("reading graft file %s failed: %s",
2265-
revs_file, strerror(errno));
2264+
die_errno("reading graft file '%s' failed", revs_file);
22662265

22672266
if (cmd_is_annotate) {
22682267
output_option |= OUTPUT_ANNOTATE_COMPAT;
@@ -2350,7 +2349,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
23502349

23512350
setup_work_tree();
23522351
if (!has_string_in_work_tree(path))
2353-
die("cannot stat path %s: %s", path, strerror(errno));
2352+
die_errno("cannot stat path '%s'", path);
23542353
}
23552354

23562355
setup_revisions(argc, argv, &revs, NULL);

builtin-clone.c

+5-6
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,7 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest)
252252
}
253253

254254
if (unlink(dest->buf) && errno != ENOENT)
255-
die("failed to unlink %s: %s",
256-
dest->buf, strerror(errno));
255+
die_errno("failed to unlink '%s'", dest->buf);
257256
if (!option_no_hardlinks) {
258257
if (!link(src->buf, dest->buf))
259258
continue;
@@ -420,11 +419,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
420419
if (!option_bare) {
421420
junk_work_tree = work_tree;
422421
if (safe_create_leading_directories_const(work_tree) < 0)
423-
die("could not create leading directories of '%s': %s",
424-
work_tree, strerror(errno));
422+
die_errno("could not create leading directories of '%s'",
423+
work_tree);
425424
if (!dest_exists && mkdir(work_tree, 0755))
426-
die("could not create work tree dir '%s': %s.",
427-
work_tree, strerror(errno));
425+
die_errno("could not create work tree dir '%s'.",
426+
work_tree);
428427
set_git_work_tree(work_tree);
429428
}
430429
junk_git_dir = git_dir;

builtin-commit-tree.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
124124
}
125125

126126
if (strbuf_read(&buffer, 0, 0) < 0)
127-
die("git commit-tree: read returned %s", strerror(errno));
127+
die_errno("git commit-tree: failed to read");
128128

129129
if (!commit_tree(buffer.buf, tree_sha1, parents, commit_sha1, NULL)) {
130130
printf("%s\n", sha1_to_hex(commit_sha1));

builtin-commit.c

+10-13
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
438438
hook_arg1 = "message";
439439
} else if (logfile) {
440440
if (strbuf_read_file(&sb, logfile, 0) < 0)
441-
die("could not read log file '%s': %s",
442-
logfile, strerror(errno));
441+
die_errno("could not read log file '%s'",
442+
logfile);
443443
hook_arg1 = "message";
444444
} else if (use_message) {
445445
buffer = strstr(use_message_buffer, "\n\n");
@@ -450,16 +450,15 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
450450
hook_arg2 = use_message;
451451
} else if (!stat(git_path("MERGE_MSG"), &statbuf)) {
452452
if (strbuf_read_file(&sb, git_path("MERGE_MSG"), 0) < 0)
453-
die("could not read MERGE_MSG: %s", strerror(errno));
453+
die_errno("could not read MERGE_MSG");
454454
hook_arg1 = "merge";
455455
} else if (!stat(git_path("SQUASH_MSG"), &statbuf)) {
456456
if (strbuf_read_file(&sb, git_path("SQUASH_MSG"), 0) < 0)
457-
die("could not read SQUASH_MSG: %s", strerror(errno));
457+
die_errno("could not read SQUASH_MSG");
458458
hook_arg1 = "squash";
459459
} else if (template_file && !stat(template_file, &statbuf)) {
460460
if (strbuf_read_file(&sb, template_file, 0) < 0)
461-
die("could not read %s: %s",
462-
template_file, strerror(errno));
461+
die_errno("could not read '%s'", template_file);
463462
hook_arg1 = "template";
464463
}
465464

@@ -472,8 +471,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
472471

473472
fp = fopen(git_path(commit_editmsg), "w");
474473
if (fp == NULL)
475-
die("could not open %s: %s",
476-
git_path(commit_editmsg), strerror(errno));
474+
die_errno("could not open '%s'", git_path(commit_editmsg));
477475

478476
if (cleanup_mode != CLEANUP_NONE)
479477
stripspace(&sb, 0);
@@ -497,7 +495,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
497495
}
498496

499497
if (fwrite(sb.buf, 1, sb.len, fp) < sb.len)
500-
die("could not write commit template: %s", strerror(errno));
498+
die_errno("could not write commit template");
501499

502500
strbuf_release(&sb);
503501

@@ -940,8 +938,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
940938
pptr = &commit_list_insert(lookup_commit(head_sha1), pptr)->next;
941939
fp = fopen(git_path("MERGE_HEAD"), "r");
942940
if (fp == NULL)
943-
die("could not open %s for reading: %s",
944-
git_path("MERGE_HEAD"), strerror(errno));
941+
die_errno("could not open '%s' for reading",
942+
git_path("MERGE_HEAD"));
945943
while (strbuf_getline(&m, fp, '\n') != EOF) {
946944
unsigned char sha1[20];
947945
if (get_sha1_hex(m.buf, sha1) < 0)
@@ -952,8 +950,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
952950
strbuf_release(&m);
953951
if (!stat(git_path("MERGE_MODE"), &statbuf)) {
954952
if (strbuf_read_file(&sb, git_path("MERGE_MODE"), 0) < 0)
955-
die("could not read MERGE_MODE: %s",
956-
strerror(errno));
953+
die_errno("could not read MERGE_MODE");
957954
if (!strcmp(sb.buf, "no-ff"))
958955
allow_fast_forward = 0;
959956
}

builtin-config.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,8 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)
383383
check_argc(argc, 0, 0);
384384
if (git_config(show_all_config, NULL) < 0) {
385385
if (config_exclusive_filename)
386-
die("unable to read config file %s: %s",
387-
config_exclusive_filename, strerror(errno));
386+
die_errno("unable to read config file '%s'",
387+
config_exclusive_filename);
388388
else
389389
die("error processing config file(s)");
390390
}

builtin-diff.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static int builtin_diff_b_f(struct rev_info *revs,
7070
usage(builtin_diff_usage);
7171

7272
if (lstat(path, &st))
73-
die("'%s': %s", path, strerror(errno));
73+
die_errno("failed to stat '%s'", path);
7474
if (!(S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)))
7575
die("'%s': not a regular file or symlink", path);
7676

builtin-fast-export.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ static void import_marks(char *input_file)
451451
char line[512];
452452
FILE *f = fopen(input_file, "r");
453453
if (!f)
454-
die("cannot read %s: %s", input_file, strerror(errno));
454+
die_errno("cannot read '%s'", input_file);
455455

456456
while (fgets(line, sizeof(line), f)) {
457457
uint32_t mark;

builtin-fetch--tool.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ static char *get_stdin(void)
88
{
99
struct strbuf buf = STRBUF_INIT;
1010
if (strbuf_read(&buf, 0, 1024) < 0) {
11-
die("error reading standard input: %s", strerror(errno));
11+
die_errno("error reading standard input");
1212
}
1313
return strbuf_detach(&buf, NULL);
1414
}

builtin-fmt-merge-msg.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
372372
}
373373

374374
if (strbuf_read(&input, fileno(in), 0) < 0)
375-
die("could not read input file %s", strerror(errno));
376-
375+
die_errno("could not read input file");
377376
ret = fmt_merge_msg(merge_summary, &input, &output);
378377
if (ret)
379378
return ret;

builtin-fsck.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,15 @@ static void check_unreachable_object(struct object *obj)
225225
&type, &size);
226226
if (buf) {
227227
if (fwrite(buf, size, 1, f) != 1)
228-
die("Could not write %s: %s",
229-
filename, strerror(errno));
228+
die_errno("Could not write '%s'",
229+
filename);
230230
free(buf);
231231
}
232232
} else
233233
fprintf(f, "%s\n", sha1_to_hex(obj->sha1));
234234
if (fclose(f))
235-
die("Could not finish %s: %s",
236-
filename, strerror(errno));
235+
die_errno("Could not finish '%s'",
236+
filename);
237237
}
238238
return;
239239
}

builtin-grep.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ static int file_callback(const struct option *opt, const char *arg, int unset)
594594

595595
patterns = fopen(arg, "r");
596596
if (!patterns)
597-
die("'%s': %s", arg, strerror(errno));
597+
die_errno("cannot open '%s'", arg);
598598
while (strbuf_getline(&sb, patterns, '\n') == 0) {
599599
/* ignore empty line like grep does */
600600
if (sb.len == 0)

builtin-merge.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,9 @@ static void squash_message(void)
294294
NULL, NULL, rev.date_mode, 0);
295295
}
296296
if (write(fd, out.buf, out.len) < 0)
297-
die("Writing SQUASH_MSG: %s", strerror(errno));
297+
die_errno("Writing SQUASH_MSG");
298298
if (close(fd))
299-
die("Finishing SQUASH_MSG: %s", strerror(errno));
299+
die_errno("Finishing SQUASH_MSG");
300300
strbuf_release(&out);
301301
}
302302

@@ -428,8 +428,8 @@ static void merge_name(const char *remote, struct strbuf *msg)
428428

429429
fp = fopen(git_path("FETCH_HEAD"), "r");
430430
if (!fp)
431-
die("could not open %s for reading: %s",
432-
git_path("FETCH_HEAD"), strerror(errno));
431+
die_errno("could not open '%s' for reading",
432+
git_path("FETCH_HEAD"));
433433
strbuf_getline(&line, fp, '\n');
434434
fclose(fp);
435435
ptr = strstr(line.buf, "\tnot-for-merge\t");

builtin-mv.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
209209
printf("Renaming %s to %s\n", src, dst);
210210
if (!show_only && mode != INDEX &&
211211
rename(src, dst) < 0 && !ignore_errors)
212-
die ("renaming %s failed: %s", src, strerror(errno));
212+
die_errno ("renaming '%s' failed", src);
213213

214214
if (mode == WORKING_DIRECTORY)
215215
continue;

builtin-pack-objects.c

+5-9
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,9 @@ static void write_pack_file(void)
536536
base_name, sha1_to_hex(sha1));
537537
free_pack_by_name(tmpname);
538538
if (adjust_perm(pack_tmp_name, mode))
539-
die("unable to make temporary pack file readable: %s",
540-
strerror(errno));
539+
die_errno("unable to make temporary pack file readable");
541540
if (rename(pack_tmp_name, tmpname))
542-
die("unable to rename temporary pack file: %s",
543-
strerror(errno));
541+
die_errno("unable to rename temporary pack file");
544542

545543
/*
546544
* Packs are runtime accessed in their mtime
@@ -566,11 +564,9 @@ static void write_pack_file(void)
566564
snprintf(tmpname, sizeof(tmpname), "%s-%s.idx",
567565
base_name, sha1_to_hex(sha1));
568566
if (adjust_perm(idx_tmp_name, mode))
569-
die("unable to make temporary index file readable: %s",
570-
strerror(errno));
567+
die_errno("unable to make temporary index file readable");
571568
if (rename(idx_tmp_name, tmpname))
572-
die("unable to rename temporary index file: %s",
573-
strerror(errno));
569+
die_errno("unable to rename temporary index file");
574570

575571
free(idx_tmp_name);
576572
free(pack_tmp_name);
@@ -1880,7 +1876,7 @@ static void read_object_list_from_stdin(void)
18801876
if (!ferror(stdin))
18811877
die("fgets returned NULL, not EOF, not error!");
18821878
if (errno != EINTR)
1883-
die("fgets: %s", strerror(errno));
1879+
die_errno("fgets");
18841880
clearerr(stdin);
18851881
continue;
18861882
}

builtin-rm.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
257257
continue;
258258
}
259259
if (!removed)
260-
die("git rm: %s: %s", path, strerror(errno));
260+
die_errno("git rm: '%s'", path);
261261
}
262262
}
263263

builtin-send-pack.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext
5959
po.out = fd;
6060
po.git_cmd = 1;
6161
if (start_command(&po))
62-
die("git pack-objects failed (%s)", strerror(errno));
62+
die_errno("git pack-objects failed");
6363

6464
/*
6565
* We feed the pack-objects we just spawned with revision

builtin-tag.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,7 @@ static void create_tag(const unsigned char *object, const char *tag,
308308
path = git_pathdup("TAG_EDITMSG");
309309
fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0600);
310310
if (fd < 0)
311-
die("could not create file '%s': %s",
312-
path, strerror(errno));
311+
die_errno("could not create file '%s'", path);
313312

314313
if (!is_null_sha1(prev))
315314
write_tag_body(fd, prev);
@@ -446,8 +445,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
446445
die("cannot read %s", msgfile);
447446
} else {
448447
if (strbuf_read_file(&buf, msgfile, 1024) < 0)
449-
die("could not open or read '%s': %s",
450-
msgfile, strerror(errno));
448+
die_errno("could not open or read '%s'",
449+
msgfile);
451450
}
452451
}
453452
}

builtin-unpack-objects.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static void *fill(int min)
6868
if (ret <= 0) {
6969
if (!ret)
7070
die("early EOF");
71-
die("read error on input: %s", strerror(errno));
71+
die_errno("read error on input");
7272
}
7373
len += ret;
7474
} while (len < min);

0 commit comments

Comments
 (0)