From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?ISO-8859-1?Q?R=FCdiger?= Sonderfeld Newsgroups: gmane.emacs.devel Subject: [PATCH] Add smerge-mode, conflicted-files support to vc-git. Date: Sat, 11 Jan 2014 02:14:37 +0100 Message-ID: <12408468.cjCttLLJHG@descartes> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1389402899 27570 80.91.229.3 (11 Jan 2014 01:14:59 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 11 Jan 2014 01:14:59 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jan 11 02:15:07 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1W1nAH-0007q6-5l for ged-emacs-devel@m.gmane.org; Sat, 11 Jan 2014 02:15:05 +0100 Original-Received: from localhost ([::1]:59721 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W1nAG-00083D-Ml for ged-emacs-devel@m.gmane.org; Fri, 10 Jan 2014 20:15:04 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55989) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W1nA9-00081W-Dn for emacs-devel@gnu.org; Fri, 10 Jan 2014 20:15:02 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W1nA3-0003js-It for emacs-devel@gnu.org; Fri, 10 Jan 2014 20:14:57 -0500 Original-Received: from ptmx.org ([178.63.28.110]:44534) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W1nA3-0003jY-8S for emacs-devel@gnu.org; Fri, 10 Jan 2014 20:14:51 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by ptmx.org (Postfix) with ESMTP id 58A3E24D51; Sat, 11 Jan 2014 02:14:50 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at ptmx.org Original-Received: from ptmx.org ([127.0.0.1]) by localhost (ptmx.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id P3mwNynoBaC8; Sat, 11 Jan 2014 02:14:48 +0100 (CET) Original-Received: from descartes.localnet (chello080108246092.7.14.vie.surfer.at [80.108.246.92]) by ptmx.org (Postfix) with ESMTPSA id 39C8924C63; Sat, 11 Jan 2014 02:14:48 +0100 (CET) User-Agent: KMail/4.11.3 (Linux/3.11.0-14-generic; KDE/4.11.3; x86_64; ; ) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 178.63.28.110 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:168056 Archived-At: 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=C3=83=C2=BCdiger Sonderfeld + +=09* vc/vc-git.el (vc-git-find-file-hook): New function. +=09(vc-git-conflicted-files): New function. + 2014-01-10 Eric S. Raymond =20 =09* 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 =20 ;;; Code: =20 @@ -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))) =20 +(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 'l= ocal) + (message "There are unresolved conflicts in this file"))) + ;;; HISTORY FUNCTIONS =20 (autoload 'vc-setup-buffer "vc-dispatcher") --=20 1.8.5.2