all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Fabian Ezequiel Gallina <galli.87@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Emacs-Devel devel <emacs-devel@gnu.org>
Subject: Re: git push/pull
Date: Sun, 6 Dec 2009 16:21:25 -0300	[thread overview]
Message-ID: <9de1a5ef0912061121l2e4645c7q6ff334d57e4ec3bf@mail.gmail.com> (raw)
In-Reply-To: <jwvr5r9pfef.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1101 bytes --]

2009/12/5 Stefan Monnier <monnier@iro.umontreal.ca>:
>> Below is the code, I sure there is a lot of room for improvement since
>> I consider an Emacs LISP newbie myself, but I guess is a good starting
>> point for a better implementation.
>
> I'll let git users decide whether they like your specific choices, but
> what I'd want on my side is to add support for it directly in vc.el
> (i.e. have `vc-push' and `vc-pull' commands which then delegate the
> core of the work to the backends.  You don't have to implement any
> other backend than Git).
>

Stefan, two diffs are attached in this reply.

The first adds vc-pull and vc-push to vc.el. I'm not sure if I'm
missing something in their definitions since I looked at the vc
package very quickly.

The second diff adds vc-git-push and vc-git-pull to vc-git.el. I
modified the how the completions are computed so they render the same
as when you try the git autocompletion from the terminal.

I played around a bit with these changes and seems to work OK.


Regards,
-- 
Fabián E. Gallina
http://www.from-the-cloud.com

[-- Attachment #2: vc.el.diff --]
[-- Type: text/plain, Size: 1603 bytes --]

diff --git a/lisp/vc.el b/lisp/vc.el
index cd9f11b..5519ff6 100644
--- a/lisp/vc.el
+++ b/lisp/vc.el
@@ -884,7 +884,7 @@ Within directories, only files already under version control are noticed."
 				    state-model-only-files)
   "Deduce a set of files and a backend to which to apply an operation.
 
