>From 0e0c14b0d8ff8582301eab65c91120a52aad5597 Mon Sep 17 00:00:00 2001 From: Davis Herring Date: Sun, 12 Jun 2016 05:37:49 -0600 Subject: [PATCH 4/6] Snap `vc-parent-buffer' chains This avoids having to search the tree and check for loops. * lisp/vc/vc-dispatcher.el (vc-get-parent-buffer, vc-set-parent-buffer): New functions. (vc-setup-buffer, vc-start-logentry): Use `vc-set-parent-buffer'. * lisp/vc/vc.el (vc-ensure-vc-buffer, vc-find-revision): Use both. --- lisp/vc/vc-dispatcher.el | 22 ++++++++++++++++------ lisp/vc/vc.el | 9 ++------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lisp/vc/vc-dispatcher.el b/lisp/vc/vc-dispatcher.el index a551542..f39d517 100644 --- a/lisp/vc/vc-dispatcher.el +++ b/lisp/vc/vc-dispatcher.el @@ -166,6 +166,20 @@ Another is that undo information is not kept." (insert s) (set-marker (process-mark p) (point)))))))) +(defun vc-get-parent-buffer () + "Return the current buffer or its parent if it has one." + (if (buffer-live-p vc-parent-buffer) vc-parent-buffer (current-buffer))) +(defun vc-set-parent-buffer (buf &optional silent) + "Set current buffer's parent to BUF (or its parent if it has one). +Do nothing if that is the current buffer. +Set the mode line name as well unless SILENT." + (setq buf (with-current-buffer buf (vc-get-parent-buffer))) + (unless (eq buf (current-buffer)) + (set (make-local-variable 'vc-parent-buffer) buf) + (unless silent + (set (make-local-variable 'vc-parent-buffer-name) + (concat " from " (buffer-name buf)))))) + (defun vc-setup-buffer (buf) "Prepare BUF for executing a slave command and make it current." (let ((camefrom (current-buffer)) @@ -178,9 +192,7 @@ Another is that undo information is not kept." ;; want any of its output to appear from now on. (when oldproc (delete-process oldproc))) (kill-all-local-variables) - (set (make-local-variable 'vc-parent-buffer) camefrom) - (set (make-local-variable 'vc-parent-buffer-name) - (concat " from " (buffer-name camefrom))) + (vc-set-parent-buffer camefrom) (setq default-directory olddir) (let ((buffer-undo-list t) (inhibit-read-only t)) @@ -662,9 +674,7 @@ BACKEND, if non-nil, specifies a VC backend for the Log Edit buffer." (if (and comment (not initial-contents)) (set-buffer (get-buffer-create logbuf)) (pop-to-buffer (get-buffer-create logbuf))) - (set (make-local-variable 'vc-parent-buffer) parent) - (set (make-local-variable 'vc-parent-buffer-name) - (concat " from " (buffer-name vc-parent-buffer))) + (vc-set-parent-buffer parent) (vc-log-edit files mode backend) (make-local-variable 'vc-log-after-operation-hook) (when after-hook diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 343cd70..bb5cdd5 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -1069,12 +1069,7 @@ BEWARE: this function may change the current buffer." ((derived-mode-p 'vc-dir-mode) (set-buffer (find-file-noselect (vc-dir-current-file)))) (t - (while (and vc-parent-buffer - (buffer-live-p vc-parent-buffer) - ;; Avoid infinite looping when vc-parent-buffer and - ;; current buffer are the same buffer. - (not (eq vc-parent-buffer (current-buffer)))) - (set-buffer vc-parent-buffer)) + (set-buffer (vc-get-parent-buffer)) (if (not buffer-file-name) (error "Buffer %s is not associated with a file" (buffer-name)) (unless (vc-backend buffer-file-name) @@ -1978,7 +1973,7 @@ Use BACKEND as the VC backend if specified." (with-current-buffer result-buf ;; Set the parent buffer so that things like ;; C-x v g, C-x v l, ... etc work. - (set (make-local-variable 'vc-parent-buffer) filebuf)) + (vc-set-parent-buffer filebuf t)) result-buf))) ;; Header-insertion code -- 1.7.1