unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Fabian Ezequiel Gallina <galli.87@gmail.com>
Cc: Emacs-Devel devel <emacs-devel@gnu.org>
Subject: Re: git push/pull
Date: Mon, 07 Dec 2009 23:50:20 -0500	[thread overview]
Message-ID: <jwvein6gk0k.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <9de1a5ef0912061121l2e4645c7q6ff334d57e4ec3bf@mail.gmail.com> (Fabian Ezequiel Gallina's message of "Sun, 6 Dec 2009 16:21:25 -0300")

> Stefan, two diffs are attached in this reply.

Thanks.  See comments below.

>  ;;;###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))))

Please don't (vc-find-backend-function backend 'pull) just to signal
such an error:  vc-call-backend should do it for you already.
More importantly, this has a major shortcoming: it lets the backend
handle all the updating of the vc-dir.  It should instead call the
backend operation in a similar way as what is done with dir-status
(i.e. passing a callback function that's called once per file/directory
that's changed by the pull).

> +(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))

Don't use call-interactively here.  And don't pass arguments implicitly
via global vars.  I.e. this should really be

> +(defun vc-git-push ()
> +  "Update remote refs along with associated objects."
> +  (vc-git--do-push-pull 'push))

Another thing: `setq' is bad.  It's often useful, but better avoid it
when it's not needed.  So rather than

  (let (var1 var2 var3)
    (setq var2 foo2)
    (setq var1 foo1)
    (setq var3 foo3)
    ...)

do

  (let ((var2 foo2)
        (var1 foo1)
        (var3 foo3))
    ...)

Oh, one more: eliminate common-subsexpressions, e.g.:

        (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]+\\).*$")))
=>
        (setq ref-regexp (if (and (not (equal "." current-repo))
                                  (equal vc-git-push-pull-perform 'pull))
                             (concat
                              "^refs/\\(remotes/"
                              (regexp-quote current-repo)
                              "\\|tags\\)/\\([^\n]+\\).*$")
                           (concat
                            "^refs/\\(remotes\\|heads\\|tags\\)/\\("
                            (regexp-quote current-repo)
                            "/[^\n]+\\|[^\n]+\\).*$")))

This change also happens to make it possible to fold this `setq'
directly into the `let' where ref-regexp is declared.

Of course, it could be CSE'd further using `format':

        (setq ref-regexp
              (format (if (and (not (equal "." current-repo))
                               (equal vc-git-push-pull-perform 'pull))
                          "^refs/\\(remotes/%s\\|tags\\)/\\([^\n]+\\).*$"
                        "^refs/\\(remotes\\|heads\\|tags\\)/\\(%s/[^\n]+\\|[^\n]+\\).*$")
                      (regexp-quote current-repo)))


-- Stefan




  parent reply	other threads:[~2009-12-08  4:50 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
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 [this message]
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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=jwvein6gk0k.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=galli.87@gmail.com \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).