From: Dmitry Gutov Date: Tue, 25 Oct 2022 21:09:01 +0000 (+0300) Subject: vc-hg-checkin-patch: Add implementation for Hg X-Git-Tag: emacs-29.0.90~1616^2~464 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d062482c3f9c243e3224d9de0d776be05c54926b;p=emacs.git vc-hg-checkin-patch: Add implementation for Hg * lisp/vc/vc-hg.el (vc-hg-checkin-patch): Add Hg-specific implementation (bug#52349), like suggested in https://lists.gnu.org/archive/html/emacs-devel/2022-10/msg01533.html. (vc-hg--extract-headers): Extract from vc-hg-checkin. --- diff --git a/lisp/vc/vc-hg.el b/lisp/vc/vc-hg.el index 2eebe2d5434..1b1c1683dd5 100644 --- a/lisp/vc/vc-hg.el +++ b/lisp/vc/vc-hg.el @@ -51,6 +51,7 @@ ;; - receive-file (file rev) ?? PROBABLY NOT NEEDED ;; - unregister (file) OK ;; * checkin (files rev comment) OK +;; - checkin-patch (patch-string comment) OK ;; * find-revision (file rev buffer) OK ;; * checkout (file &optional rev) OK ;; * revert (file &optional contents-done) OK @@ -1189,16 +1190,31 @@ It is based on `log-edit-mode', and has Hg-specific extensions.") (defun vc-hg-checkin (files comment &optional _rev) "Hg-specific version of `vc-backend-checkin'. REV is ignored." - (let ((amend-extract-fn - (lambda (value) - (when (equal value "yes") - (list "--amend"))))) - (apply #'vc-hg-command nil 0 files - (nconc (list "commit" "-m") - (log-edit-extract-headers `(("Author" . "--user") - ("Date" . "--date") - ("Amend" . ,amend-extract-fn)) - comment))))) + (apply #'vc-hg-command nil 0 files + (nconc (list "commit" "-m") + (vc-hg--extract-headers comment)))) + +(defun vc-hg-checkin-patch (patch-string comment) + (let ((patch-file (make-temp-file "hg-patch"))) + (write-region patch-string nil patch-file) + (unwind-protect + (progn + (apply #'vc-hg-command nil 0 nil + (nconc (list "import" "--bypass" patch-file "-m") + (vc-hg--extract-headers comment))) + (vc-hg-command nil 0 nil + "update" + "--merge" "--tool" "internal:local" + "tip")) + (delete-file patch-file)))) + +(defun vc-hg--extract-headers (comment) + (log-edit-extract-headers `(("Author" . "--user") + ("Date" . "--date") + ("Amend" . (lambda (value) + (when (equal value "yes") + (list "--amend"))))) + comment)) (defun vc-hg-find-revision (file rev buffer) (let ((coding-system-for-read 'binary)