comparison mercurial/wireprotoserver.py @ 50444:45c7bada5200

hidden: add support to explicitly access hidden changesets with SSH peers This implements support for using --remote-hidden with an SSH server. The remote `hg serve --stdio` call is passed the `--hidden` flag as a request to access hidden changesets. This approach has benefits similar to the one we used for HTTP peers. It * works around the lack of global parameters in wire protocol v1, * reuses the `--hidden` flag (that does not use the wireproto), and * can be safely ignored by older client (fitting the best effort contract). Same as for HTTP, the feature is experimental so we have all the room we needs to update the implementation in the future if deemed necessary. The SSH version of the `--remote-hidden` config uses the same configuration as the HTTP support to control the access to this feature. The name of the user running the command is used for the checking. Test written by Pierre-Yves David.
author Manuel Jacob <me@manueljacob.de>
date Sat, 13 Apr 2019 03:44:55 +0200
parents 3b199593fedd
children 13c004b54cbe
comparison
equal deleted inserted replaced
50443:afb27fc92717 50444:45c7bada5200
444 444
445 def checkperm(self, perm): 445 def checkperm(self, perm):
446 pass 446 pass
447 447
448 448
449 def _runsshserver(ui, repo, fin, fout, ev): 449 def _runsshserver(ui, repo, fin, fout, ev, accesshidden=False):
450 # This function operates like a state machine of sorts. The following 450 # This function operates like a state machine of sorts. The following
451 # states are defined: 451 # states are defined:
452 # 452 #
453 # protov1-serving 453 # protov1-serving
454 # Server is in protocol version 1 serving mode. Commands arrive on 454 # Server is in protocol version 1 serving mode. Commands arrive on
485 # back to waiting for a new command. 485 # back to waiting for a new command.
486 if not available: 486 if not available:
487 _sshv1respondbytes(fout, b'') 487 _sshv1respondbytes(fout, b'')
488 continue 488 continue
489 489
490 rsp = wireprotov1server.dispatch(repo, proto, request) 490 rsp = wireprotov1server.dispatch(
491 repo, proto, request, accesshidden=accesshidden
492 )
491 repo.ui.fout.flush() 493 repo.ui.fout.flush()
492 repo.ui.ferr.flush() 494 repo.ui.ferr.flush()
493 495
494 if isinstance(rsp, bytes): 496 if isinstance(rsp, bytes):
495 _sshv1respondbytes(fout, rsp) 497 _sshv1respondbytes(fout, rsp)
520 b'unhandled ssh server state: %s' % state 522 b'unhandled ssh server state: %s' % state
521 ) 523 )
522 524
523 525
524 class sshserver: 526 class sshserver:
525 def __init__(self, ui, repo, logfh=None): 527 def __init__(self, ui, repo, logfh=None, accesshidden=False):
526 self._ui = ui 528 self._ui = ui
527 self._repo = repo 529 self._repo = repo
528 self._fin, self._fout = ui.protectfinout() 530 self._fin, self._fout = ui.protectfinout()
531 self._accesshidden = accesshidden
529 532
530 # Log write I/O to stdout and stderr if configured. 533 # Log write I/O to stdout and stderr if configured.
531 if logfh: 534 if logfh:
532 self._fout = util.makeloggingfileobject( 535 self._fout = util.makeloggingfileobject(
533 logfh, self._fout, b'o', logdata=True 536 logfh, self._fout, b'o', logdata=True
540 self.serveuntil(threading.Event()) 543 self.serveuntil(threading.Event())
541 self._ui.restorefinout(self._fin, self._fout) 544 self._ui.restorefinout(self._fin, self._fout)
542 545
543 def serveuntil(self, ev): 546 def serveuntil(self, ev):
544 """Serve until a threading.Event is set.""" 547 """Serve until a threading.Event is set."""
545 _runsshserver(self._ui, self._repo, self._fin, self._fout, ev) 548 _runsshserver(
549 self._ui, self._repo, self._fin, self._fout, ev, self._accesshidden
550 )