# Recoding of {git,cg}-log output

4 messages from 2006-02-27 to 2006-02-27. Participants: Krzysiek Pawlik, Johannes Schindelin, Petr Baudis.
Thread: https://gitlist.dev/t/3472

## Krzysiek Pawlik, 2006-02-27 00:10

Subject: Recoding of {git,cg}-log output
Message-ID: <44024384.4060406@people.pl>
URL: https://gitlist.dev/e/44024384.4060406%40people.pl

```

First: a little "why": having /usr/bin/vim as PAGER allows to enter
UTF-8 commit messages quite easily, the problem is when git-log (or
cg-log) is run in terminal that's not UTF-8. In my case: terminal is
ISO-8859-2 and:

nelchael@nelchael ~$ cat ~/.vimrc | grep gitci
au BufRead /tmp/gitci* setlocal textwidth=75 fileencoding=utf-8
encoding=utf-8 fileencodings=utf-8,default

So... having {git,cg}-log recode the log entires when displaying is
quite useful. Two patches attached:

 a. git-log-recode.patch - uses iconv to recode the log output to
GIT_LOG_RECODE encoding
 b. cg-log-recode.patch - the same, but for cogito

With this patches it's possible to write UTF-8 commit messages and see
them ok in non-UTF-8 terminal in log by having GIT_LOG_RECODE=iso-8859-2.

Comments?

-- 
Krzysiek Pawlik (Nelchael)
RLU #322999 GPG Key ID: 0xBC555551


--- /usr/bin/cg-log	2006-01-19 17:22:22.000000000 +0100
+++ bin/cg-log	2006-02-27 00:59:07.000000000 +0100
@@ -348,13 +348,21 @@
 
 if [ "$shortlog" ]; then
 	# Special care here.
-	$revls $sep "${ARGS[@]}" | git-shortlog | pager
+	if [ -n "${GIT_LOG_RECODE}" ]; then
+		$revls $sep "${ARGS[@]}" | git-shortlog | iconv --from-code=UTF-8 --to-code="${GIT_LOG_RECODE}" | pager
+	else
+		$revls $sep "${ARGS[@]}" | git-shortlog | pager
+	fi
 	exit
 fi
 
 
 # LESS="S" will prevent less to wrap too long titles to multiple lines;
 # you can scroll horizontally.
-$revls $sep "${ARGS[@]}" | print_commit_log | _local_CG_LESS="S" pager
+if [ -n "${GIT_LOG_RECODE}" ]; then
+	$revls $sep "${ARGS[@]}" | print_commit_log | iconv --from-code=UTF-8 --to-code="${GIT_LOG_RECODE}" | _local_CG_LESS="S" pager
+else
+	$revls $sep "${ARGS[@]}" | print_commit_log | _local_CG_LESS="S" pager
+fi
 
 exit 0


--- /usr/bin/git-log	2006-02-23 18:31:32.000000000 +0100
+++ bin/git-log	2006-02-27 00:47:34.000000000 +0100
@@ -11,5 +11,11 @@
 [ "$revs" ] || {
 	die "No HEAD ref"
 }
-git-rev-list --pretty $(git-rev-parse --default HEAD "$@") |
-LESS=-S ${PAGER:-less}
+if [ -n "${GIT_LOG_RECODE}" ]; then
+	git-rev-list --pretty $(git-rev-parse --default HEAD "$@") | \
+		iconv --from-code=UTF-8 --to-code="${GIT_LOG_RECODE}" | \
+		LESS=-S ${PAGER:-less}
+else
+	git-rev-list --pretty $(git-rev-parse --default HEAD "$@") | \
+	LESS=-S ${PAGER:-less}
+fi

```

## Johannes Schindelin, 2006-02-27 00:36

Subject: Re: Recoding of {git,cg}-log output
Message-ID: <Pine.LNX.4.63.0602270133330.5275@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0602270133330.5275%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <44024384.4060406@people.pl>

```
Hi,

On Mon, 27 Feb 2006, Krzysiek Pawlik wrote:

> First: a little "why": having /usr/bin/vim as PAGER allows to enter
> UTF-8 commit messages quite easily, the problem is when git-log (or
> cg-log) is run in terminal that's not UTF-8.

Of course, you could always set up a script doing the recoding and the 
paging, like

-- snip --
#!/bin/sh

iconv -f UTF-8 -t ISO-8859-2 "$@" | vim
-- snap --

and point your PAGER to that script (which is untested BTW). The advantage 
of this approach compared to adjusting git is that other programs use 
PAGER, too.

Hth,
Dscho

```

## Krzysiek Pawlik, 2006-02-27 00:50

Subject: Re: Recoding of {git,cg}-log output
Message-ID: <44024CC6.8010401@people.pl>
URL: https://gitlist.dev/e/44024CC6.8010401%40people.pl
In-Reply-To: <Pine.LNX.4.63.0602270133330.5275@wbgn013.biozentrum.uni-wuerzburg.de>

```
Johannes Schindelin wrote:
> Of course, you could always set up a script doing the recoding and
> the paging, like

No.

> The advantage of this approach compared to adjusting git is that
> other programs use PAGER, too.

Passing code (web pages, etc) throught iconv is not a good idea -
{git,cg}-diff should show the file content as it is, not altered by iconv.

Changing PAGER is a bit... ugly and messy way of doing it. Assume that I
work on some files and want to look at some unversioned files outside
the tree (like docs, man pages, whatever) and the $PAGER passes the
legitimate ISO8859-2 files through iconv, what gives us garbage. And we
end up changing pager very often - Bad Idea (TM).

-- 
Krzysiek Pawlik (Nelchael)
RLU #322999 GPG Key ID: 0xBC555551


```

## Petr Baudis, 2006-02-27 01:26

Subject: Re: Recoding of {git,cg}-log output
Message-ID: <20060227012656.GX31278@pasky.or.cz>
URL: https://gitlist.dev/e/20060227012656.GX31278%40pasky.or.cz
In-Reply-To: <44024384.4060406@people.pl>

```
Dear diary, on Mon, Feb 27, 2006 at 01:10:44AM CET, I got a letter
where Krzysiek Pawlik <krzysiek.pawlik@people.pl> said that...
> 
> First: a little "why": having /usr/bin/vim as PAGER allows to enter
> UTF-8 commit messages quite easily, the problem is when git-log (or
> cg-log) is run in terminal that's not UTF-8. In my case: terminal is
> ISO-8859-2 and:
> 
> nelchael@nelchael ~$ cat ~/.vimrc | grep gitci
> au BufRead /tmp/gitci* setlocal textwidth=75 fileencoding=utf-8
> encoding=utf-8 fileencodings=utf-8,default

Wouldn't it be enough to also set termencoding?

> So... having {git,cg}-log recode the log entires when displaying is
> quite useful. Two patches attached:
> 
>  a. git-log-recode.patch - uses iconv to recode the log output to
> GIT_LOG_RECODE encoding
>  b. cg-log-recode.patch - the same, but for cogito
> 
> With this patches it's possible to write UTF-8 commit messages and see
> them ok in non-UTF-8 terminal in log by having GIT_LOG_RECODE=iso-8859-2.
> 
> Comments?

Not opposed in principle. But it would be much more sensible to have
something like $GIT_META_ENCODING (defaulting probably to utf8), recode
to whatever is your current locale, have the appropriate setting in the
configfile, ...

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
Of the 3 great composers Mozart tells us what it's like to be human,
Beethoven tells us what it's like to be Beethoven and Bach tells us
what it's like to be the universe.  -- Douglas Adams

```
