]> git.eshelyaron.com Git - emacs.git/commitdiff
Fixes to gnus-agent-retrieve-headers girzel/gnus-headers
authorEric Abrahamsen <eric@ericabrahamsen.net>
Sun, 17 Jan 2021 02:37:57 +0000 (18:37 -0800)
committerEric Abrahamsen <eric@ericabrahamsen.net>
Sun, 17 Jan 2021 02:37:57 +0000 (18:37 -0800)
* lisp/gnus/gnus-agent.el (gnus-agent-retrieve-headers): The
sort->append call was altering fetched-headers in-place. Also, we
should explicitly sort-numeric-fields in this
function. gnus-agent-check-overview-buffer will do this, but treats it
as a failure mode and will make a backup of the overview file.

lisp/gnus/gnus-agent.el

index 97df48b46082db2e877918ac395069b414c9c048..32d0a85d004dbd241ed8c1c605fa7e4393c2116c 100644 (file)
@@ -3627,7 +3627,7 @@ has been fetched."
          (when fetched-headers
            (setq headers
                  (delete-dups
-                  (sort (append headers fetched-headers)
+                  (sort (append headers (copy-sequence fetched-headers))
                         (lambda (l r)
                           (< (mail-header-number l)
                              (mail-header-number r))))))
@@ -3636,8 +3636,14 @@ has been fetched."
            (let ((coding-system-for-write
                   gnus-agent-file-coding-system))
              (with-current-buffer gnus-agent-overview-buffer
+               ;; We stick the new headers in at the end, then
+               ;; re-sort the whole buffer with
+               ;; `sort-numeric-fields'.  If this turns out to be
+               ;; slow, we could consider a loop to add the headers
+               ;; in sorted order to begin with.
                (goto-char (point-max))
                (mapc #'nnheader-insert-nov fetched-headers)
+               (sort-numeric-fields 1 (point-min) (point-max))
                (gnus-agent-check-overview-buffer)
                (write-region (point-min) (point-max) file nil 'silent)
                (gnus-agent-update-view-total-fetched-for group t)