@Override
public ReceivePack create( final BaseGitCommand req,
final Repository db ) throws ServiceNotEnabledException, ServiceNotAuthorizedException {
return new ReceivePack( db ) {{
final ClusterService clusterService = clusterMap.get( db );
final JGitFileSystem fs = repoIndex.get( db );
final Map<String, RevCommit> oldTreeRefs = new HashMap<String, RevCommit>();
setPreReceiveHook( new PreReceiveHook() {
@Override
public void onPreReceive( final ReceivePack rp,
final Collection<ReceiveCommand> commands ) {
if ( clusterService != null ) {
clusterService.lock();
}
for ( final ReceiveCommand command : commands ) {
final RevCommit lastCommit = JGitUtil.getLastCommit( fs.gitRepo(), command.getRefName() );
oldTreeRefs.put( command.getRefName(), lastCommit );
}
}
} );
setPostReceiveHook( new PostReceiveHook() {
@Override
public void onPostReceive( final ReceivePack rp,
final Collection<ReceiveCommand> commands ) {
for ( Map.Entry<String, RevCommit> oldTreeRef : oldTreeRefs.entrySet() ) {
final List<RevCommit> commits = JGitUtil.getCommits( fs, oldTreeRef.getKey(), oldTreeRef.getValue(), JGitUtil.getLastCommit( fs.gitRepo(), oldTreeRef.getKey() ) );
for ( final RevCommit revCommit : commits ) {
notifyDiffs( fs, oldTreeRef.getKey(), "<ssh>", req.getUser().getName(), revCommit.getFullMessage(), revCommit.getParent( 0 ).getTree(), revCommit.getTree() );
}
}
if ( clusterService != null ) {
//TODO {porcelli} hack, that should be addressed in future
clusterService.broadcast( DEFAULT_IO_SERVICE_NAME,
new MessageType() {
@Override
public String toString() {
return "SYNC_FS";
}
@Override
public int hashCode() {
return "SYNC_FS".hashCode();
}
},
new HashMap<String, String>() {{
put( "fs_scheme", "git" );
put( "fs_id", fs.id() );
put( "fs_uri", fs.toString() );
}}
);
clusterService.unlock();
}
}
} );
}};
}