From 49596095d09227d828ffb6fed955ba0b660b4d92 Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Tue, 4 Dec 2012 20:49:31 -0500 Subject: [PATCH] Add conflict detection/resolution to vc-hg (bug#10709) * lisp/vc/vc-hg.el (vc-hg-resolve-when-done, vc-hg-find-file-hook): New functions, for detecting and resolving conflicts. --- lisp/ChangeLog | 5 +++++ lisp/vc/vc-hg.el | 31 ++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ff9b0e2a86f..45fa38042a0 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2012-12-05 Glenn Morris + + * vc/vc-hg.el (vc-hg-resolve-when-done, vc-hg-find-file-hook): + New functions, for detecting and resolving conflicts. (Bug#10709) + 2012-12-04 Jambunathan K * hi-lock.el (hi-lock-auto-select-face): New user variable. diff --git a/lisp/vc/vc-hg.el b/lisp/vc/vc-hg.el index 50678fad075..a240fdeb658 100644 --- a/lisp/vc/vc-hg.el +++ b/lisp/vc/vc-hg.el @@ -93,7 +93,7 @@ ;; - clear-headers () ?? ;; - delete-file (file) TEST IT ;; - rename-file (old new) OK -;; - find-file-hook () PROBABLY NOT NEEDED +;; - find-file-hook () added for bug#10709 ;; 2) Implement Stefan Monnier's advice: ;; vc-hg-registered and vc-hg-state @@ -464,6 +464,35 @@ REV is the revision to check out into WORKFILE." (vc-hg-command t 0 file "cat" "-r" rev) (vc-hg-command t 0 file "cat"))))) +(defun vc-hg-resolve-when-done () + "Call \"hg resolve -m\" if the conflict markers have been removed." + (save-excursion + (goto-char (point-min)) + (unless (re-search-forward "^<<<<<<< " nil t) + (vc-hg-command nil 0 buffer-file-name "resolve" "-m") + ;; Remove the hook so that it is not called multiple times. + (remove-hook 'after-save-hook 'vc-hg-resolve-when-done t)))) + +(defun vc-hg-find-file-hook () + (when (and buffer-file-name + (file-exists-p (concat buffer-file-name ".orig")) + ;; Hg does not seem to have a "conflict" status, eg + ;; hg http://bz.selenic.com/show_bug.cgi?id=2724 + (memq (vc-file-getprop buffer-file-name 'vc-state) + '(edited conflict)) + ;; Maybe go on to check that "hg resolve -l" says "U"? + ;; If "hg resolve -l" says there's a conflict but there are no + ;; conflict markers, it's not clear what we should do. + (save-excursion + (goto-char (point-min)) + (re-search-forward "^<<<<<<< " nil t))) + ;; Hg may not recognize "conflict" as a state, but we can do better. + (vc-file-setprop buffer-file-name 'vc-state 'conflict) + (smerge-start-session) + (add-hook 'after-save-hook 'vc-hg-resolve-when-done nil t) + (message "There are unresolved conflicts in this file"))) + + ;; Modeled after the similar function in vc-bzr.el (defun vc-hg-workfile-unchanged-p (file) (eq 'up-to-date (vc-hg-state file))) -- 2.39.5