From e09ef67ea6cf8eb886e177c7b6f05426628632bb Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Tue, 30 Mar 2010 22:32:43 +0100 Subject: [PATCH 01/10] SHA1 gets colour. --- magit.el | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/magit.el b/magit.el index 59430cd1..daaf99e7 100644 --- a/magit.el +++ b/magit.el @@ -3553,6 +3553,7 @@ Prefix arg means justify as well." (define-key map (kbd "M") 'magit-branches-window-automatic-merge) (define-key map (kbd "$") 'magit-display-process) (define-key map (kbd "q") 'magit-quit-branches-window) + (define-key map (kbd "g") 'magit-show-branches) (define-key map (kbd "V") 'magit-show-branches) map)) @@ -3618,16 +3619,53 @@ With prefix force the removal even it it hasn't been merged." "Return t if the branch at point is a remote tracking branch" (> (line-number-at-pos) (or magit-number-local-branches 0))) +(defun magit--branch-view-details (branch-line) + "Extract details from branch -va output." + (string-match (concat + "^\\(\\*? \\{1,2\\}\\)" ; current branch marker (maybe) + "\\(.+?\\) +" ; branch name + + "\\(?:" + "\\([0-9a-fA-F]\\{7\\}\\) " ; sha1 + "\\|\\(->\\)" ; or the pointer to a ref + "\\)" + + "\\(.+\\)" ; message or ref + ) + branch-line) + (let ((res (list (cons 'current (match-string 1 branch-line)) + (cons 'branch (match-string 2 branch-line))))) + (if (match-string 4 branch-line) + (cons (cons 'other-ref (match-string 5 branch-line)) res) + (append + (list + (cons 'sha1 (match-string 3 branch-line)) + (cons 'msg (match-string 5 branch-line))) + res)))) + (defun magit-show-branches () "Show all of the current branches in other-window." (interactive) (save-selected-window (unless (string= (buffer-name) magit-branches-buffer-name) (switch-to-buffer-other-window magit-branches-buffer-name)) - (let ((inhibit-read-only t)) + (let ((inhibit-read-only t) + (branches (mapcar 'magit--branch-view-details + (magit-git-lines "branch" "-va")))) (erase-buffer) - (insert (magit-git-string "branch" "-va")) - (insert "\n")) + (insert + (mapconcat + (lambda (b) + (concat + (cdr (assoc 'current b)) + (propertize (or (cdr (assoc 'sha1 b)) + " ") + 'face 'magit-log-sha1) + " " + (cdr (assoc 'branch b)))) + branches + "\n"))) + (magit-show-branches-mode) (set (make-local-variable 'magit-number-local-branches) (with-temp-buffer From 79d7f46502b064109b02360fc5d5fd15b2df99a7 Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Tue, 30 Mar 2010 22:45:05 +0100 Subject: [PATCH 02/10] Bit more output. --- magit.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/magit.el b/magit.el index daaf99e7..0b617443 100644 --- a/magit.el +++ b/magit.el @@ -3627,7 +3627,7 @@ With prefix force the removal even it it hasn't been merged." "\\(?:" "\\([0-9a-fA-F]\\{7\\}\\) " ; sha1 - "\\|\\(->\\)" ; or the pointer to a ref + "\\|\\(-> \\)" ; or the pointer to a ref "\\)" "\\(.+\\)" ; message or ref @@ -3662,7 +3662,9 @@ With prefix force the removal even it it hasn't been merged." " ") 'face 'magit-log-sha1) " " - (cdr (assoc 'branch b)))) + (cdr (assoc 'branch b)) + (when (assoc 'other-ref b) + (concat " (" (cdr (assoc 'other-ref b)) ")")))) branches "\n"))) From b261669efe6ad7e5f73004f1a546d57dec070568 Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Tue, 30 Mar 2010 22:45:59 +0100 Subject: [PATCH 03/10] Have `magit--branch-name-from-line' pull out the branch name. --- magit.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/magit.el b/magit.el index 0b617443..a3f67698 100644 --- a/magit.el +++ b/magit.el @@ -3569,8 +3569,8 @@ Prefix arg means justify as well." "Extract the branch name from one line of 'git branch' output. Will remove the 'remotes/' prefix if it exists." (save-match-data - (if (string-match "^[[:blank:]]*\\*?[[:blank:]]+\\(remotes/\\)?\\([^[:blank:]]+\\)[[:blank:]]" line) - (match-string 2 line)))) + (if (string-match " \\([^ ]+\\)$" line) + (match-string 1 line)))) (defun magit--branch-name-at-point () "Get the branch name in the line at point." From 1ae36db8910b624f9cd70ea0d84850820eb6257d Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Tue, 30 Mar 2010 23:07:09 +0100 Subject: [PATCH 04/10] Put branch name in text properties. --- magit.el | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/magit.el b/magit.el index a3f67698..1fb8a5d2 100644 --- a/magit.el +++ b/magit.el @@ -3568,9 +3568,7 @@ Prefix arg means justify as well." (defun magit--branch-name-from-line (line) "Extract the branch name from one line of 'git branch' output. Will remove the 'remotes/' prefix if it exists." - (save-match-data - (if (string-match " \\([^ ]+\\)$" line) - (match-string 1 line)))) + (get-text-property 0 'branch-name line)) (defun magit--branch-name-at-point () "Get the branch name in the line at point." @@ -3648,7 +3646,7 @@ With prefix force the removal even it it hasn't been merged." (interactive) (save-selected-window (unless (string= (buffer-name) magit-branches-buffer-name) - (switch-to-buffer-other-window magit-branches-buffer-name)) + (switch-to-buffer-other-window magit-branches-buffer-name)) (let ((inhibit-read-only t) (branches (mapcar 'magit--branch-view-details (magit-git-lines "branch" "-va")))) @@ -3656,15 +3654,17 @@ With prefix force the removal even it it hasn't been merged." (insert (mapconcat (lambda (b) - (concat - (cdr (assoc 'current b)) - (propertize (or (cdr (assoc 'sha1 b)) - " ") - 'face 'magit-log-sha1) - " " - (cdr (assoc 'branch b)) - (when (assoc 'other-ref b) - (concat " (" (cdr (assoc 'other-ref b)) ")")))) + (propertize + (concat + (cdr (assoc 'current b)) + (propertize (or (cdr (assoc 'sha1 b)) + " ") + 'face 'magit-log-sha1) + " " + (cdr (assoc 'branch b)) + (when (assoc 'other-ref b) + (concat " (" (cdr (assoc 'other-ref b)) ")"))) + 'branch-name (cdr (assoc 'branch b)))) branches "\n"))) From a86fab4e977405cf7a9b20cb40c0de2f8f29c22c Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Tue, 30 Mar 2010 23:08:50 +0100 Subject: [PATCH 05/10] n/p now allow the user to move about in branch-view. --- magit.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/magit.el b/magit.el index 1fb8a5d2..89dd5a8e 100644 --- a/magit.el +++ b/magit.el @@ -3555,6 +3555,8 @@ Prefix arg means justify as well." (define-key map (kbd "q") 'magit-quit-branches-window) (define-key map (kbd "g") 'magit-show-branches) (define-key map (kbd "V") 'magit-show-branches) + (define-key map (kbd "n") 'next-line) + (define-key map (kbd "p") 'previous-line) map)) (define-derived-mode magit-show-branches-mode text-mode "Magit Branches") From bf49b72cf0a1a553f061ce0845bbea75524a302d Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Thu, 1 Apr 2010 01:17:09 +0100 Subject: [PATCH 06/10] Removed "remotes" from the branch name. --- magit.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/magit.el b/magit.el index 89dd5a8e..8d15f5be 100644 --- a/magit.el +++ b/magit.el @@ -3623,7 +3623,7 @@ With prefix force the removal even it it hasn't been merged." "Extract details from branch -va output." (string-match (concat "^\\(\\*? \\{1,2\\}\\)" ; current branch marker (maybe) - "\\(.+?\\) +" ; branch name + "\\(?:remotes/\\)?\\(.+?\\) +" ; branch name "\\(?:" "\\([0-9a-fA-F]\\{7\\}\\) " ; sha1 From f735945848334acbd03db40c6d1a61554c94a38e Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Thu, 1 Apr 2010 01:48:28 +0100 Subject: [PATCH 07/10] Fix `magit--is-branch-at-point-remote' --- magit.el | 77 ++++++++++++++++++++++++++------------------------------ 1 file changed, 36 insertions(+), 41 deletions(-) diff --git a/magit.el b/magit.el index 8d15f5be..403b307c 100644 --- a/magit.el +++ b/magit.el @@ -3568,8 +3568,7 @@ Prefix arg means justify as well." (delete-window)) (defun magit--branch-name-from-line (line) - "Extract the branch name from one line of 'git branch' output. -Will remove the 'remotes/' prefix if it exists." + "Extract the branch name from one line of 'git branch' output." (get-text-property 0 'branch-name line)) (defun magit--branch-name-at-point () @@ -3593,7 +3592,7 @@ With prefix force the removal even it it hasn't been merged." (interactive "P") (let ((args (list "branch" (if force "-D" "-d") - (if (magit--is-branch-at-point-remote) "-r") + (when (magit--is-branch-at-point-remote) "-r") (magit--branch-name-at-point)))) (save-excursion (apply 'magit-run-git (remq nil args)) @@ -3612,18 +3611,16 @@ With prefix force the removal even it it hasn't been merged." (magit-show-branches)) (defvar magit-branches-buffer-name "*magit-branches*") -(defvar magit-number-local-branches nil - "Number of local branches for the branches window") (defun magit--is-branch-at-point-remote() "Return t if the branch at point is a remote tracking branch" - (> (line-number-at-pos) (or magit-number-local-branches 0))) + (get-text-property (point) 'remote)) (defun magit--branch-view-details (branch-line) "Extract details from branch -va output." (string-match (concat "^\\(\\*? \\{1,2\\}\\)" ; current branch marker (maybe) - "\\(?:remotes/\\)?\\(.+?\\) +" ; branch name + "\\(remotes/\\)?\\(.+?\\) +" ; branch name "\\(?:" "\\([0-9a-fA-F]\\{7\\}\\) " ; sha1 @@ -3634,48 +3631,46 @@ With prefix force the removal even it it hasn't been merged." ) branch-line) (let ((res (list (cons 'current (match-string 1 branch-line)) - (cons 'branch (match-string 2 branch-line))))) - (if (match-string 4 branch-line) - (cons (cons 'other-ref (match-string 5 branch-line)) res) + (cons 'remote (not (not (match-string 2 branch-line)))) + (cons 'branch (match-string 3 branch-line))))) + (if (match-string 5 branch-line) + (cons (cons 'other-ref (match-string 6 branch-line)) res) (append (list - (cons 'sha1 (match-string 3 branch-line)) - (cons 'msg (match-string 5 branch-line))) + (cons 'sha1 (match-string 4 branch-line)) + (cons 'msg (match-string 6 branch-line))) res)))) (defun magit-show-branches () "Show all of the current branches in other-window." (interactive) - (save-selected-window - (unless (string= (buffer-name) magit-branches-buffer-name) - (switch-to-buffer-other-window magit-branches-buffer-name)) - (let ((inhibit-read-only t) - (branches (mapcar 'magit--branch-view-details - (magit-git-lines "branch" "-va")))) - (erase-buffer) - (insert - (mapconcat - (lambda (b) - (propertize - (concat - (cdr (assoc 'current b)) - (propertize (or (cdr (assoc 'sha1 b)) - " ") - 'face 'magit-log-sha1) - " " - (cdr (assoc 'branch b)) - (when (assoc 'other-ref b) - (concat " (" (cdr (assoc 'other-ref b)) ")"))) - 'branch-name (cdr (assoc 'branch b)))) - branches - "\n"))) - + (unless (string= (buffer-name) magit-branches-buffer-name) + (switch-to-buffer-other-window magit-branches-buffer-name)) + (let ((inhibit-read-only t) + (old-point (point)) + (branches (mapcar 'magit--branch-view-details + (magit-git-lines "branch" "-va")))) + (erase-buffer) + (insert + (mapconcat + (lambda (b) + (propertize + (concat + (cdr (assoc 'current b)) + (propertize (or (cdr (assoc 'sha1 b)) + " ") + 'face 'magit-log-sha1) + " " + (cdr (assoc 'branch b)) + (when (assoc 'other-ref b) + (concat " (" (cdr (assoc 'other-ref b)) ")"))) + 'remote (cdr (assoc 'remote b)) + 'branch-name (cdr (assoc 'branch b)))) + branches + "\n")) (magit-show-branches-mode) - (set (make-local-variable 'magit-number-local-branches) - (with-temp-buffer - (insert (magit-git-string "branch")) - (line-number-at-pos))) - (setq buffer-read-only t))) + (goto-char old-point)) + (setq buffer-read-only t)) (defvar magit-ediff-file) (defvar magit-ediff-windows) From 290d5fe70f47e4502d260c77f52b69ab00787e64 Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Thu, 1 Apr 2010 01:51:43 +0100 Subject: [PATCH 08/10] Comments, removed old-point code which did nothing. --- magit.el | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/magit.el b/magit.el index 403b307c..b0e4d689 100644 --- a/magit.el +++ b/magit.el @@ -3620,7 +3620,7 @@ With prefix force the removal even it it hasn't been merged." "Extract details from branch -va output." (string-match (concat "^\\(\\*? \\{1,2\\}\\)" ; current branch marker (maybe) - "\\(remotes/\\)?\\(.+?\\) +" ; branch name + "\\(remotes/\\)?\\(.+?\\) +" ; is it remote, branch name "\\(?:" "\\([0-9a-fA-F]\\{7\\}\\) " ; sha1 @@ -3647,7 +3647,6 @@ With prefix force the removal even it it hasn't been merged." (unless (string= (buffer-name) magit-branches-buffer-name) (switch-to-buffer-other-window magit-branches-buffer-name)) (let ((inhibit-read-only t) - (old-point (point)) (branches (mapcar 'magit--branch-view-details (magit-git-lines "branch" "-va")))) (erase-buffer) @@ -3668,8 +3667,7 @@ With prefix force the removal even it it hasn't been merged." 'branch-name (cdr (assoc 'branch b)))) branches "\n")) - (magit-show-branches-mode) - (goto-char old-point)) + (magit-show-branches-mode)) (setq buffer-read-only t)) (defvar magit-ediff-file) From db44227cb07548e75ea979add27b4ff6c0988a9f Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Thu, 1 Apr 2010 01:53:35 +0100 Subject: [PATCH 09/10] Use `fundamental-mode' rather than `text-mode' --- magit.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/magit.el b/magit.el index b0e4d689..a67d961f 100644 --- a/magit.el +++ b/magit.el @@ -3559,7 +3559,8 @@ Prefix arg means justify as well." (define-key map (kbd "p") 'previous-line) map)) -(define-derived-mode magit-show-branches-mode text-mode "Magit Branches") +(define-derived-mode magit-show-branches-mode fundamental-mode + "Magit Branches") (defun magit-quit-branches-window () "Bury the branches buffer and delete its window." From e7a3b608e6c0c6276bda6cf4709d190928635384 Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Thu, 1 Apr 2010 01:23:36 +0100 Subject: [PATCH 10/10] Fix `magit--branch-name-at-point'. --- magit.el | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/magit.el b/magit.el index a67d961f..98c1a466 100644 --- a/magit.el +++ b/magit.el @@ -3575,10 +3575,7 @@ Prefix arg means justify as well." (defun magit--branch-name-at-point () "Get the branch name in the line at point." (let ((branch (magit--branch-name-from-line (thing-at-point 'line)))) - (if (or (= (point) (point-max)) - (not branch)) - (error "No branch found in current line")) - branch)) + (or branch (error "No branch at point")))) (defun magit-branches-window-checkout () "Check out the branch in the line at point."