#!/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)


[((15, 4, 15, 52), 'os.chdir', 'os.chdir', ({(15, 13, 15, 51): "('/x1/repos/asf/%s.git' % cfg.repo_name)"}, {}), "('/x1/repos/asf/%s.git' % cfg.repo_name)", False, 'import subprocess, os, time\n'), ((17, 18, 17, 44), 'asfgit.git.stream_refs', 'git.stream_refs', ({(17, 34, 17, 43): 'sys.stdin'}, {}), '(sys.stdin)', True, 'import asfgit.git as git\n'), ((25, 8, 25, 65), 'asfgit.util.abort', 'util.abort', ({(25, 19, 25, 64): "('Could not sync with GitHub: %s' % err.output)"}, {}), "('Could not sync with GitHub: %s' % err.output)", True, 'import asfgit.util as util\n'), ((20, 13, 20, 98), 'subprocess.check_call', 'subprocess.check_call', ({(20, 35, 20, 97): "['git', 'push', '-f', ghurl, '%s:%s' % (ref.newsha, ref.name)]"}, {}), "(['git', 'push', '-f', ghurl, '%s:%s' % (ref.newsha,\n    ref.name)])", False, 'import subprocess, os, time\n'), ((23, 13, 23, 92), 'subprocess.check_call', 'subprocess.check_call', ({(23, 35, 23, 91): "['git', 'push', ghurl, '%s:%s' % (ref.newsha, ref.name)]"}, {}), "(['git', 'push', ghurl, '%s:%s' % (ref.newsha, ref.name)])", False, 'import subprocess, os, time\n')]