(let* ((file buffer-file-name)\r
(backend (vc-backend file)))\r
(when backend\r
- (cl-case (vc-state file backend)\r
- (edited\r
- (let* ((buf-name " *diff-hl* ")\r
- res)\r
- (diff-hl-with-diff-switches\r
- (vc-call-backend backend 'diff (list file) nil nil buf-name))\r
- (with-current-buffer buf-name\r
- (goto-char (point-min))\r
- (unless (eobp)\r
- (diff-beginning-of-hunk t)\r
- (while (looking-at diff-hunk-header-re-unified)\r
- (let ((line (string-to-number (match-string 3)))\r
- (len (let ((m (match-string 4)))\r
- (if m (string-to-number m) 1)))\r
- (beg (point)))\r
- (diff-end-of-hunk)\r
- (let* ((inserts (diff-count-matches "^\\+" beg (point)))\r
- (deletes (diff-count-matches "^-" beg (point)))\r
- (type (cond ((zerop deletes) 'insert)\r
- ((zerop inserts) 'delete)\r
- (t 'change))))\r
- (when (eq type 'delete)\r
- (setq len 1)\r
- (cl-incf line))\r
- (push (list line len type) res))))))\r
- (nreverse res)))\r
- (added\r
- `((1 ,(line-number-at-pos (point-max)) insert)))\r
- (removed\r
- `((1 ,(line-number-at-pos (point-max)) delete)))))))\r
+ (let ((state (vc-state file backend)))\r
+ (cond\r
+ ((or (eq state 'edited)\r
+ (and (eq state 'up-to-date)\r
+ ;; VC state is stale in after-revert-hook.\r
+ revert-buffer-in-progress-p))\r
+ (let* ((buf-name " *diff-hl* ")\r
+ res)\r
+ (diff-hl-with-diff-switches\r
+ (vc-call-backend backend 'diff (list file) nil nil buf-name))\r
+ (with-current-buffer buf-name\r
+ (goto-char (point-min))\r
+ (unless (eobp)\r
+ (diff-beginning-of-hunk t)\r
+ (while (looking-at diff-hunk-header-re-unified)\r
+ (let ((line (string-to-number (match-string 3)))\r
+ (len (let ((m (match-string 4)))\r
+ (if m (string-to-number m) 1)))\r
+ (beg (point)))\r
+ (diff-end-of-hunk)\r
+ (let* ((inserts (diff-count-matches "^\\+" beg (point)))\r
+ (deletes (diff-count-matches "^-" beg (point)))\r
+ (type (cond ((zerop deletes) 'insert)\r
+ ((zerop inserts) 'delete)\r
+ (t 'change))))\r
+ (when (eq type 'delete)\r
+ (setq len 1)\r
+ (cl-incf line))\r
+ (push (list line len type) res))))))\r
+ (nreverse res)))\r
+ ((eq state 'added)\r
+ `((1 ,(line-number-at-pos (point-max)) insert)))\r
+ ((eq state 'removed)\r
+ `((1 ,(line-number-at-pos (point-max)) delete))))))))\r
\r
(defun diff-hl-update ()\r
(let ((changes (diff-hl-changes))\r