all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Rüdiger Sonderfeld" <ruediger@c-plusplus.de>
To: emacs-devel@gnu.org
Subject: [PATCH] Add smerge-mode, conflicted-files support to vc-git.
Date: Sat, 11 Jan 2014 02:14:37 +0100	[thread overview]
Message-ID: <12408468.cjCttLLJHG@descartes> (raw)

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




             reply	other threads:[~2014-01-11  1:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-11  1:14 Rüdiger Sonderfeld [this message]
2014-01-12  2:52 ` [PATCH] Add smerge-mode, conflicted-files support to vc-git Stefan Monnier
2014-01-13 12:31   ` Rüdiger Sonderfeld

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=12408468.cjCttLLJHG@descartes \
    --to=ruediger@c-plusplus.de \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.