Skip to content

Commit

Permalink
Convert existing die(..., strerror(errno)) to die_errno()
Browse files Browse the repository at this point in the history
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 <trast@student.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
trast authored and gitster committed Jun 27, 2009
1 parent f8b5a8e commit d824cbb
Show file tree
Hide file tree
Showing 42 changed files with 117 additions and 133 deletions.
5 changes: 2 additions & 3 deletions bisect.c
Expand Up @@ -461,7 +461,7 @@ void read_bisect_paths(struct argv_array *array)
FILE *fp = fopen(filename, "r");

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

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

if (fd < 0)
die("could not create file '%s': %s",
filename, strerror(errno));
die_errno("could not create file '%s'", filename);

bisect_rev_hex[len] = '\n';
write_or_die(fd, bisect_rev_hex, len + 1);
Expand Down
4 changes: 2 additions & 2 deletions branch.c
Expand Up @@ -172,7 +172,7 @@ void create_branch(const char *head,

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

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

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

strbuf_release(&ref);
free(real_ref);
Expand Down
6 changes: 3 additions & 3 deletions builtin-apply.c
Expand Up @@ -280,7 +280,7 @@ static void say_patch_name(FILE *output, const char *pre,
static void read_patch_file(struct strbuf *sb, int fd)
{
if (strbuf_read(sb, fd, 0) < 0)
die("git apply: read returned %s", strerror(errno));
die_errno("git apply: failed to read");

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

if (close(fd) < 0)
die("closing file %s: %s", path, strerror(errno));
die_errno("closing file '%s'", path);
return 0;
}

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

fd = open(arg, O_RDONLY);
if (fd < 0)
die("can't open patch '%s': %s", arg, strerror(errno));
die_errno("can't open patch '%s'", arg);
read_stdin = 0;
set_default_whitespace_mode(whitespace_option);
errs |= apply_patch(fd, arg, options);
Expand Down
7 changes: 3 additions & 4 deletions builtin-blame.c
Expand Up @@ -2035,7 +2035,7 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
contents_from = "standard input";
mode = 0;
if (strbuf_read(&buf, 0, 0) < 0)
die("read error %s from stdin", strerror(errno));
die_errno("failed to read from stdin");
}
convert_to_git(path, buf.buf, buf.len, &buf, 0);
origin->file.ptr = buf.buf;
Expand Down Expand Up @@ -2261,8 +2261,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
argc = parse_options_end(&ctx);

if (revs_file && read_ancestry(revs_file))
die("reading graft file %s failed: %s",
revs_file, strerror(errno));
die_errno("reading graft file '%s' failed", revs_file);

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

setup_work_tree();
if (!has_string_in_work_tree(path))
die("cannot stat path %s: %s", path, strerror(errno));
die_errno("cannot stat path '%s'", path);
}

setup_revisions(argc, argv, &revs, NULL);
Expand Down
11 changes: 5 additions & 6 deletions builtin-clone.c
Expand Up @@ -252,8 +252,7 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest)
}

if (unlink(dest->buf) && errno != ENOENT)
die("failed to unlink %s: %s",
dest->buf, strerror(errno));
die_errno("failed to unlink '%s'", dest->buf);
if (!option_no_hardlinks) {
if (!link(src->buf, dest->buf))
continue;
Expand Down Expand Up @@ -420,11 +419,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
if (!option_bare) {
junk_work_tree = work_tree;
if (safe_create_leading_directories_const(work_tree) < 0)
die("could not create leading directories of '%s': %s",
work_tree, strerror(errno));
die_errno("could not create leading directories of '%s'",
work_tree);
if (!dest_exists && mkdir(work_tree, 0755))
die("could not create work tree dir '%s': %s.",
work_tree, strerror(errno));
die_errno("could not create work tree dir '%s'.",
work_tree);
set_git_work_tree(work_tree);
}
junk_git_dir = git_dir;
Expand Down
2 changes: 1 addition & 1 deletion builtin-commit-tree.c
Expand Up @@ -124,7 +124,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
}

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

if (!commit_tree(buffer.buf, tree_sha1, parents, commit_sha1, NULL)) {
printf("%s\n", sha1_to_hex(commit_sha1));
Expand Down
23 changes: 10 additions & 13 deletions builtin-commit.c
Expand Up @@ -438,8 +438,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
hook_arg1 = "message";
} else if (logfile) {
if (strbuf_read_file(&sb, logfile, 0) < 0)
die("could not read log file '%s': %s",
logfile, strerror(errno));
die_errno("could not read log file '%s'",
logfile);
hook_arg1 = "message";
} else if (use_message) {
buffer = strstr(use_message_buffer, "\n\n");
Expand All @@ -450,16 +450,15 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
hook_arg2 = use_message;
} else if (!stat(git_path("MERGE_MSG"), &statbuf)) {
if (strbuf_read_file(&sb, git_path("MERGE_MSG"), 0) < 0)
die("could not read MERGE_MSG: %s", strerror(errno));
die_errno("could not read MERGE_MSG");
hook_arg1 = "merge";
} else if (!stat(git_path("SQUASH_MSG"), &statbuf)) {
if (strbuf_read_file(&sb, git_path("SQUASH_MSG"), 0) < 0)
die("could not read SQUASH_MSG: %s", strerror(errno));
die_errno("could not read SQUASH_MSG");
hook_arg1 = "squash";
} else if (template_file && !stat(template_file, &statbuf)) {
if (strbuf_read_file(&sb, template_file, 0) < 0)
die("could not read %s: %s",
template_file, strerror(errno));
die_errno("could not read '%s'", template_file);
hook_arg1 = "template";
}

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

