Subject: bug#50689: 28.0.50; Wrong VC repo URL detection in bug-reference-mode

From: "Basil L. Contovounesios" <[email-masked]>
Date: Mon, 20 Sep 2021 00:43:07 +0100

Tags: patch

In a clone of https://github.com/abo-abo/swiper.git, with the following
remotes:

    $ git remote -v
    elpa	savannah:/srv/git/emacs/elpa.git (fetch)
    elpa	savannah:/srv/git/emacs/elpa.git (push)
    origin	[email-masked]:basil-conto/swiper.git (fetch)
    origin	[email-masked]:basil-conto/swiper.git (push)
    upstream	[email-masked]:abo-abo/swiper.git (fetch)
    upstream	[email-masked]:abo-abo/swiper.git (push)

0. emacs -Q ivy.el
1. M-: (vc-call-backend 'Git 'repository-url "upstream") RET

This returns: "[email-masked]:basil-conto/swiper.git"
instead of:   "[email-masked]:abo-abo/swiper.git"

Step 1 is effectively what bug-reference-try-setup-from-vc does, and I
believe the incorrect result is due to vc-git-repository-url expecting a
file name, not a Git remote name, as its first argument.

How's the attached fix?

>From dd1be2b9c277a53078fb20242702ecf2599cbb7b Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <[email-masked]>
Date: Sun, 19 Sep 2021 21:13:17 +0100
Subject: [PATCH 1/2] Fix VC repo URL detection in bug-reference-mode

* lisp/progmodes/bug-reference.el (bug-reference-try-setup-from-vc):
Pass file or directory name in question as the first argument to the
backend's repository-url implementation.  Use when-let and seq-some
to flatten nested conditionals.
---
 lisp/progmodes/bug-reference.el | 31 +++++++++++++------------------
 1 file changed, 13 insertions(+), 18 deletions(-)

diff --git a/lisp/progmodes/bug-reference.el b/lisp/progmodes/bug-reference.el
index b646a47c85..fd014a38d9 100644
--- a/lisp/progmodes/bug-reference.el
+++ b/lisp/progmodes/bug-reference.el
@@ -376,24 +376,19 @@ bug-reference-try-setup-from-vc
 Test each configuration in `bug-reference-setup-from-vc-alist'
 and `bug-reference--setup-from-vc-alist' and apply it if
 applicable."
-  (let ((file-or-dir (or buffer-file-name
-                         ;; Catches modes such as vc-dir and Magit.
-                         default-directory)))
-    (when file-or-dir
-      (let* ((backend (vc-responsible-backend file-or-dir t))
-             (url
-              (or (ignore-errors
-                    (vc-call-backend backend 'repository-url "upstream"))
-                  (ignore-errors
-                    (vc-call-backend backend 'repository-url)))))
-        (when url
-          (catch 'found
-            (dolist (config (append
-                             bug-reference-setup-from-vc-alist
-                             (bug-reference--setup-from-vc-alist)))
-              (when (apply #'bug-reference-maybe-setup-from-vc
-                           url config)
-                (throw 'found t)))))))))
+  (when-let ((file-or-dir (or buffer-file-name
+                              ;; Catches modes such as vc-dir and Magit.
+                              default-directory))
+             (backend (vc-responsible-backend file-or-dir t))
+             (url (seq-some (lambda (remote)
+                              (ignore-errors
+                                (vc-call-backend backend 'repository-url
+                                                 file-or-dir remote)))
+                            '("upstream" nil))))
+    (seq-some (lambda (config)
+                (apply #'bug-reference-maybe-setup-from-vc url config))
+              (append bug-reference-setup-from-vc-alist
+                      (bug-reference--setup-from-vc-alist)))))
 
 (defvar bug-reference-setup-from-mail-alist
   `((,(regexp-opt '("emacs" "auctex" "gnus" "tramp" "orgmode") 'words)
-- 
2.33.0

Thanks,

-- 
Basil

In GNU Emacs 28.0.50 (build 2, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0, Xaw3d scroll bars)
 of 2021-09-20 built on tia
Repository revision: 3c513435369826e44a53dcb12ecc14657e03c73d
Repository branch: HEAD
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Debian GNU/Linux bookworm/sid

Configured using:
 'configure 'CC=ccache gcc' 'CFLAGS=-Og -ggdb' --config-cache
 --prefix=/home/blc/.local --enable-checking=structs
 --with-x-toolkit=lucid --with-file-notification=yes --with-x'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY
INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF TOOLKIT_SCROLL_BARS
X11 XAW3D XDBE XIM XPM LUCID ZLIB

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

Major mode: ELisp/l

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  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

Load-path shadows:
None found.

Features:
(vc-git diff-mode easy-mmode vc-dispatcher help-mode pp shadow sort
mail-extr emacsbug message rmc puny dired dired-loaddefs rfc822 mml
mml-sec epa derived epg rfc6068 epg-config gnus-util rmail
rmail-loaddefs auth-source cl-seq eieio eieio-core cl-macs
eieio-loaddefs password-cache json map text-property-search time-date
subr-x seq byte-opt gv bytecomp byte-compile cconv mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs
cl-lib sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
iso-transl tooltip eldoc electric uniquify ediff-hook vc-hooks
lisp-float-type elisp-mode mwheel term/x-win x-win term/common-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list replace
newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar
rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock
font-lock syntax font-core term/tty-colors frame minibuffer 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 composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice button loaddefs faces cus-face macroexp files
window text-properties overlay sha1 md5 base64 format env code-pages
mule custom widget hashtable-print-readable backquote threads dbusbind
inotify lcms2 dynamic-setting system-font-setting font-render-setting
cairo x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 57729 7685)
 (symbols 48 7242 5)
 (strings 32 21156 1629)
 (string-bytes 1 675261)
 (vectors 16 14813)
 (vector-slots 8 196771 13743)
 (floats 8 31 55)
 (intervals 56 350 15)
 (buffers 992 12))