{"thread":{"id":"11895","subject":"[PATCH] git.el: automatically revert emacs buffers","startedAt":"2008-01-21T18:07:59Z","lastAt":"2008-02-07T13:03:53Z","messageCount":3,"participants":["Sergei Organov","Alexandre Julliard"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"67516","messageId":"874pcnh4ej.fsf@osv.gnss.ru","threadId":"11895","inReplyTo":null,"subject":"[PATCH] git.el: automatically revert emacs buffers","fromName":"Sergei Organov","fromEmail":"osv@javad.com","sentAt":"2008-01-21T18:07:59Z","receivedAt":"2008-01-21T18:07:59Z","isPatch":true,"sender":{"key":"osv@javad.com","avatar":null},"body":"If new custom variable git-auto-revert is 't', after git-revert-file,\nrevert corresponding emacs buffers from reverted files provided the\nbuffers were not changed. This is how pcl-cvs behaves.\n\n* git-auto-revert: new customizable variable.\n* git-revert-some-buffers: new function.\n* git-revert-file: call git-revert-some-buffers.\n\nSigned-off-by: Sergei Organov <osv@javad.com>\n---\n contrib/emacs/git.el |   23 +++++++++++++++++++++++\n 1 files changed, 23 insertions(+), 0 deletions(-)\n\ndiff --git a/contrib/emacs/git.el b/contrib/emacs/git.el\nindex d8a0638..c3c0c45 100644\n--- a/contrib/emacs/git.el\n+++ b/contrib/emacs/git.el\n@@ -112,6 +112,11 @@ if there is already one that displays the same directory.\"\n   :group 'git\n   :type 'boolean)\n \n+(defcustom git-auto-revert t\n+  \"Non-nil if `git-revert-file' should automatically revert corresponding buffers.\"\n+  :group 'git\n+  :type 'boolean)\n+\n \n (defface git-status-face\n   '((((class color) (background light)) (:foreground \"purple\"))\n@@ -989,6 +994,23 @@ Return the list of files that haven't been handled.\"\n           (git-success-message \"Removed\" files))\n       (message \"Aborting\"))))\n \n+;; stolen from pcl-cvs's cvs-revert-if-needed\n+(defun git-revert-some-buffers (fis)\n+  (dolist (fileinfo fis)\n+    (let* ((file (git-fileinfo->name fileinfo))\n+\t   (buffer (find-buffer-visiting file)))\n+      ;; For a revert to happen the user must be editing the file...\n+      (unless (or (null buffer)\n+\t\t  (buffer-modified-p buffer))\n+\t(with-current-buffer buffer\n+\t  (ignore-errors\n+\t    (revert-buffer 'ignore-auto 'dont-ask 'preserve-modes)\n+\t    ;; `preserve-modes' avoids changing the (minor) modes.  But we\n+\t    ;; do want to reset the mode for VC, so we do it explicitly.\n+\t    (vc-find-file-hook)\n+\t    (when (eq (git-fileinfo->state fileinfo) 'unmerged)\n+\t      (smerge-mode 1))))))))\n+\n (defun git-revert-file ()\n   \"Revert changes to the marked file(s).\"\n   (interactive)\n@@ -1008,6 +1030,7 @@ Return the list of files that haven't been handled.\"\n       (when modified\n         (apply #'git-call-process-env nil nil \"checkout\" \"HEAD\" modified))\n       (git-update-status-files (append added modified) 'uptodate)\n+      (if git-auto-revert (git-revert-some-buffers files))\n       (git-success-message \"Reverted\" (git-get-filenames files)))))\n \n (defun git-resolve-file ()\n-- \n1.5.4.18.gd0b8\n"},{"id":"67792","messageId":"87ir10q5yy.fsf@wine.dyndns.org","threadId":"11895","inReplyTo":"874pcnh4ej.fsf@osv.gnss.ru","subject":"Re: [PATCH] git.el: automatically revert emacs buffers","fromName":"Alexandre Julliard","fromEmail":"julliard@winehq.org","sentAt":"2008-02-07T12:57:41Z","receivedAt":"2008-02-07T12:57:41Z","isPatch":true,"sender":{"key":"julliard@winehq.org","avatar":null},"body":"Sergei Organov <osv@javad.com> writes:\n\n> If new custom variable git-auto-revert is 't', after git-revert-file,\n> revert corresponding emacs buffers from reverted files provided the\n> buffers were not changed. This is how pcl-cvs behaves.\n>\n> * git-auto-revert: new customizable variable.\n> * git-revert-some-buffers: new function.\n> * git-revert-file: call git-revert-some-buffers.\n\nI had implemented this a bit differently in the patch series I just\nsent, I did it the VC way by also checking for modified buffers and\nrefusing to revert their corresponding files. I didn't add a custom\nvariable for it though, so I'll merge that part of your patch.\n\n-- \nAlexandre Julliard\njulliard@winehq.org\n"},{"id":"67793","messageId":"87tzkk2a12.fsf@osv.gnss.ru","threadId":"11895","inReplyTo":"87ir10q5yy.fsf@wine.dyndns.org","subject":"Re: [PATCH] git.el: automatically revert emacs buffers","fromName":"Sergei Organov","fromEmail":"osv@javad.com","sentAt":"2008-02-07T13:03:53Z","receivedAt":"2008-02-07T13:03:53Z","isPatch":true,"sender":{"key":"osv@javad.com","avatar":null},"body":"Alexandre Julliard <julliard@winehq.org> writes:\n> Sergei Organov <osv@javad.com> writes:\n>\n>> If new custom variable git-auto-revert is 't', after git-revert-file,\n>> revert corresponding emacs buffers from reverted files provided the\n>> buffers were not changed. This is how pcl-cvs behaves.\n>>\n>> * git-auto-revert: new customizable variable.\n>> * git-revert-some-buffers: new function.\n>> * git-revert-file: call git-revert-some-buffers.\n>\n> I had implemented this a bit differently in the patch series I just\n> sent, I did it the VC way by also checking for modified buffers and\n> refusing to revert their corresponding files. I didn't add a custom\n> variable for it though, so I'll merge that part of your patch.\n\nI don't think the custom variable is necessary. I added it only because\nPCL-CVS had it, even though I didn't ever customize it in PCL-CVS. So\nplease feel free to drop my patch entirely.\n\n-- Sergei Organov.\n"}]}