Skip to content

Commit d9e2677

Browse files
committed
Merge branch 'jk/log-warn-on-bogus-encoding' into maint
Doc update plus improved error reporting. * jk/log-warn-on-bogus-encoding: docs: use "character encoding" to refer to commit-object encoding logmsg_reencode(): warn when iconv() fails
2 parents 48939c5 + 1e93770 commit d9e2677

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

Documentation/config/gui.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ gui.displayUntracked::
1111
in the file list. The default is "true".
1212

1313
gui.encoding::
14-
Specifies the default encoding to use for displaying of
14+
Specifies the default character encoding to use for displaying of
1515
file contents in linkgit:git-gui[1] and linkgit:gitk[1].
1616
It can be overridden by setting the 'encoding' attribute
1717
for relevant files (see linkgit:gitattributes[5]).

Documentation/pretty-options.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@ people using 80-column terminals.
3333
used together.
3434

3535
--encoding=<encoding>::
36-
The commit objects record the encoding used for the log message
36+
Commit objects record the character encoding used for the log message
3737
in their encoding header; this option can be used to tell the
3838
command to re-code the commit log message in the encoding
3939
preferred by the user. For non plumbing commands this
4040
defaults to UTF-8. Note that if an object claims to be encoded
4141
in `X` and we are outputting in `X`, we will output the object
4242
verbatim; this means that invalid sequences in the original
43-
commit may be copied to the output.
43+
commit may be copied to the output. Likewise, if iconv(3) fails
44+
to convert the commit, we will output the original object
45+
verbatim, along with a warning.
4446

4547
--expand-tabs=<n>::
4648
--expand-tabs::

pretty.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,11 @@ const char *repo_logmsg_reencode(struct repository *r,
671671
* If the re-encoding failed, out might be NULL here; in that
672672
* case we just return the commit message verbatim.
673673
*/
674-
return out ? out : msg;
674+
if (!out) {
675+
warning("unable to reencode commit to '%s'", output_encoding);
676+
return msg;
677+
}
678+
return out;
675679
}
676680

677681
static int mailmap_name(const char **email, size_t *email_len,

t/t4210-log-i18n.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,11 @@ do
131131
fi
132132
done
133133

134+
test_expect_success 'log shows warning when conversion fails' '
135+
enc=this-encoding-does-not-exist &&
136+
git log -1 --encoding=$enc 2>err &&
137+
echo "warning: unable to reencode commit to ${SQ}${enc}${SQ}" >expect &&
138+
test_cmp expect err
139+
'
140+
134141
test_done

0 commit comments

Comments
 (0)