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

Re: Use of new .gitattributes working-tree-encoding attribute across different platform types

From
Lars Schneider <larsxschneider@gmail.com>
Date
Jul 2, 2018, 14:09 UTC
Message-ID
<4621C69D-B837-43ED-8570-462D4CF2BBA0@gmail.com>
In-Reply-To
<OFAD36A6D5.F36D27E7-ON002582BE.0043296C-002582BE.0043297F@notes.na.collabserv.com>
Show 53 quoted lines
> -----Lars Schneider <larsxschneider@gmail.com> wrote: -----
> To: Jeff King <peff@peff.net>
> From: Lars Schneider <larsxschneider@gmail.com>
> Date: 06/28/2018 18:21
> Cc: "brian m. carlson" <sandals@crustytoothpaste.net>, Steve Groeger <GROEGES@uk.ibm.com>, git@vger.kernel.org
> Subject: Re: Use of new .gitattributes working-tree-encoding attribute across different platform types
> 
> 
>> On Jun 28, 2018, at 4:34 PM, Jeff King <peff@peff.net> wrote:
>> 
>> On Thu, Jun 28, 2018 at 02:44:47AM +0000, brian m. carlson wrote:
>> 
>>> On Wed, Jun 27, 2018 at 07:54:52AM +0000, Steve Groeger wrote:
>>>> We have common code that is supposed to be usable across different platforms and hence different file encodings. With the full support of the working-tree-encoding in the latest version of git on all platforms, how do we have files converted to different encodings on different platforms?
>>>> I could not find anything that would allow us to say 'if platform = z/OS then encoding=EBCDIC else encoding=ASCII'.   Is there a way this can be done?
>>> 
>>> I don't believe there is such functionality.  Git doesn't have
>>> attributes that are conditional on the platform in that sort of way.
>>> You could use a smudge/clean filter and adjust the filter for the
>>> platform you're on, which might meet your needs.
>> 
>> We do have prior art in the line-ending code, though. There the
>> attributes say either that a file needs a specific line-ending type
>> (which is relatively rare), or that it should follow the system type,
>> which is then set separately in the config.
>> 
>> I have the impression that the working-tree-encoding stuff was made to
>> handle the first case, but not the second. It doesn't seem like an
>> outrageous thing to eventually add.
>> 
>> (Though I agree that clean/smudge filters would work, and can even
>> implement the existing working-tree-encoding feature, albeit less
>> efficiently and conveniently).
> 
> Thanks for the suggestion Peff! 
> How about this:
> 
> 1) We allow users to set the encoding "auto". Example:
> 
> 	*.txt working-tree-encoding=auto
> 
> 2) We define a new variable `core.autoencoding`. By default the value is 
> UTF-8 (== no re-encoding) but user can set to any value in their Git config. 
> Example:
> 
>    git config --global core.autoencoding UTF-16
> 
> All files marked with the value "auto" will use the encoding defined in
> `core.autoencoding`.
> 
> Would that work?
> 
> @steve: Would that fix your problem?
On Jul 2, 2018, at 2:13 PM, Steve Groeger <GROEGES@uk.ibm.com> wrote:
> 
> I think this proposed solution may resolve my issue.
Thanks for the confirmation!

Brian had a good argument [1] for an even more flexible system proposed by Peff:

1) We allow users to define custom encoding mappings in their Git config. 
Example:
    git config --global core.encoding.myenc UTF-16
2) Users can reuse these mappings in ther .gitattributes files:
    *.txt working-tree-encoding=myenc
Does this idea look good to everyone?

Thanks, Lars

[1] https://public-inbox.org/git/20180701175657.GC7965@genre.crustytoothpaste.net/
Previous: Steve GroegerNext: Jeff King
Message 11 of 12 in “Use of new .gitattributes working-tree-encoding attribute across different platform types”
  1. Steve GroegerJun 27, 2018
  2. Torsten BögershausenJun 27, 2018
  3. brian m. carlsonJun 28, 2018
  4. Jeff KingJun 28, 2018
  5. Lars SchneiderJun 28, 2018
  6. Jeff KingJun 28, 2018
  7. brian m. carlsonJul 1, 2018
  8. Jeff KingJul 2, 2018
  9. Junio C HamanoJul 3, 2018
  10. Steve GroegerJul 2, 2018
  11. Lars SchneiderJul 2, 2018
  12. Jeff KingJul 2, 2018

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.