fp = fopen(git_path(commit_editmsg), "w");
if (fp == NULL)
die("could not open %s: %s",
git_path(commit_editmsg), strerror(errno));
die_errno("could not open '%s'", git_path(commit_editmsg));

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

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

strbuf_release(&sb);

Expand Down Expand Up @@ -940,8 +938,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
pptr = &commit_list_insert(lookup_commit(head_sha1), pptr)->next;
fp = fopen(git_path("MERGE_HEAD"), "r");
if (fp == NULL)
die("could not open %s for reading: %s",
git_path("MERGE_HEAD"), strerror(errno));
die_errno("could not open '%s' for reading",
git_path("MERGE_HEAD"));
while (strbuf_getline(&m, fp, '\n') != EOF) {
unsigned char sha1[20];
if (get_sha1_hex(m.buf, sha1) < 0)
Expand All @@ -952,8 +950,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
strbuf_release(&m);
if (!stat(git_path("MERGE_MODE"), &statbuf)) {
if (strbuf_read_file(&sb, git_path("MERGE_MODE"), 0) < 0)
die("could not read MERGE_MODE: %s",
strerror(errno));
die_errno("could not read MERGE_MODE");
if (!strcmp(sb.buf, "no-ff"))
allow_fast_forward = 0;
}
Expand Down
4 changes: 2 additions & 2 deletions builtin-config.c
Expand Up @@ -383,8 +383,8 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)
check_argc(argc, 0, 0);
if (git_config(show_all_config, NULL) < 0) {
if (config_exclusive_filename)
die("unable to read config file %s: %s",
config_exclusive_filename, strerror(errno));
die_errno("unable to read config file '%s'",
config_exclusive_filename);
else
die("error processing config file(s)");
}
Expand Down
2 changes: 1 addition & 1 deletion builtin-diff.c
Expand Up @@ -70,7 +70,7 @@ static int builtin_diff_b_f(struct rev_info *revs,
usage(builtin_diff_usage);

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

Expand Down
2 changes: 1 addition & 1 deletion builtin-fast-export.c
Expand Up @@ -451,7 +451,7 @@ static void import_marks(char *input_file)
char line[512];
FILE *f = fopen(input_file, "r");
if (!f)
die("cannot read %s: %s", input_file, strerror(errno));
die_errno("cannot read '%s'", input_file);

while (fgets(line, sizeof(line), f)) {
uint32_t mark;
Expand Down
2 changes: 1 addition & 1 deletion builtin-fetch--tool.c
Expand Up @@ -8,7 +8,7 @@ static char *get_stdin(void)
{
struct strbuf buf = STRBUF_INIT;
if (strbuf_read(&buf, 0, 1024) < 0) {
die("error reading standard input: %s", strerror(errno));
die_errno("error reading standard input");
}
return strbuf_detach(&buf, NULL);
}
Expand Down
3 changes: 1 addition & 2 deletions builtin-fmt-merge-msg.c
Expand Up @@ -372,8 +372,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
}

if (strbuf_read(&input, fileno(in), 0) < 0)
die("could not read input file %s", strerror(errno));

die_errno("could not read input file");
ret = fmt_merge_msg(merge_summary, &input, &output);
if (ret)
return ret;
Expand Down
8 changes: 4 additions & 4 deletions builtin-fsck.c
Expand Up @@ -225,15 +225,15 @@ static void check_unreachable_object(struct object *obj)
&type, &size);
if (buf) {
if (fwrite(buf, size, 1, f) != 1)
die("Could not write %s: %s",
filename, strerror(errno));
die_errno("Could not write '%s'",
filename);
free(buf);
}
} else
fprintf(f, "%s\n", sha1_to_hex(obj->sha1));
if (fclose(f))
die("Could not finish %s: %s",
filename, strerror(errno));
die_errno("Could not finish '%s'",
filename);
}
return;
}
Expand Down
2 changes: 1 addition & 1 deletion builtin-grep.c
Expand Up @@ -594,7 +594,7 @@ static int file_callback(const struct option *opt, const char *arg, int unset)

