From: Junio C Hamano <gitster@pobox.com>
To: Alexander Gavrilov <angavrilov@gmail.com>
Cc: git@vger.kernel.org, Paul Mackerras <paulus@samba.org>
Subject: Re: [RFC PATCH] commit: Warn about encodings unsupported by iconv.
Date: Mon, 20 Oct 2008 17:39:36 -0700 [thread overview]
Message-ID: <7vmygy233r.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <1224537918-14024-1-git-send-email-angavrilov@gmail.com> (Alexander Gavrilov's message of "Tue, 21 Oct 2008 01:25:18 +0400")
Alexander Gavrilov <angavrilov@gmail.com> writes:
> diff --git a/builtin-commit-tree.c b/builtin-commit-tree.c
> index 0453425..7f325a3 100644
> --- a/builtin-commit-tree.c
> +++ b/builtin-commit-tree.c
> @@ -45,6 +45,28 @@ static const char commit_utf8_warn[] =
> "You may want to amend it after fixing the message, or set the config\n"
> "variable i18n.commitencoding to the encoding your project uses.\n";
>
> +static const char commit_bad_encoding_warn[] =
> +"Warning: commit encoding '%s' is not supported.\n"
> +"You may want to change the value of the i18n.commitencoding config\n"
> +"variable, and redo the commit. Use 'iconv --list' to see the list of\n"
> +"available encoding names.\n";
> +
> +static void verify_commit_encoding(const char *text, const char *encoding)
> +{
> + if (is_encoding_utf8(encoding)) {
> + if (!is_utf8(text))
> + fprintf(stderr, commit_utf8_warn);
> + }
> +#ifndef NO_ICONV
> + else {
> + char *conv = reencode_string("", "utf-8", encoding);
> + if (!conv)
> + fprintf(stderr, commit_bad_encoding_warn, encoding);
> + free(conv);
> + }
> +#endif
> +}
> +
I think the issue you are attempting to tackle is worth addressing, but I
am not sure if this is the best approach.
Commit_tree() does not re-encode the payload.
It just marks it with the encoding header. Wouldn't that mean that it
should be possible for you to create a commit with its message encoded in
KOI-8, and mark the resulting commit as encoded as such, on a host that is
incapable of actually transcoding from KOI-8 to utf-8? IOW, your being
able to encode from i18n.commitencoding to utf-8 does not have much to do
with the validity of the configuration variable.
It would clarify the issues to think about what this new code would do on
a host without iconv, if you do not have the above #ifndef/#endif pair.
The replacement reencode_string() implementation always returns NULL, so
the code will always warn.
I am guessing that the reason you added #ifndef/#endif is because what the
warning message says is incorrect.
* "is not supported" is not correct. "is not supported HERE" may be.
* "is not supported" (nor "is not supported HERE") does not matter. It
is log-reading side that does the re-encoding, not the commit
generating side.
* what you would really want to say is "might be incorrectly spelled",
but your problem is that you do not have a direct way to check that.
Another reason of your "#ifndef/#endif" would be that there is no way to
squelch the warning message after seeing it on a NO_ICONV platform.
But that suggests that the "#ifndef/#endif" is not a good way to squelch
the message. What would you do, after seeing the warning message and
examining the situation, you know KOI-8 is a valid encoding name, your
editor is recording what you type in the commit log message in KOI-8, you
know you set i18n.commitencoding to KOI-8, and you know somehow your
system is incapable of reencode_string("", "utf-8" "KOI-8")? There is no
way to squelch the message.
So perhaps you would need some "state" variable that says "I know this
i18n.commitencoding configuration is valid" if you go this route? But the
reason for "I know" would be either (1) because we earlier tried
reencode_string() and it resulted in an Ok return, or (2) because the user
verified that the configuration is valid, even though on this particular
system it cannot be encoded to utf-8. IOW, the latter one would be
"because the user tells us so" --- which would be the same as trusting
i18n.commitencoding from the beginning. I dunno.
I actually have an alternative approach to suggest.
How about adding a new i18n.commit-reencode-logmessage option (boolean),
and when it is set, we actually re-encode from i18n.commitencoding to
"utf-8" before creating the commit object (and obviously we do not store
"encoding" header in the resulting commit)? When the conversion fails, we
know it failed, so the warning you added does make sense in that context.
next prev parent reply other threads:[~2008-10-21 0:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-20 21:25 [RFC PATCH] commit: Warn about encodings unsupported by iconv Alexander Gavrilov
2008-10-21 0:39 ` Junio C Hamano [this message]
2008-10-21 6:17 ` Alex Riesen
2008-10-21 10:43 ` Alexander Gavrilov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vmygy233r.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=angavrilov@gmail.com \
--cc=git@vger.kernel.org \
--cc=paulus@samba.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).