Git pager set to diff-highlight does not work in Windows 10
Asked Answered
V

2

6

I have set Git's pager option to this

[pager]
    log = diff-highlight 

I downloaded the diff-highlight script from Git's repository 3dbfe2b8 and placed it in my ~/bin folder.

$ where git
C:\Program Files\Git\cmd\git.exe
$ where diff-highlight
C:\Users\andy\bin\diff-highlight

Running git log results in the following error:

$ git log
Can't open diff-highlight: No such file or directory at C:\Users\andy\bin\diff-highlight line 36.
Segmentation fault

On the other hand, the following command runs just fine,

$ git log -p --color | diff-highlight | less -FRSX

This means diff-highlight is available from $PATH, but Git's config cannot find it.

My Git version is 2.12.0.windows.1.

Vardon answered 9/3, 2017 at 10:28 Comment(1)
I tried this today by copying /usr/share/doc/git/contrib/diff-highlight/diff-highlight from Linux side to a Windows directory in PATH and it worked okay. my git version: 2.33.1.windows.1Bronchi
D
2

Recent guidance suggests putting the whole diff-highlight | less -FRSX string into the pager.XXX config.

This works just fine for me with a Maked version of the current diff-highlight script, although I only use it for pager.diff and interactive.diffFilter.

Dannica answered 1/2, 2019 at 16:19 Comment(1)
Future visitors: I now use delta as my pager instead.Dannica
B
0

The Segmentation fault part should, at least, disappear: When a non-existent program is given as the pager, we tried to reuse an uninitialized child_process structure and crashed, which has been fixed with Git 2.35 (Q1 2022).

See commit f917f57 (24 Nov 2021) by Enzo Matsumiya (ematsumiya).
(Merged by Junio C Hamano -- gitster -- in commit bb47eee, 10 Dec 2021)

pager: fix crash when pager program doesn't exist

Signed-off-by: Enzo Matsumiya

When prepare_cmd() fails for, e.g., pager process setup, child_process_clear() frees the memory in pager_process.args, but .argv was pointed to pager_process.args.v earlier in start_command(), so it's now a dangling pointer.

setup_pager() is then called a second time, from cmd_log_init_finish() in this case, and any further operations using its .argv, e.g. strvec_*, will use the dangling pointer and eventually crash. According to trivial tests, setup_pager() is not called twice if the first call is successful.

This patch makes sure that pager_process is properly initialized on setup_pager(). Drop CHILD_PROCESS_INIT from its declaration since it's no longer really necessary.

Add a test to catch possible regressions.

Reproducer:

$ git config pager.show INVALID_PAGER
$ git show $VALID_COMMIT
error: cannot run INVALID_PAGER: No such file or directory
[1]    3619 segmentation fault (core dumped)  git show $VALID_COMMIT
Bennet answered 12/12, 2021 at 3:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.