# Reacting to new commits in a poll-mirror

4 messages from 2010-02-02 to 2010-02-03. Participants: martin f krafft, Junio C Hamano.
Thread: https://gitlist.dev/t/22498

## martin f krafft, 2010-02-02 22:02

Subject: Reacting to new commits in a poll-mirror
Message-ID: <20100202220234.GA17107@lapse.rw.madduck.net>
URL: https://gitlist.dev/e/20100202220234.GA17107%40lapse.rw.madduck.net

```
Folks,

I am trying to set up Patchwork-Git integration on host A for
a project whose Git repo is on host B. I thought I could use
a mirror (git clone --mirror) on A and regularly fetch from B, but
I cannot find a way (hook) to make Git on A react to new commits it
fetched from B.

I can probably hack something up, e.g. store refs before a fetch and
then iterate the refs between the stored refs and the HEAD, but this
seems exceedingly hackish and I'd much rather have this information
from git-fetch (like git-push calls post-receive).

Is this at all possible?
Would it be possible?
Where would this be done?

-- 
martin | http://madduck.net/ | http://two.sentenc.es/
 
the uncertainty principle:
  you can never be sure how many
  beers you had last night.
 
spamtraps: madduck.bogus@madduck.net

```

## martin f krafft, 2010-02-03 01:10

Subject: Re: Reacting to new commits in a poll-mirror
Message-ID: <20100203011050.GA23249@lapse.rw.madduck.net>
URL: https://gitlist.dev/e/20100203011050.GA23249%40lapse.rw.madduck.net
In-Reply-To: <20100202220234.GA17107@lapse.rw.madduck.net>

```
also sprach martin f krafft <madduck@madduck.net> [2010.02.03.1102 +1300]:
> I am trying to set up Patchwork-Git integration on host A for
> a project whose Git repo is on host B. I thought I could use
> a mirror (git clone --mirror) on A and regularly fetch from B, but
> I cannot find a way (hook) to make Git on A react to new commits it
> fetched from B.

One way is to have a mirror on A, as well as a second repo: first,
fetch to synchronise the mirror, the push to the second repo, where
the post-receive hook will get executed. Works, but it's hackish.
I'd much rather have hooks react right away to the fetch.

-- 
martin | http://madduck.net/ | http://two.sentenc.es/
 
"life is what happens to you while you're busy making other plans."
                                                        -- john lennon
 
spamtraps: madduck.bogus@madduck.net

```

## Junio C Hamano, 2010-02-03 01:32

Subject: Re: Reacting to new commits in a poll-mirror
Message-ID: <7vzl3rt88c.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vzl3rt88c.fsf%40alter.siamese.dyndns.org
In-Reply-To: <20100203011050.GA23249@lapse.rw.madduck.net>

```
martin f krafft <madduck@madduck.net> writes:

> also sprach martin f krafft <madduck@madduck.net> [2010.02.03.1102 +1300]:
>> I am trying to set up Patchwork-Git integration on host A for
>> a project whose Git repo is on host B. I thought I could use
>> a mirror (git clone --mirror) on A and regularly fetch from B, but
>> I cannot find a way (hook) to make Git on A react to new commits it
>> fetched from B.
>
> One way is to have a mirror on A, as well as a second repo: first,
> fetch to synchronise the mirror, the push to the second repo, where
> the post-receive hook will get executed. Works, but it's hackish.
> I'd much rather have hooks react right away to the fetch.

Sorry, but I don't understand the motivation.

You are the one with a desire to know "what new things I got by 'git
fetch' I am going to run right now".

And most importantly, that "right now" is under complete control of you.

Unlike post-receive hook that was invented as a way to be triggered by an
action done by somebody else, iow, an action you (the hook owner) do not
control at all, you do not need any hook around fetch to do what you are
trying to do.  You know when you run fetch.  You are the only one who
updates that repository A.  Until you decide to fetch, nothing will change
in the repository A.

So I don't see what you find wrong about writing your script like:

    #!/bin/sh
    before_fetch=$(git for-each-ref --format='%(objectname)') &&
    git fetch || exit

    git rev-list --all --not $before_fetch |
    while read rev
    do
	do your patchwork magic...
    done

It seems (at least to me) to be exactly the way git plumbing layer was
designed to be used.

```

## martin f krafft, 2010-02-03 10:48

Subject: Re: Reacting to new commits in a poll-mirror
Message-ID: <20100203104857.GC20450@lapse.rw.madduck.net>
URL: https://gitlist.dev/e/20100203104857.GC20450%40lapse.rw.madduck.net
In-Reply-To: <7vzl3rt88c.fsf@alter.siamese.dyndns.org>

```
also sprach Junio C Hamano <gitster@pobox.com> [2010.02.03.1432 +1300]:
> So I don't see what you find wrong about writing your script like:
> 
>     #!/bin/sh
>     before_fetch=$(git for-each-ref --format='%(objectname)') &&
>     git fetch || exit
> 
>     git rev-list --all --not $before_fetch |
>     while read rev
>     do
> 	do your patchwork magic...
>     done

This sounds pretty much what I had in mind, and you have convinced
me that this is the right/better approach. Thanks for keeping those
feet on the ground!

-- 
martin | http://madduck.net/ | http://two.sentenc.es/
 
half a bee, philosophically, must ipso facto half not be.
but half the bee has got to be, vis-a-vis its entity. you see?
but can a bee be said to be or not to be an entire bee,
when half the bee is not a bee, due to some ancient injury?
                                                       -- monty python
 
spamtraps: madduck.bogus@madduck.net

```
