Fixed svn-ref-info for most non-standard layouts

This commit is contained in:
Alexey Voinov 2010-03-11 13:32:28 +03:00
parent f65dfce86e
commit 4e59fade68

View file

@ -1968,16 +1968,20 @@ in log buffer."
(format "%s/%s..HEAD" remote branch))) (format "%s/%s..HEAD" remote branch)))
(defun magit-insert-unpulled-svn-commits (&optional use-cache) (defun magit-insert-unpulled-svn-commits (&optional use-cache)
(magit-git-section 'svn-unpulled (let ((svn-ref (magit-get-svn-ref use-cache)))
"Unpulled commits (SVN):" 'magit-wash-log (when svn-ref
"log" "--pretty=format:* %H %s" (magit-git-section 'svn-unpulled
(format "HEAD..%s" (magit-get-svn-ref use-cache)))) "Unpulled commits (SVN):" 'magit-wash-log
"log" "--pretty=format:* %H %s"
(format "HEAD..%s" svn-ref)))))
(defun magit-insert-unpushed-svn-commits (&optional use-cache) (defun magit-insert-unpushed-svn-commits (&optional use-cache)
(magit-git-section 'svn-unpushed (let ((svn-ref (magit-get-svn-ref use-cache)))
"Unpushed commits (SVN):" 'magit-wash-log (when svn-ref
"log" "--pretty=format:* %H %s" (magit-git-section 'svn-unpushed
(format "%s..HEAD" (magit-get-svn-ref use-cache)))) "Unpushed commits (SVN):" 'magit-wash-log
"log" "--pretty=format:* %H %s"
(format "%s..HEAD" svn-ref)))))
;;; Status ;;; Status
@ -2241,6 +2245,27 @@ merge will be squashed."
(defun magit-svn-enabled () (defun magit-svn-enabled ()
(not (null (magit-get-svn-ref-info)))) (not (null (magit-get-svn-ref-info))))
(defun magit-get-svn-local-ref (url)
(let ((branches (cons (magit-get "svn-remote" "svn" "fetch")
(magit-get-all "svn-remote" "svn" "branches")))
(base-url (magit-get "svn-remote" "svn" "url"))
(result nil))
(while branches
(let* ((pats (split-string (pop branches) ":"))
(src (replace-regexp-in-string "\\*" "\\\\(.*\\\\)" (car pats)))
(dst (replace-regexp-in-string "\\*" "\\\\1" (cadr pats)))
(base-url (replace-regexp-in-string "\\+" "\\\\+" base-url))
(pat1 (concat "^" src "$"))
(pat2 (cond ((equal src "") (concat "^" base-url "$"))
(t (concat "^" base-url "/" src "$")))))
(cond ((string-match pat1 url)
(setq result (replace-match dst nil nil url))
(setq branches nil))
((string-match pat2 url)
(setq result (replace-match dst nil nil url))
(setq branches nil)))))
result))
(defvar magit-get-svn-ref-info-cache nil (defvar magit-get-svn-ref-info-cache nil
"As `magit-get-svn-ref-info' might be considered a quite "As `magit-get-svn-ref-info' might be considered a quite
expensive operation a cache is taken so that `magit-status' expensive operation a cache is taken so that `magit-status'
@ -2257,31 +2282,35 @@ of `magit-get-svn-ref-info-cache'."
(url) (url)
(revision)) (revision))
(when fetch (when fetch
(setq magit-get-svn-ref-info-cache (let* ((ref (cadr (split-string fetch ":")))
(list (ref-path (file-name-directory ref))
(cons 'ref-path (file-name-directory (trunk-ref-name (file-name-nondirectory ref)))
(cadr (split-string fetch ":")))) (setq magit-get-svn-ref-info-cache
(cons 'trunk-ref-name (file-name-nondirectory (list
(cadr (split-string fetch ":")))) (cons 'ref-path ref-path)
;; get the local ref from the log. This is actually (cons 'trunk-ref-name trunk-ref-name)
;; the way that git-svn does it. ;; get the local ref from the log. This is actually
(cons 'local-ref-name ;; the way that git-svn does it.
(with-temp-buffer (cons 'local-ref
(insert (magit-git-string "log" "--first-parent")) (with-temp-buffer
(goto-char (point-min)) (insert (or (magit-git-string "log" "--first-parent")
(when (re-search-forward "git-svn-id: \\(.+/\\(.+?\\)\\)@\\([0-9]+\\)" nil t) ""))
(setq url (match-string 1) (goto-char (point-min))
revision (match-string 3)) (cond ((re-search-forward "git-svn-id: \\(.+/.+?\\)@\\([0-9]+\\)" nil t)
(match-string 2)))) (setq url (match-string 1)
(cons 'revision revision) revision (match-string 2))
(cons 'url url))))))) (magit-get-svn-local-ref url))
(t
(setq url (magit-get "svn-remote" "svn" "url"))
nil))))
(cons 'revision revision)
(cons 'url url))))))))
(defun magit-get-svn-ref (&optional use-cache) (defun magit-get-svn-ref (&optional use-cache)
"Get the best guess remote ref for the current git-svn based "Get the best guess remote ref for the current git-svn based
branch." branch."
(let ((info (magit-get-svn-ref-info use-cache))) (let ((info (magit-get-svn-ref-info use-cache)))
(concat (cdr (assoc 'ref-path info)) (cdr (assoc 'local-ref info))))
(cdr (assoc 'local-ref-name info)))))
;;; Resetting ;;; Resetting