diff options
| author | Sean Whitton | 2025-05-30 13:32:00 +0100 |
|---|---|---|
| committer | Sean Whitton | 2025-06-05 11:57:28 +0100 |
| commit | 7d0a605a70215acd79f920d1c250d6ea4e40bb78 (patch) | |
| tree | 14e7c287bb35381f5d79c3fa27b4b6c43ad5b20b | |
| parent | 6d0a71af9a99b50b2c5a8db778311123ba3ecbcf (diff) | |
| download | emacs-7d0a605a70215acd79f920d1c250d6ea4e40bb78.tar.gz emacs-7d0a605a70215acd79f920d1c250d6ea4e40bb78.zip | |
Delay running vc-checkin-hook for an async checkin
* lisp/vc/vc-git.el (vc-git-checkin):
* lisp/vc/vc-hg.el (vc-hg-checkin, vc-hg-checkin-patch): Run
vc-checkin-hook using vc-run-delayed.
* lisp/vc/vc.el (vc-checkin): Don't pass vc-checkin-hook to
vc-start-logentry when doing an async checkin. That runs the
hook too early.
| -rw-r--r-- | lisp/vc/vc-git.el | 8 | ||||
| -rw-r--r-- | lisp/vc/vc-hg.el | 16 | ||||
| -rw-r--r-- | lisp/vc/vc.el | 78 |
3 files changed, 61 insertions, 41 deletions
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 77f1f747d69..f460eafacbf 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el | |||
| @@ -1125,7 +1125,8 @@ It is based on `log-edit-mode', and has Git-specific extensions." | |||
| 1125 | (delete-file ,temp)))) | 1125 | (delete-file ,temp)))) |
| 1126 | 1126 | ||
| 1127 | (defun vc-git-checkin (files comment &optional _rev) | 1127 | (defun vc-git-checkin (files comment &optional _rev) |
| 1128 | (let* ((file1 (or (car files) default-directory)) | 1128 | (let* ((parent (current-buffer)) |
| 1129 | (file1 (or (car files) default-directory)) | ||
| 1129 | (root (vc-git-root file1)) | 1130 | (root (vc-git-root file1)) |
| 1130 | (default-directory (expand-file-name root)) | 1131 | (default-directory (expand-file-name root)) |
| 1131 | (only (or (cdr files) | 1132 | (only (or (cdr files) |
| @@ -1253,7 +1254,10 @@ It is based on `log-edit-mode', and has Git-specific extensions." | |||
| 1253 | (with-current-buffer buffer | 1254 | (with-current-buffer buffer |
| 1254 | (vc-run-delayed | 1255 | (vc-run-delayed |
| 1255 | (vc-compilation-mode 'git) | 1256 | (vc-compilation-mode 'git) |
| 1256 | (funcall post))) | 1257 | (funcall post) |
| 1258 | (when (buffer-live-p parent) | ||
| 1259 | (with-current-buffer parent | ||
| 1260 | (run-hooks 'vc-checkin-hook))))) | ||
| 1257 | (vc-set-async-update buffer)) | 1261 | (vc-set-async-update buffer)) |
| 1258 | (apply #'vc-git-command nil 0 files args) | 1262 | (apply #'vc-git-command nil 0 files args) |
| 1259 | (funcall post))))) | 1263 | (funcall post))))) |
diff --git a/lisp/vc/vc-hg.el b/lisp/vc/vc-hg.el index 490118ad0f3..e1527935861 100644 --- a/lisp/vc/vc-hg.el +++ b/lisp/vc/vc-hg.el | |||
| @@ -1186,7 +1186,8 @@ It is based on `log-edit-mode', and has Hg-specific extensions.") | |||
| 1186 | (defun vc-hg-checkin (files comment &optional _rev) | 1186 | (defun vc-hg-checkin (files comment &optional _rev) |
| 1187 | "Hg-specific version of `vc-backend-checkin'. | 1187 | "Hg-specific version of `vc-backend-checkin'. |
| 1188 | REV is ignored." | 1188 | REV is ignored." |
| 1189 | (let ((args (nconc (list "commit" "-m") | 1189 | (let ((parent (current-buffer)) |
| 1190 | (args (nconc (list "commit" "-m") | ||
| 1190 | (vc-hg--extract-headers comment)))) | 1191 | (vc-hg--extract-headers comment)))) |
| 1191 | (if vc-async-checkin | 1192 | (if vc-async-checkin |
| 1192 | (let ((buffer (vc-hg--async-buffer))) | 1193 | (let ((buffer (vc-hg--async-buffer))) |
| @@ -1195,12 +1196,16 @@ REV is ignored." | |||
| 1195 | "Finishing checking in files...") | 1196 | "Finishing checking in files...") |
| 1196 | (with-current-buffer buffer | 1197 | (with-current-buffer buffer |
| 1197 | (vc-run-delayed | 1198 | (vc-run-delayed |
| 1198 | (vc-compilation-mode 'hg))) | 1199 | (vc-compilation-mode 'hg) |
| 1200 | (when (buffer-live-p parent) | ||
| 1201 | (with-current-buffer parent | ||
| 1202 | (run-hooks 'vc-checkin-hook))))) | ||
| 1199 | (vc-set-async-update buffer)) | 1203 | (vc-set-async-update buffer)) |
| 1200 | (apply #'vc-hg-command nil 0 files args)))) | 1204 | (apply #'vc-hg-command nil 0 files args)))) |
| 1201 | 1205 | ||
| 1202 | (defun vc-hg-checkin-patch (patch-string comment) | 1206 | (defun vc-hg-checkin-patch (patch-string comment) |
| 1203 | (let ((patch-file (make-temp-file "hg-patch"))) | 1207 | (let ((parent (current-buffer)) |
| 1208 | (patch-file (make-temp-file "hg-patch"))) | ||
| 1204 | (write-region patch-string nil patch-file) | 1209 | (write-region patch-string nil patch-file) |
| 1205 | (unwind-protect | 1210 | (unwind-protect |
| 1206 | (let ((args (list "update" | 1211 | (let ((args (list "update" |
| @@ -1214,7 +1219,10 @@ REV is ignored." | |||
| 1214 | (apply #'vc-hg--async-command buffer args) | 1219 | (apply #'vc-hg--async-command buffer args) |
| 1215 | (with-current-buffer buffer | 1220 | (with-current-buffer buffer |
| 1216 | (vc-run-delayed | 1221 | (vc-run-delayed |
| 1217 | (vc-compilation-mode 'hg))) | 1222 | (vc-compilation-mode 'hg) |
| 1223 | (when (buffer-live-p parent) | ||
| 1224 | (with-current-buffer parent | ||
| 1225 | (run-hooks 'vc-checkin-hook))))) | ||
| 1218 | (vc-set-async-update buffer)) | 1226 | (vc-set-async-update buffer)) |
| 1219 | (apply #'vc-hg-command nil 0 nil args))) | 1227 | (apply #'vc-hg-command nil 0 nil args))) |
| 1220 | (delete-file patch-file)))) | 1228 | (delete-file patch-file)))) |
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 1fad73face1..64d58265816 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el | |||
| @@ -1894,41 +1894,49 @@ The optional argument PATCH-STRING is a string to check in as a patch. | |||
| 1894 | 1894 | ||
| 1895 | Runs the normal hooks `vc-before-checkin-hook' and `vc-checkin-hook'." | 1895 | Runs the normal hooks `vc-before-checkin-hook' and `vc-checkin-hook'." |
| 1896 | (run-hooks 'vc-before-checkin-hook) | 1896 | (run-hooks 'vc-before-checkin-hook) |
| 1897 | (vc-start-logentry | 1897 | (let ((do-async (and vc-async-checkin |
| 1898 | files comment initial-contents | 1898 | (memq backend vc-async-checkin-backends)))) |
| 1899 | "Enter a change comment." | 1899 | (vc-start-logentry |
| 1900 | "*vc-log*" | 1900 | files comment initial-contents |
| 1901 | (lambda () | 1901 | "Enter a change comment." |
| 1902 | (vc-call-backend backend 'log-edit-mode)) | 1902 | "*vc-log*" |
| 1903 | (lambda (files comment) | 1903 | (lambda () |
| 1904 | ;; "This log message intentionally left almost blank". | 1904 | (vc-call-backend backend 'log-edit-mode)) |
| 1905 | ;; RCS 5.7 gripes about whitespace-only comments too. | 1905 | (lambda (files comment) |
| 1906 | (unless (and comment (string-match "[^\t\n ]" comment)) | 1906 | ;; "This log message intentionally left almost blank". |
| 1907 | (setq comment "*** empty log message ***")) | 1907 | ;; RCS 5.7 gripes about whitespace-only comments too. |
| 1908 | (cl-labels ((do-it () | 1908 | (unless (and comment (string-match "[^\t\n ]" comment)) |
| 1909 | ;; We used to change buffers to get local value of | 1909 | (setq comment "*** empty log message ***")) |
| 1910 | ;; `vc-checkin-switches', but the (singular) local | 1910 | (cl-labels ((do-it () |
| 1911 | ;; buffer is not well defined for filesets. | 1911 | ;; We used to change buffers to get local value of |
| 1912 | (if patch-string | 1912 | ;; `vc-checkin-switches', but the (singular) local |
| 1913 | (vc-call-backend backend 'checkin-patch | 1913 | ;; buffer is not well defined for filesets. |
| 1914 | patch-string comment) | 1914 | (if patch-string |
| 1915 | (vc-call-backend backend 'checkin | 1915 | (vc-call-backend backend 'checkin-patch |
| 1916 | files comment rev)) | 1916 | patch-string comment) |
| 1917 | (mapc #'vc-delete-automatic-version-backups files))) | 1917 | (vc-call-backend backend 'checkin |
| 1918 | (if (and vc-async-checkin (memq backend vc-async-checkin-backends)) | 1918 | files comment rev)) |
| 1919 | ;; Rely on `vc-set-async-update' to update properties. | 1919 | (mapc #'vc-delete-automatic-version-backups files))) |
| 1920 | (do-it) | 1920 | (if do-async |
| 1921 | (message "Checking in %s..." (vc-delistify files)) | 1921 | ;; Rely on `vc-set-async-update' to update properties. |
| 1922 | (with-vc-properties files (do-it) | 1922 | (do-it) |
| 1923 | `((vc-state . up-to-date) | 1923 | (message "Checking in %s..." (vc-delistify files)) |
| 1924 | (vc-checkout-time | 1924 | (with-vc-properties files (do-it) |
| 1925 | . ,(file-attribute-modification-time | 1925 | `((vc-state . up-to-date) |
| 1926 | (file-attributes file))) | 1926 | (vc-checkout-time |
| 1927 | (vc-working-revision . nil))) | 1927 | . ,(file-attribute-modification-time |
| 1928 | (message "Checking in %s...done" (vc-delistify files))))) | 1928 | (file-attributes file))) |
| 1929 | 'vc-checkin-hook | 1929 | (vc-working-revision . nil))) |
| 1930 | backend | 1930 | (message "Checking in %s...done" (vc-delistify files))))) |
| 1931 | patch-string)) | 1931 | |
| 1932 | ;; FIXME: In the async case we need the hook to be added to the | ||
| 1933 | ;; buffer with the checkin process, using `vc-run-delayed'. Ideally | ||
| 1934 | ;; the identity of that buffer would be exposed to this code, | ||
| 1935 | ;; somehow, so we could always handle running the hook up here. | ||
| 1936 | (and (not do-async) 'vc-checkin-hook) | ||
| 1937 | |||
| 1938 | backend | ||
| 1939 | patch-string))) | ||
| 1932 | 1940 | ||
| 1933 | (defun vc-default-checkin-patch (_backend patch-string comment) | 1941 | (defun vc-default-checkin-patch (_backend patch-string comment) |
| 1934 | (pcase-let* ((`(,backend ,files) (with-temp-buffer | 1942 | (pcase-let* ((`(,backend ,files) (with-temp-buffer |