git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Should the --encoding argument to log/show commands make any guarantees about their output?

From
JGJan-Philip Gehrcke <jgehrcke@googlemail.com>
Date
Jun 17, 2015, 17:07 UTC
Message-ID
<5581A964.4000500@googlemail.com>
In-Reply-To
<xmqqzj3y2snq.fsf@gitster.dls.corp.google.com>
On 17.06.2015 18:42, Junio C Hamano wrote:
Show 17 quoted lines
> Jan-Philip Gehrcke <jgehrcke@googlemail.com> writes:
>
>> I was surprised to see that the output of
>>
>>      git log --encoding=utf-8 "--format=format:%b"
>>
>> can contain byte sequences that are invalid in UTF-8. Note: I am using
>> git 2.1.4 and the %b format specifier represents the commit message
>> body.
>
> Yeah, if the original was bad and cannot be sanely expressed in
> UTF-8, you have two options.  You can show the contents as raw bytes
> recorded in the object with a warning so that the user can use it as
> such (e.g. perhaps the original was indeed an iso8859-2 but was
> incorrectly marked as UTF-8, or something like that, and a human
> that is more intelligent than a tool _could_ guess and attempt to
> recover).  Or you can error out and refuse to produce output.

The two-option scenario is totally clear. Although one must stress that the "error-out" option can, as discussed, be kept minimally invasive: it is sufficient (and common) to just skip those byte sequences (and replace them with a replacement symbol) that would be invalid in the requested output encoding. This would retain as much information as possible while guaranteeing a subsequent decoder to retrieve valid input.

> We deliberately made a design choice to take the former option.

I totally support this design choice in general, especially when invoking `git whatever` without options. This here is, I think, mainly about documentation and the semantics of "--encoding". From my point of view, `--encoding=utf-8` semantically suggests that the output *is* valid UTF-8. But it is not, not always. May initial question was: what do you think about this? Should we

* just make this more clear in the docs and/or
* should we adjust the behavior of --encoding or
* should we do something entirely different, like adding a new command 
line option or
* should we just leave things as they are?
Thanks and cheers,
Jan-Philip
Previous: Junio C HamanoNext: Jeff King
Message 6 of 9 in “Should the --encoding argument to log/show commands make any guarantees about their output?”
  1. Jan-Philip GehrckeJun 15, 2015
  2. Torsten BögershausenJun 15, 2015
  3. Jan-Philip GehrckeJun 16, 2015
  4. Torsten BögershausenJun 16, 2015
  5. Junio C HamanoJun 17, 2015
  6. Jan-Philip GehrckeJun 17, 2015
  7. Jeff KingJun 17, 2015
  8. Junio C HamanoJun 17, 2015
  9. Torsten BögershausenJun 17, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.