-Return (BACKEND FILESET FILESET-ONLY-FILES STATE CHECKOUT-MODEL).
+Return (BACKEND FILESET FILESET-ONLY-FILES STATE CHECKOUT-MODEL.
 If we're in VC-dir mode, the fileset is the list of marked files.
 Otherwise, if we're looking at a buffer visiting a version-controlled file,
 the fileset is a singleton containing this file.
@@ -1185,6 +1185,26 @@ merge in the changes into your working copy."
 (declare-function vc-dir-move-to-goal-column "vc-dir" ())
 
 ;;;###autoload
+(defun vc-pull ()
+  "Merges changes between branches."
+  (interactive)
+  (vc-ensure-vc-buffer)
+  (let ((backend (vc-backend buffer-file-name)))
+    (if (not (vc-find-backend-function backend 'pull))
+        (error "Sorry, pull is not implemented for %s" backend)
+      (vc-call-backend backend 'pull))))
+
+;;;###autoload
+(defun vc-push ()
+  "Pushes commits to some branch."
+  (interactive)
+  (vc-ensure-vc-buffer)
+  (let ((backend (vc-backend buffer-file-name)))
+    (if (not (vc-find-backend-function backend 'push))
+        (error "Sorry, push is not implemented for %s" backend)
+      (vc-call-backend backend 'push))))
+
+;;;###autoload
 (defun vc-register (&optional set-revision vc-fileset comment)
   "Register into a version control system.
 If VC-FILESET is given, register the files in that fileset.

[-- Attachment #3: vc-git.el.diff --]
[-- Type: text/plain, Size: 3494 bytes --]

diff --git a/lisp/vc-git.el b/lisp/vc-git.el
index a33a0f5..bb95b70 100644
--- a/lisp/vc-git.el
+++ b/lisp/vc-git.el
@@ -489,6 +489,80 @@ If nil, use the value of `vc-diff-switches'.  If t, use no switches."
 
 ;;; STATE-CHANGING FUNCTIONS
 
+(defvar vc-git-push-pull-perform 'pull
+  "The git command `vc-git--do-push-pull' should execute")
+
+(defun vc-git--do-push-pull (repository refspec)
+  "Calls git push/pull with REPOSITORY and REFSPEC as parameters.
+
+The decision of using push or pull is beign made depending the
+value of `vc-git-push-pull-perform'."
+  (interactive
+   (let ((default-refspec (vc-git-working-revision buffer-file-name))
+         (default-repo)
+         (available-repos)
+         (available-refspecs)
+         (current-repo)
+         (current-refspec))
+     (setq available-repos
+           (let ((table (list ".")))
+             (with-temp-buffer
+               (vc-git-command t nil nil "for-each-ref" "--format=%(refname)")
+               (goto-char (point-min))
+               (while (re-search-forward "^refs/remotes/\\([^/]+\\).*$" nil t)
+                 (push (match-string 1) table)))
+             table))
+     (setq default-repo (nth 0 available-repos))
+     (setq current-repo
+           (completing-read (format "Repository (default %s): " default-repo)
+                            available-repos nil 'confirm nil nil default-repo))
+     (setq available-refspecs
+           (let ((table (list "HEAD"))
+                 (ref-regexp))
+             (with-temp-buffer
+               (vc-git-command t nil nil "for-each-ref" "--format=%(refname)")
+               (if (and (not (equal "." current-repo))
+                        (equal vc-git-push-pull-perform 'pull))
+                   (setq ref-regexp (concat
+                                     "^refs/\\(remotes/"
+                                     (regexp-quote current-repo)
+                                     "\\|tags\\)/\\([^\n]+\\).*$"))
+                 (setq ref-regexp (concat
+                                   "^refs/\\(remotes\\|heads\\|tags\\)/\\("
+                                   (regexp-quote current-repo)
+                                   "/[^\n]+\\|[^\n]+\\).*$")))
+               (goto-char (point-min))
+               (while (re-search-forward
+                       ref-regexp
+                       nil t)
+                 (push (match-string 2) table)))
+             table))
+     (setq current-refspec
+           (completing-read (format "Branch (default %s): " default-refspec)
+                            available-refspecs nil 'confirm nil nil
+                            default-refspec))
+     (list current-repo current-refspec)))
+  (let ((buffer (current-buffer))
+        (command-buffer-name "*vc-push-pull*"))
+    (vc-git-command
+     command-buffer-name 0 nil
+     (prin1-to-string vc-git-push-pull-perform) repository refspec)
+    (set-buffer command-buffer-name)
+    (message (buffer-string))
+    (set-buffer buffer)))
+
+(defun vc-git-push ()
+  "Update remote refs along with associated objects."
+  (interactive)
+  (setq vc-git-push-pull-perform 'push)
+  (call-interactively 'vc-git--do-push-pull))
+
+(defun vc-git-pull ()
+  "Fetch from and merge with another repository or a local branch."
+  (interactive)
+  (setq vc-git-push-pull-perform 'pull)
+  (call-interactively 'vc-git--do-push-pull))
+
 (defun vc-git-create-repo ()
   "Create a new Git repository."
   (vc-git-command nil 0 nil "init"))

  parent reply	other threads:[~2009-12-06 19:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-05  8:09 git push/pull [was: support for bzr shelve/unshelve in vc-dir] Fabian Ezequiel Gallina
2009-12-05  9:07 ` Andreas Schwab
2009-12-05 16:15 ` git push/pull Stefan Monnier
2009-12-06  3:12   ` Fabian Ezequiel Gallina
2009-12-06 19:21   ` Fabian Ezequiel Gallina [this message]
2009-12-06 20:33     ` Andreas Schwab
2009-12-06 21:13       ` Fabian Ezequiel Gallina
2009-12-06 22:45         ` Andreas Schwab
2009-12-08  4:50     ` Stefan Monnier
2009-12-09 17:19       ` Fabian Ezequiel Gallina

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9de1a5ef0912061121l2e4645c7q6ff334d57e4ec3bf@mail.gmail.com \
    --to=galli.87@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.