Mercurial > emacs
comparison lisp/vc-hg.el @ 81474:51869b1d11fd
* vc-hg.el: New file.
author | Dan Nicolaescu <dann@ics.uci.edu> |
---|---|
date | Wed, 20 Jun 2007 05:59:41 +0000 |
parents | |
children | 3dedb2297b98 |
comparison
equal
deleted
inserted
replaced
81473:834afc8fa2e5 | 81474:51869b1d11fd |
---|---|
1 ;;; vc-hg.el --- VC backend for the mercurial version control system | |
2 | |
3 ;; Copyright (C) 2006 Ivan Kanis | |
4 ;; Author: Ivan Kanis | |
5 ;; $Id: vc-hg.el 1889 2007-06-17 12:39:26Z ivan $ | |
6 ;; | |
7 ;; This program is free software ; you can redistribute it and/or modify | |
8 ;; it under the terms of the GNU General Public License as published by | |
9 ;; the Free Software Foundation ; either version 2 of the License, or | |
10 ;; (at your option) any later version. | |
11 ;; | |
12 ;; This program is distributed in the hope that it will be useful, but | |
13 ;; WITHOUT ANY WARRANTY ; without even the implied warranty of | |
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 ;; General Public License for more details. | |
16 ;; | |
17 ;; You should have received a copy of the GNU General Public License | |
18 ;; along with this program ; if not, write to the Free Software | |
19 ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 | |
21 ;;; Commentary: | |
22 | |
23 ;; This is a mercurial version control backend | |
24 | |
25 ;;; THANKS: | |
26 | |
27 ;;; BUGS: | |
28 | |
29 ;;; INSTALLATION: | |
30 | |
31 ;;; Code: | |
32 | |
33 (eval-when-compile | |
34 (require 'vc)) | |
35 | |
36 ;; (setq vc-handled-backends '(CVS SVN hg)) | |
37 | |
38 ;;; Customization options | |
39 | |
40 (defcustom vc-hg-global-switches nil | |
41 "*Global switches to pass to any Hg command." | |
42 :type '(choice (const :tag "None" nil) | |
43 (string :tag "Argument String") | |
44 (repeat :tag "Argument List" | |
45 :value ("") | |
46 string)) | |
47 :version "22.1" | |
48 :group 'vc) | |
49 | |
50 ;;; State querying functions | |
51 | |
52 (defun vc-hg-registered (file) | |
53 "Return t if FILE is registered in Hg" | |
54 (if (eq 0 (call-process "hg" nil nil nil | |
55 "--cwd" (file-name-directory file) | |
56 "status" (file-name-nondirectory file))) | |
57 (vc-file-setprop file 'vc-name file) nil)) | |
58 | |
59 (defun vc-hg-state (file) | |
60 "Return state of files in Hg" | |
61 (let ((out (vc-hg-internal-status file))) | |
62 (if (eq 0 (length out)) 'up-to-date | |
63 (let ((state (aref out 0))) | |
64 (cond | |
65 ((eq state ?M) 'edited) | |
66 ((eq state ?P) 'needs-patch) | |
67 (t 'up-to-date)))))) | |
68 | |
69 (defun vc-hg-workfile-version (file) | |
70 "Return version number of file" | |
71 (let ((out (vc-hg-internal-log file))) | |
72 (if (string-match "changeset: *\\([0-9]*\\)" out) | |
73 (match-string 1 out) | |
74 "0"))) | |
75 | |
76 (defun vc-hg-internal-log(file) | |
77 "Return log of FILE" | |
78 (with-output-to-string | |
79 (with-current-buffer | |
80 standard-output | |
81 (call-process | |
82 "hg" nil t nil "--cwd" (file-name-directory file) | |
83 "log" "-l1" (file-name-nondirectory file))))) | |
84 | |
85 ;;; History functions | |
86 | |
87 (defun vc-hg-print-log(file &optional buffer) | |
88 "Get change log associated with FILE." | |
89 (vc-hg-command | |
90 buffer | |
91 (if (and (vc-stay-local-p file) (fboundp 'start-process)) 'async 0) | |
92 file "log")) | |
93 | |
94 (defun vc-hg-internal-status(file) | |
95 "Return status of FILE" | |
96 (with-output-to-string | |
97 (with-current-buffer | |
98 standard-output | |
99 (call-process | |
100 "hg" nil t nil "--cwd" (file-name-directory file) | |
101 "status" (file-name-nondirectory file))))) | |
102 | |
103 (defun vc-hg-diff (file &optional oldvers newvers buffers) | |
104 "Get a difference report using hg between two versions of FILE." | |
105 (when buffers (message buffers)) | |
106 (unless buffers (setq buffers "*vc-diff*")) | |
107 (when oldvers (message oldvers)) | |
108 (when newvers (message newvers)) | |
109 (call-process "hg" nil buffers nil | |
110 "--cwd" (file-name-directory file) | |
111 "diff" (file-name-nondirectory file))) | |
112 | |
113 ;;; Internal functions | |
114 | |
115 (defun vc-hg-command (buffer okstatus file &rest flags) | |
116 "A wrapper around `vc-do-command' for use in vc-hg.el. | |
117 The difference to vc-do-command is that this function always invokes `hg', | |
118 and that it passes `vc-hg-global-switches' to it before FLAGS." | |
119 (apply 'vc-do-command buffer okstatus "hg" file | |
120 (if (stringp vc-hg-global-switches) | |
121 (cons vc-hg-global-switches flags) | |
122 (append vc-hg-global-switches | |
123 flags)))) | |
124 | |
125 (provide 'vc-hg) | |
126 |