[Top][All Lists]

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

vc.el and modified time

From: Rasmus
Subject: vc.el and modified time
Date: Wed, 27 Apr 2016 17:36:38 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)


I would like to obtain the modification time of a file as registered by my
version control.  Thus, vc.el springs to mind.

My first attempt is below, but I’m not entirely happy with it.  First, it
is intrusive as it might overwrite the user’s *vc-change-log*.  Second,
*vc-change-log* is build asynchronously, at least sometimes, and I don’t
know how I can check if it’s done.

Does there exists a more systematic or "script friendly" way to consumer
logs from vc.el?  The only interface that I found that seems public is the
ones that write the information to *vc-change-log*.


(defun org--get-modified-time-vc (file)
  "Get the modified time of FILE as recorded by version control."
  (when (vc-backend file)
    ;; TODO: It seems that `*vc-change-log*' is the hardcoded.  It is
    ;; quite intrusive as it would mean that calling the function
    ;; would change this buffer.  Is there a better way than to kill
    ;; old buffer to make sure `*vc-change-log*' is current?
    (if (get-buffer "*vc-change-log*")
        (kill-buffer "*vc-change-log*"))
      (with-current-buffer (or (find-buffer-visiting file)
                               (find-file-noselect file))
        (vc-print-log nil 1)
    (when (get-buffer "*vc-change-log*")
      (let ((date (with-current-buffer  (get-buffer "*vc-change-log*")
                    ;; TODO: The buffer is updated asynchronously so
                    ;; we need to wait.  Is there a better way to wait
                    ;; until vc-log has done its thing?
                    (sit-for .1)
                    (goto-char (point-min))
                    (when (search-forward-regexp "Date:?[ \t]*" nil t)
                      (buffer-substring (point) (point-at-eol))))))
        (let ((time (parse-time-string (or date ""))))
          (when (org-some 'identity time) time))))))


reply via email to

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