patterns = fopen(arg, "r");
if (!patterns)
die("'%s': %s", arg, strerror(errno));
die_errno("cannot open '%s'", arg);
while (strbuf_getline(&sb, patterns, '\n') == 0) {
/* ignore empty line like grep does */
if (sb.len == 0)
Expand Down
8 changes: 4 additions & 4 deletions builtin-merge.c
Expand Up @@ -294,9 +294,9 @@ static void squash_message(void)
NULL, NULL, rev.date_mode, 0);
}
if (write(fd, out.buf, out.len) < 0)
die("Writing SQUASH_MSG: %s", strerror(errno));
die_errno("Writing SQUASH_MSG");
if (close(fd))
die("Finishing SQUASH_MSG: %s", strerror(errno));
die_errno("Finishing SQUASH_MSG");
strbuf_release(&out);
}

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

fp = fopen(git_path("FETCH_HEAD"), "r");
if (!fp)
die("could not open %s for reading: %s",
git_path("FETCH_HEAD"), strerror(errno));
die_errno("could not open '%s' for reading",
git_path("FETCH_HEAD"));
strbuf_getline(&line, fp, '\n');
fclose(fp);
ptr = strstr(line.buf, "\tnot-for-merge\t");
Expand Down
2 changes: 1 addition & 1 deletion builtin-mv.c
Expand Up @@ -209,7 +209,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
printf("Renaming %s to %s\n", src, dst);
if (!show_only && mode != INDEX &&
rename(src, dst) < 0 && !ignore_errors)
die ("renaming %s failed: %s", src, strerror(errno));
die_errno ("renaming '%s' failed", src);

if (mode == WORKING_DIRECTORY)
continue;
Expand Down
14 changes: 5 additions & 9 deletions builtin-pack-objects.c
Expand Up @@ -536,11 +536,9 @@ static void write_pack_file(void)
base_name, sha1_to_hex(sha1));
free_pack_by_name(tmpname);
if (adjust_perm(pack_tmp_name, mode))
die("unable to make temporary pack file readable: %s",
strerror(errno));
die_errno("unable to make temporary pack file readable");
if (rename(pack_tmp_name, tmpname))
die("unable to rename temporary pack file: %s",
strerror(errno));
die_errno("unable to rename temporary pack file");

/*
* Packs are runtime accessed in their mtime
Expand All @@ -566,11 +564,9 @@ static void write_pack_file(void)
snprintf(tmpname, sizeof(tmpname), "%s-%s.idx",
base_name, sha1_to_hex(sha1));
if (adjust_perm(idx_tmp_name, mode))
die("unable to make temporary index file readable: %s",
strerror(errno));
die_errno("unable to make temporary index file readable");
if (rename(idx_tmp_name, tmpname))
die("unable to rename temporary index file: %s",
strerror(errno));
die_errno("unable to rename temporary index file");

free(idx_tmp_name);
free(pack_tmp_name);
Expand Down Expand Up @@ -1880,7 +1876,7 @@ static void read_object_list_from_stdin(void)
if (!ferror(stdin))
die("fgets returned NULL, not EOF, not error!");
if (errno != EINTR)
die("fgets: %s", strerror(errno));
die_errno("fgets");
clearerr(stdin);
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion builtin-rm.c
Expand Up @@ -257,7 +257,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
continue;
}
if (!removed)
die("git rm: %s: %s", path, strerror(errno));
die_errno("git rm: '%s'", path);
}
}

Expand Down
2 changes: 1 addition & 1 deletion builtin-send-pack.c
Expand Up @@ -59,7 +59,7 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext
po.out = fd;
po.git_cmd = 1;
if (start_command(&po))
die("git pack-objects failed (%s)", strerror(errno));
die_errno("git pack-objects failed");

/*
* We feed the pack-objects we just spawned with revision
Expand Down
7 changes: 3 additions & 4 deletions builtin-tag.c
Expand Up @@ -308,8 +308,7 @@ static void create_tag(const unsigned char *object, const char *tag,
path = git_pathdup("TAG_EDITMSG");
fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0600);
if (fd < 0)
die("could not create file '%s': %s",
path, strerror(errno));
die_errno("could not create file '%s'", path);

if (!is_null_sha1(prev))
write_tag_body(fd, prev);
Expand Down Expand Up @@ -446,8 +445,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
die("cannot read %s", msgfile);
} else {
if (strbuf_read_file(&buf, msgfile, 1024) < 0)
die("could not open or read '%s': %s",
msgfile, strerror(errno));
die_errno("could not open or read '%s'",
msgfile);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion builtin-unpack-objects.c
Expand Up @@ -68,7 +68,7 @@ static void *fill(int min)
if (ret <= 0) {
if (!ret)
die("early EOF");
die("read error on input: %s", strerror(errno));
die_errno("read error on input");
}
len += ret;
} while (len < min);
Expand Down

0 comments on commit d824cbb

Please sign in to comment.