aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/vc
diff options
context:
space:
mode:
authorChong Yidong2011-01-28 22:12:32 -0500
committerChong Yidong2011-01-28 22:12:32 -0500
commit659114fdba7d5ea14541cdc713c7f9745eb93c46 (patch)
tree32cbb5f428dc239902df39d7869377b85e2338fb /lisp/vc
parentbc68bd3998b317499fb5df713470f78fbdf3a78d (diff)
downloademacs-659114fdba7d5ea14541cdc713c7f9745eb93c46.tar.gz
emacs-659114fdba7d5ea14541cdc713c7f9745eb93c46.zip
Rudimentary support for vc-pull and vc-merge in Git and Mercurial.
* lisp/vc/vc.el (vc-pull): Make vc-update an alias for this, instead of the other way around. * lisp/vc/vc-git.el (vc-git-branches, vc-git-pull) (vc-git-merge-branch): New functions. (vc-git-history): New var. * lisp/vc/vc-hg.el (vc-hg-history): New var. (vc-hg-pull): Perform default pull if called via Lisp by vc-pull. (vc-hg-merge-branch): New function.
Diffstat (limited to 'lisp/vc')
-rw-r--r--lisp/vc/vc-dispatcher.el2
-rw-r--r--lisp/vc/vc-git.el51
-rw-r--r--lisp/vc/vc-hg.el47
-rw-r--r--lisp/vc/vc.el4
4 files changed, 91 insertions, 13 deletions
diff --git a/lisp/vc/vc-dispatcher.el b/lisp/vc/vc-dispatcher.el
index 19a276b635c..53b0d9ef8b3 100644
--- a/lisp/vc/vc-dispatcher.el
+++ b/lisp/vc/vc-dispatcher.el
@@ -373,7 +373,7 @@ Display the buffer in some window, but don't select it."
373 (unless (eq (point) (point-min)) 373 (unless (eq (point) (point-min))
374 (insert " \n")) 374 (insert " \n"))
375 (setq new-window-start (point)) 375 (setq new-window-start (point))
376 (insert "Running \"" command " ") 376 (insert "Running \"" command)
377 (dolist (arg args) 377 (dolist (arg args)
378 (insert " " arg)) 378 (insert " " arg))
379 (insert "\"...\n") 379 (insert "\"...\n")
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index c3ffa1fcf46..592fc77e2e3 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -122,6 +122,9 @@ If nil, use the value of `vc-diff-switches'. If t, use no switches."
122(defvar vc-git-commits-coding-system 'utf-8 122(defvar vc-git-commits-coding-system 'utf-8
123 "Default coding system for git commits.") 123 "Default coding system for git commits.")
124 124
125;; History of Git commands.
126(defvar vc-git-history nil)
127
125;;; BACKEND PROPERTIES 128;;; BACKEND PROPERTIES
126 129
127(defun vc-git-revision-granularity () 'repository) 130(defun vc-git-revision-granularity () 'repository)
@@ -526,6 +529,21 @@ or an empty string if none."
526 'help-echo stash-help-echo 529 'help-echo stash-help-echo
527 'face 'font-lock-variable-name-face)))))) 530 'face 'font-lock-variable-name-face))))))
528 531
532(defun vc-git-branches ()
533 "Return the existing branches, as a list of strings.
534The car of the list is the current branch."
535 (with-temp-buffer
536 (call-process "git" nil t nil "branch")
537 (goto-char (point-min))
538 (let (current-branch branches)
539 (while (not (eobp))
540 (when (looking-at "^\\([ *]\\) \\(.+\\)$")
541 (if (string-equal (match-string 1) "*")
542 (setq current-branch (match-string 2))
543 (push (match-string 2) branches)))
544 (forward-line 1))
545 (cons current-branch (nreverse branches)))))
546
529;;; STATE-CHANGING FUNCTIONS 547;;; STATE-CHANGING FUNCTIONS
530 548
531(defun vc-git-create-repo () 549(defun vc-git-create-repo ()
@@ -587,6 +605,39 @@ or an empty string if none."
587 (vc-git-command nil 0 file "reset" "-q" "--") 605 (vc-git-command nil 0 file "reset" "-q" "--")
588 (vc-git-command nil nil file "checkout" "-q" "--"))) 606 (vc-git-command nil nil file "checkout" "-q" "--")))
589 607
608(defun vc-git-pull (prompt)
609 "Pull changes into the current Git branch.
610Normally, this runs \"git pull\".If there is no default
611location from which to pull or update, or if PROMPT is non-nil,
612prompt for the Git command to run."
613 (let* ((root (vc-git-root default-directory))
614 (buffer (format "*vc-git : %s*" (expand-file-name root)))
615 (command "pull")
616 (git-program "git")
617 args)
618 ;; If necessary, prompt for the exact command.
619 (when prompt
620 (setq args (split-string
621 (read-shell-command "Run Git (like this): "
622 "git pull"
623 'vc-git-history)
624 " " t))
625 (setq git-program (car args)
626 command (cadr args)
627 args (cddr args)))
628 (apply 'vc-do-async-command buffer root git-program command args)))
629
630(defun vc-git-merge-branch ()
631 "Merge changes into the current Git branch.
632This prompts for a branch to merge from."
633 (let* ((root (vc-git-root default-directory))
634 (buffer (format "*vc-git : %s*" (expand-file-name root)))
635 (branches (cdr (vc-git-branches)))
636 (merge-source
637 (completing-read "Merge from branch: " branches nil t)))
638 (apply 'vc-do-async-command buffer root "git" "merge"
639 (list merge-source))))
640
590;;; HISTORY FUNCTIONS 641;;; HISTORY FUNCTIONS
591 642
592(defun vc-git-print-log (files buffer &optional shortlog start-revision limit) 643(defun vc-git-print-log (files buffer &optional shortlog start-revision limit)
diff --git a/lisp/vc/vc-hg.el b/lisp/vc/vc-hg.el
index 890d97923bc..8acff1ee2ca 100644
--- a/lisp/vc/vc-hg.el
+++ b/lisp/vc/vc-hg.el
@@ -141,6 +141,8 @@ If nil, use the value of `vc-diff-switches'. If t, use no switches."
141 141
142;;; Properties of the backend 142;;; Properties of the backend
143 143
144(defvar vc-hg-history nil)
145
144(defun vc-hg-revision-granularity () 'repository) 146(defun vc-hg-revision-granularity () 'repository)
145(defun vc-hg-checkout-model (files) 'implicit) 147(defun vc-hg-checkout-model (files) 'implicit)
146 148
@@ -607,16 +609,41 @@ REV is the revision to check out into WORKFILE."
607 (mapcar (lambda (arg) (list "-r" arg)) marked-list))) 609 (mapcar (lambda (arg) (list "-r" arg)) marked-list)))
608 (error "No log entries selected for push")))) 610 (error "No log entries selected for push"))))
609 611
610(defun vc-hg-pull () 612(defun vc-hg-pull (prompt)
611 (interactive) 613 (interactive "P")
612 (let ((marked-list (log-view-get-marked))) 614 (let (marked-list)
613 (if marked-list 615 (if (and (called-interactively-p 'interactive)
614 (apply #'vc-hg-command 616 (setq marked-list (log-view-get-marked)))
615 nil 0 nil 617 (apply #'vc-hg-command
616 "pull" 618 nil 0 nil
617 (apply 'nconc 619 "pull"
618 (mapcar (lambda (arg) (list "-r" arg)) marked-list))) 620 (apply 'nconc
619 (error "No log entries selected for pull")))) 621 (mapcar (lambda (arg) (list "-r" arg))
622 marked-list)))
623 (let* ((root (vc-hg-root default-directory))
624 (buffer (format "*vc-hg : %s*" (expand-file-name root)))
625 (command "pull")
626 (hg-program "hg")
627 ;; Todo: maybe check if we're up-to-date before updating
628 ;; the working copy to the latest state.
629 (args '("-u")))
630 ;; If necessary, prompt for the exact command.
631 (when prompt
632 (setq args (split-string
633 (read-shell-command "Run Hg (like this): " "hg -u"
634 'vc-hg-history)
635 " " t))
636 (setq hg-program (car args)
637 command (cadr args)
638 args (cddr args)))
639 (apply 'vc-do-async-command buffer root hg-program
640 command args)))))
641
642(defun vc-hg-merge-branch ()
643 "Merge incoming changes into the current Mercurial working directory."
644 (let* ((root (vc-hg-root default-directory))
645 (buffer (format "*vc-hg : %s*" (expand-file-name root))))
646 (apply 'vc-do-async-command buffer root "hg" '("merge"))))
620 647
621;;; Internal functions 648;;; Internal functions
622 649
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index 7f11a4b3333..be0f568d304 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -2297,7 +2297,7 @@ depending on the underlying version-control system."
2297(define-obsolete-function-alias 'vc-revert-buffer 'vc-revert "23.1") 2297(define-obsolete-function-alias 'vc-revert-buffer 'vc-revert "23.1")
2298 2298
2299;;;###autoload 2299;;;###autoload
2300(defun vc-update (&optional arg) 2300(defun vc-pull (&optional arg)
2301 "Update the current fileset or branch. 2301 "Update the current fileset or branch.
2302On a distributed version control system, this runs a \"pull\" 2302On a distributed version control system, this runs a \"pull\"
2303operation to update the current branch, prompting for an argument 2303operation to update the current branch, prompting for an argument
@@ -2337,7 +2337,7 @@ tip revision are merged into the working file."
2337 (error "VC update is unsupported for `%s'" backend))))) 2337 (error "VC update is unsupported for `%s'" backend)))))
2338 2338
2339;;;###autoload 2339;;;###autoload
2340(defalias 'vc-pull 'vc-update) 2340(defalias 'vc-update 'vc-pull)
2341 2341
2342(defun vc-version-backup-file (file &optional rev) 2342(defun vc-version-backup-file (file &optional rev)
2343 "Return name of backup file for revision REV of FILE. 2343 "Return name of backup file for revision REV of FILE.