git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* post-fetch, tweak-fetch hook
@ 2012-05-06 20:52 Mitar
  2012-05-06 23:10 ` Seth Robertson
  0 siblings, 1 reply; 6+ messages in thread
From: Mitar @ 2012-05-06 20:52 UTC (permalink / raw)
  To: git

Hi!

I am writing a plugin which allows syncing of GitHub repositories with
local Trac mirrored ones.

http://trac-hacks.org/wiki/GitHubSyncPlugin

In this configuration, I have a git clone --mirror local repository of
GitHub repository and on each push to GitHub repository, GitHub does a
POST notification to my Trac installation, where my Trac plugin
receives that notification and calls fetch on local mirror.

The problem is that I also have to notify Trac of all new revisions
(their hashes) the fetch retrieved. If this would be push,
post-receive hook would be a place to get this information. But as I
read, there is no post-fetch hook. The argument is that it is not
needed. That locally run fetch can also run needed post-processing.
But I have three counter arguments to this, based on my current
experience:

Code reuse: having same interface for both post-fetch and post-receive
hooks would mean easier post-processing. They are similar and I can
imagine that there exist many scenarios where same script would be
used for both hooks. Together with this is also maintainability: you
could make a myfetch command doing custom post-processing, but
interfacing this with a known API through hooks, all in one directory,
would make things much easier to maintain. Not that one script is in
hooks (post-receive) and the other is invoked in some other manner.

I am a git newbie, but after few hours or reading and searching I have
not found a simple way to get a list of revisions retrieved by a
fetch, so that I could call my custom post-processing. If this is
really so simple that there is no need for post-fetch hook, I am all
ears. FETCH_HEAD file contains only last revisions for each branch,
not a range (old-new, like post-receive). Furthermore, even if there
have been no new revisions retrieved, FETCH_HEAD file stays at its old
state (not for example deleting it), so some additional logic would be
needed. Parsing the output of git fetch also does not look like
something easily parsed by a program.

Even if there is a way to reconstruct data passed to post-receive (to
be given to post-fetch), I am concerned about race-condition of this.
Because in post-receive this data is tightly connected to the push
being done. Even if there is another push in process at the same time,
git would take care post-receive is called with exactly those
revisions. In case of reconstructing those revisions, it could happen,
that two fetches overlap in such a manner that in my custom myfetch
script I reconstruct same revisions for both fetches (for example,
read same version of FETCH_HEAD file which has been updated twice by
fetch, but I would get only one version), while there were of course
different.

I have found some work from Joey Hess on tweak-fetch hook and I would
really welcome such addition. Maybe my problems stem only from me
being a git novice, but post-fetch (tweak-fetch) hook would really
really make things simple and intuitive also for such users.

So I would kindly ask for some advice on how to get in a safe manner
data similar to what is provided to post-receive.


Mitar

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

end of thread, other threads:[~2012-05-07 13:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-06 20:52 post-fetch, tweak-fetch hook Mitar
2012-05-06 23:10 ` Seth Robertson
2012-05-06 23:54   ` Mitar
2012-05-07  7:29   ` Jeff King
2012-05-07  9:11     ` Mitar
2012-05-07 13:38       ` Jeff King

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