git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Question: How to find the commits in the ancestry path of seen down to _and_ including a given topic?

From
Elijah Newren <newren@gmail.com>
Date
Jul 22, 2022, 23:25 UTC
Message-ID
<CABPp-BF+8aqysioP_e27Q9kJ02rE2SuSqXu+XphzKWnk5a_Q+A@mail.gmail.com>
In-Reply-To
<8315230c-f79c-8027-9711-6e21a4bc25c4@github.com>
On Fri, Jul 22, 2022 at 4:06 AM Derrick Stolee <derrickstolee@github.com> wrote:
Show 54 quoted lines
>
> On 7/21/22 3:34 PM, Elijah Newren wrote:
> > On Thu, Jul 21, 2022 at 8:37 AM Junio C Hamano <gitster@pobox.com> wrote:
> >>
> >> Elijah Newren <newren@gmail.com> writes:
> >>
> >>> A simple question that I'm spinning out of [1]: How can I get `git
> >>> log` to show the commits in the ancestry path from seen, back to *and
> >>> including* a given topic (but not commits from unrelated topics)?
> >>
> >> Drawing of a sample history, please.
> >>
> >> I feel stupid asking this, but I do not think I even understand what
> >> the question is X-<.
> >>
> >> Commits that are ancestors of 'seen' and are descendants of the tip
> >> of the topic?
> >
> > What you said *plus* commits from the topic itself.  From this graph:
> >
> >     A---B---C---J---K <-- main
> >             |\       \
> >             | \       N---------------O---P---Q <-- seen
> >             |  \     /               /
> >             |   L---M  <-- topic    /
> >              \                     /
> >               D---E---F---G---H---I  <-- other_topic
> >
> > I want the commits L-Q.  If I run
>
> Here is the thing I misunderstood. "topic" is already in "seen", so
> a seen...topic won't work at all.
>
> This idea is complicated by the fact that you have a concrete idea
> of which commits are in "topic", but you really can't do that without
> a definition of what it's based on. $(git merge-base main topic)
> would get you C, but then there are multiple paths from Q to C that
> don't go through topic.
>
> You can pull out that "first" commit in topic with this:
>
>   git revlist -1 --reverse main..topic
>
> but it only works if topic is a linear branch off of a single point
> in the history of main.
>
> > The closest I seem to be able to get is
> >
> >    git log --ancestry-path topic~${commits_in_topic_minus_one}..seen
> >
> > which includes all commits I want except the first commit of the topic
> > branch.
>
> If you add --boundary, you should get that last commit as you want.

It is nice that there's a way to get at least the commits I want (and which is more limited than "C..topic"), but unfortunately this adds 16 extraneous commits to the 36 I want:

    $ git log --oneline --ancestry-path --boundary
5b893f7d81~11..ac0248bfba | wc -l
    52
I guess what I really want is something like (made up syntax):
    git log --ancestry-path=${tip_of_topic} main..seen

and have that be translated as listing commits in main..seen which has $tip_of_topic directly within its ancestry path somewhere along the line (i.e. either (1) has $tip_of_topic as an ancestor, or (2) has $tip_of_topic as a descendant, or (3) is $tip_of_topic). Then I'd get exactly the 36 commits I want. It'd be backward compatible too, since a plain `--ancestry-path` with no stuck argument could just default to using the bottom commit(s) in the range, as it does now.

Previous: Derrick Stolee
Message 6 of 6 in “Question: How to find the commits in the ancestry path of seen down to _and_ including a given topic?”
  1. Elijah NewrenJul 21, 2022
  2. Junio C HamanoJul 21, 2022
  3. Derrick StoleeJul 21, 2022
  4. Elijah NewrenJul 21, 2022
  5. Derrick StoleeJul 22, 2022
  6. Elijah NewrenJul 22, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.