Skip to content

Commit

Permalink
Use string-join instead of mapconcat
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsius committed Jun 23, 2024
1 parent be54926 commit 196abe7
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 53 deletions.
5 changes: 2 additions & 3 deletions lisp/git-commit.el
Original file line number Diff line number Diff line change
Expand Up @@ -1235,9 +1235,8 @@ Added to `font-lock-extend-region-functions'."
;; because in repositories have thousands of
;; branches that would be very slow. See #4353.
(format "\\(\\(?:%s\\)\\|\\)\\([^']+\\)"
(mapconcat #'identity
(magit-list-local-branch-names)
"\\|")))
(string-join (magit-list-local-branch-names)
"\\|")))
"\\([^']*\\)"))
(setq-local font-lock-multiline t)
(add-hook 'font-lock-extend-region-functions
Expand Down
6 changes: 2 additions & 4 deletions lisp/magit-apply.el
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,8 @@ adjusted as \"@@ -10,6 +10,7 @@\" and \"@@ -18,6 +19,7 @@\"."
(magit-apply-patch
file args
(concat (oref file header)
(mapconcat #'identity
(magit-apply--adjust-hunk-new-starts
(mapcar #'magit-apply--section-content hunks))
"")))))
(string-join (magit-apply--adjust-hunk-new-starts
(mapcar #'magit-apply--section-content hunks)))))))

(defun magit-apply-hunk (hunk &rest args)
(let ((file (oref hunk parent)))
Expand Down
11 changes: 5 additions & 6 deletions lisp/magit-base.el
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ This is similar to `read-string', but
(let ((parts (nconc (list ,@(mapcar #'cadr clauses))
,(and verbose '(list "[C-g] to abort")))))
(concat ,prompt
(mapconcat #'identity (butlast parts) ", ")
(string-join (butlast parts) ", ")
", or " (car (last parts)) " "))
',(mapcar #'car clauses))
,@(--map `(,(car it) ,@(cddr it)) clauses))
Expand Down Expand Up @@ -816,7 +816,7 @@ ACTION is a member of option `magit-slow-confirm'."
((length= items 1)
(and (magit-y-or-n-p prompt action) items))
((length> items 1)
(and (magit-y-or-n-p (concat (mapconcat #'identity items "\n")
(and (magit-y-or-n-p (concat (string-join items "\n")
"\n\n" prompt-n)
action)
items)))
Expand Down Expand Up @@ -1191,10 +1191,9 @@ Magit."
default-directory)))
(list (tramp-get-method-parameter
vec 'tramp-remote-shell)
(mapconcat #'identity
(tramp-get-method-parameter
vec 'tramp-remote-shell-args)
" "))))))
(string-join (tramp-get-method-parameter
vec 'tramp-remote-shell-args)
" "))))))
,@body)
,@body)))

Expand Down
10 changes: 5 additions & 5 deletions lisp/magit-bookmark.el
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
('undefined
(delq nil (list magit-buffer-typearg magit-buffer-range-hashed))))
(if magit-buffer-diff-files
(concat " -- " (mapconcat #'identity magit-buffer-diff-files " "))
(concat " -- " (string-join magit-buffer-diff-files " "))
"")))

;;;; Revision
Expand All @@ -79,7 +79,7 @@
(format "magit-revision(%s %s)"
(magit-rev-abbrev magit-buffer-revision)
(if magit-buffer-diff-files
(mapconcat #'identity magit-buffer-diff-files " ")
(string-join magit-buffer-diff-files " ")
(magit-rev-format "%s" magit-buffer-revision))))

;;;; Stash
Expand All @@ -93,7 +93,7 @@
(format "magit-stash(%s %s)"
(magit-rev-abbrev magit-buffer-revision)
(if magit-buffer-diff-files
(mapconcat #'identity magit-buffer-diff-files " ")
(string-join magit-buffer-diff-files " ")
(magit-rev-format "%s" magit-buffer-revision))))

