#!/usr/local/bin/python

import json
import socket
import sys

import asfgit.cfg as cfg
import asfgit.git as git
import asfgit.log as log
import asfgit.util as util
import subprocess, os, time

def main():
    ghurl = "git@github:apache/%s.git" % cfg.repo_name
    os.chdir("/x1/repos/asf/%s.git" % cfg.repo_name)
    try:
       for ref in git.stream_refs(sys.stdin):
          if ref.is_rewrite():
             print("Syncing %s (FORCED)..." % ref.name)
             subprocess.check_call(["git", "push", "-f", ghurl, "%s:%s" % (ref.newsha, ref.name)])
          else:
             print("Syncing %s..." % ref.name)
             subprocess.check_call(["git", "push", ghurl, "%s:%s" % (ref.newsha, ref.name)])
    except subprocess.CalledProcessError as err:
        util.abort("Could not sync with GitHub: %s" % err.output)


[((265, 313), 'os.chdir', 'os.chdir', (["('/x1/repos/asf/%s.git' % cfg.repo_name)"], {}), "('/x1/repos/asf/%s.git' % cfg.repo_name)\n", (273, 313), False, 'import subprocess, os, time\n'), ((341, 367), 'asfgit.git.stream_refs', 'git.stream_refs', (['sys.stdin'], {}), '(sys.stdin)\n', (356, 367), True, 'import asfgit.git as git\n'), ((768, 825), 'asfgit.util.abort', 'util.abort', (["('Could not sync with GitHub: %s' % err.output)"], {}), "('Could not sync with GitHub: %s' % err.output)\n", (778, 825), True, 'import asfgit.util as util\n'), ((469, 558), 'subprocess.check_call', 'subprocess.check_call', (["['git', 'push', '-f', ghurl, '%s:%s' % (ref.newsha, ref.name)]"], {}), "(['git', 'push', '-f', ghurl, '%s:%s' % (ref.newsha,\n    ref.name)])\n", (490, 558), False, 'import subprocess, os, time\n'), ((631, 710), 'subprocess.check_call', 'subprocess.check_call', (["['git', 'push', ghurl, '%s:%s' % (ref.newsha, ref.name)]"], {}), "(['git', 'push', ghurl, '%s:%s' % (ref.newsha, ref.name)])\n", (652, 710), False, 'import subprocess, os, time\n')]