Re: [PATCH] Reencode committer info to utf-8 before formatting mail header

Subsystems: the rest

7 messages, 4 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] Reencode committer info to utf-8 before formatting mail header

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:49

Side note.  The previous patch does not help if your commit were
made in non UTF-8 with not too recent git; the code assumes that
commit messages without the new "encoding" headers are in UTF-8.

We might want to help transitioning people by doing something
like this on top of the previous patch.  Then when dealing with
an ancient commit (sorry, I am not saying commits older than 3
weeks are ancient -- but it will be 6 months from now ;-), you
can override that default by setting an environment variable.

---
diff --git a/commit.c b/commit.c
index 9b2b842..a1b5705 100644
--- a/commit.c
+++ b/commit.c
@@ -692,8 +692,12 @@ static char *logmsg_reencode(const struct commit *commit,
 	if (!*output_encoding)
 		return NULL;
 	encoding = get_header(commit, "encoding");
-	if (!encoding)
-		encoding = utf8;
+	if (!encoding) {
+		if (getenv("GIT_OLD_COMMIT_ENCODING"))
+			encoding = strdup(getenv("GIT_OLD_COMMIT_ENCODING"));
+		else
+			encoding = utf8;
+	}
 	if (!strcmp(encoding, output_encoding))
 		out = strdup(commit->buffer);
 	else

Re: [PATCH] Reencode committer info to utf-8 before formatting mail header

From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:42:49

Hi,

On Fri, 12 Jan 2007, Junio C Hamano wrote:
Side note.  The previous patch does not help if your commit were
made in non UTF-8 with not too recent git; the code assumes that
commit messages without the new "encoding" headers are in UTF-8.
Why not just use is_utf8() and warn, or error out, if the message is not 
UTF-8? (I tend towards the erroring out, since this _is_ a new feature, 
and gives undesired results with "old" commits.)

Ciao,
Dscho

Re: [PATCH] Reencode committer info to utf-8 before formatting mail header

From: Robin Rosenberg <hidden>
Date: 2016-06-15 22:42:49

lördag 13 januari 2007 02:43 skrev Junio C Hamano:
Side note.  The previous patch does not help if your commit were
made in non UTF-8 with not too recent git; the code assumes that
commit messages without the new "encoding" headers are in UTF-8.
Wasn't there a repository option, "commitencoding"?  I can't see it being
used here. I.e., we should err out if the log message is not UTF-8 and the 
option is not set (giving a message telling the user to set it).  If it is 
set we should consider the repository encoding to be the one and if that too 
is wrong (only possible to detect for some encodings), just assume iso-8859-1 
as anything could in theory be iso-8859-1 encoded.  

-- robin

Re: [PATCH] Reencode committer info to utf-8 before formatting mail header

From: David Kågedal <hidden>
Date: 2016-06-15 22:42:49

Junio C Hamano [off-list ref] writes:
Side note.  The previous patch does not help if your commit were
made in non UTF-8 with not too recent git; the code assumes that
commit messages without the new "encoding" headers are in UTF-8.
This was exactly the problem I was trying to solve.
quoted hunk
We might want to help transitioning people by doing something
like this on top of the previous patch.  Then when dealing with
an ancient commit (sorry, I am not saying commits older than 3
weeks are ancient -- but it will be 6 months from now ;-), you
can override that default by setting an environment variable.

---
diff --git a/commit.c b/commit.c
index 9b2b842..a1b5705 100644
--- a/commit.c
+++ b/commit.c
@@ -692,8 +692,12 @@ static char *logmsg_reencode(const struct commit *commit,
 	if (!*output_encoding)
 		return NULL;
 	encoding = get_header(commit, "encoding");
-	if (!encoding)
-		encoding = utf8;
+	if (!encoding) {
+		if (getenv("GIT_OLD_COMMIT_ENCODING"))
+			encoding = strdup(getenv("GIT_OLD_COMMIT_ENCODING"));
+		else
+			encoding = utf8;
+	}
 	if (!strcmp(encoding, output_encoding))
 		out = strdup(commit->buffer);
 	else

-- 
David Kågedal

Re: [PATCH] Reencode committer info to utf-8 before formatting mail header

From: David Kågedal <hidden>
Date: 2016-06-15 22:42:49

Johannes Schindelin [off-list ref] writes:
Hi,

On Fri, 12 Jan 2007, Junio C Hamano wrote:
quoted
Side note.  The previous patch does not help if your commit were
made in non UTF-8 with not too recent git; the code assumes that
commit messages without the new "encoding" headers are in UTF-8.
Why not just use is_utf8() and warn, or error out, if the message is not 
UTF-8? (I tend towards the erroring out, since this _is_ a new feature, 
and gives undesired results with "old" commits.)
What do you mean? I have an old repository with latin1 commits without
any encoding markers.  I want to be able to use format-patch from that
and at least get a From: line with something readable.  You can't just
barf and say "This isn't UTF-8, go away".

-- 
David Kågedal

Re: [PATCH] Reencode committer info to utf-8 before formatting mail header

From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:42:49

Hi,

On Mon, 15 Jan 2007, David Kågedal wrote:
Johannes Schindelin [off-list ref] writes:
quoted
On Fri, 12 Jan 2007, Junio C Hamano wrote:
quoted
Side note.  The previous patch does not help if your commit were
made in non UTF-8 with not too recent git; the code assumes that
commit messages without the new "encoding" headers are in UTF-8.
Why not just use is_utf8() and warn, or error out, if the message is not 
UTF-8? (I tend towards the erroring out, since this _is_ a new feature, 
and gives undesired results with "old" commits.)
What do you mean? I have an old repository with latin1 commits without
any encoding markers.  I want to be able to use format-patch from that
and at least get a From: line with something readable.  You can't just
barf and say "This isn't UTF-8, go away".
So what do you want to do instead? Just pretend that the unrecoded -- 
Latin-1 encoded -- text is UTF-8? That's plain wrong.

Ciao,
Dscho

Re: [PATCH] Reencode committer info to utf-8 before formatting mail header

From: David Kågedal <hidden>
Date: 2016-06-15 22:42:49

Johannes Schindelin [off-list ref] writes:
Hi,

On Mon, 15 Jan 2007, David Kågedal wrote:
quoted
Johannes Schindelin [off-list ref] writes:
quoted
On Fri, 12 Jan 2007, Junio C Hamano wrote:
quoted
Side note.  The previous patch does not help if your commit were
made in non UTF-8 with not too recent git; the code assumes that
commit messages without the new "encoding" headers are in UTF-8.
Why not just use is_utf8() and warn, or error out, if the message is not 
UTF-8? (I tend towards the erroring out, since this _is_ a new feature, 
and gives undesired results with "old" commits.)
What do you mean? I have an old repository with latin1 commits without
any encoding markers.  I want to be able to use format-patch from that
and at least get a From: line with something readable.  You can't just
barf and say "This isn't UTF-8, go away".
So what do you want to do instead? Just pretend that the unrecoded -- 
Latin-1 encoded -- text is UTF-8? That's plain wrong.
That is what git did before I wrote my patch, so it obviously not what
I want.  I want to be able to tell git what encoding it is.

My patch reused the i18n.commitencoding configuration parameter for
that, but Junio is probably right in that that is only meant for new
commits, and an evironment variable makes more sense.

So just barfing on a commit that isn't utf-8 isn't a complete
solution.  But maybe there was some context to your comment above that
I missed.

-- 
David Kågedal
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help