Function: vc-git-previous-revision

vc-git-previous-revision is a byte-compiled function defined in vc-git.el.gz.

Signature

(vc-git-previous-revision FILE REV)

Documentation

Git-specific version of vc-previous-revision.

Source Code

;; Defined in /usr/src/emacs/lisp/vc/vc-git.el.gz
(defun vc-git-previous-revision (file rev)
  "Git-specific version of `vc-previous-revision'."
  (cond ((string-match "\\`HEAD\\(\\^*\\)\\'" rev)
         (format "HEAD~%d" (1+ (length (match-string 1 rev)))))
        ((string-match "\\`HEAD~\\([0-9]+\\)\\'" rev)
         (format "HEAD~%d" (1+ (string-to-number (match-string 1 rev)))))
        (file
         (let* ((fname (file-relative-name file))
                (prev-rev (with-temp-buffer
                            (and
                             (vc-git--out-ok "rev-list"
                                             (vc-git--maybe-abbrev)
                                             "-2" rev "--" fname)
                             (goto-char (point-max))
                             (bolp)
                             (zerop (forward-line -1))
                             (not (bobp))
                             (buffer-substring-no-properties
                              (point)
                              (1- (point-max)))))))
           (or (vc-git-symbolic-commit prev-rev) prev-rev)))
        (t
         ;; We used to use "^" here, but that fails on MS-Windows if git
         ;; is invoked via a batch file, in which case cmd.exe strips
         ;; the "^" because it is a special character for cmd which
         ;; process-file does not (and cannot) quote.
         (vc-git--rev-parse (concat rev "~1")))))