Re: [PATCH v1] convert: add support for 'encoding' attribute

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Dec 11, 2017 at 6:47 PM, Lars Schneider
<larsxschneider@xxxxxxxxx> wrote:
> On 11 Dec 2017, at 19:39, Eric Sunshine <sunshine@xxxxxxxxxxxxxx> wrote:
>> On Mon, Dec 11, 2017 at 10:50 AM,  <lars.schneider@xxxxxxxxxxxx> wrote:
>>> From: Lars Schneider <larsxschneider@xxxxxxxxx>
>>>
>>> Git and its tools (e.g. git diff) expect all text files in UTF-8
>>> encoding. Git will happily accept content in all other encodings, too,
>>> but it might not be able to process the text (e.g. viewing diffs or
>>> changing line endings).
>>>
>>> Add an attribute to tell Git what encoding the user has defined for a
>>> given file. If the content is added to the index, then Git converts the
>>> content to a canonical UTF-8 representation. On checkout Git will
>>> reverse the conversion.
>>>
>>> Reviewed-by: Patrick Lühne <patrick@xxxxxxxxx>
>>> Signed-off-by: Lars Schneider <larsxschneider@xxxxxxxxx>
>>> ---
>>> +static int encode_to_git(const char *path, const char *src, size_t src_len,
>>> +                        struct strbuf *buf, struct encoding *enc)
>>> +{
>>> +       if (enc->to_git == invalid_conversion) {
>>> +               enc->to_git = iconv_open(default_encoding, encoding->name);
>>> +               if (enc->to_git == invalid_conversion)
>>> +                       warning(_("unsupported encoding %s"), encoding->name);
>>> +       }
>>> +
>>> +       if (enc->to_worktree == invalid_conversion)
>>> +               enc->to_worktree = iconv_open(encoding->name, default_encoding);
>>
>> Do you need to be calling iconv_close() somewhere on the result of the
>> iconv_open() calls? [Answering myself after reading the rest of the
>> patch: You're caching these opened 'iconv' descriptors, so you don't
>> plan on closing them.]
>
> Should this information go into the commit message to avoid confusing
> future readers? I think, yes.

Maybe. However, the code which does the actual caching is so distant
from these iconv_open() invocations that it might be more helpful to
have an in-code comment here saying that the "missing" iconv_close()
invocations is intentional.




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux