git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Fix file mark handling and sort side-effects in git.el

From
Brent Goodrick <bgoodr@gmail.com>
Date
Feb 11, 2009, 06:12 UTC
Message-ID
<18834.27724.991388.339214@hungover.brentg.com>

The `sort' Elisp function works destructively, causing anomalies where operations on multiple files would be performed on one file. This checkin works around that by doing a deep copy with `append'.

Also, git-add-file needed to pass 'modified to git-marked-files-state, as otherwise, files that are modified but not yet in the index would not show up in the git-marked-files-state return value, which would then cause a prompt for file to show up when the files are clearly marked in the status buffer.

Signed-off-by: Brent Goodrick <bgoodr@gmail.com>
---
 contrib/emacs/git.el |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index fcbe2d9..93e47c1 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -532,7 +532,7 @@ Each entry is a cons of (SHORT-NAME . FULL-NAME)."
 (defun git-status-filenames-map (status func files &rest args)
   "Apply FUNC to the status files names in the FILES list."
   (when files
-    (setq files (sort files #'string-lessp))
+    (setq files (sort (append files nil) #'string-lessp))
     (let ((file (pop files))
           (node (ewoc-nth status 0)))
       (while (and file node)
@@ -773,7 +773,7 @@ Return the list of files that haven't been handled."
   "Update the status of FILES from the index."
   (unless git-status (error "Not in git-status buffer."))
   ;; set the needs-update flag on existing files
-  (if (setq files (sort files #'string-lessp))
+  (if (setq files (sort (append files nil) #'string-lessp))
       (git-status-filenames-map
        git-status (lambda (info) (setf (git-fileinfo->needs-update info) t)) files)
     (ewoc-map (lambda (info) (setf (git-fileinfo->needs-update info) t) nil) git-status)
@@ -1041,7 +1041,7 @@ Return the list of files that haven't been handled."
 (defun git-add-file ()
   "Add marked file(s) to the index cache."
   (interactive)
-  (let ((files (git-get-filenames (git-marked-files-state 'unknown 'ignored))))
+  (let ((files (git-get-filenames (git-marked-files-state 'modified 'unknown 'ignored))))
     ;; FIXME: add support for directories
     (unless files
       (push (file-relative-name (read-file-name "File to add: " nil nil t)) files))
-- 
1.6.2.rc0.10.gf6b9.dirty
Next: Alexandre Julliard
Message 1 of 7 in “Fix file mark handling and sort side-effects in git.el”
  1. Fix file mark handling and sort side-effects in git.elBrent Goodrick, Feb 11, 2009
  2. Alexandre JulliardFeb 11, 2009
  3. Brent GoodrickFeb 12, 2009
  4. Alexandre JulliardFeb 15, 2009
  5. Brent GoodrickFeb 15, 2009
  6. Alexandre JulliardFeb 15, 2009
  7. Brent GoodrickFeb 16, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.