From 2cc441ecbf093d2d7e319f2359b80fd358589b0f Mon Sep 17 00:00:00 2001
From: "Eric S. Raymond" <esr@thyrsus.com>
Date: Wed, 13 Aug 2014 04:05:45 -0400
Subject: [PATCH] =?utf8?q?Integrate=20R=C3=BCdiger=20Sonderfeld's=20code?=
 =?utf8?q?=20for=20detecting=20conflicted=20files=20under=20git.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

---
 lisp/ChangeLog    |  7 +++++++
 lisp/vc/vc-git.el | 18 ++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 7bb7415bc9c..764d6d12c8a 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
+2014-08-13  Eric S. Raymond  <esr@thyrsus.com>
+
+	* vc/vc-git.el (vc-git-conflicted-files): Integrate Rüdiger
+	Sonderfeld's code for detecting conflicted files using a status
+	listing.  Useful in itself and a step towards better smerge
+	support.
+
 2014-08-12  Stefan Monnier  <monnier@iro.umontreal.ca>
 
 	* mpc.el (mpc-reorder): Don't bother splitting the "active"s elements
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 9c8ab3ba393..3e9228601d8 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -102,6 +102,7 @@
 ;; - delete-file (file)                            OK
 ;; - rename-file (old new)                         OK
 ;; - find-file-hook ()                             NOT NEEDED
+;; - conflicted-files                              OK
 
 ;;; Code:
 
@@ -769,6 +770,23 @@ This prompts for a branch to merge from."
     (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)))))))
+
+
 ;;; HISTORY FUNCTIONS
 
 (autoload 'vc-setup-buffer "vc-dispatcher")
-- 
2.39.5