Function: vc-bzr-working-revision
vc-bzr-working-revision is a byte-compiled function defined in
vc-bzr.el.gz.
Signature
(vc-bzr-working-revision FILE)
Source Code
;; Defined in /usr/src/emacs/lisp/vc/vc-bzr.el.gz
(defun vc-bzr-working-revision (file)
(let* ((rootdir (vc-bzr-root file))
(branch-format-file (expand-file-name vc-bzr-admin-branch-format-file
rootdir))
(revhistory-file (expand-file-name vc-bzr-admin-revhistory rootdir))
(lastrev-file (expand-file-name vc-bzr-admin-lastrev rootdir)))
;; This looks at internal files to avoid forking a bzr process.
;; May break if they change their format.
(if (and (file-exists-p branch-format-file)
;; For lightweight checkouts (obtained with bzr co --lightweight)
;; the branch-format-file does not contain the revision
;; information, we need to look up the branch-format-file
;; in the place where the lightweight checkout comes
;; from. We only do that if it's a local file.
(let ((location-fname (expand-file-name
(concat vc-bzr-admin-dirname
"/branch/location") rootdir)))
;; The existence of this file is how we distinguish
;; lightweight checkouts.
(if (file-exists-p location-fname)
(with-temp-buffer
(insert-file-contents location-fname)
;; If the lightweight checkout points to a
;; location in the local file system, then we can
;; look there for the version information.
(when (re-search-forward "file://\\(.+\\)" nil t)
(let ((l-c-parent-dir (match-string 1)))
(when (and (memq system-type '(ms-dos windows-nt))
(string-match-p "^/[[:alpha:]]:"
l-c-parent-dir))
;;; The non-Windows code takes a shortcut by using
;;; the host/path separator slash as the start of
;;; the absolute path. That does not work on
;;; Windows, so we must remove it (bug#5345)
(setq l-c-parent-dir (substring l-c-parent-dir 1)))
(setq branch-format-file
(expand-file-name vc-bzr-admin-branch-format-file
l-c-parent-dir))
(setq lastrev-file
(expand-file-name vc-bzr-admin-lastrev
l-c-parent-dir))
;; FIXME: maybe it's overkill to check if both these
;; files exist.
(and (file-exists-p branch-format-file)
(file-exists-p lastrev-file)
(equal (vc-bzr-version-dirstate l-c-parent-dir)
(vc-bzr-version-dirstate rootdir))))))
t)))
(with-temp-buffer
(insert-file-contents branch-format-file)
(goto-char (point-min))
(cond
((or
(looking-at "Bazaar-NG branch, format 0.0.4")
(looking-at "Bazaar-NG branch format 5"))
;; count lines in .bzr/branch/revision-history
(insert-file-contents revhistory-file)
(number-to-string (count-lines (line-end-position) (point-max))))
((or
(looking-at "Bazaar Branch Format 6 (bzr 0.15)")
(looking-at "Bazaar Branch Format 7 (needs bzr 1.6)"))
;; revno is the first number in .bzr/branch/last-revision
(insert-file-contents lastrev-file)
(when (re-search-forward "[0-9]+" nil t)
(buffer-substring (match-beginning 0) (match-end 0))))))
;; Fallback to calling "bzr revno --tree".
;; The "--tree" matters for lightweight checkouts not on the same
;; revision as the parent.
(let* ((result (vc-bzr-command-discarding-stderr
vc-bzr-program "revno" "--tree"
(file-relative-name file)))
(exitcode (car result))
(output (cdr result)))
(cond
((and (eq exitcode 0) (not (zerop (length output))))
(substring output 0 -1))
(t nil))))))