(cl-defmethod magit-bookmark--get-child-value
Expand All @@ -112,9 +112,9 @@

(cl-defmethod magit-bookmark-name (&context (major-mode magit-log-mode))
(format "magit-log(%s%s)"
(mapconcat #'identity magit-buffer-revisions " ")
(string-join magit-buffer-revisions " ")
(if magit-buffer-log-files
(concat " -- " (mapconcat #'identity magit-buffer-log-files " "))
(concat " -- " (string-join magit-buffer-log-files " "))
"")))

;;;; Cherry
Expand Down
4 changes: 1 addition & 3 deletions lisp/magit-branch.el
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,7 @@ when using `magit-branch-and-checkout'."
(if magit-completing-read--silent-default
(format "%s (starting at `%s')" prompt choice)
"Name for new branch")
(let ((def (mapconcat #'identity
(cdr (split-string choice "/"))
"/")))
(let ((def (string-join (cdr (split-string choice "/")) "/")))
(and (member choice (magit-list-remote-branch-names))
(not (member def (magit-list-local-branch-names)))
def)))
Expand Down
9 changes: 4 additions & 5 deletions lisp/magit-diff.el
Original file line number Diff line number Diff line change
Expand Up @@ -2002,8 +2002,7 @@ Staging and applying changes is documented in info node
(0)
(1 (concat " in file " (car magit-buffer-diff-files)))
(_ (concat " in files "
(mapconcat #'identity magit-buffer-diff-files
", ")))))))
(string-join magit-buffer-diff-files ", ")))))))
(setq magit-buffer-range-hashed
(and magit-buffer-range (magit-hash-range magit-buffer-range)))
(magit-insert-section (diffbuf)
Expand Down Expand Up @@ -2396,7 +2395,7 @@ section or a child thereof."
(or file orig)))
(format "--- %s\n" (or orig "/dev/null"))
(format "+++ %s\n" (or file "/dev/null")))))
(setq header (mapconcat #'identity header ""))
(setq header (string-join header))
(magit-diff-insert-file-section
file orig status modes rename header binary nil)))))

Expand Down Expand Up @@ -2578,7 +2577,7 @@ Staging and applying changes is documented in info node
(0)
(1 (concat " limited to file " (car magit-buffer-diff-files)))
(_ (concat " limited to files "
(mapconcat #'identity magit-buffer-diff-files ", "))))))
(string-join magit-buffer-diff-files ", "))))))
(magit-insert-section (commitbuf)
(magit-run-section-hook 'magit-revision-sections-hook)))

Expand Down Expand Up @@ -3557,7 +3556,7 @@ last (visual) lines of the region."
(forward-line)))
(let ((buffer-list-update-hook nil)) ; #3759
(with-temp-buffer
(insert (mapconcat #'identity (reverse patch) ""))
(insert (string-join (reverse patch)))
(diff-fixup-modifs (point-min) (point-max))
(setq patch (buffer-string))))
patch))
Expand Down
25 changes: 12 additions & 13 deletions lisp/magit-git.el
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ See info node `(magit)Debugging Tools' for more information."
(arg (and (or (null (car keys))
(string-prefix-p "--" (car keys)))
(pop keys)))
(key (mapconcat #'identity keys ".")))
(key (string-join keys ".")))
(if (and magit--refresh-cache (not arg))
(magit-config-get-from-cached-list key)
(magit-git-items "config" arg "-z" "--get-all" key))))
Expand All @@ -783,7 +783,7 @@ Also see `magit-git-config-p'."
(let ((arg (and (or (null (car keys))
(string-prefix-p "--" (car keys)))
(pop keys)))
(key (mapconcat #'identity keys ".")))
(key (string-join keys ".")))
(equal (if magit--refresh-cache
(car (last (magit-config-get-from-cached-list key)))
(magit-git-str "config" arg "--bool" key))
Expand All @@ -794,7 +794,7 @@ Also see `magit-git-config-p'."
(let ((arg (and (or (null (car keys))
(string-prefix-p "--" (car keys)))
(pop keys)))
(key (mapconcat #'identity keys ".")))
(key (string-join keys ".")))
(if value
(magit-git-success "config" arg key value)
(magit-git-success "config" arg "--unset" key))
Expand All @@ -808,7 +808,7 @@ Also see `magit-git-config-p'."
(let ((arg (and (or (null (car keys))
(string-prefix-p "--" (car keys)))
(pop keys)))
(var (mapconcat #'identity keys ".")))
(var (string-join keys ".")))
(when (magit-get var)
(magit-call-git "config" arg "--unset-all" var))
(dolist (v values)
Expand Down Expand Up @@ -2425,15 +2425,14 @@ and this option only controls what face is used.")
0 (length target) 'magit-branch-upstream nil target)
(setq upstream target)
(setq combined (delete target combined))))))
(mapconcat #'identity
(flatten-tree `(,state
,head
,upstream
,@(nreverse tags)
,@(nreverse combined)
,@(nreverse remotes)
,@other))
" ")))))
(string-join (flatten-tree `(,state
,head
,upstream
,@(nreverse tags)
,@(nreverse combined)
,@(nreverse remotes)
,@other))
" ")))))

