Mercurial > emacs
annotate lisp/vc-hg.el @ 81515:9907375f1a76
*** empty log message ***
author | Jay Belanger <jay.p.belanger@gmail.com> |
---|---|
date | Wed, 20 Jun 2007 19:35:10 +0000 |
parents | 2d50f85a03de |
children | 145f53e0ff66 |
rev | line source |
---|---|
81474 | 1 ;;; vc-hg.el --- VC backend for the mercurial version control system |
2 | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
3 ;; Copyright (C) 2006, 2007 Free Software Foundation, Inc. |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
4 |
81474 | 5 ;; Author: Ivan Kanis |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
6 ;; Keywords: tools |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
7 ;; Version: 1889 |
81479
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
8 |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
9 ;; This file is part of GNU Emacs. |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
10 |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
81474 | 12 ;; it under the terms of the GNU General Public License as published by |
81479
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
13 ;; the Free Software Foundation; either version 2, or (at your option) |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
14 ;; any later version. |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
15 |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful, |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
19 ;; GNU General Public License for more details. |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
20 |
81474 | 21 ;; You should have received a copy of the GNU General Public License |
81479
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
2d50f85a03de
Change license wording to match the rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
81476
diff
changeset
|
24 ;; Boston, MA 02110-1301, USA. |
81474 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;; This is a mercurial version control backend | |
29 | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
30 ;;; Thanks: |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
31 |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
32 ;;; Bugs: |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
33 |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
34 ;;; Installation: |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
35 |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
36 ;;; Todo: |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
37 |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
38 ;; Implement the rest of the vc interface |
81474 | 39 |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
40 ;; Implement Stefan Monnier's advice: |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
41 ;; vc-hg-registered and vc-hg-state |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
42 ;; Both of those functions should be super extra careful to fail gracefully in |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
43 ;; unexpected circumstances. The most important such case is when the `hg' |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
44 ;; executable is not available. The reason this is important is that any error |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
45 ;; there will prevent the user from even looking at the file :-( |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
46 ;; Ideally, just like in vc-arch and vc-cvs, checking that the file is under |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
47 ;; mercurial's control and extracting the current revision should be done |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
48 ;; without even using `hg' (this way even if you don't have `hg' installed, |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
49 ;; Emacs is able to tell you this file is under mercurial's control). |
81474 | 50 |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
51 ;;; History: |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
52 ;; |
81474 | 53 |
54 ;;; Code: | |
55 | |
56 (eval-when-compile | |
57 (require 'vc)) | |
58 | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
59 ;; XXX This should be moved to vc-hooks when the full vc interface is |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
60 ;; implemented. |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
61 (add-to-list 'vc-handled-backends 'HG) |
81474 | 62 |
63 ;;; Customization options | |
64 | |
65 (defcustom vc-hg-global-switches nil | |
66 "*Global switches to pass to any Hg command." | |
67 :type '(choice (const :tag "None" nil) | |
68 (string :tag "Argument String") | |
69 (repeat :tag "Argument List" | |
70 :value ("") | |
71 string)) | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
72 ;; :version "22.2" |
81474 | 73 :group 'vc) |
74 | |
75 ;;; State querying functions | |
76 | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
77 ;;; Modelled after the similar function in vc-bzr.el |
81474 | 78 (defun vc-hg-registered (file) |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
79 "Return non-nil if FILE is registered with hg." |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
80 (if (vc-find-root file ".hg") ; short cut |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
81 (vc-hg-state file))) ; expensive |
81474 | 82 |
83 (defun vc-hg-state (file) | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
84 "Hg-specific version of `vc-state'." |
81474 | 85 (let ((out (vc-hg-internal-status file))) |
86 (if (eq 0 (length out)) 'up-to-date | |
87 (let ((state (aref out 0))) | |
88 (cond | |
89 ((eq state ?M) 'edited) | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
90 ((eq state ?A) 'edited) |
81474 | 91 ((eq state ?P) 'needs-patch) |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
92 ((eq state ??) nil) |
81474 | 93 (t 'up-to-date)))))) |
94 | |
95 (defun vc-hg-workfile-version (file) | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
96 "Hg-specific version of `vc-workfile-version'." |
81474 | 97 (let ((out (vc-hg-internal-log file))) |
98 (if (string-match "changeset: *\\([0-9]*\\)" out) | |
99 (match-string 1 out) | |
100 "0"))) | |
101 | |
102 ;;; History functions | |
103 | |
104 (defun vc-hg-print-log(file &optional buffer) | |
105 "Get change log associated with FILE." | |
106 (vc-hg-command | |
107 buffer | |
108 (if (and (vc-stay-local-p file) (fboundp 'start-process)) 'async 0) | |
109 file "log")) | |
110 | |
111 (defun vc-hg-diff (file &optional oldvers newvers buffers) | |
112 "Get a difference report using hg between two versions of FILE." | |
113 (when buffers (message buffers)) | |
114 (unless buffers (setq buffers "*vc-diff*")) | |
115 (when oldvers (message oldvers)) | |
116 (when newvers (message newvers)) | |
117 (call-process "hg" nil buffers nil | |
118 "--cwd" (file-name-directory file) | |
119 "diff" (file-name-nondirectory file))) | |
120 | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
121 (defun vc-hg-register (file &optional rev comment) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
122 "Register FILE under hg. |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
123 REV is ignored. |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
124 COMMENT is ignored." |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
125 (vc-hg-command nil nil file "add")) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
126 |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
127 ;;; Modelled after the similar function in vc-bzr.el |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
128 (defun vc-hg-checkout (file &optional editable rev workfile) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
129 "Retrieve a revision of FILE into a WORKFILE. |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
130 EDITABLE is ignored. |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
131 REV is the revision to check out into WORKFILE." |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
132 (unless workfile |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
133 (setq workfile (vc-version-backup-file-name file rev))) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
134 (let ((coding-system-for-read 'binary) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
135 (coding-system-for-write 'binary)) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
136 (with-temp-file workfile |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
137 (if rev |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
138 (vc-hg-command t nil file "cat" "-r" rev) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
139 (vc-hg-command t nil file "cat"))))) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
140 |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
141 (defun vc-hg-checkout-model (file) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
142 'implicit) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
143 |
81474 | 144 ;;; Internal functions |
145 | |
146 (defun vc-hg-command (buffer okstatus file &rest flags) | |
147 "A wrapper around `vc-do-command' for use in vc-hg.el. | |
148 The difference to vc-do-command is that this function always invokes `hg', | |
149 and that it passes `vc-hg-global-switches' to it before FLAGS." | |
150 (apply 'vc-do-command buffer okstatus "hg" file | |
151 (if (stringp vc-hg-global-switches) | |
152 (cons vc-hg-global-switches flags) | |
153 (append vc-hg-global-switches | |
154 flags)))) | |
155 | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
156 (defun vc-hg-internal-log (file) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
157 "Return log of FILE." |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
158 (with-output-to-string |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
159 (with-current-buffer |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
160 standard-output |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
161 (call-process |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
162 "hg" nil t nil "--cwd" (file-name-directory file) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
163 "log" "-l1" (file-name-nondirectory file))))) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
164 |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
165 (defun vc-hg-internal-status(file) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
166 "Return status of FILE." |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
167 (with-output-to-string |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
168 (with-current-buffer |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
169 standard-output |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
170 (call-process |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
171 "hg" nil t nil "--cwd" (file-name-directory file) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
172 "status" (file-name-nondirectory file))))) |
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
173 |
81474 | 174 (provide 'vc-hg) |
175 | |
81476
3dedb2297b98
(vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
81474
diff
changeset
|
176 ;;; vc-hg.el ends here |