aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2016-01-10 04:09:42 +0300
committerDmitry Gutov2016-01-10 04:13:01 +0300
commitc71e1e86dff7e5a385107c358d25dce9027915c0 (patch)
tree100df520f20619149fd6e9e505830a82c49c2e95
parentf50027be1ac5861dcda22cda64df69bf93e4ee70 (diff)
downloademacs-c71e1e86dff7e5a385107c358d25dce9027915c0.tar.gz
emacs-c71e1e86dff7e5a385107c358d25dce9027915c0.zip
Use short date for 'hg annotate', and output the author
* lisp/vc/vc-hg.el (vc-hg-annotate-command): Change '-d' to '-dq'. (Bug#21805) (vc-hg-annotate-switches): Default to "-u" "--follow". (vc-hg-annotate-re): Update to recognize the short date format and the optional username. (vc-hg-annotate-time) (vc-hg-annotate-extract-revision-at-line): Update accordingly. * test/automated/vc-hg.el: New file.
-rw-r--r--lisp/vc/vc-hg.el36
-rw-r--r--test/automated/vc-hg.el60
2 files changed, 82 insertions, 14 deletions
diff --git a/lisp/vc/vc-hg.el b/lisp/vc/vc-hg.el
index 8a0a9f91a48..85e23769db8 100644
--- a/lisp/vc/vc-hg.el
+++ b/lisp/vc/vc-hg.el
@@ -131,7 +131,7 @@ If nil, use the value of `vc-diff-switches'. If t, use no switches."
131 :version "23.1" 131 :version "23.1"
132 :group 'vc-hg) 132 :group 'vc-hg)
133 133
134(defcustom vc-hg-annotate-switches nil 134(defcustom vc-hg-annotate-switches '("-u" "--follow")
135 "String or list of strings specifying switches for hg annotate under VC. 135 "String or list of strings specifying switches for hg annotate under VC.
136If nil, use the value of `vc-annotate-switches'. If t, use no 136If nil, use the value of `vc-annotate-switches'. If t, use no
137switches." 137switches."
@@ -380,36 +380,44 @@ If LIMIT is non-nil, show no more than this many entries."
380(defun vc-hg-annotate-command (file buffer &optional revision) 380(defun vc-hg-annotate-command (file buffer &optional revision)
381 "Execute \"hg annotate\" on FILE, inserting the contents in BUFFER. 381 "Execute \"hg annotate\" on FILE, inserting the contents in BUFFER.
382Optional arg REVISION is a revision to annotate from." 382Optional arg REVISION is a revision to annotate from."
383 (apply #'vc-hg-command buffer 0 file "annotate" "-d" "-n" "--follow" 383 (apply #'vc-hg-command buffer 0 file "annotate" "-dq" "-n"
384 (append (vc-switches 'hg 'annotate) 384 (append (vc-switches 'hg 'annotate)
385 (if revision (list (concat "-r" revision)))))) 385 (if revision (list (concat "-r" revision))))))
386 386
387(declare-function vc-annotate-convert-time "vc-annotate" (&optional time)) 387(declare-function vc-annotate-convert-time "vc-annotate" (&optional time))
388 388
389;; The format for one line output by "hg annotate -d -n" looks like this: 389;; One line printed by "hg annotate -dq -n -u --follow" looks like this:
390;;215 Wed Jun 20 21:22:58 2007 -0700: CONTENTS 390;; b56girard 114590 2012-03-13 CLOBBER: Lorem ipsum dolor sit
391;; i.e: VERSION_NUMBER DATE: CONTENTS 391;; i.e. AUTHOR REVISION DATE FILENAME: CONTENTS
392;; If the user has set the "--follow" option, the output looks like: 392;; The user can omit options "-u" and/or "--follow". Then it'll look like:
393;;215 Wed Jun 20 21:22:58 2007 -0700 foo.c: CONTENTS 393;; 114590 2012-03-13 CLOBBER:
394;; i.e. VERSION_NUMBER DATE FILENAME: CONTENTS 394;; or
395;; b56girard 114590 2012-03-13:
395(defconst vc-hg-annotate-re 396(defconst vc-hg-annotate-re
396 "^[ \t]*\\([0-9]+\\) \\(.\\{30\\}\\)\\(?:\\(: \\)\\|\\(?: +\\([^:\n]+\\(?::\\(?:[^: \n][^:\n]*\\)?\\)*\\): \\)\\)") 397 (concat
398 "^\\(?: *[^ ]+ +\\)?\\([0-9]+\\) " ;User and revision.
399 "\\([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\\)" ;Date.
400 "\\( [^:]+\\)?:")) ;Filename,
397 401
398(defun vc-hg-annotate-time () 402(defun vc-hg-annotate-time ()
399 (when (looking-at vc-hg-annotate-re) 403 (when (looking-at vc-hg-annotate-re)
400 (goto-char (match-end 0)) 404 (goto-char (match-end 0))
401 (vc-annotate-convert-time 405 (vc-annotate-convert-time
402 (date-to-time (match-string-no-properties 2))))) 406 (let ((str (match-string-no-properties 2)))
407 (encode-time 0 0 0
408 (string-to-number (substring str 6 8))
409 (string-to-number (substring str 4 6))
410 (string-to-number (substring str 0 4)))))))
403 411
404(defun vc-hg-annotate-extract-revision-at-line () 412(defun vc-hg-annotate-extract-revision-at-line ()
405 (save-excursion 413 (save-excursion
406 (beginning-of-line) 414 (beginning-of-line)
407 (when (looking-at vc-hg-annotate-re) 415 (when (looking-at vc-hg-annotate-re)
408 (if (match-beginning 3) 416 (if (match-beginning 3)
409 (match-string-no-properties 1) 417 (cons (match-string-no-properties 1)
410 (cons (match-string-no-properties 1) 418 (expand-file-name (substring (match-string-no-properties 3) 1)
411 (expand-file-name (match-string-no-properties 4) 419 (vc-hg-root default-directory)))
412 (vc-hg-root default-directory))))))) 420 (match-string-no-properties 1)))))
413 421
414;;; Tag system 422;;; Tag system
415 423
diff --git a/test/automated/vc-hg.el b/test/automated/vc-hg.el
new file mode 100644
index 00000000000..6a746ce5890
--- /dev/null
+++ b/test/automated/vc-hg.el
@@ -0,0 +1,60 @@
1;;; vc-hg.el --- tests for vc/vc-hg.el
2
3;; Copyright (C) 2016 Free Software Foundation, Inc.
4
5;; Author: Dmitry Gutov <dgutov@yandex.ru>
6;; Maintainer: emacs-devel@gnu.org
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software: you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23;;; Commentary:
24
25;;; Code:
26
27(require 'vc-hg)
28(require 'vc-annotate)
29
30(ert-deftest vc-hg-annotate-extract-revision-at-line-with-filename ()
31 ;; with filename
32 (with-temp-buffer
33 (save-excursion (insert "215 2007-06-20 CONTENTS:"))
34 (should (equal (vc-hg-annotate-extract-revision-at-line)
35 (cons
36 "215"
37 (expand-file-name "test/automated/CONTENTS"
38 source-directory))))))
39
40(ert-deftest vc-hg-annotate-extract-revision-at-line-with-user ()
41 (with-temp-buffer
42 (save-excursion (insert " gerv 107217 2012-09-17:"))
43 (should (equal (vc-hg-annotate-extract-revision-at-line)
44 "107217"))))
45
46(ert-deftest vc-hg-annotate-extract-revision-at-line-with-both ()
47 (with-temp-buffer
48 (save-excursion (insert "philringnalda 218075 2014-11-28 CLOBBER:"))
49 (should (equal (vc-hg-annotate-extract-revision-at-line)
50 (cons
51 "218075"
52 (expand-file-name "test/automated/CLOBBER"
53 source-directory))))))
54
55(ert-deftest vc-hg-annotate-time ()
56 (with-temp-buffer
57 (save-excursion (insert "philringnalda 218075 2014-11-28 CLOBBER:"))
58 (should (floatp (vc-hg-annotate-time)))))
59
60;;; vc-hg.el ends here