@matheusbsbs / matheus-bagliano / commits / 21ba0e8435
Fork 0

git.el: Make sure that file lists are sorted as they are created.

This avoids a possibly redundant sort in git-update-status-files and git-status-filenames-map, and allows callers to continue using the list without having to copy it. It also fixes the confusing success messages reported by Brent Goodrick. Signed-off-by: Alexandre Julliard <julliard@winehq.org>

Alexandre Julliard committed Feb 16, 2009 at 11:39 UTC 21ba0e84356cb73faecc4c5bf30df7b2222961d2
1 file changed +16 -13
contrib/emacs/git.el
+16 -13
@@ -530,9 +530,9 @@ Each entry is a cons of (SHORT-NAME . FULL-NAME)."
530 (git-fileinfo->needs-refresh info) t)))
531
532 (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."
535 (when files
535 - (setq files (sort files #'string-lessp))
536 (let ((file (pop files))
537 (node (ewoc-nth status 0)))
538 (while (and file node)
@@ -545,7 +545,7 @@ Each entry is a cons of (SHORT-NAME . FULL-NAME)."
545 (setq file (pop files))))))))
546
547 (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"
549 (when files
550 (git-status-filenames-map status #'git-set-fileinfo-state files state)
551 (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."
750 (let (unmerged-files)
751 (while (re-search-forward "[0-7]\\{6\\} [0-9a-f]\\{40\\} [123]\t\\([^\0]+\\)\0" nil t)
752 (push (match-string 1) unmerged-files))
753 + (setq unmerged-files (nreverse unmerged-files)) ;; assume it is sorted already
754 (git-set-filenames-state status unmerged-files 'unmerged))))
755
756 (defun git-get-exclude-files ()
@@ -770,17 +771,18 @@ Return the list of files that haven't been handled."
771 (append options (mapcar (lambda (f) (concat "--exclude-from=" f)) exclude-files)))))
772
773 (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."
776 (unless git-status (error "Not in git-status buffer."))
777 ;; set the needs-update flag on existing files
776 - (if (setq files (sort files #'string-lessp))
778 + (if files
779 (git-status-filenames-map
780 git-status (lambda (info) (setf (git-fileinfo->needs-update info) t)) files)
781 (ewoc-map (lambda (info) (setf (git-fileinfo->needs-update info) t) nil) git-status)
782 (git-call-process nil "update-index" "--refresh")
783 (when git-show-uptodate
784 (git-run-ls-files-cached git-status nil 'uptodate)))
783 - (let* ((remaining-files
785 + (let ((remaining-files
786 (if (git-empty-db-p) ; we need some special handling for an empty db
787 (git-run-ls-files-cached git-status files 'added)
788 (git-run-diff-index git-status files))))
@@ -825,13 +827,13 @@ Return the list of files that haven't been handled."
827 (list (ewoc-data (ewoc-locate git-status)))))
828
829 (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."
831 (let ((files (git-marked-files))
832 result)
833 (dolist (info files)
834 (when (memq (git-fileinfo->state info) states)
835 (push info result)))
834 - result))
836 + (nreverse result)))
837
838 (defun git-refresh-files ()
839 "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."
1103 (or (not added)
1104 (apply 'git-call-process-display-error "update-index" "--force-remove" "--" added))
1105 (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)
1109 (when ok
1110 (dolist (file modified)
1111 (let ((buffer (get-file-buffer file)))
1112 (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))))))
1114
1115 (defun git-resolve-file ()
1116 "Resolve conflicts in marked file(s)."
@@ -1365,14 +1368,14 @@ Return the list of files that haven't been handled."
1368 (mapconcat #'identity msg "\n"))))
1369
1370 (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."
1372 (let (files)
1373 (with-temp-buffer
1374 (git-call-process t "diff-tree" "-m" "-r" "-z" "--name-only" "--no-commit-id" "--root" commit)
1375 (goto-char (point-min))
1376 (while (re-search-forward "\\([^\0]*\\)\0" nil t 1)
1377 (push (match-string 1) files)))
1375 - files))
1378 + (sort files #'string-lessp)))
1379
1380 (defun git-read-commit-name (prompt &optional default)
1381 "Ask for a commit name, with completion for local branch, remote branch and tag."