git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Question: How to find the commits in the ancestry path of seen down to _and_ including a given topic?
@ 2022-07-21  7:23 Elijah Newren
  2022-07-21 15:37 ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Elijah Newren @ 2022-07-21  7:23 UTC (permalink / raw)
  To: Git Mailing List

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)?

   git log --ancestry-path $TOPIC..seen

doesn't work, because that excludes $TOPIC.  (It does get me the merge
of $TOPIC into seen, as well as all merges into seen following that
merge, which I want, but it's missing the topic itself.)

  git log --ancestry-path $BASE_OF_TOPIC..seen

usually doesn't work, because $BASE_OF_TOPIC is usually a commit from
"main" or "master", and this results in pulling in hundreds of commits
from unrelated topics that also happen to be based on a version of
"main" or "master" at or after $BASE_OF_TOPIC.

Is there some magic that does what I want, or is this just not
possible currently?

Thanks,
Elijah


[1] https://lore.kernel.org/git/CABPp-BHARfYcsEM7Daeb7+vYxeB9Awo8=qbrOMXG6BQ0gX1RiA@mail.gmail.com/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question: How to find the commits in the ancestry path of seen down to _and_ including a given topic?
  2022-07-21  7:23 Question: How to find the commits in the ancestry path of seen down to _and_ including a given topic? Elijah Newren
@ 2022-07-21 15:37 ` Junio C Hamano
  2022-07-21 18:48   ` Derrick Stolee
  2022-07-21 19:34   ` Elijah Newren
  0 siblings, 2 replies; 6+ messages in thread
From: Junio C Hamano @ 2022-07-21 15:37 UTC (permalink / raw)
  To: Elijah Newren; +Cc: Git Mailing List

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?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question: How to find the commits in the ancestry path of seen down to _and_ including a given topic?
  2022-07-21 15:37 ` Junio C Hamano
@ 2022-07-21 18:48   ` Derrick Stolee
  2022-07-21 19:34   ` Elijah Newren
  1 sibling, 0 replies; 6+ messages in thread
From: Derrick Stolee @ 2022-07-21 18:48 UTC (permalink / raw)
  To: Junio C Hamano, Elijah Newren; +Cc: Git Mailing List

On 7/21/2022 11:37 AM, Junio C Hamano 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?

Have you tried 

  git log --graph --oneline --boundary --ancestry-path <A>...<B>

The triple dots show the symmetric diff, and the --boundary shows
the possible merge-bases. The --ancestry-path option seems to trim
the output significantly in the example I tried.

Thanks,
-Stolee

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question: How to find the commits in the ancestry path of seen down to _and_ including a given topic?
  2022-07-21 15:37 ` Junio C Hamano
  2022-07-21 18:48   ` Derrick Stolee
@ 2022-07-21 19:34   ` Elijah Newren
  2022-07-22 11:06     ` Derrick Stolee
  1 sibling, 1 reply; 6+ messages in thread
From: Elijah Newren @ 2022-07-21 19:34 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

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

   git log --ancestry-path topic..seen

I only get N-Q, missing L & M.  If I run

   git log --ancestry-path main..seen

then I get D-Q, providing me with D-I and J-K that I don't want.

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.


An example, from git.git; 5b893f7d81 is a topic (ab/submodule-cleanup)
with 12 commits, and ac0248bfba is some older version of 'next' .  I
want all 12 commits in that topic plus all commits that are both
descendants of that tip and ancestors of that old version of 'next',
which adds up to 36 commits.  (Note that this includes the 12 commits
in ab/submodule clean, 9 commits from gc/submodule-use-super-prefix
since that happens to be a descendant of ab/submodule-cleanup, and
about 15 merge commits from merging other topics into next, but does
not include those other 15 topics.)  If I run (notice the "11" instead
of "12"):

   git log --oneline --ancestry-path 5b893f7d81~11..ac0248bfba | wc -l

it reports 35 commits -- it's just missing the first commit from the
topic.  If I change "11" to "12" to try to get that first commit too:

   git log --oneline --ancestry-path 5b893f7d81~11..ac0248bfba | wc -l

then it reports 228 commits, 192 of which I don't want.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question: How to find the commits in the ancestry path of seen down to _and_ including a given topic?
  2022-07-21 19:34   ` Elijah Newren
@ 2022-07-22 11:06     ` Derrick Stolee
  2022-07-22 23:25       ` Elijah Newren
  0 siblings, 1 reply; 6+ messages in thread
From: Derrick Stolee @ 2022-07-22 11:06 UTC (permalink / raw)
  To: Elijah Newren, Junio C Hamano; +Cc: Git Mailing List

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.

Thanks,
-Stolee

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question: How to find the commits in the ancestry path of seen down to _and_ including a given topic?
  2022-07-22 11:06     ` Derrick Stolee
@ 2022-07-22 23:25       ` Elijah Newren
  0 siblings, 0 replies; 6+ messages in thread
From: Elijah Newren @ 2022-07-22 23:25 UTC (permalink / raw)
  To: Derrick Stolee; +Cc: Junio C Hamano, Git Mailing List

On Fri, Jul 22, 2022 at 4:06 AM Derrick Stolee <derrickstolee@github.com> wrote:
>
> 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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-07-22 23:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-21  7:23 Question: How to find the commits in the ancestry path of seen down to _and_ including a given topic? Elijah Newren
2022-07-21 15:37 ` Junio C Hamano
2022-07-21 18:48   ` Derrick Stolee
2022-07-21 19:34   ` Elijah Newren
2022-07-22 11:06     ` Derrick Stolee
2022-07-22 23:25       ` Elijah Newren

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).