Merge branch 't/upstream/extensions' into t/int/extensions

- fix dep to topgit in core
- remove 'cl runtime dependency
This commit is contained in:
Yann Hodique 2010-07-06 20:43:37 +02:00
commit 71f76c9053
3 changed files with 157 additions and 82 deletions

View file

@ -151,33 +151,32 @@ If USE-CACHE is non nil, use the cached information."
(cdr (assoc 'revision svn-info)))))) (cdr (assoc 'revision svn-info))))))
(defun magit-svn-remote-update () (defun magit-svn-remote-update ()
(interactive)
(when (magit-svn-enabled) (when (magit-svn-enabled)
(magit-run-git-async "svn" "fetch"))) (magit-run-git-async "svn" "fetch")))
(defvar magit-svn-extension-keys (defvar magit-svn-extension-keys
`((,(kbd "N r") . magit-svn-rebase) `((,(kbd "N r") . magit-svn-rebase)
(,(kbd "N c") . magit-svn-dcommit) (,(kbd "N c") . magit-svn-dcommit)
(,(kbd "N f") . magit-svn-find-rev))) (,(kbd "N f") . magit-svn-remote-update)
(,(kbd "N s") . magit-svn-find-rev)))
(easy-menu-define magit-svn-extension-menu (easy-menu-define magit-svn-extension-menu
nil nil
"Git SVN extension menu" "Git SVN extension menu"
'("Git SVN" '("Git SVN"
["Rebase" magit-svn-rebase (magit-svn-enabled)] ["Rebase" magit-svn-rebase (magit-svn-enabled)]
["Fetch" magit-svn-remote-update (magit-svn-enabled)]
["Commit" magit-svn-dcommit (magit-svn-enabled)])) ["Commit" magit-svn-dcommit (magit-svn-enabled)]))
(defvar magit-svn-extension-inserters (defvar magit-svn-extension-inserters
'((:after unpulled-commits (lambda () (magit-insert-svn-unpulled t))) '((:after unpulled-commits (lambda () (magit-insert-svn-unpulled t)))
(:after unpushed-commits (lambda () (magit-insert-svn-unpushed t))))) (:after unpushed-commits (lambda () (magit-insert-svn-unpushed t)))))
(defvar magit-svn-extension-commands
'((remote-update . magit-svn-remote-update)))
(defvar magit-svn-extension (defvar magit-svn-extension
(make-magit-extension :keys magit-svn-extension-keys (make-magit-extension :keys magit-svn-extension-keys
:menu magit-svn-extension-menu :menu magit-svn-extension-menu
:insert magit-svn-extension-inserters :insert magit-svn-extension-inserters
:commands magit-svn-extension-commands
:remote-string 'magit-svn-remote-string)) :remote-string 'magit-svn-remote-string))
(magit-install-extension magit-svn-extension) (magit-install-extension magit-svn-extension)

219
magit.el
View file

@ -151,6 +151,22 @@ after a confirmation."
:group 'magit :group 'magit
:type 'boolean) :type 'boolean)
(defcustom magit-remote-ref-format 'branch-then-remote
"What format to use for autocompleting refs, in pariticular for remotes.
Autocompletion is used by functions like `magit-checkout',
`magit-interactive-rebase' and others which offer branch name
completion.
The value 'name-then-remote means remotes will be of the
form \"name (remote)\", while the value 'remote-slash-name
means that they'll be of the form \"remote/name\". I.e. something that's
listed as \"remotes/upstream/next\" by \"git branch -l -a\"
will be \"upstream/next\"."
:group 'magit
:type '(choice (const :tag "name (remote)" branch-then-remote)
(const :tag "remote/name" remote-slash-branch)))
(defcustom magit-process-connection-type (not (eq system-type 'cygwin)) (defcustom magit-process-connection-type (not (eq system-type 'cygwin))
"Connection type used for the git process. "Connection type used for the git process.
@ -512,12 +528,42 @@ return nil."
(or (magit-get-top-dir default-directory) (or (magit-get-top-dir default-directory)
default-directory))))) default-directory)))))
(defun magit-rev-parse (ref)
"Return the SHA hash for REF."
(magit-git-string "rev-parse" ref))
(defun magit-ref-ambiguous-p (ref)
"Return whether or not REF is ambiguous."
;; If REF is ambiguous, rev-parse just prints errors,
;; so magit-git-string returns nil.
(not (magit-git-string "rev-parse" "--abbrev-ref" ref)))
(defun magit-name-rev (rev) (defun magit-name-rev (rev)
(and rev "Return a human-readable name for REV.
(let ((name (magit-git-string "name-rev" "--name-only" rev))) Unlike git name-rev, this will remove tags/ and remotes/ prefixes
(if (or (not name) (string= name "undefined")) if that can be done unambiguously. In addition, it will filter
rev out revs involving HEAD."
name)))) (when rev
(let ((name (magit-git-string "name-rev" "--no-undefined" "--name-only" rev)))
;; There doesn't seem to be a way of filtering HEAD out from name-rev,
;; so we have to do it manually.
;; HEAD-based names are too transient to allow.
(when (string-match "^\\(.*\\<HEAD\\)\\([~^].*\\|$\\)" name)
(let ((head-ref (match-string 1 name))
(modifier (match-string 2 name)))
;; Sometimes when name-rev gives a HEAD-based name,
;; rev-parse will give an actual branch or remote name.
(setq name (concat (magit-git-string "rev-parse" "--abbrev-ref" head-ref)
modifier))
;; If rev-parse doesn't give us what we want, just use the SHA.
(when (or (null name) (string-match-p "\\<HEAD\\>" name))
(setq name (magit-rev-parse rev)))))
(setq rev (or name rev))
(when (string-match "^\\(?:tags\\|remotes\\)/\\(.*\\)" rev)
(let ((plain-name (match-string 1 rev)))
(unless (magit-ref-ambiguous-p plain-name)
(setq rev plain-name))))
rev)))
(defun magit-put-line-property (prop val) (defun magit-put-line-property (prop val)
(put-text-property (line-beginning-position) (line-beginning-position 2) (put-text-property (line-beginning-position) (line-beginning-position 2)
@ -575,12 +621,20 @@ return nil."
(let ((branch (match-string 1 ref))) (let ((branch (match-string 1 ref)))
(push (cons branch branch) refs))) (push (cons branch branch) refs)))
((string-match "refs/tags/\\(.*\\)" ref) ((string-match "refs/tags/\\(.*\\)" ref)
(push (cons (format "%s (tag)" (match-string 1 ref)) ref) (push (cons (format
(if (eq magit-remote-ref-format 'branch-then-remote)
"%s (tag)" "%s")
(match-string 1 ref))
ref)
refs)) refs))
((string-match "refs/remotes/\\([^/]+\\)/\\(.+\\)" ref) ((string-match "refs/remotes/\\([^/]+\\)/\\(.+\\)" ref)
(push (cons (format "%s (%s)" (push (cons (if (eq magit-remote-ref-format 'branch-then-remote)
(match-string 2 ref) (format "%s (%s)"
(match-string 1 ref)) (match-string 2 ref)
(match-string 1 ref))
(format "%s/%s"
(match-string 1 ref)
(match-string 2 ref)))
ref) ref)
refs)))))) refs))))))
refs)) refs))
@ -1302,8 +1356,7 @@ FUNC should leave point at the end of the modified region"
,doc ,doc
,inter ,inter
(or (run-hook-with-args-until-success (or (run-hook-with-args-until-success
',hook ,@(remove-if (lambda (x) (member x '(&optional &rest))) ',hook ,@(remq '&optional (remq '&rest arglist)))
arglist))
,@instr)))) ,@instr))))
;;; Running commands ;;; Running commands
@ -2464,19 +2517,27 @@ insert a line to tell how to insert more of them"
(or magit-marked-commit (or magit-marked-commit
(error "No commit marked"))) (error "No commit marked")))
(defun magit-remote-branch-name (remote branch)
"Get the name of the branch BRANCH on remote REMOTE"
(if (string= remote ".")
branch
(concat remote "/" branch)))
(magit-define-inserter unpulled-commits (remote branch) (magit-define-inserter unpulled-commits (remote branch)
(when remote (when remote
(magit-git-section 'unpulled (magit-git-section 'unpulled
"Unpulled commits:" 'magit-wash-log "Unpulled commits:" 'magit-wash-log
"log" "--pretty=format:* %H %s" "log" "--pretty=format:* %H %s"
(format "HEAD..%s/%s" remote branch)))) (format "HEAD..%s"
(magit-remote-branch-name remote branch)))))
(magit-define-inserter unpushed-commits (remote branch) (magit-define-inserter unpushed-commits (remote branch)
(when remote (when remote
(magit-git-section 'unpushed (magit-git-section 'unpushed
"Unpushed commits:" 'magit-wash-log "Unpushed commits:" 'magit-wash-log
"log" "--pretty=format:* %H %s" "log" "--pretty=format:* %H %s"
(format "%s/%s..HEAD" remote branch)))) (format "%s..HEAD"
(magit-remote-branch-name remote branch)))))
(defun magit-remote-branch-for (local-branch) (defun magit-remote-branch-for (local-branch)
"Guess the remote branch name that LOCAL-BRANCH is tracking." "Guess the remote branch name that LOCAL-BRANCH is tracking."
@ -2489,52 +2550,62 @@ insert a line to tell how to insert more of them"
(defvar magit-remote-string-hook nil) (defvar magit-remote-string-hook nil)
(defun magit-remote-string (remote) (defun magit-remote-string (remote remote-branch)
(if remote (cond
(concat remote " " (magit-get "remote" remote "url")) ((string= "." remote)
(run-hook-with-args-until-success 'magit-remote-string-hook))) (format "branch %s"
(propertize remote-branch 'face 'magit-branch)))
(defvar magit-refresh-status-hook nil) (remote
(concat
(propertize remote-branch 'face 'magit-branch)
" @ "
remote
" ("
(magit-get "remote" remote "url")
")"))
(t
(run-hook-with-args-until-success 'magit-remote-string-hook))))
(defun magit-refresh-status () (defun magit-refresh-status ()
(magit-create-buffer-sections (magit-create-buffer-sections
(magit-with-section 'status nil (magit-with-section 'status nil
(let* ((branch (magit-get-current-branch)) (let* ((branch (magit-get-current-branch))
(remote (and branch (magit-get "branch" branch "remote"))) (remote (and branch (magit-get "branch" branch "remote")))
(remote-string (magit-remote-string remote)) (remote-branch (or (and branch (magit-remote-branch-for branch)) branch))
(head (magit-git-string (remote-string (magit-remote-string remote remote-branch))
"log" "--max-count=1" "--abbrev-commit" "--pretty=oneline")) (head (magit-git-string
(no-commit (not head))) "log" "--max-count=1" "--abbrev-commit" "--pretty=oneline"))
(when remote-string (no-commit (not head)))
(insert "Remote: " remote-string "\n")) (when remote-string
(insert (format "Local: %s %s\n" (insert "Remote: " remote-string "\n"))
(propertize (or branch "(detached)") (insert (format "Local: %s %s\n"
'face 'magit-branch) (propertize (or branch "(detached)")
(abbreviate-file-name default-directory))) 'face 'magit-branch)
(insert (format "Head: %s\n" (abbreviate-file-name default-directory)))
(if no-commit "nothing commited (yet)" head))) (insert (format "Head: %s\n"
(let ((merge-heads (magit-file-lines ".git/MERGE_HEAD"))) (if no-commit "nothing commited (yet)" head)))
(if merge-heads (let ((merge-heads (magit-file-lines ".git/MERGE_HEAD")))
(insert (format "Merging: %s\n" (if merge-heads
(magit-concat-with-delim (insert (format "Merging: %s\n"
", " (magit-concat-with-delim
(mapcar 'magit-name-rev merge-heads)))))) ", "
(let ((rebase (magit-rebase-info))) (mapcar 'magit-name-rev merge-heads))))))
(if rebase (let ((rebase (magit-rebase-info)))
(insert (apply 'format "Rebasing: %s (%s of %s)\n" rebase)))) (if rebase
(insert "\n") (insert (apply 'format "Rebasing: %s (%s of %s)\n" rebase))))
(magit-git-exit-code "update-index" "--refresh") (insert "\n")
(magit-insert-untracked-files) (magit-git-exit-code "update-index" "--refresh")
(magit-insert-stashes) (magit-insert-untracked-files)
(magit-insert-pending-changes) (magit-insert-stashes)
(magit-insert-pending-commits) (magit-insert-pending-changes)
(magit-insert-unpulled-commits remote branch) (magit-insert-pending-commits)
(let ((staged (or no-commit (magit-anything-staged-p)))) (magit-insert-unpulled-commits remote remote-branch)
(magit-insert-unstaged-changes (let ((staged (or no-commit (magit-anything-staged-p))))
(if staged "Unstaged changes:" "Changes:")) (magit-insert-unstaged-changes
(magit-insert-staged-changes staged no-commit)) (if staged "Unstaged changes:" "Changes:"))
(magit-insert-unpushed-commits remote branch) (magit-insert-staged-changes staged no-commit))
(run-hooks 'magit-refresh-status-hook))))) (magit-insert-unpushed-commits remote remote-branch)
(run-hooks 'magit-refresh-status-hook)))))
(defun magit-init (dir) (defun magit-init (dir)
"Initialize git repository in the DIR directory." "Initialize git repository in the DIR directory."
@ -2648,7 +2719,9 @@ With prefix argument, add remaining untracked files as well.
tracking brach name suggesting a sensible default." tracking brach name suggesting a sensible default."
(when (yes-or-no-p (when (yes-or-no-p
(format "Create local tracking branch for %s? " branch)) (format "Create local tracking branch for %s? " branch))
(let* ((default-name (concat remote "-" branch)) (let* ((default-name (concat remote
"-"
(replace-regexp-in-string "[/]" "-" branch)))
(chosen-name (read-string (format "Call local branch (%s): " default-name) (chosen-name (read-string (format "Call local branch (%s): " default-name)
nil nil
nil nil
@ -2874,7 +2947,7 @@ Uncomitted changes in both working tree and staging area are lost.
(error "You have uncommitted changes")) (error "You have uncommitted changes"))
(or (not (magit-read-rewrite-info)) (or (not (magit-read-rewrite-info))
(error "Rewrite in progress")) (error "Rewrite in progress"))
(let* ((orig (magit-git-string "rev-parse" "HEAD")) (let* ((orig (magit-rev-parse "HEAD"))
(base (or (car (magit-commit-parents from)) (base (or (car (magit-commit-parents from))
(error "Can't rewrite a commit without a parent, sorry"))) (error "Can't rewrite a commit without a parent, sorry")))
(pending (magit-git-lines "rev-list" (concat base "..")))) (pending (magit-git-lines "rev-list" (concat base ".."))))
@ -2890,7 +2963,7 @@ Uncomitted changes in both working tree and staging area are lost.
(when (or noconfirm (when (or noconfirm
(yes-or-no-p "Stop rewrite? ")) (yes-or-no-p "Stop rewrite? "))
(magit-write-rewrite-info nil) (magit-write-rewrite-info nil)
(magit-need-refresh)))) (magit-refresh))))
(defun magit-rewrite-abort () (defun magit-rewrite-abort ()
(interactive) (interactive)
@ -2936,7 +3009,6 @@ prefix arg is given. With prefix arg, prompt for a remote and
update it." update it."
(interactive (list (when current-prefix-arg (magit-read-remote)))) (interactive (list (when current-prefix-arg (magit-read-remote))))
(cond (cond
((magit-svn-enabled) (magit-run-git-async "svn" "fetch"))
(remote (magit-run-git-async "fetch" remote)) (remote (magit-run-git-async "fetch" remote))
(t (magit-run-git-async "remote" "update")))) (t (magit-run-git-async "remote" "update"))))
@ -3037,8 +3109,7 @@ Prefix arg means justify as well."
(define-derived-mode magit-log-edit-mode text-mode "Magit Log Edit" (define-derived-mode magit-log-edit-mode text-mode "Magit Log Edit"
(set (make-local-variable 'fill-paragraph-function) (set (make-local-variable 'fill-paragraph-function)
'magit-log-fill-paragraph) 'magit-log-fill-paragraph))
(run-mode-hooks 'magit-log-edit-mode-hook))
(defun magit-log-edit-cleanup () (defun magit-log-edit-cleanup ()
(save-excursion (save-excursion
@ -3686,7 +3757,7 @@ level commits."
(dolist (branch branches) (dolist (branch branches)
(let* ((name (car branch)) (let* ((name (car branch))
(ref (cdr branch)) (ref (cdr branch))
(hash (magit-git-string "rev-parse" ref)) (hash (magit-rev-parse ref))
(reported-branch (gethash hash reported))) (reported-branch (gethash hash reported)))
(unless (or (and reported-branch (unless (or (and reported-branch
(string= (file-name-nondirectory ref) (string= (file-name-nondirectory ref)
@ -3930,6 +4001,7 @@ Return values:
(defvar magit-show-branches-mode-map (defvar magit-show-branches-mode-map
(let ((map (make-sparse-keymap))) (let ((map (make-sparse-keymap)))
(define-key map (kbd "RET") 'magit-branches-window-checkout)
(define-key map (kbd "b") 'magit-branches-window-checkout) (define-key map (kbd "b") 'magit-branches-window-checkout)
(define-key map (kbd "k") 'magit-remove-branch) (define-key map (kbd "k") 'magit-remove-branch)
(define-key map (kbd "m") 'magit-branches-window-manual-merge) (define-key map (kbd "m") 'magit-branches-window-manual-merge)
@ -3953,12 +4025,7 @@ Return values:
(defun magit--branch-name-from-line (line) (defun magit--branch-name-from-line (line)
"Extract the branch name from line LINE of 'git branch' output." "Extract the branch name from line LINE of 'git branch' output."
(let ((branch (get-text-property 0 'branch-name line))) (get-text-property 0 'branch-name line))
(if (and branch
(get-text-property 0 'remote line)
(string-match-p "^remotes/" branch))
(substring branch 8)
branch)))
(defun magit--branch-name-at-point () (defun magit--branch-name-at-point ()
"Get the branch name in the line at point." "Get the branch name in the line at point."
@ -3972,6 +4039,12 @@ Return values:
(save-excursion (save-excursion
(magit-show-branches))) (magit-show-branches)))
(defun magit-remove-remote (ref)
"Return REF with any remote part removed."
(if (string-match "^remotes/" ref)
(substring ref 8)
ref))
(defun magit-remove-branch (&optional force) (defun magit-remove-branch (&optional force)
"Remove the branch in the line at point. "Remove the branch in the line at point.
With prefix force the removal even it it hasn't been merged." With prefix force the removal even it it hasn't been merged."
@ -3979,7 +4052,9 @@ With prefix force the removal even it it hasn't been merged."
(let ((args (list "branch" (let ((args (list "branch"
(if force "-D" "-d") (if force "-D" "-d")
(when (magit--is-branch-at-point-remote) "-r") (when (magit--is-branch-at-point-remote) "-r")
(magit--branch-name-at-point)))) ;; remove the remotes part
(magit-remove-remote
(magit--branch-name-at-point)))))
(save-excursion (save-excursion
(apply 'magit-run-git (remq nil args)) (apply 'magit-run-git (remq nil args))
(magit-show-branches)))) (magit-show-branches))))

View file

@ -500,7 +500,8 @@ local branch. Deleting works for both local and remote branches.
You can merge the branch in the current line by typing @kbd{m} for a You can merge the branch in the current line by typing @kbd{m} for a
manual merge and @kbd{M} for an automatic merge. manual merge and @kbd{M} for an automatic merge.
With @kbd{b} you can check out the branch in the current line. With @kbd{RET} or @kbd{b} you can check out the branch in the current
line.
Typing @kbd{$} shows the @code{*magit-process*} buffer which contains Typing @kbd{$} shows the @code{*magit-process*} buffer which contains
the transcript of the most recent command. the transcript of the most recent command.
@ -678,13 +679,13 @@ Magit shows them in a section called @emph{Unpulled changes}. Typing
@node Interfacing with Subversion @node Interfacing with Subversion
@chapter Interfacing with Subversion @chapter Interfacing with Subversion
Typing @kbd{N r} runs @code{git svn rebase} and typing @kbd{N c} runs Typing @kbd{N r} runs @code{git svn rebase}, typing @kbd{N c} runs
@code{git svn dcommit}. @code{git svn dcommit} and typing @kbd{N f} runs @code{git svn fetch}.
@kbd{N f} will prompt you for a (numeric, Subversion) revision and @kbd{N s} will prompt you for a (numeric, Subversion) revision and
then search for a corresponding Git sha1 for the commit. This is then search for a corresponding Git sha1 for the commit. This is
limited to the path of the remote Subversion repository. With a prefix limited to the path of the remote Subversion repository. With a prefix
(@kbd{C-u N f} the user will also be prompted for a branch to search (@kbd{C-u N s} the user will also be prompted for a branch to search
in. in.
@node Using Git Directly @node Using Git Directly