                      (year (substring date 0 4))
                      (month (substring date 4 6))
                      (day (substring date 6 8))
+                     (hour (substring date 8 10))
+                     (min (substring date 10 12))
+                     (sec (substring date 12 14))
+                     (time (vc-annotate-convert-time
+                            (encode-time
+                             (vc-darcs-parse-integer sec)
+                             (vc-darcs-parse-integer min)
+                             (vc-darcs-parse-integer hour)
+                             (vc-darcs-parse-integer day)
+                             (vc-darcs-parse-integer month)
+                             (vc-darcs-parse-integer year))))
                      (begin (point)))
-                (insert (format "%-7s %s/%s/%s %s\n"
+                (insert (format "%-7s "
                                 (if (> (length author) 7)
                                     (substring author 0 7)
-                                    author)
-                                day month year
-                                line))))))))))
-
-(defun vc-darcs-parse-integer (s)
-  (let ((value 0)
-        (index 0)
-        (len (length s)))
-    (while (< index len)
-      (setq value (+ (* 10 value) (- (aref s index) ?0)))
-      (incf index))
-    value))
+                                    author)))
+                (insert
+                 (if (> (- now time) 0.9)
+                     (format "%s/%s/%s " day month (substring year 2 4))
+                     (format "%s:%s:%s " hour min sec)))
+                (insert line)
+                (insert "\n")
+                (add-text-properties
+                 begin (point)
+                 (list 'vc-darcs-annotate (cons rev time)))))))))))
+
+(defun vc-darcs-annotate-extract-revision-at-line ()
+  (car (get-text-property (point) 'vc-darcs-annotate (current-buffer))))
 
 (defun vc-darcs-annotate-time ()
-  (when (looking-at "........[0-9]")
-    (forward-char 8)
-    (and
-     (looking-at "\\(..\\)/\\(..\\)/\\(....\\)")
-     (let ((day (vc-darcs-parse-integer (match-string 1)))
-           (month (vc-darcs-parse-integer (match-string 2)))
-           (year (vc-darcs-parse-integer (match-string 3))))
-       (vc-annotate-convert-time
-        (encode-time 0 0 0 day month year))))))
+  (cdr (get-text-property (point) 'vc-darcs-annotate (current-buffer))))
 
 ;;; protection against editing files under _darcs
 ;;; adapted from an idea by Rob Giardine
 
 (defun vc-darcs-find-file-hook ()
   (let ((f (buffer-file-name (current-buffer))))
-    (and f (string-match "/_darcs" f) (not (string-match "/_darcs/prefs" f))
-         (let ((open-instead
-                (yes-or-no-p
-                 "This is a _darcs file, open the real file instead? ")))
+    (and f (vc-darcs-special-file-p f)
+         (let* ((candidate
+                 (let* ((f (buffer-file-name (current-buffer)))
+                        (match
+                         (and f (string-match
+                                 "/_darcs/\\(current\\|pristine\\)/" f))))
+                   (and match
+                        (concat (substring f 0 (match-beginning 0))
+                                "/"
+                                (substring f (match-end 0))))))
+                (open-instead
+                 (and candidate
+                      (yes-or-no-p
+                       "This is a _darcs file, open the real file instead? "))))
            (cond
              (open-instead
-              (let* ((f (buffer-file-name (current-buffer)))
-                     (match
-                      (and f (string-match
-                              "/_darcs/\\(current\\|pristine\\)/" f))))
-                (unless match
-                  (error "Couldn't find alternate file name"))
-                (find-alternate-file
-                 (concat (substring f 0 (match-beginning 0))
-                         "/"
-                         (substring f (match-end 0))))))
+              (find-alternate-file candidate))
              (t
               (setq buffer-read-only t)
               (push '(:propertize "_DARCS-FILE:" face font-lock-warning-face)

;;; vc-darcs.el --- a VC backend for darcs

;;; Copyright (C)  2004  Jorgen Schaefer <forcer@forcix.cx>
;;; Copyright (C)  2004-2006  Juliusz Chroboczek <jch@pps.jussieu.fr>

;;; This program is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU General Public License

;; Darcs is David's Advanced Revision Control System at
;; http://www.darcs.net/

;; A few ideas for this file are directly taken from vc-svn.el.  Thanks to
;; Jim Blandy.

;; To install, put this file into your load-path and add the following to
;; your .emacs:

;; (add-to-list 'vc-handled-backends 'DARCS)
;; (autoload 'vc-darcs-find-file-hook "vc-darcs")
;; (add-hook 'find-file-hooks 'vc-darcs-find-file-hook)

;; There are a few reasons why vc is difficult to coerce into using darcs
;; as a backend.  By default, vc expects files (not trees) to be versioned
;; as nodes in an AND/OR tree, as is done by RCS and CVS.  Recent version
;; of vc allow some customisation of that, which allows smooth integration
;; with e.g. subversion.

;; Darcs doesn't version files at all; a darcs repository is a collection
;; of patches, and a particular file version is just the set of patches
;; that have been applied in order to build it.  While patches might be
;; reordered when moving between repositories, they usually remain ordered
;; (notable exceptions to that being unpull and optimize); hence,
;; a convenient mental shortcut is to identify a version by the latest
;; patch included in that version.  This is what we do.

;; Internally, darcs identifies a patch by its hash, which you may obtain
;; by using changes --xml.  We follow that approach in this code.  However,
;; as a hash might be difficult to remember at times (it's 65 characters
;; long), all commands that might take an interactive argument also accept
;; a regexp identifying a patch name.  See VC-DARCS-REV-TO-HASH.

;; The fit with vc is still not quite perfect.  A sore point is that vc
;; doesn't normalise versions; hence, if you have a patch called ``Initial
;; import'', you might end up with distinct but identical buffers called
;; vc-darcs.el~Init~, vc-darcs.el~Initial~ and so on.


(defvar vc-darcs-version-string "1.9"
  "The version string for vc-darcs.el.")

;;; Code:
