summaryrefslogtreecommitdiff
path: root/ref-filter.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2018-11-10 05:16:11 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-11-12 05:47:09 (GMT)
commit9440b831ad5b1750b65fa3f1d0b99179ab317c76 (patch)
tree64f2fa307e00fef20bc714ca6ba06fcca1b65b79 /ref-filter.c
parentc83d950e591c393c241dcd656d14a21cd16c2b81 (diff)
downloadgit-9440b831ad5b1750b65fa3f1d0b99179ab317c76.zip
git-9440b831ad5b1750b65fa3f1d0b99179ab317c76.tar.gz
git-9440b831ad5b1750b65fa3f1d0b99179ab317c76.tar.bz2
parse-options: replace opterror() with optname()
Introduce optname() that does the early half of original opterror() to come up with the name of the option reported back to the user, and use it to kill opterror(). The callers of opterror() now directly call error() using the string returned by opterror() instead. There are a few issues with opterror() - it tries to assemble an English sentence from pieces. This is not great for translators because we give them pieces instead of a full sentence. - It's a wrapper around error() and needs some hack to let the compiler know it always returns -1. - Since it takes a string instead of printf format, one call site has to assemble the string manually before passing to it. Using error() directly solves the second and third problems. It kind helps the first problem as well because "%s does foo" does give a translator a full sentence in a sense and let them reorder if needed. But it has limitations, if the subject part has to change based on the rest of the sentence, that language is screwed. This is also why I try to avoid calling optname() when 'flags' is known in advance. Mark of these strings for translation as well while at there. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'ref-filter.c')
-rw-r--r--ref-filter.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/ref-filter.c b/ref-filter.c
index 2a05619..0681359 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -2302,9 +2302,11 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
if (rf->merge) {
if (no_merged) {
- return opterror(opt, "is incompatible with --merged", 0);
+ return error(_("option `%s' is incompatible with --merged"),
+ opt->long_name);
} else {
- return opterror(opt, "is incompatible with --no-merged", 0);
+ return error(_("option `%s' is incompatible with --no-merged"),
+ opt->long_name);
}
}
@@ -2318,7 +2320,7 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
rf->merge_commit = lookup_commit_reference_gently(the_repository,
&oid, 0);
if (!rf->merge_commit)
- return opterror(opt, "must point to a commit", 0);
+ return error(_("option `%s' must point to a commit"), opt->long_name);
return 0;
}