{"thread":{"id":"58201","subject":"Question: How to find the commits in the ancestry path of seen down to _and_ including a given topic?","startedAt":"2022-07-21T07:24:10Z","lastAt":"2022-07-22T23:25:20Z","messageCount":6,"participants":["Elijah Newren","Junio C Hamano","Derrick Stolee"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"459585","messageId":"CABPp-BEK+SJh2uF=rrM-f1u9diMQJ7D3H0fJLdzWpyOww=ys+w@mail.gmail.com","threadId":"58201","inReplyTo":null,"subject":"Question: How to find the commits in the ancestry path of seen down to _and_ including a given topic?","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2022-07-21T07:23:53Z","receivedAt":"2022-07-21T07:24:10Z","isPatch":false,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"A simple question that I'm spinning out of [1]: How can I get `git\nlog` to show the commits in the ancestry path from seen, back to *and\nincluding* a given topic (but not commits from unrelated topics)?\n\n   git log --ancestry-path $TOPIC..seen\n\ndoesn't work, because that excludes $TOPIC.  (It does get me the merge\nof $TOPIC into seen, as well as all merges into seen following that\nmerge, which I want, but it's missing the topic itself.)\n\n  git log --ancestry-path $BASE_OF_TOPIC..seen\n\nusually doesn't work, because $BASE_OF_TOPIC is usually a commit from\n\"main\" or \"master\", and this results in pulling in hundreds of commits\nfrom unrelated topics that also happen to be based on a version of\n\"main\" or \"master\" at or after $BASE_OF_TOPIC.\n\nIs there some magic that does what I want, or is this just not\npossible currently?\n\nThanks,\nElijah\n\n\n[1] https://lore.kernel.org/git/CABPp-BHARfYcsEM7Daeb7+vYxeB9Awo8=qbrOMXG6BQ0gX1RiA@mail.gmail.com/\n"},{"id":"459635","messageId":"xmqqy1wmlbnn.fsf@gitster.g","threadId":"58201","inReplyTo":"CABPp-BEK+SJh2uF=rrM-f1u9diMQJ7D3H0fJLdzWpyOww=ys+w@mail.gmail.com","subject":"Re: Question: How to find the commits in the ancestry path of seen down to _and_ including a given topic?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-07-21T15:37:32Z","receivedAt":"2022-07-21T15:41:04Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Elijah Newren <newren@gmail.com> writes:\n\n> A simple question that I'm spinning out of [1]: How can I get `git\n> log` to show the commits in the ancestry path from seen, back to *and\n> including* a given topic (but not commits from unrelated topics)?\n\nDrawing of a sample history, please.\n\nI feel stupid asking this, but I do not think I even understand what\nthe question is X-<.\n\nCommits that are ancestors of 'seen' and are descendants of the tip\nof the topic?\n"},{"id":"459681","messageId":"571ad4e2-e6de-35a2-0d58-2329cf8684ab@github.com","threadId":"58201","inReplyTo":"xmqqy1wmlbnn.fsf@gitster.g","subject":"Re: Question: How to find the commits in the ancestry path of seen down to _and_ including a given topic?","fromName":"Derrick Stolee","fromEmail":"derrickstolee@github.com","sentAt":"2022-07-21T18:48:35Z","receivedAt":"2022-07-21T18:48:43Z","isPatch":false,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 7/21/2022 11:37 AM, Junio C Hamano wrote:\n> Elijah Newren <newren@gmail.com> writes:\n> \n>> A simple question that I'm spinning out of [1]: How can I get `git\n>> log` to show the commits in the ancestry path from seen, back to *and\n>> including* a given topic (but not commits from unrelated topics)?\n> \n> Drawing of a sample history, please.\n> \n> I feel stupid asking this, but I do not think I even understand what\n> the question is X-<.\n> \n> Commits that are ancestors of 'seen' and are descendants of the tip\n> of the topic?\n\nHave you tried \n\n  git log --graph --oneline --boundary --ancestry-path <A>...<B>\n\nThe triple dots show the symmetric diff, and the --boundary shows\nthe possible merge-bases. The --ancestry-path option seems to trim\nthe output significantly in the example I tried.\n\nThanks,\n-Stolee\n"},{"id":"459714","messageId":"CABPp-BEqWX3Nr2HDxwS9d-_QjcKb_jS=fSjsP_Pbutw7-P5gbg@mail.gmail.com","threadId":"58201","inReplyTo":"xmqqy1wmlbnn.fsf@gitster.g","subject":"Re: Question: How to find the commits in the ancestry path of seen down to _and_ including a given topic?","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2022-07-21T19:34:42Z","receivedAt":"2022-07-21T19:34:56Z","isPatch":false,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Thu, Jul 21, 2022 at 8:37 AM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Elijah Newren <newren@gmail.com> writes:\n>\n> > A simple question that I'm spinning out of [1]: How can I get `git\n> > log` to show the commits in the ancestry path from seen, back to *and\n> > including* a given topic (but not commits from unrelated topics)?\n>\n> Drawing of a sample history, please.\n>\n> I feel stupid asking this, but I do not think I even understand what\n> the question is X-<.\n>\n> Commits that are ancestors of 'seen' and are descendants of the tip\n> of the topic?\n\nWhat you said *plus* commits from the topic itself.  From this graph:\n\n    A---B---C---J---K <-- main\n            |\\       \\\n            | \\       N---------------O---P---Q <-- seen\n            |  \\     /               /\n            |   L---M  <-- topic    /\n             \\                     /\n              D---E---F---G---H---I  <-- other_topic\n\nI want the commits L-Q.  If I run\n\n   git log --ancestry-path topic..seen\n\nI only get N-Q, missing L & M.  If I run\n\n   git log --ancestry-path main..seen\n\nthen I get D-Q, providing me with D-I and J-K that I don't want.\n\nThe closest I seem to be able to get is\n\n   git log --ancestry-path topic~${commits_in_topic_minus_one}..seen\n\nwhich includes all commits I want except the first commit of the topic\nbranch.\n\n\nAn example, from git.git; 5b893f7d81 is a topic (ab/submodule-cleanup)\nwith 12 commits, and ac0248bfba is some older version of 'next' .  I\nwant all 12 commits in that topic plus all commits that are both\ndescendants of that tip and ancestors of that old version of 'next',\nwhich adds up to 36 commits.  (Note that this includes the 12 commits\nin ab/submodule clean, 9 commits from gc/submodule-use-super-prefix\nsince that happens to be a descendant of ab/submodule-cleanup, and\nabout 15 merge commits from merging other topics into next, but does\nnot include those other 15 topics.)  If I run (notice the \"11\" instead\nof \"12\"):\n\n   git log --oneline --ancestry-path 5b893f7d81~11..ac0248bfba | wc -l\n\nit reports 35 commits -- it's just missing the first commit from the\ntopic.  If I change \"11\" to \"12\" to try to get that first commit too:\n\n   git log --oneline --ancestry-path 5b893f7d81~11..ac0248bfba | wc -l\n\nthen it reports 228 commits, 192 of which I don't want.\n"},{"id":"459767","messageId":"8315230c-f79c-8027-9711-6e21a4bc25c4@github.com","threadId":"58201","inReplyTo":"CABPp-BEqWX3Nr2HDxwS9d-_QjcKb_jS=fSjsP_Pbutw7-P5gbg@mail.gmail.com","subject":"Re: Question: How to find the commits in the ancestry path of seen down to _and_ including a given topic?","fromName":"Derrick Stolee","fromEmail":"derrickstolee@github.com","sentAt":"2022-07-22T11:06:51Z","receivedAt":"2022-07-22T11:07:02Z","isPatch":false,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 7/21/22 3:34 PM, Elijah Newren wrote:\n> On Thu, Jul 21, 2022 at 8:37 AM Junio C Hamano <gitster@pobox.com> wrote:\n>>\n>> Elijah Newren <newren@gmail.com> writes:\n>>\n>>> A simple question that I'm spinning out of [1]: How can I get `git\n>>> log` to show the commits in the ancestry path from seen, back to *and\n>>> including* a given topic (but not commits from unrelated topics)?\n>>\n>> Drawing of a sample history, please.\n>>\n>> I feel stupid asking this, but I do not think I even understand what\n>> the question is X-<.\n>>\n>> Commits that are ancestors of 'seen' and are descendants of the tip\n>> of the topic?\n> \n> What you said *plus* commits from the topic itself.  From this graph:\n> \n>     A---B---C---J---K <-- main\n>             |\\       \\\n>             | \\       N---------------O---P---Q <-- seen\n>             |  \\     /               /\n>             |   L---M  <-- topic    /\n>              \\                     /\n>               D---E---F---G---H---I  <-- other_topic\n> \n> I want the commits L-Q.  If I run\n\nHere is the thing I misunderstood. \"topic\" is already in \"seen\", so\na seen...topic won't work at all.\n\nThis idea is complicated by the fact that you have a concrete idea\nof which commits are in \"topic\", but you really can't do that without\na definition of what it's based on. $(git merge-base main topic)\nwould get you C, but then there are multiple paths from Q to C that\ndon't go through topic.\n\nYou can pull out that \"first\" commit in topic with this:\n\n  git revlist -1 --reverse main..topic\n\nbut it only works if topic is a linear branch off of a single point\nin the history of main.\n\n> The closest I seem to be able to get is\n> \n>    git log --ancestry-path topic~${commits_in_topic_minus_one}..seen\n> \n> which includes all commits I want except the first commit of the topic\n> branch.\n\nIf you add --boundary, you should get that last commit as you want.\n\nThanks,\n-Stolee\n"},{"id":"459801","messageId":"CABPp-BF+8aqysioP_e27Q9kJ02rE2SuSqXu+XphzKWnk5a_Q+A@mail.gmail.com","threadId":"58201","inReplyTo":"8315230c-f79c-8027-9711-6e21a4bc25c4@github.com","subject":"Re: Question: How to find the commits in the ancestry path of seen down to _and_ including a given topic?","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2022-07-22T23:25:04Z","receivedAt":"2022-07-22T23:25:20Z","isPatch":false,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Fri, Jul 22, 2022 at 4:06 AM Derrick Stolee <derrickstolee@github.com> wrote:\n>\n> On 7/21/22 3:34 PM, Elijah Newren wrote:\n> > On Thu, Jul 21, 2022 at 8:37 AM Junio C Hamano <gitster@pobox.com> wrote:\n> >>\n> >> Elijah Newren <newren@gmail.com> writes:\n> >>\n> >>> A simple question that I'm spinning out of [1]: How can I get `git\n> >>> log` to show the commits in the ancestry path from seen, back to *and\n> >>> including* a given topic (but not commits from unrelated topics)?\n> >>\n> >> Drawing of a sample history, please.\n> >>\n> >> I feel stupid asking this, but I do not think I even understand what\n> >> the question is X-<.\n> >>\n> >> Commits that are ancestors of 'seen' and are descendants of the tip\n> >> of the topic?\n> >\n> > What you said *plus* commits from the topic itself.  From this graph:\n> >\n> >     A---B---C---J---K <-- main\n> >             |\\       \\\n> >             | \\       N---------------O---P---Q <-- seen\n> >             |  \\     /               /\n> >             |   L---M  <-- topic    /\n> >              \\                     /\n> >               D---E---F---G---H---I  <-- other_topic\n> >\n> > I want the commits L-Q.  If I run\n>\n> Here is the thing I misunderstood. \"topic\" is already in \"seen\", so\n> a seen...topic won't work at all.\n>\n> This idea is complicated by the fact that you have a concrete idea\n> of which commits are in \"topic\", but you really can't do that without\n> a definition of what it's based on. $(git merge-base main topic)\n> would get you C, but then there are multiple paths from Q to C that\n> don't go through topic.\n>\n> You can pull out that \"first\" commit in topic with this:\n>\n>   git revlist -1 --reverse main..topic\n>\n> but it only works if topic is a linear branch off of a single point\n> in the history of main.\n>\n> > The closest I seem to be able to get is\n> >\n> >    git log --ancestry-path topic~${commits_in_topic_minus_one}..seen\n> >\n> > which includes all commits I want except the first commit of the topic\n> > branch.\n>\n> If you add --boundary, you should get that last commit as you want.\n\nIt is nice that there's a way to get at least the commits I want (and\nwhich is more limited than \"C..topic\"), but unfortunately this adds 16\nextraneous commits to the 36 I want:\n\n    $ git log --oneline --ancestry-path --boundary\n5b893f7d81~11..ac0248bfba | wc -l\n    52\n\nI guess what I really want is something like (made up syntax):\n\n    git log --ancestry-path=${tip_of_topic} main..seen\n\nand have that be translated as listing commits in main..seen which has\n$tip_of_topic directly within its ancestry path somewhere along the\nline (i.e. either (1) has $tip_of_topic as an ancestor, or (2) has\n$tip_of_topic as a descendant, or (3) is $tip_of_topic).  Then I'd get\nexactly the 36 commits I want.  It'd be backward compatible too, since\na plain `--ancestry-path` with no stuck argument could just default to\nusing the bottom commit(s) in the range, as it does now.\n"}]}