{"thread":{"id":"17985","subject":"[PATCH] git.el: Only show completions from refs/heads, refs/remotes and refs/tags","startedAt":"2009-02-24T08:32:30Z","lastAt":"2009-03-03T14:48:51Z","messageCount":12,"participants":["David Kågedal","Alexandre Julliard"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"106002","messageId":"1235464350-23383-1-git-send-email-davidk@lysator.liu.se","threadId":"17985","inReplyTo":null,"subject":"[PATCH] git.el: Only show completions from refs/heads, refs/remotes and refs/tags","fromName":"David Kågedal","fromEmail":"davidk@lysator.liu.se","sentAt":"2009-02-24T08:32:30Z","receivedAt":"2009-02-24T08:32:30Z","isPatch":true,"sender":{"key":"davidk@lysator.liu.se","avatar":"https://avatars.githubusercontent.com/u/60530?v=4"},"body":"Otherwise it will pick up e.g. lots of irrelevant stuff from\nrefs/bisect, refs/stash or refs/patches (for StGit users).\n\nSigned-off-by: David Kågedal <davidk@lysator.liu.se>\n---\n contrib/emacs/git.el |    5 ++++-\n 1 files changed, 4 insertions(+), 1 deletions(-)\n\ndiff --git a/contrib/emacs/git.el b/contrib/emacs/git.el\nindex feb229c..125e684 100644\n--- a/contrib/emacs/git.el\n+++ b/contrib/emacs/git.el\n@@ -1388,7 +1388,10 @@ With a prefix arg, diff the marked files instead.\"\n (defun git-read-commit-name (prompt &optional default)\n   \"Ask for a commit name, with completion for local branch, remote branch and tag.\"\n   (completing-read prompt\n-                   (list* \"HEAD\" \"ORIG_HEAD\" \"FETCH_HEAD\" (mapcar #'car (git-for-each-ref)))\n+                   (list* \"HEAD\" \"ORIG_HEAD\" \"FETCH_HEAD\"\n+                          (mapcar #'car (git-for-each-ref \"refs/heads\"\n+                                                          \"refs/remotes\"\n+                                                          \"refs/tags\")))\n \t\t   nil nil nil nil default))\n \n (defun git-checkout (branch &optional merge)\n-- \n1.6.2.rc1.21.gda6d\n"},{"id":"106006","messageId":"87fxi4ut2p.fsf@krank.kagedal.org","threadId":"17985","inReplyTo":"1235464350-23383-1-git-send-email-davidk@lysator.liu.se","subject":"Re: [PATCH] git.el: Only show completions from refs/heads, refs/remotes and refs/tags","fromName":"David Kågedal","fromEmail":"davidk@lysator.liu.se","sentAt":"2009-02-24T08:39:42Z","receivedAt":"2009-02-24T08:39:42Z","isPatch":true,"sender":{"key":"davidk@lysator.liu.se","avatar":"https://avatars.githubusercontent.com/u/60530?v=4"},"body":"David Kågedal <davidk@lysator.liu.se> writes:\n\n> Otherwise it will pick up e.g. lots of irrelevant stuff from\n> refs/bisect, refs/stash or refs/patches (for StGit users).\n>\n> Signed-off-by: David Kågedal <davidk@lysator.liu.se>\n> ---\n>  contrib/emacs/git.el |    5 ++++-\n>  1 files changed, 4 insertions(+), 1 deletions(-)\n>\n> diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el\n> index feb229c..125e684 100644\n> --- a/contrib/emacs/git.el\n> +++ b/contrib/emacs/git.el\n> @@ -1388,7 +1388,10 @@ With a prefix arg, diff the marked files instead.\"\n>  (defun git-read-commit-name (prompt &optional default)\n>    \"Ask for a commit name, with completion for local branch, remote branch and tag.\"\n>    (completing-read prompt\n> -                   (list* \"HEAD\" \"ORIG_HEAD\" \"FETCH_HEAD\" (mapcar #'car (git-for-each-ref)))\n> +                   (list* \"HEAD\" \"ORIG_HEAD\" \"FETCH_HEAD\"\n\nSorry, I didn't check this properly. I thought I was fixing inside the\ngit-checkout function, but this is git-read-commit-name which is used\nin more than one place.\n\nBut for git-checkout, I would like to see a much shorter list of named\ncommits, namely those that can be called \"branches\". I'll come up with\na better patch.\n\n> +                          (mapcar #'car (git-for-each-ref \"refs/heads\"\n> +                                                          \"refs/remotes\"\n> +                                                          \"refs/tags\")))\n>  \t\t   nil nil nil nil default))\n>  \n>  (defun git-checkout (branch &optional merge)\n\n-- \nDavid Kågedal\n"},{"id":"106007","messageId":"87d4d8usyd.fsf@krank.kagedal.org","threadId":"17985","inReplyTo":"87fxi4ut2p.fsf@krank.kagedal.org","subject":"Re: [PATCH] git.el: Only show completions from refs/heads, refs/remotes and refs/tags","fromName":"David Kågedal","fromEmail":"davidk@lysator.liu.se","sentAt":"2009-02-24T08:42:18Z","receivedAt":"2009-02-24T08:42:18Z","isPatch":true,"sender":{"key":"davidk@lysator.liu.se","avatar":"https://avatars.githubusercontent.com/u/60530?v=4"},"body":"David Kågedal <davidk@lysator.liu.se> writes:\n\n> David Kågedal <davidk@lysator.liu.se> writes:\n>\n>> Otherwise it will pick up e.g. lots of irrelevant stuff from\n>> refs/bisect, refs/stash or refs/patches (for StGit users).\n>>\n>> Signed-off-by: David Kågedal <davidk@lysator.liu.se>\n>> ---\n>>  contrib/emacs/git.el |    5 ++++-\n>>  1 files changed, 4 insertions(+), 1 deletions(-)\n>>\n>> diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el\n>> index feb229c..125e684 100644\n>> --- a/contrib/emacs/git.el\n>> +++ b/contrib/emacs/git.el\n>> @@ -1388,7 +1388,10 @@ With a prefix arg, diff the marked files instead.\"\n>>  (defun git-read-commit-name (prompt &optional default)\n>>    \"Ask for a commit name, with completion for local branch, remote branch and tag.\"\n>>    (completing-read prompt\n>> -                   (list* \"HEAD\" \"ORIG_HEAD\" \"FETCH_HEAD\" (mapcar #'car (git-for-each-ref)))\n>> +                   (list* \"HEAD\" \"ORIG_HEAD\" \"FETCH_HEAD\"\n>\n> Sorry, I didn't check this properly. I thought I was fixing inside the\n> git-checkout function, but this is git-read-commit-name which is used\n> in more than one place.\n>\n> But for git-checkout, I would like to see a much shorter list of named\n> commits, namely those that can be called \"branches\".\n\n... which means that I would like git-read-commit-name to actually\nwork as its documentation string says it does: \"Ask for a commit name,\nwith completion for local branch, remote branch and tag.\"\n\n-- \nDavid Kågedal\n"},{"id":"106055","messageId":"87ocwrx527.fsf@wine.dyndns.org","threadId":"17985","inReplyTo":"87fxi4ut2p.fsf@krank.kagedal.org","subject":"Re: [PATCH] git.el: Only show completions from refs/heads, refs/remotes and refs/tags","fromName":"Alexandre Julliard","fromEmail":"julliard@winehq.org","sentAt":"2009-02-24T14:50:08Z","receivedAt":"2009-02-24T14:50:08Z","isPatch":true,"sender":{"key":"julliard@winehq.org","avatar":null},"body":"David Kågedal <davidk@lysator.liu.se> writes:\n\n> Sorry, I didn't check this properly. I thought I was fixing inside the\n> git-checkout function, but this is git-read-commit-name which is used\n> in more than one place.\n>\n> But for git-checkout, I would like to see a much shorter list of named\n> commits, namely those that can be called \"branches\". I'll come up with\n> a better patch.\n\nI think it's reasonable to do this for the other uses of\ngit-read-commit-name too, so your original patch looks OK.\n\n-- \nAlexandre Julliard\njulliard@winehq.org\n"},{"id":"106064","messageId":"871vtnvo55.fsf@krank.kagedal.org","threadId":"17985","inReplyTo":"87ocwrx527.fsf@wine.dyndns.org","subject":"Re: [PATCH] git.el: Only show completions from refs/heads, refs/remotes and refs/tags","fromName":"David Kågedal","fromEmail":"davidk@lysator.liu.se","sentAt":"2009-02-24T15:40:54Z","receivedAt":"2009-02-24T15:40:54Z","isPatch":true,"sender":{"key":"davidk@lysator.liu.se","avatar":"https://avatars.githubusercontent.com/u/60530?v=4"},"body":"Alexandre Julliard <julliard@winehq.org> writes:\n\n> David Kågedal <davidk@lysator.liu.se> writes:\n>\n>> Sorry, I didn't check this properly. I thought I was fixing inside the\n>> git-checkout function, but this is git-read-commit-name which is used\n>> in more than one place.\n>>\n>> But for git-checkout, I would like to see a much shorter list of named\n>> commits, namely those that can be called \"branches\". I'll come up with\n>> a better patch.\n>\n> I think it's reasonable to do this for the other uses of\n> git-read-commit-name too, so your original patch looks OK.\n\nActually, I'd like to go one step further. I'm only interested in\nbranches, and only in branches I can commit to. So only asking for\nrefs/heads seems the best solution.\n\nAnd the default parameter to git-read-commit-name is never used, so I\nremoved it.\n\nAnd completing-read works fine with an alist, so the mapcar isn't\nnedded any more.\n\nHere is an updated patch:\n\nFrom: David Kågedal <davidk@lysator.liu.se>\nSubject: [PATCH] git.el: Only show completions from refs/heads\n\nSigned-off-by: David Kågedal <davidk@lysator.liu.se>\n---\n contrib/emacs/git.el |    6 ++----\n 1 files changed, 2 insertions(+), 4 deletions(-)\n\ndiff --git a/contrib/emacs/git.el b/contrib/emacs/git.el\nindex feb229c..d4f8710 100644\n--- a/contrib/emacs/git.el\n+++ b/contrib/emacs/git.el\n@@ -1385,11 +1385,9 @@ With a prefix arg, diff the marked files instead.\"\n         (push (match-string 1) files)))\n     files))\n \n-(defun git-read-commit-name (prompt &optional default)\n+(defun git-read-commit-name (prompt)\n   \"Ask for a commit name, with completion for local branch, remote branch and tag.\"\n-  (completing-read prompt\n-                   (list* \"HEAD\" \"ORIG_HEAD\" \"FETCH_HEAD\" (mapcar #'car (git-for-each-ref)))\n-\t\t   nil nil nil nil default))\n+  (completing-read prompt (git-for-each-ref \"refs/heads\")))\n \n (defun git-checkout (branch &optional merge)\n   \"Checkout a branch, tag, or any commit.\n-- \n1.6.2.rc1.21.gda6d\n\n\n\n-- \nDavid Kågedal\n"},{"id":"106065","messageId":"87fxi3x2es.fsf@wine.dyndns.org","threadId":"17985","inReplyTo":"871vtnvo55.fsf@krank.kagedal.org","subject":"Re: [PATCH] git.el: Only show completions from refs/heads, refs/remotes and refs/tags","fromName":"Alexandre Julliard","fromEmail":"julliard@winehq.org","sentAt":"2009-02-24T15:47:23Z","receivedAt":"2009-02-24T15:47:23Z","isPatch":true,"sender":{"key":"julliard@winehq.org","avatar":null},"body":"David Kågedal <davidk@lysator.liu.se> writes:\n\n> Alexandre Julliard <julliard@winehq.org> writes:\n>\n>> David Kågedal <davidk@lysator.liu.se> writes:\n>>\n>>> Sorry, I didn't check this properly. I thought I was fixing inside the\n>>> git-checkout function, but this is git-read-commit-name which is used\n>>> in more than one place.\n>>>\n>>> But for git-checkout, I would like to see a much shorter list of named\n>>> commits, namely those that can be called \"branches\". I'll come up with\n>>> a better patch.\n>>\n>> I think it's reasonable to do this for the other uses of\n>> git-read-commit-name too, so your original patch looks OK.\n>\n> Actually, I'd like to go one step further. I'm only interested in\n> branches, and only in branches I can commit to. So only asking for\n> refs/heads seems the best solution.\n\nI think that's going too far. It's useful to be able to checkout a tag,\nor to cherry-pick from a remote branch.\n\n-- \nAlexandre Julliard\njulliard@winehq.org\n"},{"id":"106069","messageId":"87y6vvu8sa.fsf@krank.kagedal.org","threadId":"17985","inReplyTo":"87fxi3x2es.fsf@wine.dyndns.org","subject":"Re: [PATCH] git.el: Only show completions from refs/heads, refs/remotes and refs/tags","fromName":"David Kågedal","fromEmail":"davidk@lysator.liu.se","sentAt":"2009-02-24T15:57:57Z","receivedAt":"2009-02-24T15:57:57Z","isPatch":true,"sender":{"key":"davidk@lysator.liu.se","avatar":"https://avatars.githubusercontent.com/u/60530?v=4"},"body":"Alexandre Julliard <julliard@winehq.org> writes:\n\n> David Kågedal <davidk@lysator.liu.se> writes:\n>\n>> Alexandre Julliard <julliard@winehq.org> writes:\n>>\n>>> David Kågedal <davidk@lysator.liu.se> writes:\n>>>\n>>>> Sorry, I didn't check this properly. I thought I was fixing inside the\n>>>> git-checkout function, but this is git-read-commit-name which is used\n>>>> in more than one place.\n>>>>\n>>>> But for git-checkout, I would like to see a much shorter list of named\n>>>> commits, namely those that can be called \"branches\". I'll come up with\n>>>> a better patch.\n>>>\n>>> I think it's reasonable to do this for the other uses of\n>>> git-read-commit-name too, so your original patch looks OK.\n>>\n>> Actually, I'd like to go one step further. I'm only interested in\n>> branches, and only in branches I can commit to. So only asking for\n>> refs/heads seems the best solution.\n>\n> I think that's going too far. It's useful to be able to checkout a tag,\n> or to cherry-pick from a remote branch.\n\nCherry-pick, yes. And checkout, sometimes. My problem is that I have a\ntruckload of remote (svn) branches and that means I can't see the\nobvious checkout candidates for all the noise.\n\nBut add \"refs/remotes\" and \"refs/tags\" to the last patch, and maybe we\nhave a good compromise.\n\n-- \nDavid Kågedal\n"},{"id":"106071","messageId":"87bpsrx1j1.fsf@wine.dyndns.org","threadId":"17985","inReplyTo":"87y6vvu8sa.fsf@krank.kagedal.org","subject":"Re: [PATCH] git.el: Only show completions from refs/heads, refs/remotes and refs/tags","fromName":"Alexandre Julliard","fromEmail":"julliard@winehq.org","sentAt":"2009-02-24T16:06:26Z","receivedAt":"2009-02-24T16:06:26Z","isPatch":true,"sender":{"key":"julliard@winehq.org","avatar":null},"body":"David Kågedal <davidk@lysator.liu.se> writes:\n\n> Cherry-pick, yes. And checkout, sometimes. My problem is that I have a\n> truckload of remote (svn) branches and that means I can't see the\n> obvious checkout candidates for all the noise.\n>\n> But add \"refs/remotes\" and \"refs/tags\" to the last patch, and maybe we\n> have a good compromise.\n\nWe could of course make it customizable...\n\n-- \nAlexandre Julliard\njulliard@winehq.org\n"},{"id":"106101","messageId":"87vdqztvrl.fsf_-_@krank.kagedal.org","threadId":"17985","inReplyTo":"87bpsrx1j1.fsf@wine.dyndns.org","subject":"[PATCH] git.el: Only show completions from refs/heads","fromName":"David Kågedal","fromEmail":"davidk@lysator.liu.se","sentAt":"2009-02-24T20:39:10Z","receivedAt":"2009-02-24T20:39:10Z","isPatch":true,"sender":{"key":"davidk@lysator.liu.se","avatar":"https://avatars.githubusercontent.com/u/60530?v=4"},"body":"Signed-off-by: David Kågedal <davidk@lysator.liu.se>\n---\n\nHere is a version that can to both commit name lookup and branch name\nlookup, and with a configuration parameter that determines how to find\nbranch names to complete on.\n\ncontrib/emacs/git.el |   34 +++++++++++++++++++++++++---------\n 1 files changed, 25 insertions(+), 9 deletions(-)\n\ndiff --git a/contrib/emacs/git.el b/contrib/emacs/git.el\nindex feb229c..a5138d7 100644\n--- a/contrib/emacs/git.el\n+++ b/contrib/emacs/git.el\n@@ -118,6 +118,12 @@ if there is already one that displays the same directory.\"\n   :group 'git\n   :type 'boolean)\n \n+(defcustom git-complete-branch-patterns\n+  '(\"refs/heads\" \"refs/tags\" \"refs/remotes\")\n+  \"Which patterns to use when completing branch names.\"\n+  :group 'git\n+  :type '(repeat string))\n+\n \n (defface git-status-face\n   '((((class color) (background light)) (:foreground \"purple\"))\n@@ -1385,17 +1391,27 @@ With a prefix arg, diff the marked files instead.\"\n         (push (match-string 1) files)))\n     files))\n \n-(defun git-read-commit-name (prompt &optional default)\n-  \"Ask for a commit name, with completion for local branch, remote branch and tag.\"\n-  (completing-read prompt\n-                   (list* \"HEAD\" \"ORIG_HEAD\" \"FETCH_HEAD\" (mapcar #'car (git-for-each-ref)))\n-\t\t   nil nil nil nil default))\n+(defun git-read-commit-name (prompt specials &optional ref-patterns)\n+  \"Ask for a commit name, with completion.\n+If SPECIALS is non-nil, add HEAD and similar names to the list of possible\n+completions. The patterns in REF-PATTERNS are passed to `git-for-each-ref'\n+to get a list of completions.\"\n+  (let ((refs (apply #'git-for-each-ref ref-patterns)))\n+    (completing-read prompt (if specials (list* '(\"HEAD\" . nil)\n+                                                '(\"FETCH_HEAD\" . nil)\n+                                                '(\"ORIG_HEAD\" . nil)\n+                                                refs)\n+                              refs))))\n+\n+(defun git-read-branch-name (prompt)\n+  \"Ask for a branch name, with completion.\"\n+  (git-read-commit-name prompt nil git-complete-branch-patterns))\n \n (defun git-checkout (branch &optional merge)\n   \"Checkout a branch, tag, or any commit.\n Use a prefix arg if git should merge while checking out.\"\n   (interactive\n-   (list (git-read-commit-name \"Checkout: \")\n+   (list (git-read-branch-name \"Checkout: \")\n          current-prefix-arg))\n   (unless git-status (error \"Not in git-status buffer.\"))\n   (let ((args (list branch \"--\")))\n@@ -1405,7 +1421,7 @@ Use a prefix arg if git should merge while checking out.\"\n \n (defun git-branch (branch)\n   \"Create a branch from the current HEAD and switch to it.\"\n-  (interactive (list (git-read-commit-name \"Branch: \")))\n+  (interactive (list (git-read-branch-name \"Branch: \")))\n   (unless git-status (error \"Not in git-status buffer.\"))\n   (if (git-rev-parse (concat \"refs/heads/\" branch))\n       (if (yes-or-no-p (format \"Branch %s already exists, replace it? \" branch))\n@@ -1433,7 +1449,7 @@ amended version of it.\"\n \n (defun git-cherry-pick-commit (arg)\n   \"Cherry-pick a commit.\"\n-  (interactive (list (git-read-commit-name \"Cherry-pick commit: \")))\n+  (interactive (list (git-read-commit-name \"Cherry-pick commit: \" t)))\n   (unless git-status (error \"Not in git-status buffer.\"))\n   (let ((commit (git-rev-parse (concat arg \"^0\"))))\n     (unless commit (error \"Not a valid commit '%s'.\" arg))\n@@ -1452,7 +1468,7 @@ amended version of it.\"\n \n (defun git-revert-commit (arg)\n   \"Revert a commit.\"\n-  (interactive (list (git-read-commit-name \"Revert commit: \")))\n+  (interactive (list (git-read-commit-name \"Revert commit: \" t)))\n   (unless git-status (error \"Not in git-status buffer.\"))\n   (let ((commit (git-rev-parse (concat arg \"^0\"))))\n     (unless commit (error \"Not a valid commit '%s'.\" arg))\n-- \n1.6.2.rc1.21.gda6d\n\n\n-- \nDavid Kågedal\n"},{"id":"106617","messageId":"87prh1tc5y.fsf@wine.dyndns.org","threadId":"17985","inReplyTo":"87vdqztvrl.fsf_-_@krank.kagedal.org","subject":"Re: [PATCH] git.el: Only show completions from refs/heads","fromName":"Alexandre Julliard","fromEmail":"julliard@winehq.org","sentAt":"2009-03-01T16:56:09Z","receivedAt":"2009-03-01T16:56:09Z","isPatch":true,"sender":{"key":"julliard@winehq.org","avatar":null},"body":"David Kågedal <davidk@lysator.liu.se> writes:\n\n> Signed-off-by: David Kågedal <davidk@lysator.liu.se>\n> ---\n>\n> Here is a version that can to both commit name lookup and branch name\n> lookup, and with a configuration parameter that determines how to find\n> branch names to complete on.\n\nWhy do you introduce a separate function for checkouts?  I don't see\nmuch need to have a different set of completions for checkout\nvs. cherry-pick, they both can be used with an arbitrary commit anyway.\n\n-- \nAlexandre Julliard\njulliard@winehq.org\n"},{"id":"106673","messageId":"87zlg4qsfk.fsf@krank.kagedal.org","threadId":"17985","inReplyTo":"87prh1tc5y.fsf@wine.dyndns.org","subject":"Re: [PATCH] git.el: Only show completions from refs/heads","fromName":"David Kågedal","fromEmail":"davidk@lysator.liu.se","sentAt":"2009-03-02T07:45:19Z","receivedAt":"2009-03-02T07:45:19Z","isPatch":true,"sender":{"key":"davidk@lysator.liu.se","avatar":"https://avatars.githubusercontent.com/u/60530?v=4"},"body":"Alexandre Julliard <julliard@winehq.org> writes:\n\n> David Kågedal <davidk@lysator.liu.se> writes:\n>\n>> Signed-off-by: David Kågedal <davidk@lysator.liu.se>\n>> ---\n>>\n>> Here is a version that can to both commit name lookup and branch name\n>> lookup, and with a configuration parameter that determines how to find\n>> branch names to complete on.\n>\n> Why do you introduce a separate function for checkouts?  I don't see\n> much need to have a different set of completions for checkout\n> vs. cherry-pick, they both can be used with an arbitrary commit anyway.\n\nYes, but the typical uses differ a lot. The (overwhelmingly) typical\nuse of checkout is to switch to another branch. The typical use of\ncherry-pick is to pick any commit and not treat branch heads\nspecially.\n\nSo when switching branches, I obviously want a simple way to select\nwhich branch to switch to. When cherry-picking, I would need some\nsimple way of picking any single commit, but that's hard so making it\neasy to pick any named commit is probably the reasonable solution.\n\n-- \nDavid Kågedal\n"},{"id":"106841","messageId":"87tz6aslv0.fsf@wine.dyndns.org","threadId":"17985","inReplyTo":"87zlg4qsfk.fsf@krank.kagedal.org","subject":"Re: [PATCH] git.el: Only show completions from refs/heads","fromName":"Alexandre Julliard","fromEmail":"julliard@winehq.org","sentAt":"2009-03-03T14:48:51Z","receivedAt":"2009-03-03T14:48:51Z","isPatch":true,"sender":{"key":"julliard@winehq.org","avatar":null},"body":"David Kågedal <davidk@lysator.liu.se> writes:\n\n> Yes, but the typical uses differ a lot. The (overwhelmingly) typical\n> use of checkout is to switch to another branch. The typical use of\n> cherry-pick is to pick any commit and not treat branch heads\n> specially.\n>\n> So when switching branches, I obviously want a simple way to select\n> which branch to switch to. When cherry-picking, I would need some\n> simple way of picking any single commit, but that's hard so making it\n> easy to pick any named commit is probably the reasonable solution.\n\nIt sounds like what you want is to customize it independently for each\noperation. That would be better than having two completion functions,\nwhere it's not clear how they differ and why only one can be\ncustomized.\n\n-- \nAlexandre Julliard\njulliard@winehq.org\n"}]}