comparison lisp/vc-hg.el @ 81964:ba5a7f46413b

Put the lower half (the back-end) of NewVC in place. This commit makes only the minimum changes needed to get the old vc.el logic working with the new back ends.
author Eric S. Raymond <esr@snark.thyrsus.com>
date Wed, 18 Jul 2007 16:32:35 +0000
parents d4e68ecdb000
children d4b8336cd8f5
comparison
equal deleted inserted replaced
81963:535f90fff765 81964:ba5a7f46413b
48 ;; * checkout-model (file) OK 48 ;; * checkout-model (file) OK
49 ;; - workfile-unchanged-p (file) ?? 49 ;; - workfile-unchanged-p (file) ??
50 ;; - mode-line-string (file) NOT NEEDED 50 ;; - mode-line-string (file) NOT NEEDED
51 ;; - dired-state-info (file) NEEDED 51 ;; - dired-state-info (file) NEEDED
52 ;; STATE-CHANGING FUNCTIONS 52 ;; STATE-CHANGING FUNCTIONS
53 ;; * register (file &optional rev comment) OK 53 ;; * register (files &optional rev comment) OK
54 ;; - init-version () NOT NEEDED 54 ;; - init-version () NOT NEEDED
55 ;; - responsible-p (file) OK 55 ;; - responsible-p (file) OK
56 ;; - could-register (file) OK 56 ;; - could-register (file) OK
57 ;; - receive-file (file rev) ?? PROBABLY NOT NEEDED 57 ;; - receive-file (file rev) ?? PROBABLY NOT NEEDED
58 ;; - unregister (file) COMMENTED OUT, MAY BE INCORRECT 58 ;; - unregister (file) COMMENTED OUT, MAY BE INCORRECT
59 ;; * checkin (file rev comment) OK 59 ;; * checkin (files rev comment) OK
60 ;; * find-version (file rev buffer) OK 60 ;; * find-version (file rev buffer) OK
61 ;; * checkout (file &optional editable rev) NOT NEEDED, COMMENTED OUT 61 ;; * checkout (file &optional editable rev) NOT NEEDED, COMMENTED OUT
62 ;; * revert (file &optional contents-done) OK 62 ;; * revert (file &optional contents-done) OK
63 ;; - cancel-version (file editable) ?? PROBABLY NOT NEEDED 63 ;; - rollback (files) ?? PROBABLY NOT NEEDED
64 ;; - merge (file rev1 rev2) NEEDED 64 ;; - merge (file rev1 rev2) NEEDED
65 ;; - merge-news (file) NEEDED 65 ;; - merge-news (file) NEEDED
66 ;; - steal-lock (file &optional version) NOT NEEDED 66 ;; - steal-lock (file &optional version) NOT NEEDED
67 ;; HISTORY FUNCTIONS 67 ;; HISTORY FUNCTIONS
68 ;; * print-log (file &optional buffer) OK 68 ;; * print-log (files &optional buffer) OK
69 ;; - log-view-mode () OK 69 ;; - log-view-mode () OK
70 ;; - show-log-entry (version) NOT NEEDED, DEFAULT IS GOOD 70 ;; - show-log-entry (version) NOT NEEDED, DEFAULT IS GOOD
71 ;; - wash-log (file) ?? 71 ;; - wash-log (file) ??
72 ;; - logentry-check () NOT NEEDED 72 ;; - logentry-check () NOT NEEDED
73 ;; - comment-history (file) NOT NEEDED 73 ;; - comment-history (file) NOT NEEDED
74 ;; - update-changelog (files) NOT NEEDED 74 ;; - update-changelog (files) NOT NEEDED
75 ;; * diff (file &optional rev1 rev2 buffer) OK 75 ;; * diff (files &optional rev1 rev2 buffer) OK
76 ;; - revision-completion-table (file) ?? 76 ;; - revision-completion-table (file) ??
77 ;; - diff-tree (dir &optional rev1 rev2) TEST IT 77 ;; - diff-tree (dir &optional rev1 rev2) TEST IT
78 ;; - annotate-command (file buf &optional rev) OK 78 ;; - annotate-command (file buf &optional rev) OK
79 ;; - annotate-time () OK 79 ;; - annotate-time () OK
80 ;; - annotate-current-time () ?? NOT NEEDED 80 ;; - annotate-current-time () ?? NOT NEEDED
122 (repeat :tag "Argument List" 122 (repeat :tag "Argument List"
123 :value ("") 123 :value ("")
124 string)) 124 string))
125 :version "22.2" 125 :version "22.2"
126 :group 'vc) 126 :group 'vc)
127
128
129 ;;; Properties of the backend
130
131 (defun vc-hg-revision-granularity ()
132 'repository)
127 133
128 ;;; State querying functions 134 ;;; State querying functions
129 135
130 ;;;###autoload (defun vc-hg-registered (file) 136 ;;;###autoload (defun vc-hg-registered (file)
131 ;;;###autoload "Return non-nil if FILE is registered with hg." 137 ;;;###autoload "Return non-nil if FILE is registered with hg."
189 (match-string 1 out) 195 (match-string 1 out)
190 "0")))) 196 "0"))))
191 197
192 ;;; History functions 198 ;;; History functions
193 199
194 (defun vc-hg-print-log(file &optional buffer) 200 (defun vc-hg-print-log(files &optional buffer)
195 "Get change log associated with FILE." 201 "Get change log associated with FILES."
196 ;; `log-view-mode' needs to have the file name in order to function 202 ;; `log-view-mode' needs to have the file name in order to function
197 ;; correctly. "hg log" does not print it, so we insert it here by 203 ;; correctly. "hg log" does not print it, so we insert it here by
198 ;; hand. 204 ;; hand.
199 205
200 ;; `vc-do-command' creates the buffer, but we need it before running 206 ;; `vc-do-command' creates the buffer, but we need it before running
203 ;; If the buffer exists from a previous invocation it might be 209 ;; If the buffer exists from a previous invocation it might be
204 ;; read-only. 210 ;; read-only.
205 (let ((inhibit-read-only t)) 211 (let ((inhibit-read-only t))
206 (with-current-buffer 212 (with-current-buffer
207 buffer 213 buffer
208 (insert "File: " (file-name-nondirectory file) "\n"))) 214 (insert "File: " (vc-delistify (mapcar (lambda (file) (file-name-nondirectory file)) files)) "\n")))
209 (vc-hg-command 215 (vc-hg-command
210 buffer 216 buffer
211 (if (and (vc-stay-local-p file) (fboundp 'start-process)) 'async 0) 217 (if (and (vc-stay-local-p file) (fboundp 'start-process)) 'async 0)
212 file "log")) 218 files "log"))
213 219
214 (defvar log-view-message-re) 220 (defvar log-view-message-re)
215 (defvar log-view-file-re) 221 (defvar log-view-file-re)
216 (defvar log-view-font-lock-keywords) 222 (defvar log-view-font-lock-keywords)
217 223
234 (1 'change-log-name) 240 (1 'change-log-name)
235 (2 'change-log-email)) 241 (2 'change-log-email))
236 ("^date: \\(.+\\)" (1 'change-log-date)) 242 ("^date: \\(.+\\)" (1 'change-log-date))
237 ("^summary:[ \t]+\\(.+\\)" (1 'log-view-message)))))) 243 ("^summary:[ \t]+\\(.+\\)" (1 'log-view-message))))))
238 244
239 (defun vc-hg-diff (file &optional oldvers newvers buffer) 245 (defun vc-hg-diff (files &optional oldvers newvers buffer)
240 "Get a difference report using hg between two versions of FILE." 246 "Get a difference report using hg between two versions of FILES."
241 (let ((working (vc-workfile-version file))) 247 (let ((working (vc-workfile-version (car files))))
242 (if (and (equal oldvers working) (not newvers)) 248 (if (and (equal oldvers working) (not newvers))
243 (setq oldvers nil)) 249 (setq oldvers nil))
244 (if (and (not oldvers) newvers) 250 (if (and (not oldvers) newvers)
245 (setq oldvers working)) 251 (setq oldvers working))
246 (apply 'call-process "hg" nil (or buffer "*vc-diff*") nil 252 (apply 'call-process "hg" nil (or buffer "*vc-diff*") nil
247 "--cwd" (file-name-directory file) "diff" 253 "--cwd" (file-name-directory (car files)) "diff"
248 (append 254 (append
249 (if oldvers 255 (if oldvers
250 (if newvers 256 (if newvers
251 (list "-r" oldvers "-r" newvers) 257 (list "-r" oldvers "-r" newvers)
252 (list "-r" oldvers)) 258 (list "-r" oldvers))
253 (list "")) 259 (list ""))
254 (list (file-name-nondirectory file)))))) 260 (mapcar (lambda (file) (file-name-nondirectory file)) files)))))
255 261
256 (defalias 'vc-hg-diff-tree 'vc-hg-diff) 262 (defun vc-hg-diff-tree (file &optional oldvers newvers buffer)
263 (vc-hg-diff (list file) oldvers newvers buffer))
257 264
258 (defun vc-hg-annotate-command (file buffer &optional version) 265 (defun vc-hg-annotate-command (file buffer &optional version)
259 "Execute \"hg annotate\" on FILE, inserting the contents in BUFFER. 266 "Execute \"hg annotate\" on FILE, inserting the contents in BUFFER.
260 Optional arg VERSION is a version to annotate from." 267 Optional arg VERSION is a version to annotate from."
261 (vc-hg-command buffer 0 file "annotate" "-d" "-n" (if version (concat "-r" version))) 268 (vc-hg-command buffer 0 file "annotate" "-d" "-n" (if version (concat "-r" version)))
310 ;; Modelled after the similar function in vc-bzr.el 317 ;; Modelled after the similar function in vc-bzr.el
311 (defun vc-hg-rename-file (old new) 318 (defun vc-hg-rename-file (old new)
312 "Rename file from OLD to NEW using `hg mv'." 319 "Rename file from OLD to NEW using `hg mv'."
313 (vc-hg-command nil nil new old "mv")) 320 (vc-hg-command nil nil new old "mv"))
314 321
315 (defun vc-hg-register (file &optional rev comment) 322 (defun vc-hg-register (files &optional rev comment)
316 "Register FILE under hg. 323 "Register FILES under hg.
317 REV is ignored. 324 REV is ignored.
318 COMMENT is ignored." 325 COMMENT is ignored."
319 (vc-hg-command nil nil file "add")) 326 (vc-hg-command nil nil files "add"))
327
328 (defun vc-hg-create-repo ()
329 "Create a new Mercurial repository."
330 (vc-do-command nil 0 "svn" '("init")))
320 331
321 (defalias 'vc-hg-responsible-p 'vc-hg-root) 332 (defalias 'vc-hg-responsible-p 'vc-hg-root)
322 333
323 ;; Modelled after the similar function in vc-bzr.el 334 ;; Modelled after the similar function in vc-bzr.el
324 (defun vc-hg-could-register (file) 335 (defun vc-hg-could-register (file)
334 ;; XXX This would remove the file. Is that correct? 345 ;; XXX This would remove the file. Is that correct?
335 ;; (defun vc-hg-unregister (file) 346 ;; (defun vc-hg-unregister (file)
336 ;; "Unregister FILE from hg." 347 ;; "Unregister FILE from hg."
337 ;; (vc-hg-command nil nil file "remove")) 348 ;; (vc-hg-command nil nil file "remove"))
338 349
339 (defun vc-hg-checkin (file rev comment) 350 (defun vc-hg-checkin (files rev comment)
340 "HG-specific version of `vc-backend-checkin'. 351 "HG-specific version of `vc-backend-checkin'.
341 REV is ignored." 352 REV is ignored."
342 (vc-hg-command nil nil file "commit" "-m" comment)) 353 (vc-hg-command nil nil files "commit" "-m" comment))
343 354
344 (defun vc-hg-find-version (file rev buffer) 355 (defun vc-hg-find-version (file rev buffer)
345 (let ((coding-system-for-read 'binary) 356 (let ((coding-system-for-read 'binary)
346 (coding-system-for-write 'binary)) 357 (coding-system-for-write 'binary))
347 (if rev 358 (if rev
372 (unless contents-done 383 (unless contents-done
373 (with-temp-buffer (vc-hg-command t nil file "revert")))) 384 (with-temp-buffer (vc-hg-command t nil file "revert"))))
374 385
375 ;;; Internal functions 386 ;;; Internal functions
376 387
377 (defun vc-hg-command (buffer okstatus file &rest flags) 388 (defun vc-hg-command (buffer okstatus file-or-list &rest flags)
378 "A wrapper around `vc-do-command' for use in vc-hg.el. 389 "A wrapper around `vc-do-command' for use in vc-hg.el.
379 The difference to vc-do-command is that this function always invokes `hg', 390 The difference to vc-do-command is that this function always invokes `hg',
380 and that it passes `vc-hg-global-switches' to it before FLAGS." 391 and that it passes `vc-hg-global-switches' to it before FLAGS."
381 (apply 'vc-do-command buffer okstatus "hg" file 392 (apply 'vc-do-command buffer okstatus "hg" file-or-list
382 (if (stringp vc-hg-global-switches) 393 (if (stringp vc-hg-global-switches)
383 (cons vc-hg-global-switches flags) 394 (cons vc-hg-global-switches flags)
384 (append vc-hg-global-switches 395 (append vc-hg-global-switches
385 flags)))) 396 flags))))
386 397