git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Thomas Harning Jr." <harningt@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Best method of detecting if list of commit refs is a parent
Date: Sun, 17 Aug 2008 21:41:15 -0700	[thread overview]
Message-ID: <7vfxp3ndec.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <e47324780808171924j237688faj9e13740f89e75fdf@mail.gmail.com> (Thomas Harning, Jr.'s message of "Sun, 17 Aug 2008 22:24:20 -0400")

"Thomas Harning Jr." <harningt@gmail.com> writes:

> I'm working on my 'Stick' git bug-tracking tool and am working on the
> functionality to get a list of relevant bug-items at a specific point
> in history.
>
> Before I get into figuring out the 'best' way to do this, I thought
> I'd at least get the simple single-item case of detecting if a
> specific commit can be walked to from another commit...

It is unclear from your description what you are trying to do here, but if
you want to know if a commit A is reachable from commit B, the standard
way to do so is:

        git merge-base A B

If the output from the command is the object name of commit A, that means
A is reachable from B.  Otherwise A is not reachable from B.

This is because "merge-base" computes the set of ancestors common to A and
B that are not reachable from other ancestors common to A and B.

Examples.

(1) This one is obvious.

        A---o---o---o---B

(2) Merge-base between A and B is M.  The one before M is also an ancestor
    common to A and B, but because it is reachable from M which is another
    ancestor common between A and B, it won't be part of the merge-base
    output.

              o---A
             /
        o---M---o---B

If you have bunch of commits A B C D E F and if you would want to know
which one of them is reachable from X, you could of course run merge-base
once for each of A..F.  Another way to do this would be to run:

	git rev-list A B C D E F ^X

and look at the output.  The ones among A..F that appear in the output are
not reachable from X.  The ones that are reachable from X do not appear in
the output.

This is because "rev-list" outputs everything reachable from the given
commits without ^ prefix, excluding the ones that are reacahble from the
ones prefixed with ^.

  reply	other threads:[~2008-08-18  4:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-18  2:24 Best method of detecting if list of commit refs is a parent Thomas Harning Jr.
2008-08-18  4:41 ` Junio C Hamano [this message]
2008-08-18 13:37   ` Thomas Harning
2008-08-23  2:24     ` Thomas Harning

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vfxp3ndec.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=harningt@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).