Mercurial > emacs
comparison lisp/vc-hg.el @ 81726:b7c76df62fba
(vc-hg-root): New function.
(vc-hg-registered): Use it.
(vc-hg-diff-tree): New defalias.
(vc-hg-responsible-p): Likewise.
(vc-hg-checkout): Comment out, not needed.
(vc-hg-delete-file, vc-hg-rename-file, vc-hg-could-register)
(vc-hg-find-version, vc-hg-next-version): New functions.
author | Dan Nicolaescu <dann@ics.uci.edu> |
---|---|
date | Fri, 06 Jul 2007 21:14:21 +0000 |
parents | 88604a3ac7e4 |
children | d4e68ecdb000 |
comparison
equal
deleted
inserted
replaced
81725:0ce30ec432be | 81726:b7c76df62fba |
---|---|
33 | 33 |
34 ;;; Installation: | 34 ;;; Installation: |
35 | 35 |
36 ;;; Todo: | 36 ;;; Todo: |
37 | 37 |
38 ;; Implement the rest of the vc interface: | 38 ;; Implement the rest of the vc interface. See the comment at the |
39 ;; - dired | 39 ;; beginning of vc.el. The current status is: |
40 ;; - snapshot? | 40 |
41 ;; FUNCTION NAME STATUS | |
42 ;; * registered (file) OK | |
43 ;; * state (file) OK | |
44 ;; - state-heuristic (file) ?? PROBABLY NOT NEEDED | |
45 ;; - dir-state (dir) NEEDED | |
46 ;; * workfile-version (file) OK | |
47 ;; - latest-on-branch-p (file) ?? | |
48 ;; * checkout-model (file) OK | |
49 ;; - workfile-unchanged-p (file) ?? | |
50 ;; - mode-line-string (file) NOT NEEDED | |
51 ;; - dired-state-info (file) NEEDED | |
52 ;; STATE-CHANGING FUNCTIONS | |
53 ;; * register (file &optional rev comment) OK | |
54 ;; - init-version () NOT NEEDED | |
55 ;; - responsible-p (file) OK | |
56 ;; - could-register (file) OK | |
57 ;; - receive-file (file rev) ?? PROBABLY NOT NEEDED | |
58 ;; - unregister (file) COMMENTED OUT, MAY BE INCORRECT | |
59 ;; * checkin (file rev comment) OK | |
60 ;; * find-version (file rev buffer) OK | |
61 ;; * checkout (file &optional editable rev) NOT NEEDED, COMMENTED OUT | |
62 ;; * revert (file &optional contents-done) OK | |
63 ;; - cancel-version (file editable) ?? PROBABLY NOT NEEDED | |
64 ;; - merge (file rev1 rev2) NEEDED | |
65 ;; - merge-news (file) NEEDED | |
66 ;; - steal-lock (file &optional version) NOT NEEDED | |
67 ;; HISTORY FUNCTIONS | |
68 ;; * print-log (file &optional buffer) OK | |
69 ;; - log-view-mode () OK | |
70 ;; - show-log-entry (version) NOT NEEDED, DEFAULT IS GOOD | |
71 ;; - wash-log (file) ?? | |
72 ;; - logentry-check () NOT NEEDED | |
73 ;; - comment-history (file) NOT NEEDED | |
74 ;; - update-changelog (files) NOT NEEDED | |
75 ;; * diff (file &optional rev1 rev2 buffer) OK | |
76 ;; - revision-completion-table (file) ?? | |
77 ;; - diff-tree (dir &optional rev1 rev2) TEST IT | |
78 ;; - annotate-command (file buf &optional rev) OK | |
79 ;; - annotate-time () OK | |
80 ;; - annotate-current-time () ?? NOT NEEDED | |
81 ;; - annotate-extract-revision-at-line () OK | |
82 ;; SNAPSHOT SYSTEM | |
83 ;; - create-snapshot (dir name branchp) NEEDED (probably branch?) | |
84 ;; - assign-name (file name) NOT NEEDED | |
85 ;; - retrieve-snapshot (dir name update) ?? NEEDED?? | |
86 ;; MISCELLANEOUS | |
87 ;; - make-version-backups-p (file) ?? | |
88 ;; - repository-hostname (dirname) ?? | |
89 ;; - previous-version (file rev) OK | |
90 ;; - next-version (file rev) OK | |
91 ;; - check-headers () ?? | |
92 ;; - clear-headers () ?? | |
93 ;; - delete-file (file) TEST IT | |
94 ;; - rename-file (old new) OK | |
95 ;; - find-file-hook () PROBABLY NOT NEEDED | |
96 ;; - find-file-not-found-hook () PROBABLY NOT NEEDED | |
41 | 97 |
42 ;; Implement Stefan Monnier's advice: | 98 ;; Implement Stefan Monnier's advice: |
43 ;; vc-hg-registered and vc-hg-state | 99 ;; vc-hg-registered and vc-hg-state |
44 ;; Both of those functions should be super extra careful to fail gracefully in | 100 ;; Both of those functions should be super extra careful to fail gracefully in |
45 ;; unexpected circumstances. The most important such case is when the `hg' | 101 ;; unexpected circumstances. The reason this is important is that any error |
46 ;; executable is not available. The reason this is important is that any error | |
47 ;; there will prevent the user from even looking at the file :-( | 102 ;; there will prevent the user from even looking at the file :-( |
48 ;; Ideally, just like in vc-arch and vc-cvs, checking that the file is under | 103 ;; Ideally, just like in vc-arch and vc-cvs, checking that the file is under |
49 ;; mercurial's control and extracting the current revision should be done | 104 ;; mercurial's control and extracting the current revision should be done |
50 ;; without even using `hg' (this way even if you don't have `hg' installed, | 105 ;; without even using `hg' (this way even if you don't have `hg' installed, |
51 ;; Emacs is able to tell you this file is under mercurial's control). | 106 ;; Emacs is able to tell you this file is under mercurial's control). |
65 :type '(choice (const :tag "None" nil) | 120 :type '(choice (const :tag "None" nil) |
66 (string :tag "Argument String") | 121 (string :tag "Argument String") |
67 (repeat :tag "Argument List" | 122 (repeat :tag "Argument List" |
68 :value ("") | 123 :value ("") |
69 string)) | 124 string)) |
70 ;; :version "22.2" | 125 :version "22.2" |
71 :group 'vc) | 126 :group 'vc) |
72 | 127 |
73 ;;; State querying functions | 128 ;;; State querying functions |
74 | 129 |
75 ;;;###autoload (defun vc-hg-registered (file) | 130 ;;;###autoload (defun vc-hg-registered (file) |
80 ;;;###autoload (vc-hg-registered file)))) | 135 ;;;###autoload (vc-hg-registered file)))) |
81 | 136 |
82 ;; Modelled after the similar function in vc-bzr.el | 137 ;; Modelled after the similar function in vc-bzr.el |
83 (defun vc-hg-registered (file) | 138 (defun vc-hg-registered (file) |
84 "Return non-nil if FILE is registered with hg." | 139 "Return non-nil if FILE is registered with hg." |
85 (if (vc-find-root file ".hg") ; short cut | 140 (if (vc-hg-root file) ; short cut |
86 (vc-hg-state file))) ; expensive | 141 (vc-hg-state file))) ; expensive |
87 | 142 |
88 (defun vc-hg-state (file) | 143 (defun vc-hg-state (file) |
89 "Hg-specific version of `vc-state'." | 144 "Hg-specific version of `vc-state'." |
90 (let* | 145 (let* |
196 (list "-r" oldvers "-r" newvers) | 251 (list "-r" oldvers "-r" newvers) |
197 (list "-r" oldvers)) | 252 (list "-r" oldvers)) |
198 (list "")) | 253 (list "")) |
199 (list (file-name-nondirectory file)))))) | 254 (list (file-name-nondirectory file)))))) |
200 | 255 |
256 (defalias 'vc-hg-diff-tree 'vc-hg-diff) | |
257 | |
201 (defun vc-hg-annotate-command (file buffer &optional version) | 258 (defun vc-hg-annotate-command (file buffer &optional version) |
202 "Execute \"hg annotate\" on FILE, inserting the contents in BUFFER. | 259 "Execute \"hg annotate\" on FILE, inserting the contents in BUFFER. |
203 Optional arg VERSION is a version to annotate from." | 260 Optional arg VERSION is a version to annotate from." |
204 (vc-hg-command buffer 0 file "annotate" "-d" "-n" (if version (concat "-r" version))) | 261 (vc-hg-command buffer 0 file "annotate" "-d" "-n" (if version (concat "-r" version))) |
205 (with-current-buffer buffer | 262 (with-current-buffer buffer |
227 (defun vc-hg-previous-version (file rev) | 284 (defun vc-hg-previous-version (file rev) |
228 (let ((newrev (1- (string-to-number rev)))) | 285 (let ((newrev (1- (string-to-number rev)))) |
229 (when (>= newrev 0) | 286 (when (>= newrev 0) |
230 (number-to-string newrev)))) | 287 (number-to-string newrev)))) |
231 | 288 |
289 (defun vc-hg-next-version (file rev) | |
290 (let ((newrev (1+ (string-to-number rev))) | |
291 (tip-version | |
292 (with-temp-buffer | |
293 (vc-hg-command t nil nil "tip") | |
294 (goto-char (point-min)) | |
295 (re-search-forward "^changeset:[ \t]*\\([0-9]+\\):") | |
296 (string-to-number (match-string-no-properties 1))))) | |
297 ;; We don't want to exceed the maximum possible version number, ie | |
298 ;; the tip version. | |
299 (when (<= newrev tip-version) | |
300 (number-to-string newrev)))) | |
301 | |
302 ;; Modelled after the similar function in vc-bzr.el | |
303 (defun vc-hg-delete-file (file) | |
304 "Delete FILE and delete it in the hg repository." | |
305 (condition-case () | |
306 (delete-file file) | |
307 (file-error nil)) | |
308 (vc-hg-command nil nil file "remove" "--after" "--force")) | |
309 | |
310 ;; Modelled after the similar function in vc-bzr.el | |
311 (defun vc-hg-rename-file (old new) | |
312 "Rename file from OLD to NEW using `hg mv'." | |
313 (vc-hg-command nil nil new old "mv")) | |
314 | |
232 (defun vc-hg-register (file &optional rev comment) | 315 (defun vc-hg-register (file &optional rev comment) |
233 "Register FILE under hg. | 316 "Register FILE under hg. |
234 REV is ignored. | 317 REV is ignored. |
235 COMMENT is ignored." | 318 COMMENT is ignored." |
236 (vc-hg-command nil nil file "add")) | 319 (vc-hg-command nil nil file "add")) |
237 | 320 |
321 (defalias 'vc-hg-responsible-p 'vc-hg-root) | |
322 | |
323 ;; Modelled after the similar function in vc-bzr.el | |
324 (defun vc-hg-could-register (file) | |
325 "Return non-nil if FILE could be registered under hg." | |
326 (and (vc-hg-responsible-p file) ; shortcut | |
327 (condition-case () | |
328 (with-temp-buffer | |
329 (vc-hg-command t nil file "add" "--dry-run")) | |
330 ;; The command succeeds with no output if file is | |
331 ;; registered. | |
332 (error)))) | |
333 | |
334 ;; XXX This would remove the file. Is that correct? | |
335 ;; (defun vc-hg-unregister (file) | |
336 ;; "Unregister FILE from hg." | |
337 ;; (vc-hg-command nil nil file "remove")) | |
338 | |
238 (defun vc-hg-checkin (file rev comment) | 339 (defun vc-hg-checkin (file rev comment) |
239 "HG-specific version of `vc-backend-checkin'. | 340 "HG-specific version of `vc-backend-checkin'. |
240 REV is ignored." | 341 REV is ignored." |
241 (vc-hg-command nil nil file "commit" "-m" comment)) | 342 (vc-hg-command nil nil file "commit" "-m" comment)) |
242 | 343 |
243 ;; Modelled after the similar function in vc-bzr.el | 344 (defun vc-hg-find-version (file rev buffer) |
244 (defun vc-hg-checkout (file &optional editable rev workfile) | |
245 "Retrieve a revision of FILE into a WORKFILE. | |
246 EDITABLE is ignored. | |
247 REV is the revision to check out into WORKFILE." | |
248 (unless workfile | |
249 (setq workfile (vc-version-backup-file-name file rev))) | |
250 (let ((coding-system-for-read 'binary) | 345 (let ((coding-system-for-read 'binary) |
251 (coding-system-for-write 'binary)) | 346 (coding-system-for-write 'binary)) |
252 (with-temp-file workfile | |
253 (if rev | 347 (if rev |
254 (vc-hg-command t nil file "cat" "-r" rev) | 348 (vc-hg-command buffer nil file "cat" "-r" rev) |
255 (vc-hg-command t nil file "cat"))))) | 349 (vc-hg-command buffer nil file "cat")))) |
350 | |
351 ;; Modelled after the similar function in vc-bzr.el | |
352 ;; This should not be needed, `vc-hg-find-version' provides the same | |
353 ;; functionality. | |
354 ;; (defun vc-hg-checkout (file &optional editable rev workfile) | |
355 ;; "Retrieve a revision of FILE into a WORKFILE. | |
356 ;; EDITABLE is ignored. | |
357 ;; REV is the revision to check out into WORKFILE." | |
358 ;; (unless workfile | |
359 ;; (setq workfile (vc-version-backup-file-name file rev))) | |
360 ;; (let ((coding-system-for-read 'binary) | |
361 ;; (coding-system-for-write 'binary)) | |
362 ;; (with-temp-file workfile | |
363 ;; (if rev | |
364 ;; (vc-hg-command t nil file "cat" "-r" rev) | |
365 ;; (vc-hg-command t nil file "cat"))))) | |
256 | 366 |
257 (defun vc-hg-checkout-model (file) | 367 (defun vc-hg-checkout-model (file) |
258 'implicit) | 368 'implicit) |
259 | 369 |
260 ;; Modelled after the similar function in vc-bzr.el | 370 ;; Modelled after the similar function in vc-bzr.el |
272 (if (stringp vc-hg-global-switches) | 382 (if (stringp vc-hg-global-switches) |
273 (cons vc-hg-global-switches flags) | 383 (cons vc-hg-global-switches flags) |
274 (append vc-hg-global-switches | 384 (append vc-hg-global-switches |
275 flags)))) | 385 flags)))) |
276 | 386 |
387 (defun vc-hg-root (file) | |
388 (vc-find-root file ".hg")) | |
389 | |
277 (provide 'vc-hg) | 390 (provide 'vc-hg) |
278 | 391 |
279 ;;; vc-hg.el ends here | 392 ;;; vc-hg.el ends here |