emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs-25 c71e1e8: Use short date for 'hg annotate', and ou


From: Dmitry Gutov
Subject: [Emacs-diffs] emacs-25 c71e1e8: Use short date for 'hg annotate', and output the author
Date: Sun, 10 Jan 2016 01:13:06 +0000

branch: emacs-25
commit c71e1e86dff7e5a385107c358d25dce9027915c0
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    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.
---
 lisp/vc/vc-hg.el        |   36 +++++++++++++++++-----------
 test/automated/vc-hg.el |   60 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+), 14 deletions(-)

diff --git a/lisp/vc/vc-hg.el b/lisp/vc/vc-hg.el
index 8a0a9f9..85e2376 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."
   :version "23.1"
   :group 'vc-hg)
 
-(defcustom vc-hg-annotate-switches nil
+(defcustom vc-hg-annotate-switches '("-u" "--follow")
   "String or list of strings specifying switches for hg annotate under VC.
 If nil, use the value of `vc-annotate-switches'.  If t, use no
 switches."
@@ -380,36 +380,44 @@ If LIMIT is non-nil, show no more than this many entries."
 (defun vc-hg-annotate-command (file buffer &optional revision)
   "Execute \"hg annotate\" on FILE, inserting the contents in BUFFER.
 Optional arg REVISION is a revision to annotate from."
-  (apply #'vc-hg-command buffer 0 file "annotate" "-d" "-n" "--follow"
+  (apply #'vc-hg-command buffer 0 file "annotate" "-dq" "-n"
         (append (vc-switches 'hg 'annotate)
                  (if revision (list (concat "-r" revision))))))
 
 (declare-function vc-annotate-convert-time "vc-annotate" (&optional time))
 
-;; The format for one line output by "hg annotate -d -n" looks like this:
-;;215 Wed Jun 20 21:22:58 2007 -0700: CONTENTS
-;; i.e: VERSION_NUMBER DATE: CONTENTS
-;; If the user has set the "--follow" option, the output looks like:
-;;215 Wed Jun 20 21:22:58 2007 -0700 foo.c: CONTENTS
-;; i.e. VERSION_NUMBER DATE FILENAME: CONTENTS
+;; One line printed by "hg annotate -dq -n -u --follow" looks like this:
+;;   b56girard 114590 2012-03-13 CLOBBER: Lorem ipsum dolor sit
+;; i.e. AUTHOR REVISION DATE FILENAME: CONTENTS
+;; The user can omit options "-u" and/or "--follow".  Then it'll look like:
+;;   114590 2012-03-13 CLOBBER:
+;; or
+;;   b56girard 114590 2012-03-13:
 (defconst vc-hg-annotate-re
-  "^[ \t]*\\([0-9]+\\) \\(.\\{30\\}\\)\\(?:\\(: \\)\\|\\(?: 
+\\([^:\n]+\\(?::\\(?:[^: \n][^:\n]*\\)?\\)*\\): \\)\\)")
+  (concat
+   "^\\(?: *[^ ]+ +\\)?\\([0-9]+\\) "   ;User and revision.
+   "\\([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\\)" ;Date.
+   "\\( [^:]+\\)?:"))                   ;Filename,
 
 (defun vc-hg-annotate-time ()
   (when (looking-at vc-hg-annotate-re)
     (goto-char (match-end 0))
     (vc-annotate-convert-time
-     (date-to-time (match-string-no-properties 2)))))
+     (let ((str (match-string-no-properties 2)))
+       (encode-time 0 0 0
+                    (string-to-number (substring str 6 8))
+                    (string-to-number (substring str 4 6))
+                    (string-to-number (substring str 0 4)))))))
 
 (defun vc-hg-annotate-extract-revision-at-line ()
   (save-excursion
     (beginning-of-line)
     (when (looking-at vc-hg-annotate-re)
       (if (match-beginning 3)
-         (match-string-no-properties 1)
-       (cons (match-string-no-properties 1)
-      (expand-file-name (match-string-no-properties 4)
- (vc-hg-root default-directory)))))))
+          (cons (match-string-no-properties 1)
+                (expand-file-name (substring (match-string-no-properties 3) 1)
+                                  (vc-hg-root default-directory)))
+        (match-string-no-properties 1)))))
 
 ;;; Tag system
 
diff --git a/test/automated/vc-hg.el b/test/automated/vc-hg.el
new file mode 100644
index 0000000..6a746ce
--- /dev/null
+++ b/test/automated/vc-hg.el
@@ -0,0 +1,60 @@
+;;; vc-hg.el --- tests for vc/vc-hg.el
+
+;; Copyright (C) 2016 Free Software Foundation, Inc.
+
+;; Author: Dmitry Gutov <address@hidden>
+;; Maintainer: address@hidden
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'vc-hg)
+(require 'vc-annotate)
+
+(ert-deftest vc-hg-annotate-extract-revision-at-line-with-filename ()
+  ;; with filename
+  (with-temp-buffer
+    (save-excursion (insert "215 2007-06-20 CONTENTS:"))
+    (should (equal (vc-hg-annotate-extract-revision-at-line)
+                   (cons
+                    "215"
+                    (expand-file-name "test/automated/CONTENTS"
+                                      source-directory))))))
+
+(ert-deftest vc-hg-annotate-extract-revision-at-line-with-user ()
+  (with-temp-buffer
+    (save-excursion (insert " gerv 107217 2012-09-17:"))
+    (should (equal (vc-hg-annotate-extract-revision-at-line)
+                   "107217"))))
+
+(ert-deftest vc-hg-annotate-extract-revision-at-line-with-both ()
+  (with-temp-buffer
+    (save-excursion (insert "philringnalda 218075 2014-11-28 CLOBBER:"))
+    (should (equal (vc-hg-annotate-extract-revision-at-line)
+                   (cons
+                    "218075"
+                    (expand-file-name "test/automated/CLOBBER"
+                                      source-directory))))))
+
+(ert-deftest vc-hg-annotate-time ()
+  (with-temp-buffer
+    (save-excursion (insert "philringnalda 218075 2014-11-28 CLOBBER:"))
+    (should (floatp (vc-hg-annotate-time)))))
+
+;;; vc-hg.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]