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

Re: [PATCH v1 2/2] convert: add alias support for 'working-tree-encoding' attributes

From
Lars Schneider <larsxschneider@gmail.com>
Date
Jul 8, 2018, 18:39 UTC
Message-ID
<9DAA19D0-AE1A-493B-B6F5-2FA38E876928@gmail.com>
In-Reply-To
<20180708183036.29459-3-larsxschneider@gmail.com>
Show 55 quoted lines
> On Jul 8, 2018, at 8:30 PM, larsxschneider@gmail.com wrote:
> 
> From: Lars Schneider <larsxschneider@gmail.com>
> 
> In 107642fe26 ("convert: add 'working-tree-encoding' attribute",
> 2018-04-15) we added an attribute which defines the working tree
> encoding of a file.
> 
> Some platforms might spell the name of a certain encoding differently or
> some users might want to use different encodings on different platforms.
> Add the Git config "encoding.<iconv-name>.insteadOf = <alias-name>" to
> support these use-cases with a user specific mapping. If the alias
> matches an existing encoding name, then the alias will take precedence.
> The alias is case insensitive.
> 
> Example:
> 
> 	(in .gitattributes)
> 	*.c	working-tree-encoding=foo
> 
> 	(in config)
> 	[encoding "UTF-16"]
> 		insteadOf = foo
> 
> Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
> ---
> Documentation/gitattributes.txt  | 19 ++++++++++++
> convert.c                        | 50 ++++++++++++++++++++++++++++++++
> t/t0028-working-tree-encoding.sh | 28 ++++++++++++++++++
> 3 files changed, 97 insertions(+)
> 
> diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
> index 92010b062e..3628f0e5cf 100644
> --- a/Documentation/gitattributes.txt
> +++ b/Documentation/gitattributes.txt
> @@ -366,6 +366,25 @@ command to guess the encoding:
> file foo.ps1
> ------------------------
> 
> ...
> 
> 	return 0;
> @@ -1225,6 +1264,17 @@ static const char *git_path_check_encoding(struct attr_check_item *check)
> 		die(_("true/false are no valid working-tree-encodings"));
> 	}
> 
> +	/* Check if an alias was defined for the encoding in the Git config */
> +	if (encoding_aliases_initialized) {
> +		struct alias2enc hashkey;
> +		struct alias2enc *entry;
> +		hashmap_entry_init(&hashkey, strihash(value));
> +		hashkey.alias = value;
> +		entry = hashmap_get(&encoding_map, &hashkey, NULL);
> +		if (entry)
> +			value = entry->encoding;

Here I reuse the char* pointer from the hashmap. The hashmap is static and no entry is ever removed. Is this OK or should I rather create a copy of the string?

Thanks, Lars

Previous: larsxschneider@gmail.comNext: Junio C Hamano
Message 7 of 8 in “convert: add alias support for 'working-tree-encoding' attributes”
  1. 0/2 convert: add alias support for 'working-tree-encoding' attributeslarsxschneider@gmail.com, Jul 8, 2018
  2. 1/2 convert: refactor conversion driver config parsinglarsxschneider@gmail.com, Jul 8, 2018
  3. Lars SchneiderJul 8, 2018
  4. Junio C HamanoJul 9, 2018
  5. Junio C HamanoJul 10, 2018
  6. 2/2 convert: add alias support for 'working-tree-encoding' attributeslarsxschneider@gmail.com, Jul 8, 2018
  7. Lars SchneiderJul 8, 2018
  8. Junio C HamanoJul 10, 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.