{"thread":{"id":"37041","subject":"Show containing branches in log?","startedAt":"2014-07-02T14:50:57Z","lastAt":"2014-08-25T23:35:01Z","messageCount":10,"participants":["Robert Dailey","Jeff King","Jason Pyeron","Peter Krefting","Øyvind A. Holm"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"245297","messageId":"CAHd499A78BRVawWSHNnzJcD1Ca7RfFeEnJf0SB7py1MD5qwL0g@mail.gmail.com","threadId":"37041","inReplyTo":null,"subject":"Show containing branches in log?","fromName":"Robert Dailey","fromEmail":"rcdailey.lists@gmail.com","sentAt":"2014-07-02T14:50:57Z","receivedAt":"2014-07-02T14:50:57Z","isPatch":false,"sender":{"key":"rcdailey.lists@gmail.com","avatar":null},"body":"I know that with the `git branch` command I can determine which\nbranches contain a commit. Is there a way to represent this\ngraphically with `git log`? Sometimes I just have a commit, and I need\nto find out what branch contains that commit. The reason why `git\nbranch --contains` doesn't solve this problem for me is that it names\nalmost all branches because of merge commits. Too much ancestry has\nbeen built since this commit, so there is no way to find the \"closest\"\nbranch that contains that commit.\n\nIs there a way to graphically see what is the \"nearest\" named ref to\nthe specified commit in the logs?\n"},{"id":"245306","messageId":"20140702163451.GB14404@sigill.intra.peff.net","threadId":"37041","inReplyTo":"CAHd499A78BRVawWSHNnzJcD1Ca7RfFeEnJf0SB7py1MD5qwL0g@mail.gmail.com","subject":"Re: Show containing branches in log?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2014-07-02T16:34:51Z","receivedAt":"2014-07-02T16:34:51Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Jul 02, 2014 at 09:50:57AM -0500, Robert Dailey wrote:\n\n> I know that with the `git branch` command I can determine which\n> branches contain a commit. Is there a way to represent this\n> graphically with `git log`? Sometimes I just have a commit, and I need\n> to find out what branch contains that commit. The reason why `git\n> branch --contains` doesn't solve this problem for me is that it names\n> almost all branches because of merge commits. Too much ancestry has\n> been built since this commit, so there is no way to find the \"closest\"\n> branch that contains that commit.\n> \n> Is there a way to graphically see what is the \"nearest\" named ref to\n> the specified commit in the logs?\n\nHave you tried \"git describe --contains --all <commit>\"?\n\nTo some degree, I fear your question isn't something git can answer. If\nthe branch containing the commit has been merged into other branches,\nthen they all \"contain\" the commit. There is not really any reason to\nprefer one over the other (\"describe --contains\" will try to find the\n\"closest\" branch, but that is based on heuristics and is not necessarily\nwell-defined).\n\n-Peff\n"},{"id":"245308","messageId":"CAHd499Bk6ZG+DDjN1HuC-RFczwd+AGZaUSkXA6a8MsZjOL5H8A@mail.gmail.com","threadId":"37041","inReplyTo":"20140702163451.GB14404@sigill.intra.peff.net","subject":"Re: Show containing branches in log?","fromName":"Robert Dailey","fromEmail":"rcdailey.lists@gmail.com","sentAt":"2014-07-02T16:52:43Z","receivedAt":"2014-07-02T16:52:43Z","isPatch":false,"sender":{"key":"rcdailey.lists@gmail.com","avatar":null},"body":"On Wed, Jul 2, 2014 at 11:34 AM, Jeff King <peff@peff.net> wrote:\n> Have you tried \"git describe --contains --all <commit>\"?\n>\n> To some degree, I fear your question isn't something git can answer. If\n> the branch containing the commit has been merged into other branches,\n> then they all \"contain\" the commit. There is not really any reason to\n> prefer one over the other (\"describe --contains\" will try to find the\n> \"closest\" branch, but that is based on heuristics and is not necessarily\n> well-defined).\n\nI have not tried that command. Note I mentioned named refs, so\nnameless branches I'm not worried about. Even if I merge branch A into\nbranch B, branch A is still closest in terms of number of steps to get\nto the commit, because to get to the commit through B you have to\ncross over a merge commit. Basically the priority should be directness\nand distance. The more direct a branch is (i.e. the lesser number of\nmerge commits it goes through to get to the commit) the more relevant\nit is. As a second condition, distance would be used in cases where\nthe directness of it is the same.\n\nSorting this in the log graph and seeing it visually (I could even use\n--simplify-by-decoration) would help me understand the topography of\ngit's history relative to the commit(s) I specify.\n"},{"id":"245309","messageId":"6C120F968C534117BC278DD93D1F84A5@black","threadId":"37041","inReplyTo":"20140702163451.GB14404@sigill.intra.peff.net","subject":"RE: Show containing branches in log?","fromName":"Jason Pyeron","fromEmail":"jpyeron@pdinc.us","sentAt":"2014-07-02T16:52:55Z","receivedAt":"2014-07-02T16:52:55Z","isPatch":false,"sender":{"key":"jpyeron@pdinc.us","avatar":"https://gravatar.com/avatar/c2e53452caa53d940768a1ffc9cf76196d851b9b534b7a39cd39852a70a0508f?d=mp&s=160"},"body":"> -----Original Message-----\n> From: Jeff King\n> Sent: Wednesday, July 02, 2014 12:35\n> \n> On Wed, Jul 02, 2014 at 09:50:57AM -0500, Robert Dailey wrote:\n> \n> > I know that with the `git branch` command I can determine which\n> > branches contain a commit. Is there a way to represent this\n> > graphically with `git log`? Sometimes I just have a commit, \n> and I need\n> > to find out what branch contains that commit. The reason why `git\n> > branch --contains` doesn't solve this problem for me is \n> that it names\n> > almost all branches because of merge commits. Too much ancestry has\n> > been built since this commit, so there is no way to find \n> the \"closest\"\n> > branch that contains that commit.\n> > \n> > Is there a way to graphically see what is the \"nearest\" named ref to\n> > the specified commit in the logs?\n> \n> Have you tried \"git describe --contains --all <commit>\"?\n> \n> To some degree, I fear your question isn't something git can \n> answer. If\n> the branch containing the commit has been merged into other branches,\n> then they all \"contain\" the commit. There is not really any reason to\n> prefer one over the other (\"describe --contains\" will try to find the\n> \"closest\" branch, but that is based on heuristics and is not \n> necessarily\n> well-defined).\n\nAnother way I answer this question is git log --oneline --graph --all and then\nsearch for the commit and follow the lines.\n\n\n--\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n-                                                               -\n- Jason Pyeron                      PD Inc. http://www.pdinc.us -\n- Principal Consultant              10 West 24th Street #100    -\n- +1 (443) 269-1555 x333            Baltimore, Maryland 21218   -\n-                                                               -\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\nThis message is copyright PD Inc, subject to license 20080407P00.\n\n \n"},{"id":"245310","messageId":"CAHd499BpaT0UWWSQm-P09iPm_QKGwOpOZyeZtQCs-OtxVRmM8w@mail.gmail.com","threadId":"37041","inReplyTo":"6C120F968C534117BC278DD93D1F84A5@black","subject":"Re: Show containing branches in log?","fromName":"Robert Dailey","fromEmail":"rcdailey.lists@gmail.com","sentAt":"2014-07-02T16:59:33Z","receivedAt":"2014-07-02T16:59:33Z","isPatch":false,"sender":{"key":"rcdailey.lists@gmail.com","avatar":null},"body":"On Wed, Jul 2, 2014 at 11:52 AM, Jason Pyeron <jpyeron@pdinc.us> wrote:\n>> -----Original Message-----\n>> From: Jeff King\n>> Sent: Wednesday, July 02, 2014 12:35\n>>\n>> On Wed, Jul 02, 2014 at 09:50:57AM -0500, Robert Dailey wrote:\n>>\n>> > I know that with the `git branch` command I can determine which\n>> > branches contain a commit. Is there a way to represent this\n>> > graphically with `git log`? Sometimes I just have a commit,\n>> and I need\n>> > to find out what branch contains that commit. The reason why `git\n>> > branch --contains` doesn't solve this problem for me is\n>> that it names\n>> > almost all branches because of merge commits. Too much ancestry has\n>> > been built since this commit, so there is no way to find\n>> the \"closest\"\n>> > branch that contains that commit.\n>> >\n>> > Is there a way to graphically see what is the \"nearest\" named ref to\n>> > the specified commit in the logs?\n>>\n>> Have you tried \"git describe --contains --all <commit>\"?\n>>\n>> To some degree, I fear your question isn't something git can\n>> answer. If\n>> the branch containing the commit has been merged into other branches,\n>> then they all \"contain\" the commit. There is not really any reason to\n>> prefer one over the other (\"describe --contains\" will try to find the\n>> \"closest\" branch, but that is based on heuristics and is not\n>> necessarily\n>> well-defined).\n>\n> Another way I answer this question is git log --oneline --graph --all and then\n> search for the commit and follow the lines.\n\nIf that were a practical solution I wouldn't be here asking this\nquestion. Unfortunately, in a repository with multiple parallel\nrelease branches, it is impossible to just \"eye-ball\" the graph and\nfind what you're looking for. Especially when the last 4 weeks worth\nof commits consumes over 10 pages of log graph.\n"},{"id":"245376","messageId":"alpine.DEB.2.00.1407031517100.4693@ds9.cixit.se","threadId":"37041","inReplyTo":"CAHd499A78BRVawWSHNnzJcD1Ca7RfFeEnJf0SB7py1MD5qwL0g@mail.gmail.com","subject":"Re: Show containing branches in log?","fromName":"Peter Krefting","fromEmail":"peter@softwolves.pp.se","sentAt":"2014-07-03T14:18:42Z","receivedAt":"2014-07-03T14:18:42Z","isPatch":false,"sender":{"key":"peter@softwolves.pp.se","avatar":"https://avatars.githubusercontent.com/u/990764?v=4"},"body":"Robert Dailey:\n\n> Is there a way to graphically see what is the \"nearest\" named ref to \n> the specified commit in the logs?\n\ngit log --graph --decorate commit..\n\nwill display all the commits that happened after the commit \"commit\", \nwith the branch names indicated, with lines indicating the ancestry. \nThat's the closest I can come to think of.\n\n-- \n\\\\// Peter - http://www.softwolves.pp.se/\n"},{"id":"245382","messageId":"20140703172539.GB20571@sigill.intra.peff.net","threadId":"37041","inReplyTo":"alpine.DEB.2.00.1407031517100.4693@ds9.cixit.se","subject":"Re: Show containing branches in log?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2014-07-03T17:25:39Z","receivedAt":"2014-07-03T17:25:39Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Jul 03, 2014 at 03:18:42PM +0100, Peter Krefting wrote:\n\n> Robert Dailey:\n> \n> >Is there a way to graphically see what is the \"nearest\" named ref to the\n> >specified commit in the logs?\n> \n> git log --graph --decorate commit..\n> \n> will display all the commits that happened after the commit \"commit\", with\n> the branch names indicated, with lines indicating the ancestry. That's the\n> closest I can come to think of.\n\nThe trouble with \"--decorate\" is that you have to manually find the\ndecorated commit that is closest. That can be hard if you have a lot of\ncommits.\n\nThere is also \"--source\", which will transmit the \"source name\" down\nfrom parent to child. So if you do:\n\n  git log --all --source\n\neach tip will be painted with its ref name, and will pass that to its\nancestors as we walk the graph. Of course ancestors that have multiple\nchildren (e.g., something that got merged) will only show one source,\nbut that painting will never cross an actual branch boundary (so if\nbranch \"A\" merged branch \"B\", the commits that are in \"B\" will still get\npainted as \"B\").\n\nThe big downside is that you are now traversing _all_ refs, instead of\njust the ones you wanted. We could fix that by letting you specify a set\nof refs to paint. For example, with the patch below, you can do:\n\n  git log --source=refs/heads\n\nand see only commits in HEAD, but painted by their source in\nrefs/heads/*. I'm not planning to work on it further anytime soon, but\nif somebody wants to pick it up and run with it, feel free. I think\nbefore inclusion one would want to consider:\n\n  1. Calling it \"--contains\" instead of \"--source\", since it is not\n     really about the source anymore.\n\n  2. Moving the storage out of commit->util into a commit-slab. This\n     would prevent it from conflicting with \"--source\" (for that matter,\n     it would be nice if \"--source\" used a slab, too).\n\n  3. Rather than showing one arbitrary way of getting to the commit,\n     keep track of _all_ of them. Unfortunately this is not quite a true\n     list of which refs contain the commit, as we might show the commit\n     before its parent paints down to it (this can happen if the commit\n     timestamps are out of order, I think). We could get around that by\n     using --topo-order.\n\n  4. Make the output less ugly (probably more like --decorate, with\n     colors and parentheses).\n\n---\ndiff --git a/builtin/log.c b/builtin/log.c\nindex a7ba211..8ad7b46 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -25,6 +25,7 @@\n #include \"version.h\"\n #include \"mailmap.h\"\n #include \"gpg-interface.h\"\n+#include \"refs.h\"\n \n /* Set a default date-time format for git log (\"log.date\" config variable) */\n static const char *default_date_mode = NULL;\n@@ -116,16 +117,61 @@ static void cmd_log_init_defaults(struct rev_info *rev)\n \trev->diffopt.touched_flags = 0;\n }\n \n+struct source_opt {\n+\tstruct string_list refs;\n+\tint enabled;\n+};\n+\n+static int parse_opt_source(const struct option *opt, const char *arg, int unset)\n+{\n+\tstruct source_opt *source = opt->value;\n+\n+\tif (unset) {\n+\t\tsource->enabled = 0;\n+\t\tstring_list_clear(&source->refs, 0);\n+\t} else {\n+\t\tsource->enabled = 1;\n+\t\tif (arg)\n+\t\t\tstring_list_append(&source->refs, arg);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int paint_source_ref(const char *refname, const unsigned char *sha1,\n+\t\t\t    int flags, void *data)\n+{\n+\tconst char *prefix = data;\n+\tstruct commit *c = lookup_commit_reference_gently(sha1, 1);\n+\n+\tif (c && !c->util) {\n+\t\tstruct strbuf buf = STRBUF_INIT;\n+\t\tstrbuf_addstr(&buf, prefix);\n+\t\tstrbuf_addstr(&buf, refname);\n+\t\tc->util = strbuf_detach(&buf, NULL);\n+\t}\n+\treturn 0;\n+}\n+\n+static int paint_source_refs_in(struct string_list_item *it, void *data)\n+{\n+\tfor_each_ref_in(it->string, paint_source_ref, it->string);\n+\treturn 0;\n+}\n+\n+\n static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,\n \t\t\t struct rev_info *rev, struct setup_revision_opt *opt)\n {\n \tstruct userformat_want w;\n-\tint quiet = 0, source = 0, mailmap = 0;\n+\tstruct source_opt source = { STRING_LIST_INIT_DUP, 0 };\n+\tint quiet = 0, mailmap = 0;\n \tstatic struct line_opt_callback_data line_cb = {NULL, NULL, STRING_LIST_INIT_DUP};\n \n \tconst struct option builtin_log_options[] = {\n \t\tOPT__QUIET(&quiet, N_(\"suppress diff output\")),\n-\t\tOPT_BOOL(0, \"source\", &source, N_(\"show source\")),\n+\t\t{ OPTION_CALLBACK, 0, \"source\", &source, N_(\"refs\"), N_(\"show source\"),\n+\t\t  PARSE_OPT_OPTARG, parse_opt_source },\n \t\tOPT_BOOL(0, \"use-mailmap\", &mailmap, N_(\"Use mail map file\")),\n \t\t{ OPTION_CALLBACK, 0, \"decorate\", NULL, NULL, N_(\"decorate options\"),\n \t\t  PARSE_OPT_OPTARG, decorate_callback},\n@@ -164,8 +210,10 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,\n \t    DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES))\n \t\trev->always_show_header = 0;\n \n-\tif (source)\n+\tif (source.enabled) {\n \t\trev->show_source = 1;\n+\t\tfor_each_string_list(&source.refs, paint_source_refs_in, NULL);\n+\t}\n \n \tif (mailmap) {\n \t\trev->mailmap = xcalloc(1, sizeof(struct string_list));\n"},{"id":"245387","messageId":"CAA787rm=Pjy-GGzxCcy=NQNLUOCrTt4hYWS9iND8EAxxs67SuQ@mail.gmail.com","threadId":"37041","inReplyTo":"CAHd499A78BRVawWSHNnzJcD1Ca7RfFeEnJf0SB7py1MD5qwL0g@mail.gmail.com","subject":"Re: Show containing branches in log?","fromName":"Øyvind A. Holm","fromEmail":"sunny@sunbase.org","sentAt":"2014-07-03T19:41:04Z","receivedAt":"2014-07-03T19:41:04Z","isPatch":false,"sender":{"key":"sunny@sunbase.org","avatar":"https://avatars.githubusercontent.com/u/113445?v=4"},"body":"On 2 July 2014 16:50, Robert Dailey <rcdailey.lists@gmail.com> wrote:\n> I know that with the `git branch` command I can determine which\n> branches contain a commit. Is there a way to represent this\n> graphically with `git log`? Sometimes I just have a commit, and I need\n> to find out what branch contains that commit. The reason why `git\n> branch --contains` doesn't solve this problem for me is that it names\n> almost all branches because of merge commits. Too much ancestry has\n> been built since this commit, so there is no way to find the \"closest\"\n> branch that contains that commit.\n>\n> Is there a way to graphically see what is the \"nearest\" named ref to\n> the specified commit in the logs?\n\nI have created a script for just this functionality which I use very\noften, and have created a gist with the files at\n<https://gist.github.com/sunny256/2eb583f21e0ffcfe994f>, I think it\nshould solve your problem. It contains these files:\n\n  git-wn\n\n\"wn\" means \"What's New\" and will create a visual graph of all commits\nwhich has a specified ref as ancestor. It also needs the following\nscript, just put it into your $PATH somewhere:\n\n  git-lc\n\n\"lc\" means \"List branches Containing this commit\" and generates a list\nof all branches containing a specified ref.\n\nThe files originates from <https://github.com/sunny256/utils>, but\nI've modified them in the gist to make your life easier. :)\n\nHope that helps,\nØyvind\n"},{"id":"247120","messageId":"CAHd499BppLXcGz3t-F1rdtKGMTvi+SVvW3TUt0DyGTLvKxpiwA@mail.gmail.com","threadId":"37041","inReplyTo":"CAA787rm=Pjy-GGzxCcy=NQNLUOCrTt4hYWS9iND8EAxxs67SuQ@mail.gmail.com","subject":"Re: Show containing branches in log?","fromName":"Robert Dailey","fromEmail":"rcdailey.lists@gmail.com","sentAt":"2014-08-01T18:01:17Z","receivedAt":"2014-08-01T18:01:17Z","isPatch":false,"sender":{"key":"rcdailey.lists@gmail.com","avatar":null},"body":"On Thu, Jul 3, 2014 at 2:41 PM, Øyvind A. Holm <sunny@sunbase.org> wrote:\n> I have created a script for just this functionality which I use very\n> often, and have created a gist with the files at\n> <https://gist.github.com/sunny256/2eb583f21e0ffcfe994f>, I think it\n> should solve your problem. It contains these files:\n>\n>   git-wn\n>\n> \"wn\" means \"What's New\" and will create a visual graph of all commits\n> which has a specified ref as ancestor. It also needs the following\n> script, just put it into your $PATH somewhere:\n>\n>   git-lc\n>\n> \"lc\" means \"List branches Containing this commit\" and generates a list\n> of all branches containing a specified ref.\n>\n> The files originates from <https://github.com/sunny256/utils>, but\n> I've modified them in the gist to make your life easier. :)\n\nSorry for the late response. I forgot to thank you for this! This is\nvery detailed and helpful... I will try this soon and see how it\nworks.\n\nGreat job.\n"},{"id":"248278","messageId":"CAHd499CrxakA6+X8M0Ty4YtrRWjtsBUpwDW132NkSmp650SH+w@mail.gmail.com","threadId":"37041","inReplyTo":"CAA787rm=Pjy-GGzxCcy=NQNLUOCrTt4hYWS9iND8EAxxs67SuQ@mail.gmail.com","subject":"Re: Show containing branches in log?","fromName":"Robert Dailey","fromEmail":"rcdailey.lists@gmail.com","sentAt":"2014-08-25T23:35:01Z","receivedAt":"2014-08-25T23:35:01Z","isPatch":false,"sender":{"key":"rcdailey.lists@gmail.com","avatar":null},"body":"On Thu, Jul 3, 2014 at 2:41 PM, Øyvind A. Holm <sunny@sunbase.org> wrote:\n> On 2 July 2014 16:50, Robert Dailey <rcdailey.lists@gmail.com> wrote:\n>> I know that with the `git branch` command I can determine which\n>> branches contain a commit. Is there a way to represent this\n>> graphically with `git log`? Sometimes I just have a commit, and I need\n>> to find out what branch contains that commit. The reason why `git\n>> branch --contains` doesn't solve this problem for me is that it names\n>> almost all branches because of merge commits. Too much ancestry has\n>> been built since this commit, so there is no way to find the \"closest\"\n>> branch that contains that commit.\n>>\n>> Is there a way to graphically see what is the \"nearest\" named ref to\n>> the specified commit in the logs?\n>\n> I have created a script for just this functionality which I use very\n> often, and have created a gist with the files at\n> <https://gist.github.com/sunny256/2eb583f21e0ffcfe994f>, I think it\n> should solve your problem. It contains these files:\n>\n>   git-wn\n>\n> \"wn\" means \"What's New\" and will create a visual graph of all commits\n> which has a specified ref as ancestor. It also needs the following\n> script, just put it into your $PATH somewhere:\n>\n>   git-lc\n>\n> \"lc\" means \"List branches Containing this commit\" and generates a list\n> of all branches containing a specified ref.\n>\n> The files originates from <https://github.com/sunny256/utils>, but\n> I've modified them in the gist to make your life easier. :)\n>\n> Hope that helps,\n> Øyvind\n\nI'm finally getting around to trying this out but it isn't working on\nWindows because there is no fmt command in msysgit. Do you have a\nworkaround I can use? Thanks.\n"}]}