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

From: Daniel Pittman <[email-masked]>
Date: Mon, 3 Nov 2014 21:47:14 +0000

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.

Fixing this wasn't too dire: we can just ask hg to not use a pager, which
solves the problem.  It might be a good idea to ask it to be entirely
non-interactive, but I didn't test that, and don't require it for this to work
on my system.

After these changes are applied, the problem is resolved:

(require 'vc-hg)
(defun dp/vc-hg-state-interactive-pager-workaround (args)
  "Potentially modify process-file arguments to work around a vc-hg bug"
  (if (and (equal (first args) vc-hg-program)
           (not (cl-search vc-hg-global-switches args :test 'equal)))
      (concatenate 'list args vc-hg-global-switches)
    args))
(advice-add 'process-file :filter-args 'dp/vc-hg-state-interactive-pager-workaround)
(setq vc-hg-global-switches '("--pager" "never"))

The `vc-hg-global-switches` setting *should* be enough, but unfortunately the
`vc-hg-state` function doesn't *use* that setting, which means that it out and
out needs awful hacks to make it work.

(I could have redefined the function, but this felt better, and should not
cause trouble if we actually fix the bug.)

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.

2. `-y` or `--noninteractive`

These cause it to pick the first choice if a prompt would have been displayed,
instead of asking interactively.  Probably good on any of the read-only
operations, at the very least.

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.

In GNU Emacs 24.4.1 (x86_64-apple-darwin14.0.0, NS apple-appkit-1343.14)
 of 2014-10-22 on dpittman-mbp.local
Windowing system distributor `Apple', version 10.3.1343
Configured using:
 `configure --prefix=/opt/local --with-ns --without-x --without-dbus
 'CFLAGS=-pipe -Os -arch x86_64' CPPFLAGS=-I/opt/local/include
 'LDFLAGS=-L/opt/local/lib -Wl,-headerpad_max_install_names -arch x86_64''

Important settings:
  locale-coding-system: utf-8-unix

Major mode: Emacs-Lisp

Minor modes in effect:
  eldoc-mode: t
  shell-dirtrack-mode: t
  flyspell-mode: t
  show-paren-mode: t
  global-auto-revert-mode: t
  display-battery-mode: t
  desktop-save-mode: t
  auto-insert-mode: t
  tooltip-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  size-indication-mode: t
  column-number-mode: t
  line-number-mode: t
  auto-fill-function: do-auto-fill
  transient-mark-mode: t

Recent input:
<elided for privacy>

Recent messages:
Tramp: Decoding local file `/var/folders/29/dht2zzt17xnff164_5vrs41r95p38b/T/tramp.43368aIF.cinc' with `base64-decode-region'...done
Tramp: Inserting `/sshx:dpittman.sb.facebook.com:/home/dpittman/elided/for/privacy.txt'...done
privacy.txt has auto save data; consider M-x recover-this-file
Can't guess python-indent-offset, using defaults: 4

Tramp: Checking `vc-registered' for /sshx:dpittman.sb.facebook.com:/home/dpittman/elided/for/privacy.txt...done
Can't guess python-indent-offset, using defaults: 4
Running hg --pager never parent --template {rev} privacy.txt in foreground...
Running hg --pager never parent --template {rev} privacy.txt...OK = 0
Mark set

Load-path shadows:
~/.emacs.d/fb-emacs/git hides /opt/local/share/emacs/site-lisp/git
~/.emacs.d/fb-emacs/git-blame hides /opt/local/share/emacs/site-lisp/git-blame

Features:
(shadow sort mail-extr gnus-msg gnus-art mm-uu mml2015 mm-view mml-smime smime
dig mailcap gnus-sum nnoo emacsbug sendmail mule-util misearch multi-isearch
eieio-opt speedbar sb-image ezimage dframe find-func apropos sh-script smie
executable info jka-compr vc-dispatcher tramp-cache python json debug vc-git
eldoc gnus-topic gnus-group gnus-undo nnmail mail-source gnus-start gnus-spec
gnus-int gnus-range message idna rfc822 mml mml-sec mm-decode mm-bodies
mm-encode mail-parse rfc2231 rfc2047 rfc2045 ietf-drums mailabbrev gmm-utils
mailheader gnus-win footnote skeleton vc-hg tramp-sh tramp tramp-compat
auth-source eieio eieio-core password-cache tramp-loaddefs trampver shell
pcomplete format-spec server emacs-lock flyspell ispell filladapt align
hippie-exp edmacro kmacro fb-coding-style cc-styles cc-align cc-engine cc-vars
cc-defs byte-opt advice .loaddefs el-get el-get-autoloads el-get-list-packages
el-get-dependencies el-get-build el-get-status pp el-get-methods el-get-fossil
el-get-svn el-get-pacman el-get-github-zip el-get-github-tar el-get-http-zip
el-get-http-tar el-get-hg el-get-go el-get-git-svn el-get-fink
el-get-emacswiki el-get-http el-get-notify help-mode easymenu
el-get-emacsmirror el-get-github el-get-git el-get-elpa package epg-config
el-get-darcs el-get-cvs el-get-bzr el-get-brew el-get-builtin el-get-apt-get
el-get-recipes el-get-byte-compile el-get-custom el-get-core autoload lisp-mnt
bytecomp byte-compile cconv dired cl-macs saveplace midnight paren icomplete
grep compile comint ansi-color ring gnus gnus-ems nnheader gnus-util
mail-utils mm-util help-fns mail-prsvr wid-edit autorevert filenotify battery
desktop frameset autoinsert cus-start cus-load assoc cl gv cl-loaddefs cl-lib
time-date tooltip electric uniquify ediff-hook vc-hooks lisp-float-type mwheel
ns-win tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment
lisp-mode prog-mode register page menu-bar rfn-eshadow timer select scroll-bar
mouse jit-lock font-lock syntax facemenu font-core frame cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese
hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer nadvice
loaddefs button faces cus-face macroexp files text-properties overlay sha1 md5
base64 format env code-pages mule custom widget hashtable-print-readable
backquote make-network-process cocoa ns multi-tty emacs)

Memory information:
((conses 16 266820 141934)
 (symbols 48 34433 2)
 (miscs 40 105 808)
 (strings 32 72690 51434)
 (string-bytes 1 2447073)
 (vectors 16 33402)
 (vector-slots 8 1327221 186720)
 (floats 8 259 880)
 (intervals 56 4074 314)
 (buffers 960 22))