11 demandload(globals(), "os re sys signal shutil imp urllib pdb") |
11 demandload(globals(), "os re sys signal shutil imp urllib pdb") |
12 demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo") |
12 demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo") |
13 demandload(globals(), "fnmatch mdiff random signal tempfile time") |
13 demandload(globals(), "fnmatch mdiff random signal tempfile time") |
14 demandload(globals(), "traceback errno socket version struct atexit sets bz2") |
14 demandload(globals(), "traceback errno socket version struct atexit sets bz2") |
15 demandload(globals(), "archival changegroup") |
15 demandload(globals(), "archival changegroup") |
16 demandload(globals(), "hgweb.server") |
16 demandload(globals(), "hgweb.server sshserver") |
17 |
17 |
18 class UnknownCommand(Exception): |
18 class UnknownCommand(Exception): |
19 """Exception raised if command is not in the command table.""" |
19 """Exception raised if command is not in the command table.""" |
20 class AmbiguousCommand(Exception): |
20 class AmbiguousCommand(Exception): |
21 """Exception raised if command shortcut matches more than one command.""" |
21 """Exception raised if command shortcut matches more than one command.""" |
2450 """ |
2450 """ |
2451 |
2451 |
2452 if opts["stdio"]: |
2452 if opts["stdio"]: |
2453 if repo is None: |
2453 if repo is None: |
2454 raise hg.RepoError(_('no repo found')) |
2454 raise hg.RepoError(_('no repo found')) |
2455 fin, fout = sys.stdin, sys.stdout |
2455 s = sshserver.sshserver(ui, repo) |
2456 sys.stdout = sys.stderr |
2456 s.serve_forever() |
2457 |
|
2458 # Prevent insertion/deletion of CRs |
|
2459 util.set_binary(fin) |
|
2460 util.set_binary(fout) |
|
2461 |
|
2462 def getarg(): |
|
2463 argline = fin.readline()[:-1] |
|
2464 arg, l = argline.split() |
|
2465 val = fin.read(int(l)) |
|
2466 return arg, val |
|
2467 def respond(v): |
|
2468 fout.write("%d\n" % len(v)) |
|
2469 fout.write(v) |
|
2470 fout.flush() |
|
2471 |
|
2472 lock = None |
|
2473 |
|
2474 while 1: |
|
2475 cmd = fin.readline()[:-1] |
|
2476 if cmd == '': |
|
2477 return |
|
2478 if cmd == "heads": |
|
2479 h = repo.heads() |
|
2480 respond(" ".join(map(hex, h)) + "\n") |
|
2481 if cmd == "lock": |
|
2482 lock = repo.lock() |
|
2483 respond("") |
|
2484 if cmd == "unlock": |
|
2485 if lock: |
|
2486 lock.release() |
|
2487 lock = None |
|
2488 respond("") |
|
2489 elif cmd == "branches": |
|
2490 arg, nodes = getarg() |
|
2491 nodes = map(bin, nodes.split(" ")) |
|
2492 r = [] |
|
2493 for b in repo.branches(nodes): |
|
2494 r.append(" ".join(map(hex, b)) + "\n") |
|
2495 respond("".join(r)) |
|
2496 elif cmd == "between": |
|
2497 arg, pairs = getarg() |
|
2498 pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] |
|
2499 r = [] |
|
2500 for b in repo.between(pairs): |
|
2501 r.append(" ".join(map(hex, b)) + "\n") |
|
2502 respond("".join(r)) |
|
2503 elif cmd == "changegroup": |
|
2504 nodes = [] |
|
2505 arg, roots = getarg() |
|
2506 nodes = map(bin, roots.split(" ")) |
|
2507 |
|
2508 cg = repo.changegroup(nodes, 'serve') |
|
2509 while 1: |
|
2510 d = cg.read(4096) |
|
2511 if not d: |
|
2512 break |
|
2513 fout.write(d) |
|
2514 |
|
2515 fout.flush() |
|
2516 |
|
2517 elif cmd == "addchangegroup": |
|
2518 if not lock: |
|
2519 respond("not locked") |
|
2520 continue |
|
2521 respond("") |
|
2522 |
|
2523 r = repo.addchangegroup(fin, 'serve') |
|
2524 respond(str(r)) |
|
2525 |
2457 |
2526 optlist = ("name templates style address port ipv6" |
2458 optlist = ("name templates style address port ipv6" |
2527 " accesslog errorlog webdir_conf") |
2459 " accesslog errorlog webdir_conf") |
2528 for o in optlist.split(): |
2460 for o in optlist.split(): |
2529 if opts[o]: |
2461 if opts[o]: |