Source

timestamp / autosync.py

Full commit
# autosync.py - defines a hook for pushing changes to a proxy
#               repositories
#
# Copyright 2009 Friedrich Kastner-Masilko <face@snoopie.at>
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.

from mercurial.i18n import _
import subprocess

def hook(ui, repo, hooktype, url=None, source=None, **kwargs):
    '''hook for pushing changes to proxy repositories'''
    remoteUrls=ui.configlist('autosync', 'path')
    if remoteUrls:
        doit = source==None
        if not doit:
            sources=ui.configlist('autosync', 'sources')
            if not sources: doit=True
            elif source in sources: doit=True
        if doit:
            if ui.configbool('autosync', 'debug'):
                ui.status(repo.root)
                ui.status(_(': '))
                ui.status(hooktype)
                ui.status(_('-hook of '))
                ui.status(source)
                ui.status(_(' from \''))
                ui.status(url)
                ui.status(_('\' with '))
                ui.status(kwargs)
                ui.status(_('\n'))
            else:
                exceptions=ui.configlist('autosync', 'exception')
                if url in exceptions:
                    ui.debug(_('source is exception, no autosync required\n'))
                else:
                    cmd=ui.config('autosync','cmd')
                    if not cmd: cmd='out'
                    for remoteUrl in remoteUrls:
                        cmd='hg -R "'+repo.root+'" '+cmd+' "'+remoteUrl+'"'
                        ui.debug(_('autosync command is \''))
                        ui.debug(cmd)
                        ui.debug(_('\'\n'))
                        subprocess.Popen(cmd, cwd=repo.root)
                        ui.status(_('autosync to \''))
                        ui.status(remoteUrl)
                        ui.status(_('\' initiated\n'))
        else:
            ui.debug(_('hook-source not in list, no autosync applied.\n'))
    return False