{"thread":{"id":"38821","subject":"[PATCH] show-branch: show all local heads when only giving one rev along --topics","startedAt":"2015-03-16T08:38:06Z","lastAt":"2015-03-16T23:50:48Z","messageCount":2,"participants":["Mike Hommey"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"257774","messageId":"1426495086-31507-1-git-send-email-mh@glandium.org","threadId":"38821","inReplyTo":null,"subject":"[PATCH] show-branch: show all local heads when only giving one rev along --topics","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2015-03-16T08:38:06Z","receivedAt":"2015-03-16T08:38:06Z","isPatch":true,"sender":{"key":"mh@glandium.org","avatar":"https://avatars.githubusercontent.com/u/1038527?v=4"},"body":"\"git show-branch --topics <rev> <revs>...\" displays ancestry graph, only\nconsidering commits that are in all given revs, except the first one.\n\n\"git show-branch\" displays ancestry graph for all local branches.\n\nUnfortunately, \"git show-branch --topics <rev>\" only prints out the rev\ninfo for the given rev, and nothing else, e.g.:\n\n  $ git show-branch --topics origin/master\n  [origin/master] Sync with 2.3.3\n\nWhile there is an option to add all remote-tracking branches (-r), and\nanother to add all local+remote branches (-a), there is no option to add\nonly local branches. Adding such an option could be considered, but a\nuser would likely already expect that the above command line considers\nthe lack of rev other than for --topics as meaning all local branches,\nlike when there is no argument at all.\n\nMoreover, when using -r and -a along with --topics, the first local or\nremote-tracking branch, depending on alphabetic order is used instead of\nthe one given after --topics (any rev given on the command line is\nactually simply ignored when either -r or -a is given). And if no rev is\ngiven at all, the fact that the first alphetical branch is the base of\ntopics is probably not expected by users (Maybe --topics should always\nrequire one rev on the command line?)\n\nThis change makes\n  \"show-branch --topics $rev\"\nact as\n  \"show-branch --topics $rev $(git for-each-ref refs/heads\n                               --format='%(refname:short)')\"\n\n  \"show-branch -r --topics $rev ...\"\nact as\n  \"show-branch --topics $rev ... $(git for-each-ref refs/remotes\n                                   --format='%(refname:short)')\"\ninstead of\n  \"show-branch --topics $(git for-each-ref refs/remotes\n                          --format='%(refname:short)')\"\n\nand\n  \"show-branch -a --topics $rev ...\"\nact as\n  \"show-branch --topics $rev ... $(git for-each-ref refs/heads refs/remotes\n                                   --format='%(refname:short)')\"\ninstead of\n  \"show-branch --topics $(git for-each-ref refs/heads refs/remotes\n                          --format='%(refname:short)')\"\n---\n builtin/show-branch.c | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/show-branch.c b/builtin/show-branch.c\nindex 365228a..ef9e719 100644\n--- a/builtin/show-branch.c\n+++ b/builtin/show-branch.c\n@@ -718,7 +718,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t}\n \n \t/* If nothing is specified, show all branches by default */\n-\tif (ac + all_heads + all_remotes == 0)\n+\tif (ac <= topics && all_heads + all_remotes == 0)\n \t\tall_heads = 1;\n \n \tif (reflog) {\n@@ -785,13 +785,13 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t}\n \t\tfree(ref);\n \t}\n-\telse if (all_heads + all_remotes)\n-\t\tsnarf_refs(all_heads, all_remotes);\n \telse {\n \t\twhile (0 < ac) {\n \t\t\tappend_one_rev(*av);\n \t\t\tac--; av++;\n \t\t}\n+\t\tif (all_heads + all_remotes)\n+\t\t\tsnarf_refs(all_heads, all_remotes);\n \t}\n \n \thead_p = resolve_ref_unsafe(\"HEAD\", RESOLVE_REF_READING,\n-- \n2.3.3.3.g6c0eb00\n"},{"id":"257824","messageId":"20150316235048.GA23824@glandium.org","threadId":"38821","inReplyTo":"1426495086-31507-1-git-send-email-mh@glandium.org","subject":"Re: [PATCH] show-branch: show all local heads when only giving one rev along --topics","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2015-03-16T23:50:48Z","receivedAt":"2015-03-16T23:50:48Z","isPatch":true,"sender":{"key":"mh@glandium.org","avatar":"https://avatars.githubusercontent.com/u/1038527?v=4"},"body":"On Mon, Mar 16, 2015 at 05:38:06PM +0900, Mike Hommey wrote:\n> \"git show-branch --topics <rev> <revs>...\" displays ancestry graph, only\n> considering commits that are in all given revs, except the first one.\n> \n> \"git show-branch\" displays ancestry graph for all local branches.\n> \n> Unfortunately, \"git show-branch --topics <rev>\" only prints out the rev\n> info for the given rev, and nothing else, e.g.:\n> \n>   $ git show-branch --topics origin/master\n>   [origin/master] Sync with 2.3.3\n> \n> While there is an option to add all remote-tracking branches (-r), and\n> another to add all local+remote branches (-a), there is no option to add\n> only local branches. Adding such an option could be considered, but a\n> user would likely already expect that the above command line considers\n> the lack of rev other than for --topics as meaning all local branches,\n> like when there is no argument at all.\n> \n> Moreover, when using -r and -a along with --topics, the first local or\n> remote-tracking branch, depending on alphabetic order is used instead of\n> the one given after --topics (any rev given on the command line is\n> actually simply ignored when either -r or -a is given). And if no rev is\n> given at all, the fact that the first alphetical branch is the base of\n> topics is probably not expected by users (Maybe --topics should always\n> require one rev on the command line?)\n> \n> This change makes\n>   \"show-branch --topics $rev\"\n> act as\n>   \"show-branch --topics $rev $(git for-each-ref refs/heads\n>                                --format='%(refname:short)')\"\n> \n>   \"show-branch -r --topics $rev ...\"\n> act as\n>   \"show-branch --topics $rev ... $(git for-each-ref refs/remotes\n>                                    --format='%(refname:short)')\"\n> instead of\n>   \"show-branch --topics $(git for-each-ref refs/remotes\n>                           --format='%(refname:short)')\"\n> \n> and\n>   \"show-branch -a --topics $rev ...\"\n> act as\n>   \"show-branch --topics $rev ... $(git for-each-ref refs/heads refs/remotes\n>                                    --format='%(refname:short)')\"\n> instead of\n>   \"show-branch --topics $(git for-each-ref refs/heads refs/remotes\n>                           --format='%(refname:short)')\"\n\nSorry, this was missing:\nSigned-off-by: Mike Hommey <mh@glandium.org>\n\nMike\n"}]}