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

Re: RFC: Native clean/smudge filter for UTF-16 files

From
Torsten Bögershausen <tboegi@web.de>
Date
Nov 23, 2017, 20:09 UTC
Message-ID
<20171123200913.GA29990@tor.lan>
In-Reply-To
<BDB9B884-6D17-4BE3-A83C-F67E2AFA2B46@gmail.com>
On Thu, Nov 23, 2017 at 04:18:59PM +0100, Lars Schneider wrote:
Show 26 quoted lines
> Hi,
> 
> I am working with a team that owns a repository with lots of UTF-16 files.
> Converting these files to UTF-8 is no good option as downstream applications
> require the UTF-16 encoding. Keeping the files in UTF-16 is no good option
> either as Git and Git related tools (e.g. GitHub) consider the files binary
> and consequently do not render diffs.
> 
> The obvious solution is to setup a clean/smudge filter like this [1]:
>     [filter "winutf16"]
>         clean = iconv -f utf-16 -t utf-8
>         smudge = iconv -f utf-8 -t utf-16
> 
> In general this works well but the "per-file" clean/smudge process invocation 
> can be slow for many files. I could apply the same trick that we used for Git
> LFS and write a iconv that processes all files with a single invocation (see
> "edcc85814c convert: add filter.<driver>.process option" [2]). 
> 
> Alternatively, I could add a native attribute to Git that translates UTF-16 
> to UTF-8 and back. A conversion function is already available in "mingw.h" [3]
> on Windows. Limiting this feature to Windows wouldn't be a problem from my
> point of view as UTF-16 is only relevant on Windows anyways. The attribute 
> could look like this:
> 
>     *.txt        text encoding=utf-16
> 

I would probably vote for UTF-16LE. But we can specify whatever iconv allows, see below.

[]
> Do you think a patch that converts UTF-16 files to UTF-8 via an attribute
> "encoding=utf-16" on Windows would have a chance to get accepted?

Yes. The thing is that we have convert.c and utf8.c (reencode_string_iconv() and possible strbuf.c, which feels that they are in charge here.

Having a path using mingw.h would mean that this is Windows only,
and that is not a good solution.
(I sometimes host files on a Linux box, export them via SAMBA to
 Mac and Windows. Having that kind of setup allows to commit
 directly on the Linux fileserver)

But even if you don't have that setup, cross platform is a must, I would say. There may be possible optimizations using xutftowcsn() and friends under Windows, but they may come later into the picture (or are not needed) What file sizes are we talking about ? 100K ? 100M ?

It is even possible to hook into the streaming interface.
> 
> Thanks,
> Lars
> 
Previous: Lars SchneiderNext: Jeff King
Message 2 of 6 in “RFC: Native clean/smudge filter for UTF-16 files”
  1. Lars SchneiderNov 23, 2017
  2. Torsten BögershausenNov 23, 2017
  3. Jeff KingNov 24, 2017
  4. Junio C HamanoNov 25, 2017
  5. Lars SchneiderDec 3, 2017
  6. Jeff KingDec 4, 2017

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.