Function: vc-hg--raw-dirstate-search
vc-hg--raw-dirstate-search is a byte-compiled function defined in
vc-hg.el.gz.
Signature
(vc-hg--raw-dirstate-search DIRSTATE FNAME)
Source Code
;; Defined in /usr/src/emacs/lisp/vc/vc-hg.el.gz
(defun vc-hg--raw-dirstate-search (dirstate fname)
(with-temp-buffer
(set-buffer-multibyte nil)
(insert-file-contents-literally dirstate)
(let* ((result nil)
(flen (length fname))
(case-fold-search nil)
;; Find a conservative bound for the loop below by using
;; Boyer-Moore on the raw dirstate without parsing it; we
;; know we can't possibly find fname _after_ the last place
;; it appears, so we can bail out early if we try to parse
;; past it, which especially helps when the file we're
;; trying to find isn't in dirstate at all. There's no way
;; to similarly bound the starting search position, since
;; the file format is such that we need to parse it from
;; the beginning to find record boundaries.
(search-limit
(progn
(goto-char (point-max))
(or (search-backward fname (+ (point-min) 40) t)
(point-min)))))
;; 40 is just after the header, which contains the working
;; directory parents
(goto-char (+ (point-min) 40))
;; Iterate over all dirstate entries; we might run this loop
;; hundreds of thousands of times, so performance is important
;; here
(while (< (point) search-limit)
;; 1+4*4 is the length of the dirstate item header.
(forward-char (1+ (* 3 4)))
(let ((this-flen (vc-hg--read-u32-be)))
(if (and (or (eq this-flen flen)
(and (> this-flen flen)
(eq (char-after (+ (point) flen)) 0)))
(search-forward fname (+ (point) flen) t))
(progn
(backward-char (+ flen (1+ (* 4 4))))
(setf result
(list (vc-hg--read-u8) ; status
(vc-hg--read-u32-be) ; mode
(vc-hg--read-u32-be) ; size (of file)
(vc-hg--read-u32-be) ; mtime
))
(goto-char (point-max)))
(forward-char this-flen))))
result)))