4

When I type git difftool under plain cygwin shell, I just receive benign exit:

~/sb/ws> git difftool
~/sb/ws>

But when I type exactly the same thing under Emacs inferior shell (running the same cygwin bash), I receive the following error:

~/sb/ws> git difftool
git difftool
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LC_ALL = (unset),
    LANG = "ENU"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
~/sb/ws> 

Any idea why this is happening and how to fix this?

(all other git commands, by the way, work perfectly under this Emacs inferior shell, so I can only assume this must be something specific to difftool)

EDIT (providing variant & version information on the tools involved):

  1. cygwin-1.7.8-1
  2. GNU Emacs 23.2.1 (i386-mingw-nt6.1.7600) of 2010-05-08 on G41R2F1
  3. git version 1.7.4
  4. Windows 7 Ultimate 64-bit
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
WinWin
  • 7,493
  • 10
  • 44
  • 53
  • 1
    What variants of Emacs and Git are you using? The Cygwin ones or native Windows? Things ought to work seamlessly with Cygwin emacs and Cygwin git. – ak2 Jul 11 '11 at 08:12
  • @ak2 Thanks +1 for reminding me that I missed this information. See edit above. As I mentioned in my post, things do work seamlessly in all other regards, except for the case described above. – WinWin Jul 11 '11 at 12:34

2 Answers2

1

you're really have wrong LANG, look onto /usr/share/locale for list of available locales..

But really question is - why're using git directly in Emacs, when it has several good git modes, and magit - the best between them? Why not perform all tasks using Emacs?

P.S. I have an article about Emacs + Git...

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
  • You have an excellent question. :) I am in the process of learning `git` and my approach has always been to start from the command line, iron out all kinks, then upgrade to a wrapper (GUI or Emacs). Thanks for the excellent article. I must solve this mystery first, though. +1 for now. – WinWin Jul 11 '11 at 12:42
  • I looked at `/usr/share/locale` and I have about 80 2-letter subdirectories. What should I be looking for? And why does it work with cygwin if I have the wrong LANG? – WinWin Jul 11 '11 at 12:44
  • I just checked `git difftool` under my Emacs (under Linux only) and everything works without problem also with incorrect locale. I think, that problem is that you have no changes in directory, or you hadn't specified correct options, like name of the branch to compare, etc., for example, `git difftool HEAD~2`... But anyway, running `git difftool` from Emacs shell isn't good idea, because Emacs terminal isn't fully functional comparing with standard terminals... – Alex Ott Jul 11 '11 at 12:55
  • I looked at `/usr/share/locale` and despite having more than 80 2-letter subdirectories, including `en_GB`, there isn't any `en_US` and certainly not `en_US.UTF-8`. Weird. – WinWin Jul 11 '11 at 13:22
  • 1
    anyway, wrong locale just lead to printing of warning, not to preventing of `git difftool` from working... – Alex Ott Jul 11 '11 at 13:53
  • You are correct, the wrong locale just leads to printing of warning, not to preventing of git difftool from working. But I am still baffled as to why this problem only exists within Emacs. What's so special about Emacs that it requires LANG to be set in a certain way? Also, do I set it for Emacs only or for the entire environment? Where do I set it? in my .profile or via `Computer > Properties > Advanced system settings`? – WinWin Jul 11 '11 at 15:14
  • 1
    you can set it explicitly from Emacs using `setenv` function – Alex Ott Jul 11 '11 at 15:19
  • Thanks. `export LANG=en_US.UTF-8` just before invoking `git difftool` did the trick. Accepting. – WinWin Jul 12 '11 at 15:23
0

Update 6 years later (2017)

all other git commands, by the way, work perfectly under this Emacs inferior shell, so I can only assume this must be something specific to difftool

What is specific to difftool is that it is still (but not for long) written in perl: git-difftool.perl

But that will change soon with Git 2.12 (Q1 2017).
That means difftool should run under Emacs just fine, not being bothered with Perl anymore.

See commit 03831ef and commit 019678d (19 Jan 2017) by Johannes Schindelin (dscho).

difftool: implement the functionality in the builtin

The motivation for converting the difftool is that Perl scripts are not at all native on Windows, and that git difftool therefore is pretty slow on that platform, when there is no good reason for it to be slow.

In addition, Perl does not really have access to Git's internals.
That means that any script will always have to jump through unnecessary hoops, and it will often need to perform unnecessary work (e.g. when reading the entire config every time git config is called to query a single config value).

The current version of the builtin difftool does not, however, make full use of the internals but instead chooses to spawn a couple of Git processes, still, to make for an easier conversion. There remains a lot of room for improvement, left later.

Note: to play it safe, the original difftool is still called unless the config setting difftool.useBuiltin is set to true.

The reason: this new, experimental, builtin difftool was shipped as part of Git for Windows v2.11.0, to allow for easier large-scale testing, but of course as an opt-in feature.

The speedup is actually more noticable on Linux than on Windows: a quick test shows that t7800-difftool.sh runs/

  • in (2.183s/0.052s/0.108s) (real/user/sys) in a Linux VM, down from (6.529s/3.112s/0.644s), while
  • on Windows, it is (36.064s/2.730s/7.194s), down from (47.637s/2.407s/6.863s).

The culprit is most likely the overhead incurred from still having to shell out to mergetool-lib.sh and difftool--helper.sh.

Still, it is an improvement.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250