#!/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, 'os.chdir', 'os.chdir', False, 'import subprocess, os, time\n'), (17, 'asfgit.git.stream_refs', 'git.stream_refs', True, 'import asfgit.git as git\n'), (25, 'asfgit.util.abort', 'util.abort', True, 'import asfgit.util as util\n'), (20, 'subprocess.check_call', 'subprocess.check_call', False, 'import subprocess, os, time\n'), (23, 'subprocess.check_call', 'subprocess.check_call', False, 'import subprocess, os, time\n')]