Subject: 25.2; mercurial vc-annotate sometimes fails when using the evolve mercurial extension

From: Valentin Gatien-Baron <[email-masked]>
Date: Sun, 7 Jul 2019 00:55:51 -0400

Sometimes, vc-annotate in a file tracked by mercurial returns an
error like this instead of a proper annotate buffer:

abort: mercurial/merge.py: no such file in rev 9117c6561b0b

Here is a reproduction (requires the evolve extension to
be enabled, for instance as described here:
https://www.mercurial-scm.org/wiki/EvolveExtension):

  rm -rf /tmp/test
  hg init /tmp/test
  cd /tmp/test
  echo b > b
  hg commit -Am0
  echo a > a
  hg commit -Am1
  hg commit --amend -m 2
  if [ $(hg log -r . -T {rev}) = 1 ]; then
      echo "Error: cannot test as evolve is not enabled"
      exit 1
  fi
  emacs -Q a -f 'vc-annotate'

What happens is:
1. vc-annotate calls vc-working-revision
2. vc-hg-working-revision calls hg parent --template {rev} file
3. that command fails saying something like "abort: filtered revision
'3ee3303ecf2621381e5d5ca14aba73f2835facb5'!"
4. vc-hg-working-revision thus returns 0
5. vc-annotate calls `hg annotate -r 0 file`, which correctly errors
out, saying "abort: file: no such file in hex-rev-of-rev-0".

Step 3 is probably an hg bug. However `hg parent` was deprecated in
2014, so people may be reluctant to change it. And it would be simpler
for vc-hg-working-revision to call `hg log -r . -T {rev}` (vc-git does
that, so I assume that it works in general on top of fixing the
current issue). `.` means the current revision, see `hg help revset`.

So something like this:
(defun vc-hg-working-revision (file)
  "Hg-specific version of `vc-working-revision'."
  (ignore-errors
    (with-output-to-string
      (vc-hg-command standard-output 0 nil
    "log" "-r" "." "--template" "{rev}"))))

(another reason to stop using `hg parents` is that during a merge, it
will in most cases print two revisions, so if you annotate a file that
was last changed in revision 123, emacs will likely get 123123 back
and `hg annotate -r 123123` will fail)

In GNU Emacs 25.2.2 (x86_64-pc-linux-gnu, GTK+ Version 3.23.2)
 of 2018-08-27, modified by Debian built on lgw01-amd64-037
Windowing system distributor 'The X.Org Foundation', version 11.0.12001000
System Description: Ubuntu 18.10

Configured using:
 'configure --build x86_64-linux-gnu --prefix=/usr
 --sharedstatedir=/var/lib --libexecdir=/usr/lib
 --localstatedir=/var/lib --infodir=/usr/share/info
 --mandir=/usr/share/man --with-pop=yes
 --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/25.2/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/25.2/site-lisp:/usr/share/emacs/site-lisp
 --with-sound=alsa --without-gconf --build x86_64-linux-gnu
 --prefix=/usr --sharedstatedir=/var/lib --libexecdir=/usr/lib
 --localstatedir=/var/lib --infodir=/usr/share/info
 --mandir=/usr/share/man --with-pop=yes
 --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/25.2/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/25.2/site-lisp:/usr/share/emacs/site-lisp
 --with-sound=alsa --without-gconf --with-x=yes --with-x-toolkit=gtk3
 --with-toolkit-scroll-bars 'CFLAGS=-g -O2
 -fdebug-prefix-map=/build/emacs-nDyT48/emacs-25.2+1=.
-fstack-protector-strong
 -Wformat -Werror=format-security -Wall' 'CPPFLAGS=-Wdate-time
 -D_FORTIFY_SOURCE=2' 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro''

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS NOTIFY
ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK3 X11

Important settings:
  value of $LC_MONETARY: fr_FR.UTF-8
  value of $LC_NUMERIC: fr_FR.UTF-8
  value of $LC_TIME: fr_FR.UTF-8
  value of $LANG: fr_FR.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Python

Minor modes in effect:
  shell-dirtrack-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent messages:
Loading debian-ispell...done
Loading /var/cache/dictionaries-common/emacsen-ispell-dicts.el
(source)...done
Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...done
Loading /etc/emacs/site-start.d/50ocaml-mode.el (source)...done
Loading /etc/emacs/site-start.d/51tuareg-mode.el (source)...done
For information about GNU Emacs and the GNU system, type C-h C-a.
Annotating...
vc-do-command: Running hg annotate -dq -n -u --follow -r0 merge.py...FAILED
(status 255)
Mark set
Making completion list...

Load-path shadows:
/usr/share/emacs/site-lisp/elpa/rust-mode-0.3.0/rust-mode-pkg hides
/usr/share/emacs/site-lisp/elpa-src/rust-mode-0.3.0/rust-mode-pkg
/usr/share/emacs/site-lisp/elpa/rust-mode-0.3.0/rust-mode hides
/usr/share/emacs/site-lisp/elpa-src/rust-mode-0.3.0/rust-mode
/usr/share/emacs/site-lisp/elpa/rust-mode-0.3.0/rust-mode-autoloads hides
/usr/share/emacs/site-lisp/elpa-src/rust-mode-0.3.0/rust-mode-autoloads

Features:
(shadow sort mail-extr emacsbug message dired rfc822 mml mml-sec epg
mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils
mailheader sendmail rfc2047 rfc2045 ietf-drums mail-utils vc-annotate vc
vc-dispatcher vc-hg python tramp-sh tramp tramp-compat auth-source
cl-seq eieio eieio-core cl-macs gnus-util mm-util help-fns mail-prsvr
password-cache tramp-loaddefs trampver ucs-normalize shell pcomplete
format-spec advice json map comint ring ansi-color finder-inf info
package epg-config seq byte-opt gv bytecomp byte-compile cl-extra
help-mode easymenu cconv cl-loaddefs pcase cl-lib time-date mule-util
tooltip eldoc electric uniquify ediff-hook vc-hooks lisp-float-type
mwheel x-win term/common-win x-dnd tool-bar dnd fontset image regexp-opt
fringe tabulated-list newcomment elisp-mode lisp-mode prog-mode register
page menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock
font-lock syntax facemenu font-core frame cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese charscript case-table epa-hook
jka-cmpr-hook help simple abbrev minibuffer cl-preloaded 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 dbusbind inotify dynamic-setting
system-font-setting font-render-setting move-toolbar gtk x-toolkit x
multi-tty make-network-process emacs)

Memory information:
((conses 16 240886 13755)
 (symbols 48 24982 0)
 (miscs 40 282 190)
 (strings 32 32555 6908)
 (string-bytes 1 1068597)
 (vectors 16 40552)
 (vector-slots 8 744800 4343)
 (floats 8 262 215)
 (intervals 56 506 0)
 (buffers 976 20))