From f2da8092e9f49cb669af4c4f6979a8ecac7b7448 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sun, 9 Dec 2018 15:13:31 -0500 Subject: km/magit-branch-backup-current: Tweak prefix meaning --- lisp/km-magit.el | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'lisp/km-magit.el') diff --git a/lisp/km-magit.el b/lisp/km-magit.el index 45b2860..58c8332 100644 --- a/lisp/km-magit.el +++ b/lisp/km-magit.el @@ -173,31 +173,34 @@ START-POINT set to the current branch. (concat it "-tmp"))))) (magit-run-git "checkout" "-b" branch)) -(defun km/magit-branch-backup-current (&optional choose-name) +(defun km/magit-branch-backup-current (&optional choose-suffix) "Create a backup branch for the current branch. -With the prefix argument CHOOSE-NAME, prompt for the name of the -backup branch. Otherwise, name it as 'b/__v', -where is incremented to form a refname that doesn't already -exist." +Name it as 'b/__v', where is incremented +to form a refname that doesn't already exist. With the prefix +argument CHOOSE-SUFFIX, prompt for a suffix to use instead of +'v'." (interactive "P") (let ((current (or (magit-get-current-branch) (user-error "No current branch")))) (magit-run-git "branch" - (if choose-name - (magit-read-string-ns "Backup name" current) - (let* ((version-re (format "\\`%s__v\\([[:digit:]]+\\)\\'" - (regexp-quote current))) - (versions (delq nil - (mapcar - (lambda (s) - (and (string-match version-re s) - (string-to-number - (match-string-no-properties 1 s)))) - (magit-list-local-branch-names))))) - (format "%s__v%d" - current - (if (null versions) 1 (1+ (apply #'max versions))))))))) + (let* ((suffix (if choose-suffix + (magit-read-string-ns "Backup suffix") + "v")) + (version-re (format "\\`%s__%s\\([[:digit:]]+\\)\\'" + (regexp-quote current) + (regexp-quote suffix))) + (versions (delq nil + (mapcar + (lambda (s) + (and (string-match version-re s) + (string-to-number + (match-string-no-properties 1 s)))) + (magit-list-local-branch-names))))) + (format "%s__%s%d" + current + suffix + (if (null versions) 1 (1+ (apply #'max versions)))))))) (defun km/magit-branch-archive (branches) "Move BRANCHES from refs/heads/ to refs/archive/." -- cgit v1.2.3