From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Albinus Newsgroups: gmane.emacs.bugs Subject: bug#11757: Acknowledgement (24.1.50; vc-git calls `process-file' too many times) Date: Fri, 29 Jun 2012 15:46:33 +0200 Message-ID: <87d34igrie.fsf@gmx.de> References: <4FE2832A.1030308@yandex.ru> <4FE994E8.9020605@yandex.ru> <87zk7qs21q.fsf@gmx.de> <4FEBAAAA.3030102@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1340977621 24347 80.91.229.3 (29 Jun 2012 13:47:01 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 29 Jun 2012 13:47:01 +0000 (UTC) Cc: 11757@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Jun 29 15:47:00 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SkbXH-0005rC-4L for geb-bug-gnu-emacs@m.gmane.org; Fri, 29 Jun 2012 15:46:59 +0200 Original-Received: from localhost ([::1]:42578 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SkbXH-0006yU-5Q for geb-bug-gnu-emacs@m.gmane.org; Fri, 29 Jun 2012 09:46:59 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:36554) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SkbXE-0006yO-1o for bug-gnu-emacs@gnu.org; Fri, 29 Jun 2012 09:46:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SkbX3-00027L-Kf for bug-gnu-emacs@gnu.org; Fri, 29 Jun 2012 09:46:55 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:55493) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SkbX3-00027C-Gr for bug-gnu-emacs@gnu.org; Fri, 29 Jun 2012 09:46:45 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1SkbbC-000591-De for bug-gnu-emacs@gnu.org; Fri, 29 Jun 2012 09:51:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <4FE2832A.1030308@yandex.ru> Resent-From: Michael Albinus Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 29 Jun 2012 13:51:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 11757 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 11757-submit@debbugs.gnu.org id=B11757.134097786119768 (code B ref 11757); Fri, 29 Jun 2012 13:51:02 +0000 Original-Received: (at 11757) by debbugs.gnu.org; 29 Jun 2012 13:51:01 +0000 Original-Received: from localhost ([127.0.0.1]:36806 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SkbbA-00058m-PR for submit@debbugs.gnu.org; Fri, 29 Jun 2012 09:51:01 -0400 Original-Received: from mailout-de.gmx.net ([213.165.64.23]:44736) by debbugs.gnu.org with smtp (Exim 4.72) (envelope-from ) id 1Skbb7-00058e-Tk for 11757@debbugs.gnu.org; Fri, 29 Jun 2012 09:50:59 -0400 Original-Received: (qmail invoked by alias); 29 Jun 2012 13:46:36 -0000 Original-Received: from p57BB961B.dip0.t-ipconnect.de (EHLO detlef.gmx.de) [87.187.150.27] by mail.gmx.net (mp031) with SMTP; 29 Jun 2012 15:46:36 +0200 X-Authenticated: #3708877 X-Provags-ID: V01U2FsdGVkX19k9Uh8y+FkgdPQKDnHo2J3ixHoHH1+EILdsjL47Y wIMERzzXROZaI2 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) X-Y-GMX-Trusted: 0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:61411 Archived-At: Dmitry Gutov writes: > Hi Michael, Hi Dmitry, > This little patch shaves 2 `process-file' invocations from both > vc-find-file-hook' and `vc-after-save'. > > It's not fully backward-compatible (it breaks when a previously > registered file became unregistered), but I think it's a good > tradeoff. I don't know whether we shall break the functionality. Instead of, I've appended a small patch, which uses the cache for vc-git-registered and vc-git-root (additionally to your patch, which uses the cache of vc-working-revision). This reduces already the number of process-file invocations from 6 to 4, when openening a new file. And there's room for other caches. > VC doesn't handle all cases of "outside interference" anyway: for > example, the cached return value of `vc-working-revision' is > invalidated only after the file is checked in, moved, or deleted, not > after each save, and switching to another branch in Git is a much more > common occurrence. A stale cache is bad, of course. We must carefully check, where a cached value has to be invalidated. But why should vc-working-revision being invalidated after saving? It is still the same, I believe. Switching to another branch shall be observed by Emacs, 'cause there is another version of the file on the disk, and Emacs warns you before editing. > A more complex solution, though also applicable to vc-hg, would be to > move most of the code from `vc-git-registered' to `vc-git-state', then > modify `vc-git-registered' and `vc-hg-registered' to call `vc-state' > (for caching) and then interpret its return value (what > vc-hg-registered' already does). Since `vc-registered' calls > vc-xx-registered' functions when selecting the backend, we'd also need > to clear the cached 'vc-state value after each call with negative > result. This I cannot answer (yet). We could apply this, when the other changes work robustly. > -- Dmitry Best regards, Michael. *** /usr/local/src/emacs/lisp/vc/vc-git.el.~108799~ 2012-06-29 15:39:15.897374680 +0200 --- /usr/local/src/emacs/lisp/vc/vc-git.el 2012-06-29 15:24:04.389401221 +0200 *************** *** 173,200 **** (defun vc-git-registered (file) "Check whether FILE is registered with git." ! (let ((dir (vc-git-root file))) ! (when dir ! (with-temp-buffer ! (let* (process-file-side-effects ! ;; Do not use the `file-name-directory' here: git-ls-files ! ;; sometimes fails to return the correct status for relative ! ;; path specs. ! ;; See also: http://marc.info/?l=git&m=125787684318129&w=2 ! (name (file-relative-name file dir)) ! (str (ignore-errors ! (cd dir) ! (vc-git--out-ok "ls-files" "-c" "-z" "--" name) ! ;; If result is empty, use ls-tree to check for deleted ! ;; file. ! (when (eq (point-min) (point-max)) ! (vc-git--out-ok "ls-tree" "--name-only" "-z" "HEAD" ! "--" name)) ! (buffer-string)))) ! (and str ! (> (length str) (length name)) ! (string= (substring str 0 (1+ (length name))) ! (concat name "\0")))))))) (defun vc-git--state-code (code) "Convert from a string to a added/deleted/modified state." --- 173,203 ---- (defun vc-git-registered (file) "Check whether FILE is registered with git." ! (or (vc-file-getprop file 'git-registered) ! (vc-file-setprop ! file 'git-registered ! (let ((dir (vc-git-root file))) ! (when dir ! (with-temp-buffer ! (let* (process-file-side-effects ! ;; Do not use the `file-name-directory' here: git-ls-files ! ;; sometimes fails to return the correct status for relative ! ;; path specs. ! ;; See also: http://marc.info/?l=git&m=125787684318129&w=2 ! (name (file-relative-name file dir)) ! (str (ignore-errors ! (cd dir) ! (vc-git--out-ok "ls-files" "-c" "-z" "--" name) ! ;; If result is empty, use ls-tree to check for deleted ! ;; file. ! (when (eq (point-min) (point-max)) ! (vc-git--out-ok "ls-tree" "--name-only" "-z" "HEAD" ! "--" name)) ! (buffer-string)))) ! (and str ! (> (length str) (length name)) ! (string= (substring str 0 (1+ (length name))) ! (concat name "\0")))))))))) (defun vc-git--state-code (code) "Convert from a string to a added/deleted/modified state." *************** *** 248,254 **** (defun vc-git-mode-line-string (file) "Return a string for `vc-mode-line' to put in the mode line for FILE." ! (let* ((branch (vc-git-working-revision file)) (def-ml (vc-default-mode-line-string 'Git file)) (help-echo (get-text-property 0 'help-echo def-ml))) (if (zerop (length branch)) --- 251,257 ---- (defun vc-git-mode-line-string (file) "Return a string for `vc-mode-line' to put in the mode line for FILE." ! (let* ((branch (vc-working-revision file)) (def-ml (vc-default-mode-line-string 'Git file)) (help-echo (get-text-property 0 'help-echo def-ml))) (if (zerop (length branch)) *************** *** 959,965 **** (defun vc-git-extra-status-menu () vc-git-extra-menu-map) (defun vc-git-root (file) ! (vc-find-root file ".git")) ;; Derived from `lgrep'. (defun vc-git-grep (regexp &optional files dir) --- 962,969 ---- (defun vc-git-extra-status-menu () vc-git-extra-menu-map) (defun vc-git-root (file) ! (or (vc-file-getprop file 'git-root) ! (vc-file-setprop file 'git-root (vc-find-root file ".git")))) ;; Derived from `lgrep'. (defun vc-git-grep (regexp &optional files dir)