Skip to content

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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 4 deletions
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

Lines changed: 5 additions & 6 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 10 additions & 13 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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;

0 commit comments

Comments
 (0)