Skip to content

Commit

Permalink
giterr_set: consistent error messages
Browse files Browse the repository at this point in the history
Error messages should be sentence fragments, and therefore:

1. Should not begin with a capital letter,
2. Should not conclude with punctuation, and
3. Should not end a sentence and begin a new one
  • Loading branch information
Edward Thomson committed Dec 29, 2016
1 parent 238b8cc commit 909d549
Show file tree
Hide file tree
Showing 94 changed files with 496 additions and 496 deletions.
4 changes: 2 additions & 2 deletions src/apply.c
Expand Up @@ -173,7 +173,7 @@ static int apply_hunk(
git_diff_line *line = git_array_get(patch->lines, linenum);

if (!line) {
error = apply_err("Preimage does not contain line %"PRIuZ, linenum);
error = apply_err("preimage does not contain line %"PRIuZ, linenum);
goto done;
}

Expand All @@ -193,7 +193,7 @@ static int apply_hunk(
line_num = hunk->hunk.new_start ? hunk->hunk.new_start - 1 : 0;

if (!find_hunk_linenum(&line_num, image, &preimage, line_num)) {
error = apply_err("Hunk at line %d did not apply",
error = apply_err("hunk at line %d did not apply",
hunk->hunk.new_start);
goto done;
}
Expand Down
10 changes: 5 additions & 5 deletions src/attr_file.c
Expand Up @@ -30,7 +30,7 @@ int git_attr_file__new(
GITERR_CHECK_ALLOC(attrs);

if (git_mutex_init(&attrs->lock) < 0) {
giterr_set(GITERR_OS, "Failed to initialize lock");
giterr_set(GITERR_OS, "failed to initialize lock");
git__free(attrs);
return -1;
}
Expand All @@ -49,7 +49,7 @@ int git_attr_file__clear_rules(git_attr_file *file, bool need_lock)
git_attr_rule *rule;

if (need_lock && git_mutex_lock(&file->lock) < 0) {
giterr_set(GITERR_OS, "Failed to lock attribute file");
giterr_set(GITERR_OS, "failed to lock attribute file");
return -1;
}

Expand Down Expand Up @@ -140,7 +140,7 @@ int git_attr_file__load(
break;
}
default:
giterr_set(GITERR_INVALID, "Unknown file source %d", source);
giterr_set(GITERR_INVALID, "unknown file source %d", source);
return -1;
}

Expand Down Expand Up @@ -212,7 +212,7 @@ int git_attr_file__out_of_date(
}

default:
giterr_set(GITERR_INVALID, "Invalid file type %d", file->source);
giterr_set(GITERR_INVALID, "invalid file type %d", file->source);
return -1;
}
}
Expand All @@ -238,7 +238,7 @@ int git_attr_file__parse_buffer(
context = attrs->entry->path;

if (git_mutex_lock(&attrs->lock) < 0) {
giterr_set(GITERR_OS, "Failed to lock attribute file");
giterr_set(GITERR_OS, "failed to lock attribute file");
return -1;
}

Expand Down
6 changes: 3 additions & 3 deletions src/attrcache.c
Expand Up @@ -12,7 +12,7 @@ GIT_INLINE(int) attr_cache_lock(git_attr_cache *cache)
GIT_UNUSED(cache); /* avoid warning if threading is off */

if (git_mutex_lock(&cache->lock) < 0) {
giterr_set(GITERR_OS, "Unable to get attr cache lock");
giterr_set(GITERR_OS, "unable to get attr cache lock");
return -1;
}
return 0;
Expand Down Expand Up @@ -365,7 +365,7 @@ int git_attr_cache__do_init(git_repository *repo)

/* set up lock */
if (git_mutex_init(&cache->lock) < 0) {
giterr_set(GITERR_OS, "Unable to initialize lock for attr cache");
giterr_set(GITERR_OS, "unable to initialize lock for attr cache");
git__free(cache);
return -1;
}
Expand Down Expand Up @@ -430,7 +430,7 @@ int git_attr_cache__insert_macro(git_repository *repo, git_attr_rule *macro)
return 0;

if (git_mutex_lock(&cache->lock) < 0) {
giterr_set(GITERR_OS, "Unable to get attr cache lock");
giterr_set(GITERR_OS, "unable to get attr cache lock");
error = -1;
} else {
git_strmap_insert(macros, macro->match.pattern, macro, error);
Expand Down
6 changes: 3 additions & 3 deletions src/blob.c
Expand Up @@ -96,7 +96,7 @@ static int write_file_stream(
p_close(fd);

if (written != file_size || read_len < 0) {
giterr_set(GITERR_OS, "Failed to read file into stream");
giterr_set(GITERR_OS, "failed to read file into stream");
error = -1;
}

Expand Down Expand Up @@ -142,7 +142,7 @@ static int write_symlink(

read_len = p_readlink(path, link_data, link_size);
if (read_len != (ssize_t)link_size) {
giterr_set(GITERR_OS, "Failed to create blob. Can't read symlink '%s'", path);
giterr_set(GITERR_OS, "failed to create blob: cannot read symlink '%s'", path);
git__free(link_data);
return -1;
}
Expand Down Expand Up @@ -186,7 +186,7 @@ int git_blob__create_from_paths(
goto done;

if (S_ISDIR(st.st_mode)) {
giterr_set(GITERR_ODB, "cannot create blob from '%s'; it is a directory", content_path);
giterr_set(GITERR_ODB, "cannot create blob from '%s': it is a directory", content_path);
error = GIT_EDIRECTORY;
goto done;
}
Expand Down
20 changes: 10 additions & 10 deletions src/branch.c
Expand Up @@ -33,7 +33,7 @@ static int retrieve_branch_reference(
/* OOM */;
else if ((error = git_reference_lookup(&branch, repo, ref_name.ptr)) < 0)
giterr_set(
GITERR_REFERENCE, "Cannot locate %s branch '%s'",
GITERR_REFERENCE, "cannot locate %s branch '%s'",
is_remote ? "remote-tracking" : "local", branch_name);

*branch_reference_out = branch; /* will be NULL on error */
Expand All @@ -46,7 +46,7 @@ static int not_a_local_branch(const char *reference_name)
{
giterr_set(
GITERR_INVALID,
"Reference '%s' is not a local branch.", reference_name);
"reference '%s' is not a local branch.", reference_name);
return -1;
}

Expand Down Expand Up @@ -80,7 +80,7 @@ static int create_branch(
}

if (is_unmovable_head && force) {
giterr_set(GITERR_REFERENCE, "Cannot force update branch '%s' as it is "
giterr_set(GITERR_REFERENCE, "cannot force update branch '%s' as it is "
"the current HEAD of the repository.", branch_name);
error = -1;
goto cleanup;
Expand Down Expand Up @@ -135,7 +135,7 @@ int git_branch_delete(git_reference *branch)
assert(branch);

if (!git_reference_is_branch(branch) && !git_reference_is_remote(branch)) {
giterr_set(GITERR_INVALID, "Reference '%s' is not a valid branch.",
giterr_set(GITERR_INVALID, "reference '%s' is not a valid branch.",
git_reference_name(branch));
return GIT_ENOTFOUND;
}
Expand All @@ -144,7 +144,7 @@ int git_branch_delete(git_reference *branch)
return is_head;

if (is_head) {
giterr_set(GITERR_REFERENCE, "Cannot delete branch '%s' as it is "
giterr_set(GITERR_REFERENCE, "cannot delete branch '%s' as it is "
"the current HEAD of the repository.", git_reference_name(branch));
return -1;
}
Expand Down Expand Up @@ -306,7 +306,7 @@ int git_branch_name(
branch_name += strlen(GIT_REFS_REMOTES_DIR);
} else {
giterr_set(GITERR_INVALID,
"Reference '%s' is neither a local nor a remote branch.", ref->name);
"reference '%s' is neither a local nor a remote branch.", ref->name);
return -1;
}
*out = branch_name;
Expand Down Expand Up @@ -436,7 +436,7 @@ int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refna

/* Verify that this is a remote branch */
if (!git_reference__is_remote(refname)) {
giterr_set(GITERR_INVALID, "Reference '%s' is not a remote branch.",
giterr_set(GITERR_INVALID, "reference '%s' is not a remote branch.",
refname);
error = GIT_ERROR;
goto cleanup;
Expand All @@ -463,7 +463,7 @@ int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refna
git_remote_free(remote);

giterr_set(GITERR_REFERENCE,
"Reference '%s' is ambiguous", refname);
"reference '%s' is ambiguous", refname);
error = GIT_EAMBIGUOUS;
goto cleanup;
}
Expand All @@ -477,7 +477,7 @@ int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refna
error = git_buf_puts(buf, remote_name);
} else {
giterr_set(GITERR_REFERENCE,
"Could not determine remote for '%s'", refname);
"could not determine remote for '%s'", refname);
error = GIT_ENOTFOUND;
}

Expand Down Expand Up @@ -566,7 +566,7 @@ int git_branch_set_upstream(git_reference *branch, const char *upstream_name)
local = 0;
else {
giterr_set(GITERR_REFERENCE,
"Cannot set upstream for branch '%s'", shortname);
"cannot set upstream for branch '%s'", shortname);
return GIT_ENOTFOUND;
}

Expand Down
8 changes: 4 additions & 4 deletions src/buffer.c
Expand Up @@ -962,14 +962,14 @@ int git_buf_unquote(git_buf *buf)
case '0': case '1': case '2': case '3':
if (j == buf->size-3) {
giterr_set(GITERR_INVALID,
"Truncated quoted character \\%c", ch);
"truncated quoted character \\%c", ch);
return -1;
}

if (buf->ptr[j+1] < '0' || buf->ptr[j+1] > '7' ||
buf->ptr[j+2] < '0' || buf->ptr[j+2] > '7') {
giterr_set(GITERR_INVALID,
"Truncated quoted character \\%c%c%c",
"truncated quoted character \\%c%c%c",
buf->ptr[j], buf->ptr[j+1], buf->ptr[j+2]);
return -1;
}
Expand All @@ -981,7 +981,7 @@ int git_buf_unquote(git_buf *buf)
break;

default:
giterr_set(GITERR_INVALID, "Invalid quoted character \\%c", ch);
giterr_set(GITERR_INVALID, "invalid quoted character \\%c", ch);
return -1;
}
}
Expand All @@ -995,6 +995,6 @@ int git_buf_unquote(git_buf *buf)
return 0;

invalid:
giterr_set(GITERR_INVALID, "Invalid quoted line");
giterr_set(GITERR_INVALID, "invalid quoted line");
return -1;
}
2 changes: 1 addition & 1 deletion src/cache.c
Expand Up @@ -70,7 +70,7 @@ int git_cache_init(git_cache *cache)
cache->map = git_oidmap_alloc();
GITERR_CHECK_ALLOC(cache->map);
if (git_rwlock_init(&cache->lock)) {
giterr_set(GITERR_OS, "Failed to initialize cache rwlock");
giterr_set(GITERR_OS, "failed to initialize cache rwlock");
return -1;
}
return 0;
Expand Down

0 comments on commit 909d549

Please sign in to comment.