comparison mercurial/commands.py @ 624:876333a295ff

Add an sshrepository class and hg serve --stdio
author Matt Mackall <mpm@selenic.com>
date Tue, 05 Jul 2005 17:55:22 -0800
parents 4051b78c53c7
children 978011cf5279
comparison
equal deleted inserted replaced
623:314867960a4a 624:876333a295ff
7 7
8 from demandload import * 8 from demandload import *
9 demandload(globals(), "os re sys signal") 9 demandload(globals(), "os re sys signal")
10 demandload(globals(), "fancyopts ui hg util") 10 demandload(globals(), "fancyopts ui hg util")
11 demandload(globals(), "hgweb mdiff random signal time traceback") 11 demandload(globals(), "hgweb mdiff random signal time traceback")
12 demandload(globals(), "errno socket version") 12 demandload(globals(), "errno socket version struct")
13 13
14 class UnknownCommand(Exception): pass 14 class UnknownCommand(Exception): pass
15 15
16 def filterfiles(filters, files): 16 def filterfiles(filters, files):
17 l = [ x for x in files if x in filters ] 17 l = [ x for x in files if x in filters ]
821 """print the root (top) of the current working dir""" 821 """print the root (top) of the current working dir"""
822 ui.write(repo.root + "\n") 822 ui.write(repo.root + "\n")
823 823
824 def serve(ui, repo, **opts): 824 def serve(ui, repo, **opts):
825 """export the repository via HTTP""" 825 """export the repository via HTTP"""
826
827 if opts["stdio"]:
828 def getarg():
829 argline = sys.stdin.readline()[:-1]
830 arg, l = argline.split()
831 val = sys.stdin.read(int(l))
832 return arg, val
833 def respond(v):
834 sys.stdout.write("%d\n" % len(v))
835 sys.stdout.write(v)
836 sys.stdout.flush()
837
838 while 1:
839 cmd = sys.stdin.readline()[:-1]
840 if cmd == '':
841 return
842 if cmd == "heads":
843 h = repo.heads()
844 respond(" ".join(map(hg.hex, h)) + "\n")
845 elif cmd == "branches":
846 arg, nodes = getarg()
847 nodes = map(hg.bin, nodes.split(" "))
848 r = []
849 for b in repo.branches(nodes):
850 r.append(" ".join(map(hg.hex, b)) + "\n")
851 respond("".join(r))
852 elif cmd == "between":
853 arg, pairs = getarg()
854 pairs = [ map(hg.bin, p.split("-")) for p in pairs.split(" ") ]
855 r = []
856 for b in repo.between(pairs):
857 r.append(" ".join(map(hg.hex, b)) + "\n")
858 respond("".join(r))
859 elif cmd == "changegroup":
860 nodes = []
861 arg, roots = getarg()
862 nodes = map(hg.bin, roots.split(" "))
863
864 b = []
865 t = 0
866 for chunk in repo.changegroup(nodes):
867 t += len(chunk)
868 b.append(chunk)
869 if t > 4096:
870 sys.stdout.write(struct.pack(">l", t))
871 for c in b:
872 sys.stdout.write(c)
873 t = 0
874 b = []
875
876 sys.stdout.write(struct.pack(">l", t))
877 for c in b:
878 sys.stdout.write(c)
879
880 sys.stdout.write(struct.pack(">l", -1))
881 sys.stdout.flush()
882
826 def openlog(opt, default): 883 def openlog(opt, default):
827 if opts[opt] and opts[opt] != '-': return open(opts[opt], 'w') 884 if opts[opt] and opts[opt] != '-': return open(opts[opt], 'w')
828 else: return default 885 else: return default
886
829 httpd = hgweb.create_server(repo.root, opts["name"], opts["templates"], 887 httpd = hgweb.create_server(repo.root, opts["name"], opts["templates"],
830 opts["address"], opts["port"], 888 opts["address"], opts["port"],
831 openlog('accesslog', sys.stdout), 889 openlog('accesslog', sys.stdout),
832 openlog('errorlog', sys.stderr)) 890 openlog('errorlog', sys.stderr))
833 if ui.verbose: 891 if ui.verbose:
1015 "^serve": (serve, [('A', 'accesslog', '', 'access log file'), 1073 "^serve": (serve, [('A', 'accesslog', '', 'access log file'),
1016 ('E', 'errorlog', '', 'error log file'), 1074 ('E', 'errorlog', '', 'error log file'),
1017 ('p', 'port', 8000, 'listen port'), 1075 ('p', 'port', 8000, 'listen port'),
1018 ('a', 'address', '', 'interface address'), 1076 ('a', 'address', '', 'interface address'),
1019 ('n', 'name', os.getcwd(), 'repository name'), 1077 ('n', 'name', os.getcwd(), 'repository name'),
1078 ('', 'stdio', None, 'for remote clients'),
1020 ('t', 'templates', "", 'template map')], 1079 ('t', 'templates', "", 'template map')],
1021 "hg serve [options]"), 1080 "hg serve [options]"),
1022 "^status": (status, [], 'hg status'), 1081 "^status": (status, [], 'hg status'),
1023 "tag": (tag, [('l', 'local', None, 'make the tag local'), 1082 "tag": (tag, [('l', 'local', None, 'make the tag local'),
1024 ('t', 'text', "", 'commit text'), 1083 ('t', 'text', "", 'commit text'),