# Testing for commit reachability through plumbing commands

4 messages from 2014-03-06 to 2014-03-06. Participants: Martin Langhoff, Andreas Schwab, Jeff King.
Thread: https://gitlist.dev/t/36076

## Martin Langhoff, 2014-03-06 17:17

Subject: Testing for commit reachability through plumbing commands
Message-ID: <CACPiFCJLyE6XC9dY_eawe2y9gS4YsPdTbqkKAd0dcPXd5-eMCg@mail.gmail.com>
URL: https://gitlist.dev/e/CACPiFCJLyE6XC9dY_eawe2y9gS4YsPdTbqkKAd0dcPXd5-eMCg%40mail.gmail.com

```
I have a shell script that trims old history on a cronjob. This is for
a repo that is used to track reports that have limited "life" (like
logs). Old history is trimmed with grafts pointing to an empty "root"
commit.

Right now, info/graft grows unbound. I am looking for a way to trim
unreachable grafts, I would like to be able to say something like:

 git is-reachable treeish

Grepping through docs and existing code hasn't helped, but perhaps I'm
missing something obvious...

This repository has a couple hundred branches (one per server
tracked). For a single branch, I can picture a relatively easy
approach with git merge-base.

thanks!



m
-- 
 martin.langhoff@gmail.com
 -  ask interesting questions
 - don't get distracted with shiny stuff  - working code first
 ~ http://docs.moodle.org/en/User:Martin_Langhoff

```

## Andreas Schwab, 2014-03-06 19:17

Subject: Re: Testing for commit reachability through plumbing commands
Message-ID: <877g879lwp.fsf@igel.home>
URL: https://gitlist.dev/e/877g879lwp.fsf%40igel.home
In-Reply-To: <CACPiFCJLyE6XC9dY_eawe2y9gS4YsPdTbqkKAd0dcPXd5-eMCg@mail.gmail.com>

```
Martin Langhoff <martin.langhoff@gmail.com> writes:

> I have a shell script that trims old history on a cronjob. This is for
> a repo that is used to track reports that have limited "life" (like
> logs). Old history is trimmed with grafts pointing to an empty "root"
> commit.
>
> Right now, info/graft grows unbound. I am looking for a way to trim
> unreachable grafts, I would like to be able to say something like:
>
>  git is-reachable treeish
>
> Grepping through docs and existing code hasn't helped, but perhaps I'm
> missing something obvious...

Does git fsck --unreachable --no-reflogs help?

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

```

## Martin Langhoff, 2014-03-06 19:29

Subject: Re: Testing for commit reachability through plumbing commands
Message-ID: <CACPiFC+hajx+z_Yq8vC88Q2DsSyD6zg0uOcjMmo7Qhj2m7r4Fg@mail.gmail.com>
URL: https://gitlist.dev/e/CACPiFC%2Bhajx%2Bz_Yq8vC88Q2DsSyD6zg0uOcjMmo7Qhj2m7r4Fg%40mail.gmail.com
In-Reply-To: <877g879lwp.fsf@igel.home>

```
On Thu, Mar 6, 2014 at 2:17 PM, Andreas Schwab <schwab@linux-m68k.org> wrote:
> Does git fsck --unreachable --no-reflogs help?

Well, my script, called regularly, does:

 - adds grafts
 - git repack -AFfd (which unpacks unreachable objects)
 - git prune --expire now

.... hmm, I guess could prune the grafts using git fsck --unreachable
--no-reflogs before pruning the objects themselves.

we'll find out if it works :-)



m
-- 
 martin.langhoff@gmail.com
 -  ask interesting questions
 - don't get distracted with shiny stuff  - working code first
 ~ http://docs.moodle.org/en/User:Martin_Langhoff

```

## Jeff King, 2014-03-06 20:23

Subject: Re: Testing for commit reachability through plumbing commands
Message-ID: <20140306202319.GB29659@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20140306202319.GB29659%40sigill.intra.peff.net
In-Reply-To: <CACPiFCJLyE6XC9dY_eawe2y9gS4YsPdTbqkKAd0dcPXd5-eMCg@mail.gmail.com>

```
On Thu, Mar 06, 2014 at 12:17:34PM -0500, Martin Langhoff wrote:

> I have a shell script that trims old history on a cronjob. This is for
> a repo that is used to track reports that have limited "life" (like
> logs). Old history is trimmed with grafts pointing to an empty "root"
> commit.
> 
> Right now, info/graft grows unbound. I am looking for a way to trim
> unreachable grafts, I would like to be able to say something like:
> 
>  git is-reachable treeish

How about:

    git rev-list --objects --all |
    cut -d' ' -f1 |
    grep $(git rev-parse treeish)

Add "--reflog" to the rev-list invocation if you want to catch things
referenced by the reflog, too.

If you're looking for a commit, you can drop the "--objects", and it
will run much faster.

-Peff

```
