annotate lisp/vc-hg.el @ 81564:99961edaa9c1

(vc-hg-print-log): Insert the file name. (vc-hg-log-view-mode): Fontify the file name.
author Dan Nicolaescu <dann@ics.uci.edu>
date Fri, 22 Jun 2007 17:22:17 +0000
parents ac8e3d72984f
children 0e2a83705e5f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
81474
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
1 ;;; vc-hg.el --- VC backend for the mercurial version control system
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
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
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
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
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
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
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
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
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
25
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
26 ;;; Commentary:
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
27
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
28 ;; This is a mercurial version control backend
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
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
81526
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
38 ;; Implement the rest of the vc interface:
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
39 ;; - dired
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
40 ;; - snapshot?
81474
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
41
81476
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
42 ;; Implement Stefan Monnier's advice:
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
43 ;; vc-hg-registered and vc-hg-state
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
44 ;; 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
45 ;; 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
46 ;; 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
47 ;; 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
48 ;; 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
49 ;; 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
50 ;; 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
51 ;; Emacs is able to tell you this file is under mercurial's control).
81474
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
52
81476
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
53 ;;; History:
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
54 ;;
81474
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
55
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
56 ;;; Code:
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
57
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
58 (eval-when-compile
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
59 (require 'vc))
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
60
81476
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
61 ;; 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
62 ;; implemented.
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
63 (add-to-list 'vc-handled-backends 'HG)
81474
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
64
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
65 ;;; Customization options
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
66
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
67 (defcustom vc-hg-global-switches nil
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
68 "*Global switches to pass to any Hg command."
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
69 :type '(choice (const :tag "None" nil)
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
70 (string :tag "Argument String")
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
71 (repeat :tag "Argument List"
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
72 :value ("")
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
73 string))
81476
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
74 ;; :version "22.2"
81474
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
75 :group 'vc)
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
76
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
77 ;;; State querying functions
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
78
81476
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
79 ;;; Modelled after the similar function in vc-bzr.el
81474
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
80 (defun vc-hg-registered (file)
81476
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
81 "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
82 (if (vc-find-root file ".hg") ; short cut
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
83 (vc-hg-state file))) ; expensive
81474
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
84
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
85 (defun vc-hg-state (file)
81476
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
86 "Hg-specific version of `vc-state'."
81474
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
87 (let ((out (vc-hg-internal-status file)))
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
88 (if (eq 0 (length out)) 'up-to-date
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
89 (let ((state (aref out 0)))
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
90 (cond
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
91 ((eq state ?M) 'edited)
81476
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
92 ((eq state ?A) 'edited)
81474
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
93 ((eq state ?P) 'needs-patch)
81476
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
94 ((eq state ??) nil)
81474
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
95 (t 'up-to-date))))))
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
96
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
97 (defun vc-hg-workfile-version (file)
81476
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
98 "Hg-specific version of `vc-workfile-version'."
81474
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
99 (let ((out (vc-hg-internal-log file)))
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
100 (if (string-match "changeset: *\\([0-9]*\\)" out)
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
101 (match-string 1 out)
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
102 "0")))
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
103
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
104 ;;; History functions
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
105
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
106 (defun vc-hg-print-log(file &optional buffer)
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
107 "Get change log associated with FILE."
81564
99961edaa9c1 (vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81538
diff changeset
108 ;; `log-view-mode' needs to have the file name in order to function
99961edaa9c1 (vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81538
diff changeset
109 ;; correctly. "hg log" does not print it, so we insert it here by
99961edaa9c1 (vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81538
diff changeset
110 ;; hand.
99961edaa9c1 (vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81538
diff changeset
111
99961edaa9c1 (vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81538
diff changeset
112 ;; `vc-do-command' creates the buffer, but we need it before running
99961edaa9c1 (vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81538
diff changeset
113 ;; the command.
99961edaa9c1 (vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81538
diff changeset
114 (vc-setup-buffer buffer)
99961edaa9c1 (vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81538
diff changeset
115 ;; If the buffer exists from a previous invocation it might be
99961edaa9c1 (vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81538
diff changeset
116 ;; read-only.
99961edaa9c1 (vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81538
diff changeset
117 (let ((inhibit-read-only t))
99961edaa9c1 (vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81538
diff changeset
118 (with-current-buffer
99961edaa9c1 (vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81538
diff changeset
119 buffer
99961edaa9c1 (vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81538
diff changeset
120 (insert "File: " (file-name-nondirectory file) "\n")))
81474
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
121 (vc-hg-command
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
122 buffer
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
123 (if (and (vc-stay-local-p file) (fboundp 'start-process)) 'async 0)
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
124 file "log"))
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
125
81538
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
126 (defvar log-view-message-re)
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
127 (defvar log-view-file-re)
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
128 (defvar log-view-font-lock-keywords)
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
129 (defvar log-view-current-tag-function)
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
130
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
131 (define-derived-mode vc-hg-log-view-mode log-view-mode "HG-Log-View"
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
132 (require 'add-log) ;; we need the faces add-log
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
133 ;; Don't have file markers, so use impossible regexp.
81564
99961edaa9c1 (vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81538
diff changeset
134 (set (make-local-variable 'log-view-file-re) "^File:[ \t]+\\(.+\\)")
81538
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
135 (set (make-local-variable 'log-view-message-re)
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
136 "^changeset:[ \t]*\\([0-9]+\\):\\(.+\\)")
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
137 (set (make-local-variable 'log-view-font-lock-keywords)
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
138 (append
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
139 ;; XXX maybe use a different face for the version number
81564
99961edaa9c1 (vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81538
diff changeset
140 `((,log-view-message-re (1 'change-log-acknowledgement))
99961edaa9c1 (vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81538
diff changeset
141 (,log-view-file-re (1 'change-log-file-face)))
81538
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
142 ;; Handle the case:
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
143 ;; user: foo@bar
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
144 '(("^user:[ \t]+\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)"
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
145 (1 'change-log-email))
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
146 ;; Handle the case:
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
147 ;; user: FirstName LastName <foo@bar>
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
148 ("^user:[ \t]+\\([^<(]+?\\)[ \t]*[(<]\\([A-Za-z0-9_.+-]+@[A-Za-z0-9_.-]+\\)[>)]"
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
149 (1 'change-log-name)
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
150 (2 'change-log-email))
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
151 ("^date: \\(.+\\)" (1 'change-log-date))
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
152 ("^summary:[ \t]+\\(.+\\)" (1 'log-view-message))))))
ac8e3d72984f (vc-hg-log-view-mode): New mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81526
diff changeset
153
81526
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
154 (defun vc-hg-diff (file &optional oldvers newvers buffer)
81474
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
155 "Get a difference report using hg between two versions of FILE."
81526
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
156 (let ((working (vc-workfile-version file)))
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
157 (if (and (equal oldvers working) (not newvers))
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
158 (setq oldvers nil))
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
159 (if (and (not oldvers) newvers)
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
160 (setq oldvers working))
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
161 (apply 'call-process "hg" nil (or buffer "*vc-diff*") nil
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
162 "--cwd" (file-name-directory file) "diff"
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
163 (append
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
164 (if oldvers
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
165 (if newvers
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
166 (list "-r" oldvers "-r" newvers)
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
167 (list "-r" oldvers))
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
168 (list ""))
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
169 (list (file-name-nondirectory file))))))
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
170
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
171 (defun vc-hg-annotate-command (file buffer &optional version)
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
172 "Execute \"hg annotate\" on FILE, inserting the contents in BUFFER.
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
173 Optional arg VERSION is a version to annotate from."
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
174 (vc-hg-command buffer 0 file "annotate" "-d" "-n" (if version (concat "-r" version)))
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
175 (with-current-buffer buffer
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
176 (goto-char (point-min))
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
177 (re-search-forward "^[0-9]")
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
178 (delete-region (point-min) (1- (point)))))
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
179
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
180
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
181 ;;; The format for one line output by "hg annotate -d -n" looks like this:
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
182 ;;;215 Wed Jun 20 21:22:58 2007 -0700: CONTENTS
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
183 ;;; i.e: VERSION_NUMBER DATE: CONTENTS
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
184 (defconst vc-hg-annotate-re "^[ \t]*\\([0-9]+\\) \\(.\\{30\\}\\): ")
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
185
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
186 (defun vc-hg-annotate-time ()
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
187 (when (looking-at vc-hg-annotate-re)
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
188 (goto-char (match-end 0))
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
189 (vc-annotate-convert-time
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
190 (date-to-time (match-string-no-properties 2)))))
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
191
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
192 (defun vc-hg-annotate-extract-revision-at-line ()
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
193 (save-excursion
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
194 (beginning-of-line)
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
195 (if (looking-at vc-hg-annotate-re) (match-string-no-properties 1))))
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
196
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
197 (defun vc-hg-previous-version (file rev)
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
198 (let ((newrev (1- (string-to-number rev))))
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
199 (when (>= newrev 0)
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
200 (number-to-string newrev))))
81474
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
201
81476
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
202 (defun vc-hg-register (file &optional rev comment)
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
203 "Register FILE under hg.
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
204 REV is ignored.
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
205 COMMENT is ignored."
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
206 (vc-hg-command nil nil file "add"))
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
207
81526
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
208 (defun vc-hg-checkin (file rev comment)
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
209 "HG-specific version of `vc-backend-checkin'.
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
210 REV is ignored."
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
211 (vc-hg-command nil nil file "commit" "-m" comment))
145f53e0ff66 Add to do items.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81479
diff changeset
212
81476
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
213 ;;; 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
214 (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
215 "Retrieve a revision of FILE into a WORKFILE.
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
216 EDITABLE is ignored.
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
217 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
218 (unless workfile
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
219 (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
220 (let ((coding-system-for-read 'binary)
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
221 (coding-system-for-write 'binary))
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
222 (with-temp-file workfile
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
223 (if rev
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
224 (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
225 (vc-hg-command t nil file "cat")))))
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
226
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
227 (defun vc-hg-checkout-model (file)
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
228 'implicit)
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
229
81474
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
230 ;;; Internal functions
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
231
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
232 (defun vc-hg-command (buffer okstatus file &rest flags)
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
233 "A wrapper around `vc-do-command' for use in vc-hg.el.
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
234 The difference to vc-do-command is that this function always invokes `hg',
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
235 and that it passes `vc-hg-global-switches' to it before FLAGS."
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
236 (apply 'vc-do-command buffer okstatus "hg" file
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
237 (if (stringp vc-hg-global-switches)
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
238 (cons vc-hg-global-switches flags)
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
239 (append vc-hg-global-switches
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
240 flags))))
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
241
81564
99961edaa9c1 (vc-hg-print-log): Insert the file name.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81538
diff changeset
242 (defun vc-hg-internal-log (file &optional buffer)
81476
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
243 "Return log of FILE."
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
244 (with-output-to-string
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
245 (with-current-buffer
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
246 standard-output
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
247 (call-process
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
248 "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
249 "log" "-l1" (file-name-nondirectory file)))))
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
250
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
251 (defun vc-hg-internal-status(file)
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
252 "Return status of FILE."
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
253 (with-output-to-string
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
254 (with-current-buffer
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
255 standard-output
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
256 (call-process
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
257 "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
258 "status" (file-name-nondirectory file)))))
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
259
81474
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
260 (provide 'vc-hg)
51869b1d11fd * vc-hg.el: New file.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
diff changeset
261
81476
3dedb2297b98 (vc-hg-global-switches): Simplify.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 81474
diff changeset
262 ;;; vc-hg.el ends here