(defun magit-object-type (object)
(magit-git-string "cat-file" "-t" object))
Expand Down
4 changes: 2 additions & 2 deletions lisp/magit-log.el
Original file line number Diff line number Diff line change
Expand Up @@ -1156,11 +1156,11 @@ Type \\[magit-reset] to reset `HEAD' to the commit at point.
(defun magit-log-header-line-sentence (revs args files)
"Return string containing all arguments."
(concat "Commits in "
(mapconcat #'identity revs " ")
(string-join revs " ")
(and (member "--reverse" args)
" in reverse")
(and files (concat " touching "
(mapconcat #'identity files " ")))
(string-join files " ")))
(--some (and (string-prefix-p "-L" it)
(concat " " it))
args)))
Expand Down
2 changes: 1 addition & 1 deletion lisp/magit-merge.el
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ If no merge is in progress, do nothing."
(range (magit--merge-range (car heads))))
(magit-insert-section (unmerged range)
(magit-insert-heading
(format "Merging %s:" (mapconcat #'identity heads ", ")))
(format "Merging %s:" (string-join heads ", ")))
(magit--insert-log nil
range
(let ((args magit-buffer-log-args))
Expand Down
6 changes: 3 additions & 3 deletions lisp/magit-process.el
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ and still alive), as well as the respective Magit status buffer.

See `magit-start-process' for more information."
(message "Running %s %s" (magit-git-executable)
(let ((m (mapconcat #'identity (flatten-tree args) " ")))
(let ((m (string-join (flatten-tree args) " ")))
(remove-list-of-text-properties 0 (length m) '(face) m)
m))
(magit-start-git nil args))
Expand Down Expand Up @@ -717,7 +717,7 @@ Magit status buffer."
" "
(propertize (magit--ellipsis)
'font-lock-face 'magit-section-heading
'help-echo (mapconcat #'identity (seq-take args global) " "))
'help-echo (string-join (seq-take args global) " "))
" "
(propertize (mapconcat #'shell-quote-argument (seq-drop args global) " ")
'font-lock-face 'magit-section-heading))))
Expand Down Expand Up @@ -1284,7 +1284,7 @@ Limited by `magit-process-error-tooltip-max-lines'."
(let ((inhibit-message t))
(when heading
(setq lines (cons heading lines)))
(message (mapconcat #'identity lines "\n"))))))
(message (string-join lines "\n"))))))

;;; _
(provide 'magit-process)
Expand Down
4 changes: 1 addition & 3 deletions lisp/magit-reflog.el
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ Type \\[magit-reset] to reset `HEAD' to the commit at point.
command))
(text (if (string= command "commit")
label
(mapconcat #'identity
(delq nil (list command option type))
" "))))
(string-join (delq nil (list command option type)) " "))))
(format "%-16s "
(magit--propertize-face
text (or (cdr (assoc label magit-reflog-labels))
Expand Down
4 changes: 2 additions & 2 deletions lisp/magit-refs.el
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ Type \\[magit-reset] to reset `HEAD' to the commit at point.
(setq magit-refs-show-commit-count nil))
(magit-set-header-line-format
(format "%s %s" magit-buffer-upstream
(mapconcat #'identity magit-buffer-arguments " ")))
(string-join magit-buffer-arguments " ")))
(magit-insert-section (branchbuf)
(magit-run-section-hook 'magit-refs-sections-hook))
(add-hook 'kill-buffer-hook #'magit-preserve-section-visibility-cache))
Expand Down Expand Up @@ -527,7 +527,7 @@ line is inserted at all."
(magit-insert-section (branchdesc branch t)
(magit-insert-heading branch ": " (car desc))
(when (cdr desc)
(insert (mapconcat #'identity (cdr desc) "\n"))
(insert (string-join (cdr desc) "\n"))
(insert "\n\n")))))

(defun magit-insert-tags ()
Expand Down
2 changes: 1 addition & 1 deletion lisp/magit-status.el
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ the status buffer causes this section to disappear again."
(when magit-buffer-diff-files
(insert " -- ")))
(when magit-buffer-diff-files
(insert (mapconcat #'identity magit-buffer-diff-files " ")))
(insert (string-join magit-buffer-diff-files " ")))
(insert ?\n))))

;;;; Reference Headers
Expand Down
2 changes: 1 addition & 1 deletion lisp/magit-submodule.el
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ to recover from making a mistake here, but don't count on it."
(if (cdr modified)
(message "Omitting %s modules with uncommitted changes: %s"
(length modified)
(mapconcat #'identity modified ", "))
(string-join modified ", "))
(message "Omitting module %s, it has uncommitted changes"
(car modified)))
(setq modules (cl-set-difference modules modified :test #'equal))))
Expand Down
2 changes: 1 addition & 1 deletion test/magit-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
(push (buffer-substring-no-properties (point) to) chunks))
(goto-char to)
(< (point) (point-max))))
(let ((result (mapconcat #'identity (nreverse chunks) nil)))
(let ((result (string-join (nreverse chunks))))
(unless raw
(setq result (string-trim result)))
result))))
Expand Down

0 comments on commit 196abe7

Please sign in to comment.