{"thread":{"id":"38308","subject":"[PATCH] show-branch --upstream: add upstream branches to the list of branches to display","startedAt":"2015-01-08T09:17:37Z","lastAt":"2015-01-13T01:33:49Z","messageCount":2,"participants":["Mike Hommey"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"254454","messageId":"1420708657-20811-1-git-send-email-mh@glandium.org","threadId":"38308","inReplyTo":null,"subject":"[PATCH] show-branch --upstream: add upstream branches to the list of branches to display","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2015-01-08T09:17:37Z","receivedAt":"2015-01-08T09:17:37Z","isPatch":true,"sender":{"key":"mh@glandium.org","avatar":"https://avatars.githubusercontent.com/u/1038527?v=4"},"body":"`git show-branch --upstream` is equivalent to `git show-branch\n$(git for-each-ref refs/heads --format '%(refname:short)')\n$(git for-each-ref refs/heads --format '%(upstream:short)')`\n\n`git show-branch --upstream foo bar` is equivalent to `git show-branch\nfoo bar $(git for-each-ref refs/heads/foo refs/heads/bar\n--format '%(upstream:short)')`\n\nCombined with --topics, it shows commits that are NOT on any of\nthe upstream branches.\n\nSigned-off-by: Mike Hommey <mh@glandium.org>\n---\n\nNote that in the --topics --upstream case, when there are different\nupstreams branches involved, only the merge-base of all of them is\nshown. I'm not sure if it's desirable to show more. The output as it\nis works for my own use cases.\n\n Documentation/git-show-branch.txt |  6 ++++++\n builtin/show-branch.c             | 42 +++++++++++++++++++++++++++++++++++++--\n 2 files changed, 46 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-show-branch.txt b/Documentation/git-show-branch.txt\nindex b91d4e5..fd29c8d 100644\n--- a/Documentation/git-show-branch.txt\n+++ b/Documentation/git-show-branch.txt\n@@ -53,6 +53,10 @@ OPTIONS\n \tbranch to the list of revs to be shown when it is not\n \tgiven on the command line.\n \n+--upstream::\n+\tWith this option, the command includes the upstream\n+\tbranch of each rev to be shown.\n+\n --topo-order::\n         By default, the branches and their commits are shown in\n         reverse chronological order.  This option makes them\n@@ -102,6 +106,8 @@ OPTIONS\n \n --topics::\n \tShows only commits that are NOT on the first branch given.\n+\tWhen used with `--upstream`, shows only commits that are NOT\n+\ton any upstream branch.\n \tThis helps track topic branches by hiding any commit that\n \tis already in the main line of development.  When given\n \t\"git show-branch --topics master topic1 topic2\", this\ndiff --git a/builtin/show-branch.c b/builtin/show-branch.c\nindex 270e39c..90e2ac3 100644\n--- a/builtin/show-branch.c\n+++ b/builtin/show-branch.c\n@@ -4,9 +4,10 @@\n #include \"builtin.h\"\n #include \"color.h\"\n #include \"parse-options.h\"\n+#include \"remote.h\"\n \n static const char* show_branch_usage[] = {\n-    N_(\"git show-branch [-a|--all] [-r|--remotes] [--topo-order | --date-order] [--current] [--color[=<when>] | --no-color] [--sparse] [--more=<n> | --list | --independent | --merge-base] [--no-name | --sha1-name] [--topics] [(<rev> | <glob>)...]\"),\n+    N_(\"git show-branch [-a|--all] [-r|--remotes] [--topo-order | --date-order] [--current] [--upstream] [--color[=<when>] | --no-color] [--sparse] [--more=<n> | --list | --independent | --merge-base] [--no-name | --sha1-name] [--topics] [(<rev> | <glob>)...]\"),\n     N_(\"git show-branch (-g|--reflog)[=<n>[,<base>]] [--list] [<ref>]\"),\n     NULL\n };\n@@ -640,6 +641,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \tint sha1_name = 0;\n \tint shown_merge_point = 0;\n \tint with_current_branch = 0;\n+\tint with_upstream_branches = 0;\n \tint head_at = -1;\n \tint topics = 0;\n \tint dense = 1;\n@@ -658,6 +660,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\tOPT_BOOL(0, \"no-name\", &no_name, N_(\"suppress naming strings\")),\n \t\tOPT_BOOL(0, \"current\", &with_current_branch,\n \t\t\t N_(\"include the current branch\")),\n+\t\tOPT_BOOL(0, \"upstream\", &with_upstream_branches,\n+\t\t\t N_(\"include upstream branches\")),\n \t\tOPT_BOOL(0, \"sha1-name\", &sha1_name,\n \t\t\t N_(\"name commits with their object names\")),\n \t\tOPT_BOOL(0, \"merge-base\", &merge_base,\n@@ -848,7 +852,41 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\tif (commit->object.flags == flag)\n \t\t\tcommit_list_insert_by_date(commit, &list);\n \t\trev[num_rev] = commit;\n+\n+\t\tif (with_upstream_branches) {\n+\t\t\tunsigned char branch_sha1[20];\n+\t\t\tstruct branch *branch;\n+\t\t\tint current_ref_name_cnt = ref_name_cnt;\n+\n+\t\t\t/* If this ref is already marked as an upstream, skip */\n+\t\t\tif (topics & flag)\n+\t\t\t\tcontinue;\n+\n+\t\t\tbranch = branch_get(ref_name[num_rev]);\n+\n+\t\t\tif (!branch || !branch->merge || !branch->merge[0] ||\n+\t\t\t    !branch->merge[0]->dst)\n+\t\t\t\tcontinue;\n+\t\t\tif (get_sha1(branch->merge[0]->dst, branch_sha1))\n+\t\t\t\tcontinue;\n+\t\t\tappend_remote_ref(branch->merge[0]->dst, branch_sha1, 0, 0);\n+\t\t\t/* If append_remote_ref didn't add a ref, it's either\n+\t\t\t * because it's an upstream of a previous ref, or because\n+\t\t\t * it was given on the command line. In neither case we\n+\t\t\t * want the bit being set. */\n+\t\t\tif (topics && current_ref_name_cnt != ref_name_cnt)\n+\t\t\t\ttopics |= 1u << (ref_name_cnt + REV_SHIFT - 1);\n+\t\t} else if (topics && num_rev == 0) {\n+\t\t\ttopics |= flag;\n+\t\t}\n \t}\n+\t/* topics is filled above with a mask of refs corresponding to\n+\t * upstream branches, or the first given ref. It also still contains\n+\t * the original bool value, which may match some bookkeeping flags,\n+\t * so filter that out.\n+\t */\n+\ttopics &= ~0u << REV_SHIFT;\n+\n \tfor (i = 0; i < num_rev; i++)\n \t\trev_mask[i] = rev[i]->object.flags;\n \n@@ -925,7 +963,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t\t\t\t  commit->parents->next);\n \t\t\tif (topics &&\n \t\t\t    !is_merge_point &&\n-\t\t\t    (this_flag & (1u << REV_SHIFT)))\n+\t\t\t    (this_flag & topics))\n \t\t\t\tcontinue;\n \t\t\tif (dense && is_merge &&\n \t\t\t    omit_in_dense(commit, rev, num_rev))\n-- \n2.2.1.4.g99d39fe.dirty\n"},{"id":"254581","messageId":"20150113013349.GA26587@glandium.org","threadId":"38308","inReplyTo":"1420708657-20811-1-git-send-email-mh@glandium.org","subject":"Re: [PATCH] show-branch --upstream: add upstream branches to the list of branches to display","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2015-01-13T01:33:49Z","receivedAt":"2015-01-13T01:33:49Z","isPatch":true,"sender":{"key":"mh@glandium.org","avatar":"https://avatars.githubusercontent.com/u/1038527?v=4"},"body":"On Thu, Jan 08, 2015 at 06:17:37PM +0900, Mike Hommey wrote:\n> `git show-branch --upstream` is equivalent to `git show-branch\n> $(git for-each-ref refs/heads --format '%(refname:short)')\n> $(git for-each-ref refs/heads --format '%(upstream:short)')`\n> \n> `git show-branch --upstream foo bar` is equivalent to `git show-branch\n> foo bar $(git for-each-ref refs/heads/foo refs/heads/bar\n> --format '%(upstream:short)')`\n> \n> Combined with --topics, it shows commits that are NOT on any of\n> the upstream branches.\n> \n> Signed-off-by: Mike Hommey <mh@glandium.org>\n> ---\n> \n> Note that in the --topics --upstream case, when there are different\n> upstreams branches involved, only the merge-base of all of them is\n> shown. I'm not sure if it's desirable to show more. The output as it\n> is works for my own use cases.\n\nSome example output (where inbound/default and b2g-inbound/default are two\ndifferent upstream repositories):\n$ git show-branch --upstream HEAD\n! [HEAD] Bug 1120680 - try: -b do -p emulator,emulator-jb,emulator-kk -t none -u none\n ! [b2g-inbound/default] Bumping manifests a=b2g-bump\n--\n+  [HEAD] Bug 1120680 - try: -b do -p emulator,emulator-jb,emulator-kk -t none -u none\n + [b2g-inbound/default] Bumping manifests a=b2g-bump\n + [b2g-inbound/default^] Backed out changeset ffdc6e420153 (bug 1107009) for Android crashes/asserts.\n + [b2g-inbound/default~2] Bumping manifests a=b2g-bump\n-- [HEAD^] Merge m-c to b2g-inbound. a=merge\n\n$ git show-branch --upstream --topics HEAD\n! [HEAD] Bug 1120680 - try: -b do -p emulator,emulator-jb,emulator-kk -t none -u none\n ! [b2g-inbound/default] Bumping manifests a=b2g-bump\n--\n+  [HEAD] Bug 1120680 - try: -b do -p emulator,emulator-jb,emulator-kk -t none -u none\n-- [HEAD^] Merge m-c to b2g-inbound. a=merge\n\n$ git show-branch --upstream --topics\n! [bug1107677] Bug 1107677 - Enable chunk recycling for 128 chunks in jemalloc3\n ! [bug1110760] Bug 1110760 - Followup to avoid build failure with Windows SDK v7.0 and v7.0A\n  ! [bug1120272] Bug 1120272 - wip\n   * [bug1120680] Bug 1120680 - try: -b do -p emulator,emulator-jb,emulator-kk -t none -u none\n    ! [inbound/default] Bug 762449 - Enable jemalloc 3 by default, but don' make it ride the trains yet. r=njn\n     ! [b2g-inbound/default] Bumping manifests a=b2g-bump\n------\n   *   [bug1120680] Bug 1120680 - try: -b do -p emulator,emulator-jb,emulator-kk -t none -u none\n  +    [bug1120272] Bug 1120272 - wip\n +     [bug1110760] Bug 1110760 - Followup to avoid build failure with Windows SDK v7.0 and v7.0A\n+      [bug1107677] Bug 1107677 - Enable chunk recycling for 128 chunks in jemalloc3\n+      [bug1107677^] Bug 1107677 - Port relevant parts from bug 1073662 part 6\n+      [bug1107677~2] Bug 1107677 - Port the relevant parts from bug 1073662 part 5\n+++*++ [bug1110760~183] Bug 1118950 - Fix mistyped DEBUG condition in GlobalHelperThreadState(). r=bhackett.\n\nMike\n"}]}