{"thread":{"id":"43241","subject":"[PATCH] Add --remotes option to show-branch","startedAt":"2006-12-18T14:53:29Z","lastAt":"2006-12-19T18:59:14Z","messageCount":4,"participants":["Brian Gernhardt","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"294121","messageId":"20061218145053.GA5175@178.242.249.10.in-addr.arpa","threadId":"43241","inReplyTo":null,"subject":"[PATCH] Add --remotes option to show-branch","fromName":"Brian Gernhardt","fromEmail":"benji@silverinsanity.com","sentAt":"2006-12-18T14:53:29Z","receivedAt":"2006-12-18T14:53:29Z","isPatch":true,"sender":{"key":"benji@silverinsanity.com","avatar":"https://gravatar.com/avatar/e06c101dbc25c68114d859b4a9ec7cf8a2c52fd2b0270ef0eac0e2e63ff22311?d=mp&s=160"},"body":"We had --heads for refs/heads and --tags for refs/tags, but no easy\nway to specify refs/remotes, which is going to be more common now that\nit's the default layout for clone.\n\nAlso add remotes to --all and update documentation.\n\nSigned-off-by: Brian Gernhardt <benji@silverinsanity.com>\n---\n\n Another patch in my \"features I wasted time looking for\" series.\n I figure that patches are more useful than feature requests, and\n that seems to be proven by the fact my patches are getting applied.\n\n This is my first serious foray into git's C code.  I simply copied\n append_head_ref to get append_remote_ref, since the goal was similar.\n If there are additional checks that would need to be done in there,\n feel free to fix it, or tell me what I should look for.\n\n As a side note, there's no documentation for the --topics option for\n show-branch.  If I figure out what it does, I'll write it, but I'd bet\n someone else already knows and would love to help a neophite git coder\n figure it out.  ;-)\n\n Documentation/git-show-branch.txt |   18 +++++++++---------\n builtin-show-branch.c             |   31 ++++++++++++++++++++++++++-----\n 2 files changed, 35 insertions(+), 14 deletions(-)\n\ndiff --git a/Documentation/git-show-branch.txt b/Documentation/git-show-branch.txt\nindex a2445a4..25136b0 100644\n--- a/Documentation/git-show-branch.txt\n+++ b/Documentation/git-show-branch.txt\n@@ -8,9 +8,9 @@ git-show-branch - Show branches and their commits\n SYNOPSIS\n --------\n [verse]\n-'git-show-branch' [--all] [--heads] [--tags] [--topo-order] [--current]\n+'git-show-branch' [--all] [--heads] [--remotes] [--tags] [--topo-order]\n \t\t[--more=<n> | --list | --independent | --merge-base]\n-\t\t[--no-name | --sha1-name] [<rev> | <glob>]...\n+\t\t[--current] [--no-name | --sha1-name] [<rev> | <glob>]...\n \n DESCRIPTION\n -----------\n@@ -37,14 +37,9 @@ OPTIONS\n \tbranches under $GIT_DIR/refs/heads/topic, giving\n \t`topic/*` would show all of them.\n \n---all --heads --tags::\n+--all --heads --remotes --tags::\n \tShow all refs under $GIT_DIR/refs, $GIT_DIR/refs/heads,\n-\tand $GIT_DIR/refs/tags, respectively.\n-\n---current::\n-\tWith this option, the command includes the current\n-\tbranch to the list of revs to be shown when it is not\n-\tgiven on the command line.\n+\t$GIT_DIR/refs/remotes, and $GIT_DIR/refs/tags, respectively.\n \n --topo-order::\n         By default, the branches and their commits are shown in\n@@ -77,6 +72,11 @@ OPTIONS\n \tAmong the <reference>s given, display only the ones that\n \tcannot be reached from any other <reference>.\n \n+--current::\n+\tWith this option, the command includes the current\n+\tbranch to the list of revs to be shown when it is not\n+\tgiven on the command line.\n+\n --no-name::\n \tDo not show naming strings for each commit.\n \ndiff --git a/builtin-show-branch.c b/builtin-show-branch.c\nindex fb1a400..91251f9 100644\n--- a/builtin-show-branch.c\n+++ b/builtin-show-branch.c\n@@ -6,7 +6,7 @@\n #include \"builtin.h\"\n \n static const char show_branch_usage[] =\n-\"git-show-branch [--sparse] [--current] [--all] [--heads] [--tags] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [<refs>...]\";\n+\"git-show-branch [--sparse] [--current] [--all] [--heads] [--remotes] [--tags] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [<refs>...]\";\n \n static int default_num;\n static int default_alloc;\n@@ -383,6 +383,20 @@ static int append_head_ref(const char *refname, const unsigned char *sha1, int f\n \treturn append_ref(refname + ofs, sha1, flag, cb_data);\n }\n \n+static int append_remote_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)\n+{\n+\tunsigned char tmp[20];\n+\tint ofs = 13;\n+\tif (strncmp(refname, \"refs/remotes/\", ofs))\n+\t\treturn 0;\n+\t/* If both remotes/_/foo and tags/foo exists, get_sha1 would\n+\t * get confused.\n+\t */\n+\tif (get_sha1(refname + ofs, tmp) || hashcmp(tmp, sha1))\n+\t\tofs = 5;\n+\treturn append_ref(refname + ofs, sha1, flag, cb_data);\n+}\n+\n static int append_tag_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)\n {\n \tif (strncmp(refname, \"refs/tags/\", 10))\n@@ -423,13 +437,18 @@ static int append_matching_ref(const char *refname, const unsigned char *sha1, i\n \treturn append_ref(refname, sha1, flag, cb_data);\n }\n \n-static void snarf_refs(int head, int tag)\n+static void snarf_refs(int head, int tag, int remote)\n {\n \tif (head) {\n \t\tint orig_cnt = ref_name_cnt;\n \t\tfor_each_ref(append_head_ref, NULL);\n \t\tsort_ref_range(orig_cnt, ref_name_cnt);\n \t}\n+\tif (remote) {\n+\t\tint orig_cnt = ref_name_cnt;\n+\t\tfor_each_ref(append_remote_ref, NULL);\n+\t\tsort_ref_range(orig_cnt, ref_name_cnt);\n+\t}\n \tif (tag) {\n \t\tint orig_cnt = ref_name_cnt;\n \t\tfor_each_ref(append_tag_ref, NULL);\n@@ -554,7 +573,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \tstruct commit_list *list = NULL, *seen = NULL;\n \tunsigned int rev_mask[MAX_REVS];\n \tint num_rev, i, extra = 0;\n-\tint all_heads = 0, all_tags = 0;\n+\tint all_heads = 0, all_tags = 0, all_remotes;\n \tint all_mask, all_revs;\n \tint lifo = 1;\n \tchar head[128];\n@@ -586,9 +605,11 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t\tbreak;\n \t\t}\n \t\telse if (!strcmp(arg, \"--all\"))\n-\t\t\tall_heads = all_tags = 1;\n+\t\t\tall_heads = all_remotes = all_tags = 1;\n \t\telse if (!strcmp(arg, \"--heads\"))\n \t\t\tall_heads = 1;\n+\t\telse if (!strcmp(arg, \"--remotes\"))\n+\t\t\tall_remotes = 1;\n \t\telse if (!strcmp(arg, \"--tags\"))\n \t\t\tall_tags = 1;\n \t\telse if (!strcmp(arg, \"--more\"))\n@@ -630,7 +651,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\tall_heads = 1;\n \n \tif (all_heads + all_tags)\n-\t\tsnarf_refs(all_heads, all_tags);\n+\t\tsnarf_refs(all_heads, all_tags, all_remotes);\n \twhile (0 < ac) {\n \t\tappend_one_rev(*av);\n \t\tac--; av++;\n-- \n1.4.4.1.GIT\n"},{"id":"298533","messageId":"5D50A3C0-4521-402B-ABD4-5698870A3BD2@silverinsanity.com","threadId":"43241","inReplyTo":"7vfybdvsq7.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Add --remotes option to show-branch","fromName":"Brian Gernhardt","fromEmail":"benji@silverinsanity.com","sentAt":"2006-12-19T05:17:58Z","receivedAt":"2006-12-19T05:17:58Z","isPatch":true,"sender":{"key":"benji@silverinsanity.com","avatar":"https://gravatar.com/avatar/e06c101dbc25c68114d859b4a9ec7cf8a2c52fd2b0270ef0eac0e2e63ff22311?d=mp&s=160"},"body":"\nOn Dec 18, 2006, at 3:45 PM, Junio C Hamano wrote:\n\n> I've never used --heads and --tags myself because\n>\n> \tgit show-branch heads/*\n>         git show-branch tags/*\n>\n> works perfectly well for me, and it often is not very useful to\n> look at _all_ the heads (tags are even much less interesting) in\n> a topic heavy repository anyway.  IOW, I more often do something\n> like:\n>\n> \tgit show-branch --topics master heads/js/*\n>\n> to see what Johannes has relative to \"master\".\n>\n> I actually was thinking about removing these flags, not adding\n> --remotes, because\n>\n> \tgit show-branch remotes/origin/*\n\nI agree that tags/* is fairly useless.  Way too much data.  And if  \nyou want to remote --heads and --tags, then --remotes doesn't have  \nmuch place.  I was simply poking around and thought that if we have  \nthose two, then the third seemed natural and odd to miss.\n\nHowever if --all meant all heads, local or remote, I'd be fairly  \npleased.  heads/* is just as easy as --heads (and leaving it blank is  \neven easier), but --remotes is significantly easier than \"remotes/ \norigin/* remotes/partner/*\".  And sometimes I'd really like to know  \nwhere all the branches are in relation to each other.\n\nPardon if this doesn't make much sense.  It's been a looooong day...\n\n"},{"id":"295911","messageId":"7vpsagtowm.fsf@assigned-by-dhcp.cox.net","threadId":"43241","inReplyTo":"5D50A3C0-4521-402B-ABD4-5698870A3BD2@silverinsanity.com","subject":"Re: [PATCH] Add --remotes option to show-branch","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-12-19T05:50:33Z","receivedAt":"2006-12-19T05:50:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Brian Gernhardt <benji@silverinsanity.com> writes:\n\n>> I actually was thinking about removing these flags, not adding\n>> --remotes, because\n>>\n>> \tgit show-branch remotes/origin/*\n>\n> ... but --remotes is significantly easier than \"remotes/\n> origin/* remotes/partner/*\".  And sometimes I'd really like to know\n> where all the branches are in relation to each other.\n\nActually, git show-branch origin/* would work equally well if\nyou do not have local \"heads/origin/*\" branches.\n\n"},{"id":"296649","messageId":"4102F0A8-3DC4-43D1-B772-A4529D769131@silverinsanity.com","threadId":"43241","inReplyTo":"7vpsagtowm.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Add --remotes option to show-branch","fromName":"Brian Gernhardt","fromEmail":"benji@silverinsanity.com","sentAt":"2006-12-19T18:59:14Z","receivedAt":"2006-12-19T18:59:14Z","isPatch":true,"sender":{"key":"benji@silverinsanity.com","avatar":"https://gravatar.com/avatar/e06c101dbc25c68114d859b4a9ec7cf8a2c52fd2b0270ef0eac0e2e63ff22311?d=mp&s=160"},"body":"\nOn Dec 19, 2006, at 12:50 AM, Junio C Hamano wrote:\n\n> Actually, git show-branch origin/* would work equally well if\n> you do not have local \"heads/origin/*\" branches.\n\nFair enough.  I'm not strongly attached to the options for the  \nvarious refs.  And there is always showbranch.default.  I still think  \nthat --all would be good to keep around as meaning refs/heads/* and  \nrefs/remotes/*/*, however (and NOT refs/tags/*).  If nothing else, so  \na small-ish repository can compare everything fairly easily.\n\n"}]}