emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RFC: Automatic setup for bug-reference-mode


From: Tassilo Horn
Subject: Re: RFC: Automatic setup for bug-reference-mode
Date: Sun, 14 Jun 2020 18:30:26 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Tassilo Horn <tsdh@gnu.org> writes:

>>> +    (let* ((backend (vc-responsible-backend (buffer-file-name) t))
>>> +           (url (pcase backend
>>> +                  ('Git (string-trim
>>> +                         (shell-command-to-string
>>> +                          "git ls-remote --get-url"))))))
>>
>> This should be moved to a new VC function.

Ok, I have implemented a new repository-url VC command for all VC
systems I have installed and were able to test: Git, Hg, Bzr, and SVN.
Looks right?

>From f117a8517dc32330aa9ed32f531b68daba2d7b62 Mon Sep 17 00:00:00 2001
From: Tassilo Horn <tsdh@gnu.org>
Date: Sun, 14 Jun 2020 18:24:14 +0200
Subject: [PATCH] New VC command repository-url

---
 lisp/vc/vc-bzr.el | 8 ++++++++
 lisp/vc/vc-git.el | 7 +++++++
 lisp/vc/vc-hg.el  | 7 +++++++
 lisp/vc/vc-svn.el | 9 ++++++++-
 lisp/vc/vc.el     | 4 ++++
 5 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/lisp/vc/vc-bzr.el b/lisp/vc/vc-bzr.el
index e5d307e7ed..504d3dcdda 100644
--- a/lisp/vc/vc-bzr.el
+++ b/lisp/vc/vc-bzr.el
@@ -1316,6 +1316,14 @@ vc-bzr-revision-completion-table
                                              vc-bzr-revision-keywords))
                             string pred)))))
 
+(defun vc-bzr-repository-url (file-or-dir)
+  (let ((default-directory (vc-bzr-root file-or-dir)))
+    (with-temp-buffer
+      (vc-bzr-command "info" (current-buffer) nil nil)
+      (goto-char (point-min))
+      (when (re-search-forward "parent branch: \\(.*\\)$")
+        (match-string 1)))))
+
 (provide 'vc-bzr)
 
 ;;; vc-bzr.el ends here
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index dcb5228265..8c9feb0e9d 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -101,6 +101,7 @@
 ;; - rename-file (old new)                         OK
 ;; - find-file-hook ()                             OK
 ;; - conflicted-files                              OK
+;; - repository-url (file-or-dir)                  OK
 
 ;;; Code:
 
@@ -1082,6 +1083,12 @@ vc-git-conflicted-files
                                 "DU" "AA" "UU"))
             (push (expand-file-name file directory) files)))))))
 
+(defun vc-git-repository-url (file-or-dir)
+  (let ((default-directory (vc-git-root file-or-dir)))
+    (with-temp-buffer
+      (vc-git--call (current-buffer) "ls-remote" "--get-url")
+      (buffer-substring-no-properties (point-min) (1- (point-max))))))
+
 ;; Everywhere but here, follows vc-git-command, which uses vc-do-command
 ;; from vc-dispatcher.
 (autoload 'vc-resynch-buffer "vc-dispatcher")
diff --git a/lisp/vc/vc-hg.el b/lisp/vc/vc-hg.el
index 40d7573806..b5cdf5a3a2 100644
--- a/lisp/vc/vc-hg.el
+++ b/lisp/vc/vc-hg.el
@@ -1525,6 +1525,13 @@ vc-hg-command
 (defun vc-hg-root (file)
   (vc-find-root file ".hg"))
 
+(defun vc-hg-repository-url (file-or-dir)
+  (let ((default-directory (vc-hg-root file-or-dir)))
+    (with-temp-buffer
+      (vc-hg-command (current-buffer) nil nil
+                     "config" "paths.default")
+      (buffer-substring-no-properties (point-min) (1- (point-max))))))
+
 (provide 'vc-hg)
 
 ;;; vc-hg.el ends here
diff --git a/lisp/vc/vc-svn.el b/lisp/vc/vc-svn.el
index d039bf3c6a..c439082390 100644
--- a/lisp/vc/vc-svn.el
+++ b/lisp/vc/vc-svn.el
@@ -816,7 +816,14 @@ vc-svn-revision-table
           (push (match-string 1 loglines) vc-svn-revisions)
           (setq start (+ start (match-end 0)))
           (setq loglines (buffer-substring-no-properties start (point-max)))))
-    vc-svn-revisions)))
+      vc-svn-revisions)))
+
+(defun vc-svn-repository-url (file-or-dir)
+  (let ((default-directory (vc-svn-root file-or-dir)))
+    (with-temp-buffer
+      (vc-svn-command (current-buffer) nil nil
+                      "info" "--show-item" "repos-root-url")
+      (buffer-substring-no-properties (point-min) (1- (point-max))))))
 
 (provide 'vc-svn)
 
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index c640ba0420..5c335ebfaa 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -553,6 +553,10 @@
 ;;   Return the list of files where conflict resolution is needed in
 ;;   the project that contains DIR.
 ;;   FIXME: what should it do with non-text conflicts?
+;;
+;; - repository-url (file)
+;;
+;;   Returns the URL of the repository of the current checkout.
 
 ;;; Changes from the pre-25.1 API:
 ;;
-- 
2.27.0

Bye,
Tassilo

reply via email to

[Prev in Thread] Current Thread [Next in Thread]