Subject: bug#18940: 24.4; vc-hg does not disable pager, leading to hangs (at least with tramp)

From: Michael Albinus <[email-masked]>
Date: Sun, 09 Nov 2014 11:24:21 +0100

Daniel Pittman <[email-masked]> writes:

> C-x C-f /sshx:[email-masked]:/path/to/file/in/hg/repo.txt
>
> …and Emacs hangs.
>
> I had problems with the Hg backend hanging via tramp; checking showed that it
> was hung waiting on `less`, which was sitting there telling me that the
> terminal wasn't fully featured and could it please, kindly, have some human
> input to let it know that it was OK to continue.

<http://mercurial.selenic.com/wiki/PagerExtension> discusses the
problem, and proposes even a solution for "Tramp in Emacs" :-)

> Anyway, options that probably make sense to set to make this smoother:
>
> 1. `HGPLAIN` exists in the environment.
>
> This disables things that might change output, and is recommended for
> non-interactive calls to try and discourage random breakage.

I'm a little bit reluctant to add this per default to
`tramp-remote-process-environment'. There shouldn't be such default
application specific settings.

But the following patch might be sufficient (could you, please, test?):

--8<---------------cut here---------------start------------->8---
*** /home/albinus/src/emacs/lisp/vc/vc-hg.el.~118313~	2014-11-09 11:19:05.851785605 +0100
--- /home/albinus/src/emacs/lisp/vc/vc-hg.el	2014-11-09 11:13:53.255025363 +0100
***************
*** 210,220 ****
  			     ;; can parse the output.
  			     (append (list "TERM=dumb" "LANGUAGE=C")
  				     process-environment)))
! 			(process-file
! 			 vc-hg-program nil t nil
! 			 "--config" "alias.status=status"
! 			 "--config" "defaults.status="
! 			 "status" "-A" (file-relative-name file)))
                      ;; Some problem happened.  E.g. We can't find an `hg'
                      ;; executable.
                      (error nil)))))))
--- 210,227 ----
  			     ;; can parse the output.
  			     (append (list "TERM=dumb" "LANGUAGE=C")
  				     process-environment)))
! 			(if (file-remote-p file)
! 			    (process-file
! 			     "env" nil t nil
! 			     "HGPLAIN=1" vc-hg-program
! 			     "--config" "alias.status=status"
! 			     "--config" "defaults.status="
! 			     "status" "-A" (file-relative-name file))
! 			  (process-file
! 			   vc-hg-program nil t nil
! 			   "--config" "alias.status=status"
! 			   "--config" "defaults.status="
! 			   "status" "-A" (file-relative-name file))))
                      ;; Some problem happened.  E.g. We can't find an `hg'
                      ;; executable.
                      (error nil)))))))
--8<---------------cut here---------------end--------------->8---

> 3. --color never
>
> ...because if you have a tty, and less/hg think it is an interactive enough
> call to invoke the pager and complain to a human, you might well get color
> displayed as well.
>
> 4. --pager never
>
> ...because you just don't want to page the output for non-interactive use.

It looks, like you need to enable the respective extensions in your .hgrc.
Therefore, they cannot be added in vg-hg.el by default, I fear.

Best regards, Michael.