unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] Add smerge-mode, conflicted-files support to vc-git.
@ 2014-01-11  1:14 Rüdiger Sonderfeld
  2014-01-12  2:52 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Rüdiger Sonderfeld @ 2014-01-11  1:14 UTC (permalink / raw)
  To: emacs-devel

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  <ruediger@c-plusplus.de>
+
+	* vc/vc-git.el (vc-git-find-file-hook): New function.
+	(vc-git-conflicted-files): New function.
+
 2014-01-10  Eric S. Raymond  <esr@thyrsus.com>
 
 	* 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




^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-01-13 12:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-11  1:14 [PATCH] Add smerge-mode, conflicted-files support to vc-git Rüdiger Sonderfeld
2014-01-12  2:52 ` Stefan Monnier
2014-01-13 12:31   ` Rüdiger Sonderfeld

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).