@@ -530,9 +530,9 @@ Each entry is a cons of (SHORT-NAME . FULL-NAME)."
530530 (git-fileinfo->needs-refresh info) t )))
531531
532532(defun git-status-filenames-map (status func files &rest args )
533- " Apply FUNC to the status files names in the FILES list."
533+ " Apply FUNC to the status files names in the FILES list.
534+ The list must be sorted."
534535 (when files
535- (setq files (sort files #'string-lessp ))
536536 (let ((file (pop files ))
537537 (node (ewoc-nth status 0 )))
538538 (while (and file node)
@@ -545,7 +545,7 @@ Each entry is a cons of (SHORT-NAME . FULL-NAME)."
545545 (setq file (pop files ))))))))
546546
547547(defun git-set-filenames-state (status files state )
548- " Set the state of a list of named files."
548+ " Set the state of a list of named files. The list must be sorted "
549549 (when files
550550 (git-status-filenames-map status #'git-set-fileinfo-state files state)
551551 (unless state ; ; delete files whose state has been set to nil
@@ -750,6 +750,7 @@ Return the list of files that haven't been handled."
750750 (let (unmerged-files)
751751 (while (re-search-forward " [0-7]\\ {6\\ } [0-9a-f]\\ {40\\ } [123]\t \\ ([^\0 ]+\\ )\0 " nil t )
752752 (push (match-string 1 ) unmerged-files))
753+ (setq unmerged-files (nreverse unmerged-files)) ; ; assume it is sorted already
753754 (git-set-filenames-state status unmerged-files 'unmerged ))))
754755
755756(defun git-get-exclude-files ()
@@ -770,17 +771,18 @@ Return the list of files that haven't been handled."
770771 (append options (mapcar (lambda (f ) (concat " --exclude-from=" f)) exclude-files)))))
771772
772773(defun git-update-status-files (&optional files mark-files )
773- " Update the status of FILES from the index."
774+ " Update the status of FILES from the index.
775+ The FILES list must be sorted."
774776 (unless git-status (error " Not in git-status buffer. " ))
775777 ; ; set the needs-update flag on existing files
776- (if ( setq files ( sort files # 'string-lessp ))
778+ (if files
777779 (git-status-filenames-map
778780 git-status (lambda (info ) (setf (git-fileinfo->needs-update info) t )) files )
779781 (ewoc-map (lambda (info ) (setf (git-fileinfo->needs-update info) t ) nil ) git-status)
780782 (git-call-process nil " update-index" " --refresh" )
781783 (when git-show-uptodate
782784 (git-run-ls-files-cached git-status nil 'uptodate )))
783- (let* ((remaining-files
785+ (let ((remaining-files
784786 (if (git-empty-db-p) ; we need some special handling for an empty db
785787 (git-run-ls-files-cached git-status files 'added )
786788 (git-run-diff-index git-status files ))))
@@ -825,13 +827,13 @@ Return the list of files that haven't been handled."
825827 (list (ewoc-data (ewoc-locate git-status)))))
826828
827829(defun git-marked-files-state (&rest states )
828- " Return marked files that are in the specified states."
830+ " Return a sorted list of marked files that are in the specified states."
829831 (let ((files (git-marked-files))
830832 result)
831833 (dolist (info files )
832834 (when (memq (git-fileinfo->state info) states)
833835 (push info result)))
834- result))
836+ ( nreverse result) ))
835837
836838(defun git-refresh-files ()
837839 " Refresh all files that need it and clear the needs-refresh flag."
@@ -1101,13 +1103,14 @@ Return the list of files that haven't been handled."
11011103 (or (not added)
11021104 (apply 'git-call-process-display-error " update-index" " --force-remove" " --" added))
11031105 (or (not modified)
1104- (apply 'git-call-process-display-error " checkout" " HEAD" modified)))))
1105- (git-update-status-files (append added modified))
1106+ (apply 'git-call-process-display-error " checkout" " HEAD" modified))))
1107+ (names (git-get-filenames files )))
1108+ (git-update-status-files names)
11061109 (when ok
11071110 (dolist (file modified)
11081111 (let ((buffer (get-file-buffer file)))
11091112 (when buffer (with-current-buffer buffer (revert-buffer t t t )))))
1110- (git-success-message " Reverted" (git-get-filenames files ) ))))))
1113+ (git-success-message " Reverted" names ))))))
11111114
11121115(defun git-resolve-file ()
11131116 " Resolve conflicts in marked file(s)."
@@ -1365,14 +1368,14 @@ Return the list of files that haven't been handled."
13651368 (mapconcat #'identity msg " \n " ))))
13661369
13671370(defun git-get-commit-files (commit )
1368- " Retrieve the list of files modified by COMMIT."
1371+ " Retrieve a sorted list of files modified by COMMIT."
13691372 (let (files )
13701373 (with-temp-buffer
13711374 (git-call-process t " diff-tree" " -m" " -r" " -z" " --name-only" " --no-commit-id" " --root" commit)
13721375 (goto-char (point-min ))
13731376 (while (re-search-forward " \\ ([^\0 ]*\\ )\0 " nil t 1 )
13741377 (push (match-string 1 ) files )))
1375- files ))
1378+ ( sort files # 'string-lessp ) ))
13761379
13771380(defun git-read-commit-name (prompt &optional default )
13781381 " Ask for a commit name, with completion for local branch, remote branch and tag."
0 commit comments