+;; Set during dumping, this is a defvar so that it can be setq'd.
+(defvar emacs-repository-version nil
+ "String giving the repository revision from which this Emacs was built.
+Value is nil if Emacs was not built from a repository checkout,
+or if we could not determine the revision.")
+
+(define-obsolete-variable-alias 'emacs-bzr-version
+ 'emacs-repository-version "24.4")
+
+(define-obsolete-function-alias 'emacs-bzr-get-version
+ 'emacs-repository-get-version "24.4")
+
+(defun emacs-repository-get-version (&optional dir external)
+ "Try to return as a string the repository revision of the Emacs sources.
+The format of the returned string is dependent on the VCS in use.
+Value is nil if the sources do not seem to be under version
+control, or if we could not determine the revision. Note that
+this reports on the current state of the sources, which may not
+correspond to the running Emacs.
+
+Optional argument DIR is a directory to use instead of
+`source-directory'. Optional argument EXTERNAL is ignored and is
+retained for compatibility."
+ (or dir (setq dir source-directory))
+ (cond ((file-directory-p (expand-file-name ".git" dir))
+ (message "Waiting for git...")
+ (with-temp-buffer
+ (let ((default-directory (file-name-as-directory dir)))
+ (and (eq 0
+ (condition-case nil
+ (call-process "git" nil '(t nil) nil "rev-parse"
+ "HEAD")
+ (error nil)))
+ (not (zerop (buffer-size)))
+ (replace-regexp-in-string "\n" "" (buffer-string))))))))
+