git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 01/03] Add helper function for branch tag and commitish to git.el

From
AJAlexandre Julliard <julliard@winehq.org>
Date
Feb 17, 2008, 18:30 UTC
Message-ID
<87wsp34er9.fsf@wine.dyndns.org>
In-Reply-To
<87ejbcu2gb.dlv_-_@maison.homelinux.org>
Rémi Vanicat <vanicat@debian.org> writes:
Show 16 quoted lines
> +(defun git-list-branches (&optional all)
> +  "Return an alist of available branches
> +if all is non-nil, return all branch, otherwise only local one
> +cdr of assoc is non-nil for the current branch
> +nil otherwise"
> +  (let ((branches ()))
> +    (with-temp-buffer
> +      (if all
> +	  (git-run-command-buffer (current-buffer) "branch" "-a")
> +	  (git-run-command-buffer (current-buffer) "branch"))
> +      (goto-char (point-min))
> +      (while (re-search-forward "^\\([ *]\\) \\([^\n]*\\)$" () t)
> +	(push (cons (match-string 2)
> +		    (string= (match-string 1) "*"))
> +	      branches)))
> +    (nreverse branches)))

git-run-command-buffer isn't really what you want to use here, look at how other functions that use a temp-buffer do it. Also that alist thing is ugly, there are better ways of finding the current branch if we need it. Besides, you probably want to use git-for-each-ref instead of git-branch, git-branch is a bit too porcelainish IMO.

-- 
Alexandre Julliard
julliard@winehq.org
Previous: Rémi VanicatNext: Rémi Vanicat
Message 10 of 14 in “Add function to checkout a branch in git.el”
  1. Add function to checkout a branch in git.el=?utf-8?q?R=C3=A9mi=20Vanicat?=, Feb 13, 2008
  2. Karl HasselströmFeb 13, 2008
  3. Karl HasselströmFeb 13, 2008
  4. Remi VanicatFeb 13, 2008
  5. Sergei OrganovFeb 13, 2008
  6. Karl HasselströmFeb 13, 2008
  7. Sergei OrganovFeb 14, 2008
  8. switching and creating branch, merging and rebasing with Emacs=?utf-8?q?R=C3=A9mi=20Vanicat?=, Feb 16, 2008
  9. 01/03 Add helper function for branch tag and commitish to git.elRémi Vanicat, Feb 16, 2008
  10. Alexandre JulliardFeb 17, 2008
  11. 02/03 Adding checkout function for commitish in git.elRémi Vanicat, Feb 16, 2008
  12. Alexandre JulliardFeb 17, 2008
  13. 03/03 Adding command for merging in git.elRémi Vanicat, Feb 16, 2008
  14. Sergei OrganovFeb 13, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.