diff options
| author | Sean Whitton | 2025-04-09 12:37:32 +0800 |
|---|---|---|
| committer | Sean Whitton | 2025-04-09 12:37:32 +0800 |
| commit | 253364e2c71bfaaa3ca623ed23f1cae6548a16c7 (patch) | |
| tree | 0f016aef179161f1a355384148e51e52e93d55df | |
| parent | 2310c12658c4b563f9860cb1196bab0d56c6f94d (diff) | |
| download | emacs-253364e2c71bfaaa3ca623ed23f1cae6548a16c7.tar.gz emacs-253364e2c71bfaaa3ca623ed23f1cae6548a16c7.zip | |
VC-Dir: Offer to register files before checking in
* lisp/vc/vc.el (vc-only-files-state-and-model): Rewrite
checking that all files are in compatible VC states. In
particular, consistently return 'edited' when all files are
either added, removed or edited, instead of allowing the return
value to depend on the order of the files in VC-Dir, and offer
to registered unregistered files if doing so would allow the
operation to proceed.
(vc-compatible-state): Delete.
(vc-next-action): Replace call to vc-compatible-state.
Document, in this command's docstring, the new feature
implemented in vc-only-files-state-and-model.
* etc/NEWS: Announce the new feature.
| -rw-r--r-- | etc/NEWS | 7 | ||||
| -rw-r--r-- | lisp/vc/vc.el | 47 |
2 files changed, 40 insertions, 14 deletions
| @@ -1505,6 +1505,13 @@ behavior or dispense with the prompting. | |||
| 1505 | These correspond to the existing 'z p' to pop a stash and 'P' to pop the | 1505 | These correspond to the existing 'z p' to pop a stash and 'P' to pop the |
| 1506 | stash at point (deleting the stash at point is also bound to C-k). | 1506 | stash at point (deleting the stash at point is also bound to C-k). |
| 1507 | 1507 | ||
| 1508 | --- | ||
| 1509 | *** VC-Dir now offers to register files when checking in mixed filesets. | ||
| 1510 | Previously, if some files to be checked in were unregistered but others | ||
| 1511 | were added, removed or edited, Emacs would refuse to proceed. | ||
| 1512 | Now Emacs prompts to first register the unregistered files, so that all | ||
| 1513 | files in the fileset are in a compatible state for a checkin. | ||
| 1514 | |||
| 1508 | ** Diff mode | 1515 | ** Diff mode |
| 1509 | 1516 | ||
| 1510 | +++ | 1517 | +++ |
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index bc3d4cdbb68..12f86907470 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el | |||
| @@ -1288,17 +1288,40 @@ BEWARE: this function may change the current buffer." | |||
| 1288 | "Compute last three `vc-deduce-fileset' return value elements for FILES. | 1288 | "Compute last three `vc-deduce-fileset' return value elements for FILES. |
| 1289 | FILES should be a pair, or list of pairs, of files and their VC states. | 1289 | FILES should be a pair, or list of pairs, of files and their VC states. |
| 1290 | BACKEND is the VC backend responsible for FILES." | 1290 | BACKEND is the VC backend responsible for FILES." |
| 1291 | (let ((state (cdar files)) | 1291 | (let* ((files (if (proper-list-p files) files (list files))) |
| 1292 | (files* (mapcar #'car | 1292 | files* states-alist states state) |
| 1293 | (if (proper-list-p files) files (list files))))) | ||
| 1294 | ;; Check that all files are in a consistent state, since we use that | 1293 | ;; Check that all files are in a consistent state, since we use that |
| 1295 | ;; state to decide which operation to perform. | 1294 | ;; state to decide which operation to perform. |
| 1296 | (dolist (crt (cdr files)) | 1295 | (pcase-dolist (`(,file . ,state) files) |
| 1297 | (unless (vc-compatible-state (cdr crt) state) | 1296 | (push file files*) |
| 1298 | (error "\ | 1297 | (push file (alist-get state states-alist nil nil #'eq))) |
| 1298 | (setq states (mapcar #'car states-alist)) | ||
| 1299 | (cond ((length= states 1) | ||
| 1300 | (setq state (car states))) | ||
| 1301 | ((cl-subsetp states '(added removed edited)) | ||
| 1302 | (setq state 'edited)) | ||
| 1303 | |||
| 1304 | ;; Special, but common case: | ||
| 1305 | ;; checking in both changes and new files at once. | ||
| 1306 | ((and (cl-subsetp states '(added removed edited unregistered)) | ||
| 1307 | (y-or-n-p "Some files are unregistered; register them first?")) | ||
| 1308 | (vc-register (list backend | ||
| 1309 | (cdr (assq 'unregistered states-alist)))) | ||
| 1310 | (setq state 'edited)) | ||
| 1311 | |||
| 1312 | (t | ||
| 1313 | (let* ((pred (lambda (elt) | ||
| 1314 | (memq (car elt) '(added removed edited)))) | ||
| 1315 | (compat-alist (cl-remove-if-not pred states-alist)) | ||
| 1316 | (other-alist (cl-remove-if pred states-alist)) | ||
| 1317 | (first (car (or compat-alist other-alist))) | ||
| 1318 | (second (if compat-alist | ||
| 1319 | (car other-alist) | ||
| 1320 | (cadr other-alist)))) | ||
| 1321 | (error "\ | ||
| 1299 | To apply VC operations to multiple files, the files must be in similar VC states. | 1322 | To apply VC operations to multiple files, the files must be in similar VC states. |
| 1300 | %s in state %s clashes with %s in state %s" | 1323 | %s in state %s clashes with %s in state %s" |
| 1301 | (car crt) (cdr crt) (caar files) state))) | 1324 | (cadr first) (car first) (cadr second) (car second))))) |
| 1302 | (list files* state | 1325 | (list files* state |
| 1303 | (and state (not (eq state 'unregistered)) | 1326 | (and state (not (eq state 'unregistered)) |
| 1304 | (vc-checkout-model backend files*))))) | 1327 | (vc-checkout-model backend files*))))) |
| @@ -1314,12 +1337,6 @@ To apply VC operations to multiple files, the files must be in similar VC states | |||
| 1314 | (or (eq (vc-checkout-model backend (list file)) 'implicit) | 1337 | (or (eq (vc-checkout-model backend (list file)) 'implicit) |
| 1315 | (memq (vc-state file) '(edited needs-merge conflict)))))) | 1338 | (memq (vc-state file) '(edited needs-merge conflict)))))) |
| 1316 | 1339 | ||
| 1317 | (defun vc-compatible-state (p q) | ||
| 1318 | "Control which states can be in the same commit." | ||
| 1319 | (or | ||
| 1320 | (eq p q) | ||
| 1321 | (and (member p '(edited added removed)) (member q '(edited added removed))))) | ||
| 1322 | |||
| 1323 | (defun vc-read-backend (prompt &optional backends default) | 1340 | (defun vc-read-backend (prompt &optional backends default) |
| 1324 | (let ((backends (or backends vc-handled-backends)) | 1341 | (let ((backends (or backends vc-handled-backends)) |
| 1325 | (completion-ignore-case t)) | 1342 | (completion-ignore-case t)) |
| @@ -1344,6 +1361,8 @@ For modern merging-based version control systems: | |||
| 1344 | backend with which to register the fileset. | 1361 | backend with which to register the fileset. |
| 1345 | If every work file in the VC fileset is either added or modified, | 1362 | If every work file in the VC fileset is either added or modified, |
| 1346 | pop up a *vc-log* buffer to commit the fileset changes. | 1363 | pop up a *vc-log* buffer to commit the fileset changes. |
| 1364 | (If some are added or modified and some are unregistered, offer to | ||
| 1365 | register the unregistered ones, first.) | ||
| 1347 | For a centralized version control system, if any work file in | 1366 | For a centralized version control system, if any work file in |
| 1348 | the VC fileset is out of date, offer to update the fileset. | 1367 | the VC fileset is out of date, offer to update the fileset. |
| 1349 | 1368 | ||
| @@ -1432,7 +1451,7 @@ from which to check out the file(s)." | |||
| 1432 | ;; do nothing | 1451 | ;; do nothing |
| 1433 | (message "Fileset is up-to-date")))) | 1452 | (message "Fileset is up-to-date")))) |
| 1434 | ;; Files have local changes | 1453 | ;; Files have local changes |
| 1435 | ((vc-compatible-state state 'edited) | 1454 | ((memq state '(added removed edited)) |
| 1436 | (let ((ready-for-commit files)) | 1455 | (let ((ready-for-commit files)) |
| 1437 | ;; CVS, SVN and bzr don't care about read-only (bug#9781). | 1456 | ;; CVS, SVN and bzr don't care about read-only (bug#9781). |
| 1438 | ;; RCS does, SCCS might (someone should check...). | 1457 | ;; RCS does, SCCS might (someone should check...). |