         (setq remaining-files (apply #'git-run-ls-files status remaining-files 'unknown "-o"
                                      (concat "--exclude-per-directory=" git-per-dir-ignore-file)
                                      (mapcar (lambda (f) (concat "--exclude-from=" f)) exclude-files)))))
-    ; mark remaining files with the default state (or remove them if nil)
-    (when remaining-files
-      (if default-state
-          (ewoc-map (lambda (info)
-                      (when (member (git-fileinfo->name info) remaining-files)
-                        (git-set-files-state (list info) default-state))
-                      nil)
-                    status)
-        (ewoc-filter status
-                     (lambda (info files)
-                       (not (member (git-fileinfo->name info) files)))
-                     remaining-files)))
+    (git-set-filenames-state status remaining-files default-state)
     (git-refresh-files)
     (git-refresh-ewoc-hf status)))
 

(defun git-run-ls-files (status files default-state &rest options)
  "Run git-ls-files on FILES and parse the results into STATUS.
Return the list of files that haven't been handled."
  (let ((refresh files))
    (with-temp-buffer
      (apply #'git-run-command t nil "ls-files" "-z" "-t" (append options (list "--") files))
      (goto-char (point-min))
      (while (re-search-forward "\\([HMRCK?]\\) \\([^\0]*\\)\0" nil t 1)
        (let ((state (match-string 1))
              (name (match-string 2)))
          (git-insert-fileinfo status (git-create-fileinfo (or (git-state-code state) default-state) name) refresh)
          (setq files (delete name files))))))
  files)

(defun git-run-ls-unmerged (status files)
  "Run git-ls-files -u on FILES and parse the results into STATUS."

                  "  " (git-escape-file-name (git-fileinfo->name info))
                  (git-rename-as-string info))))

(defun git-insert-info-list (status infolist)
  "Insert a list of file infos in the status buffer, replacing existing ones if any."
  (setq infolist (sort infolist
                       (lambda (info1 info2)
                         (string-lessp (git-fileinfo->name info1)
                                       (git-fileinfo->name info2)))))
  (let ((info (pop infolist))
        (node (ewoc-nth status 0)))
    (while info
      (setf (git-fileinfo->needs-refresh info) t)
      (cond ((not node)
             (ewoc-enter-last status info)
             (setq info (pop infolist)))
            ((string-lessp (git-fileinfo->name (ewoc-data node))
                           (git-fileinfo->name info))
             (setq node (ewoc-next status node)))
            ((string-equal (git-fileinfo->name (ewoc-data node))
                           (git-fileinfo->name info))
              ;; preserve the marked flag
              (setf (git-fileinfo->marked info) (git-fileinfo->marked (ewoc-data node)))
              (setf (ewoc-data node) info)
              (setq info (pop infolist)))
            (t
             (ewoc-enter-before status node info)
             (setq info (pop infolist)))))))

(defun git-run-diff-index (status files)
  "Run git-diff-index on FILES and parse the results into STATUS.
Return the list of files that haven't been handled."
  (let (infolist)
    (with-temp-buffer
      (apply #'git-run-command t nil "diff-index" "-z" "-M" "HEAD" "--" files)
      (goto-char (point-min))
