[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Add smerge-mode, conflicted-files support to vc-git.
From: |
Rüdiger Sonderfeld |
Subject: |
[PATCH] Add smerge-mode, conflicted-files support to vc-git. |
Date: |
Sat, 11 Jan 2014 02:14:37 +0100 |
User-agent: |
KMail/4.11.3 (Linux/3.11.0-14-generic; KDE/4.11.3; x86_64; ; ) |
I've implemented `smerge-mode' and `vc-git-conflicted-files' support.
This was requested during the current discussion about moving Emacs to
git[1]. I'm not very familiar with the internals of vc.el and I might
have overlooked some git corner cases. This patch results in one call
to `git status' per file. Which might be a problem. There was a
discussion about adding a config var for this.
There should also be a `vc-git-resolve-when-done' function added.
[1] http://lists.gnu.org/archive/html/emacs-devel/2014-01/msg00509.html
* lisp/vc/vc-git.el (vc-git-find-file-hook): New function.
(vc-git-conflicted-files): New function.
---
lisp/ChangeLog | 5 +++++
lisp/vc/vc-git.el | 32 +++++++++++++++++++++++++++++++-
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index d5104d3..9a4a0d9 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
+2014-01-11 Rüdiger Sonderfeld <address@hidden>
+
+ * vc/vc-git.el (vc-git-find-file-hook): New function.
+ (vc-git-conflicted-files): New function.
+
2014-01-10 Eric S. Raymond <address@hidden>
* version.el (emacs-bzr-get-version): Restore compatibilty with
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 6706300..369a546 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -101,7 +101,7 @@
;; - clear-headers () NOT NEEDED
;; - delete-file (file) OK
;; - rename-file (old new) OK
-;; - find-file-hook () NOT NEEDED
+;; - find-file-hook () OK
;;; Code:
@@ -769,6 +769,36 @@ (defun vc-git-merge-branch ()
(with-current-buffer buffer (vc-run-delayed (vc-compilation-mode 'git)))
(vc-set-async-update buffer)))
+(defun vc-git-conflicted-files (directory)
+ "Return the list of files with conflicts in DIRECTORY."
+ (let* ((status
+ (vc-git--run-command-string directory "status" "--porcelain" "--"))
+ (lines (split-string status "\n" 'omit-nulls))
+ files)
+ (dolist (line lines files)
+ (when (string-match "\\([ MADRCU?!][ MADRCU?!]\\) \\(.+\\)\
+\\(?: -> \\(.+\\)\\)?"
+ line)
+ (let ((state (match-string 1 line))
+ (file (match-string 2 line)))
+ ;; See git-status(1).
+ (when (member state '("AU" "UD" "UA" ;; "DD"
+ "DU" "AA" "UU"))
+ (push file files)))))))
+
+;; Inspired by `vc-hg-find-file-hook'.
+(defun vc-git-find-file-hook ()
+ "Activate `smerge-mode' if there is a conflict."
+ (when (and buffer-file-name
+ (vc-git-conflicted-files buffer-file-name)
+ (save-excursion
+ (goto-char (point-min))
+ (re-search-forward "^<<<<<<< " nil 'noerror)))
+ (vc-file-setprop buffer-file-name 'vc-state 'conflict)
+ (smerge-start-session)
+ ;;TODO (add-hook 'after-save-hook 'vc-git-resolve-when-done nil 'local)
+ (message "There are unresolved conflicts in this file")))
+
;;; HISTORY FUNCTIONS
(autoload 'vc-setup-buffer "vc-dispatcher")
--
1.8.5.2
- [PATCH] Add smerge-mode, conflicted-files support to vc-git.,
Rüdiger Sonderfeld <=