* [PATCH] git.el: automatically revert emacs buffers
@ 2008-01-21 18:07 Sergei Organov
2008-02-07 12:57 ` Alexandre Julliard
0 siblings, 1 reply; 4+ messages in thread
From: Sergei Organov @ 2008-01-21 18:07 UTC (permalink / raw)
To: git; +Cc: Alexandre Julliard, gitster
If new custom variable git-auto-revert is 't', after git-revert-file,
revert corresponding emacs buffers from reverted files provided the
buffers were not changed. This is how pcl-cvs behaves.
* git-auto-revert: new customizable variable.
* git-revert-some-buffers: new function.
* git-revert-file: call git-revert-some-buffers.
Signed-off-by: Sergei Organov <osv@javad.com>
---
contrib/emacs/git.el | 23 +++++++++++++++++++++++
1 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index d8a0638..c3c0c45 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -112,6 +112,11 @@ if there is already one that displays the same directory."
:group 'git
:type 'boolean)
+(defcustom git-auto-revert t
+ "Non-nil if `git-revert-file' should automatically revert corresponding buffers."
+ :group 'git
+ :type 'boolean)
+
(defface git-status-face
'((((class color) (background light)) (:foreground "purple"))
@@ -989,6 +994,23 @@ Return the list of files that haven't been handled."
(git-success-message "Removed" files))
(message "Aborting"))))
+;; stolen from pcl-cvs's cvs-revert-if-needed
+(defun git-revert-some-buffers (fis)
+ (dolist (fileinfo fis)
+ (let* ((file (git-fileinfo->name fileinfo))
+ (buffer (find-buffer-visiting file)))
+ ;; For a revert to happen the user must be editing the file...
+ (unless (or (null buffer)
+ (buffer-modified-p buffer))
+ (with-current-buffer buffer
+ (ignore-errors
+ (revert-buffer 'ignore-auto 'dont-ask 'preserve-modes)
+ ;; `preserve-modes' avoids changing the (minor) modes. But we
+ ;; do want to reset the mode for VC, so we do it explicitly.
+ (vc-find-file-hook)
+ (when (eq (git-fileinfo->state fileinfo) 'unmerged)
+ (smerge-mode 1))))))))
+
(defun git-revert-file ()
"Revert changes to the marked file(s)."
(interactive)
@@ -1008,6 +1030,7 @@ Return the list of files that haven't been handled."
(when modified
(apply #'git-call-process-env nil nil "checkout" "HEAD" modified))
(git-update-status-files (append added modified) 'uptodate)
+ (if git-auto-revert (git-revert-some-buffers files))
(git-success-message "Reverted" (git-get-filenames files)))))
(defun git-resolve-file ()
--
1.5.4.18.gd0b8
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] git.el: automatically revert emacs buffers
2008-01-21 18:07 [PATCH] git.el: automatically revert emacs buffers Sergei Organov
@ 2008-02-07 12:57 ` Alexandre Julliard
2008-02-07 13:03 ` Sergei Organov
0 siblings, 1 reply; 4+ messages in thread
From: Alexandre Julliard @ 2008-02-07 12:57 UTC (permalink / raw)
To: Sergei Organov; +Cc: git, gitster
Sergei Organov <osv@javad.com> writes:
> If new custom variable git-auto-revert is 't', after git-revert-file,
> revert corresponding emacs buffers from reverted files provided the
> buffers were not changed. This is how pcl-cvs behaves.
>
> * git-auto-revert: new customizable variable.
> * git-revert-some-buffers: new function.
> * git-revert-file: call git-revert-some-buffers.
I had implemented this a bit differently in the patch series I just
sent, I did it the VC way by also checking for modified buffers and
refusing to revert their corresponding files. I didn't add a custom
variable for it though, so I'll merge that part of your patch.
--
Alexandre Julliard
julliard@winehq.org
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] git.el: automatically revert emacs buffers
2008-02-07 12:57 ` Alexandre Julliard
@ 2008-02-07 13:03 ` Sergei Organov
0 siblings, 0 replies; 4+ messages in thread
From: Sergei Organov @ 2008-02-07 13:03 UTC (permalink / raw)
To: Alexandre Julliard; +Cc: git, gitster
Alexandre Julliard <julliard@winehq.org> writes:
> Sergei Organov <osv@javad.com> writes:
>
>> If new custom variable git-auto-revert is 't', after git-revert-file,
>> revert corresponding emacs buffers from reverted files provided the
>> buffers were not changed. This is how pcl-cvs behaves.
>>
>> * git-auto-revert: new customizable variable.
>> * git-revert-some-buffers: new function.
>> * git-revert-file: call git-revert-some-buffers.
>
> I had implemented this a bit differently in the patch series I just
> sent, I did it the VC way by also checking for modified buffers and
> refusing to revert their corresponding files. I didn't add a custom
> variable for it though, so I'll merge that part of your patch.
I don't think the custom variable is necessary. I added it only because
PCL-CVS had it, even though I didn't ever customize it in PCL-CVS. So
please feel free to drop my patch entirely.
-- Sergei Organov.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] git.el: automatically revert emacs buffers
@ 2008-01-21 18:07 Sergei Organov
0 siblings, 0 replies; 4+ messages in thread
From: Sergei Organov @ 2008-01-21 18:07 UTC (permalink / raw)
To: git; +Cc: Alexandre Julliard
* git-auto-revert: new customizable variable.
* git-revert-some-buffers: new function.
* git-revert-file: call git-revert-some-buffers.
Signed-off-by: Sergei Organov <osv@javad.com>
---
contrib/emacs/git.el | 23 +++++++++++++++++++++++
1 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index d8a0638..c3c0c45 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -112,6 +112,11 @@ if there is already one that displays the same directory."
:group 'git
:type 'boolean)
+(defcustom git-auto-revert t
+ "Non-nil if `git-revert-file' should automatically revert corresponding buffers."
+ :group 'git
+ :type 'boolean)
+
(defface git-status-face
'((((class color) (background light)) (:foreground "purple"))
@@ -989,6 +994,23 @@ Return the list of files that haven't been handled."
(git-success-message "Removed" files))
(message "Aborting"))))
+;; stolen from pcl-cvs's cvs-revert-if-needed
+(defun git-revert-some-buffers (fis)
+ (dolist (fileinfo fis)
+ (let* ((file (git-fileinfo->name fileinfo))
+ (buffer (find-buffer-visiting file)))
+ ;; For a revert to happen the user must be editing the file...
+ (unless (or (null buffer)
+ (buffer-modified-p buffer))
+ (with-current-buffer buffer
+ (ignore-errors
+ (revert-buffer 'ignore-auto 'dont-ask 'preserve-modes)
+ ;; `preserve-modes' avoids changing the (minor) modes. But we
+ ;; do want to reset the mode for VC, so we do it explicitly.
+ (vc-find-file-hook)
+ (when (eq (git-fileinfo->state fileinfo) 'unmerged)
+ (smerge-mode 1))))))))
+
(defun git-revert-file ()
"Revert changes to the marked file(s)."
(interactive)
@@ -1008,6 +1030,7 @@ Return the list of files that haven't been handled."
(when modified
(apply #'git-call-process-env nil nil "checkout" "HEAD" modified))
(git-update-status-files (append added modified) 'uptodate)
+ (if git-auto-revert (git-revert-some-buffers files))
(git-success-message "Reverted" (git-get-filenames files)))))
(defun git-resolve-file ()
--
1.5.4.rc3.30.g472ca
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-02-07 13:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-21 18:07 [PATCH] git.el: automatically revert emacs buffers Sergei Organov
2008-02-07 12:57 ` Alexandre Julliard
2008-02-07 13:03 ` Sergei Organov
-- strict thread matches above, loose matches on Subject: below --
2008-01-21 18:07 Sergei Organov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox