Finally make remote helper support useful
[git/dscho.git] / git-remote-hg
blob60f6fd421f00c9ce29b12c4d2ecbf38497feb32c
1 #!/usr/bin/env python
3 import sys
6 def get_repo(alias, url):
7 try:
8 from mercurial import hg, ui
9 except ImportError:
10 sys.stderr.write("Mercurial python libraries not installed!\n")
11 sys.exit(1)
13 repo = hg.repository(ui.ui(), url)
14 repo.alias = alias
15 return repo
18 def do_capabilities(repo, args):
19 """
20 """
22 sys.stderr.write("Capabilities are AWESUM.\n")
24 print # end capabilities
27 def do_list(repo, args):
28 """
29 """
31 for ref in repo.branchmap():
32 print '? %s' % (ref)
34 print # end list
37 COMMANDS = {
38 'capabilities': do_capabilities,
39 'list': do_list,
43 def main(args):
44 if len(args) < 3:
45 sys.stderr.write("Missing url and stuff.\n")
46 sys.exit(1)
48 alias = args[1]
49 url = args[2]
51 repo = get_repo(alias, url)
53 sys.stderr.write("How can I help u todayz on %s?\n" % args[1:])
54 line = sys.stdin.readline()
56 while (line):
57 cmdline = line.strip().split()
59 if not cmdline:
60 break # Blank line means we're about to quit
62 cmd = cmdline.pop(0)
63 sys.stderr.write("Got command '%s' with args '%s'\n" % (cmd, ' '.join(cmdline)))
65 if cmd not in COMMANDS:
66 sys.stderr.write("Dunno how to handle that, SUCKAH\n")
67 sys.exit(1)
69 func = COMMANDS[cmd]
70 func(repo, cmdline)
71 sys.stdout.flush()
73 line = sys.stdin.readline()
76 if __name__ == '__main__':
77 sys.exit(main(sys.argv))