Mercurial > hg-stable
changeset 20650:e811b93f2cb1
cmdserver: allow to start server without repository
Typical use case is to clone repository through command server. Clone may
require user interaction, so command-server protocol is beneficial over
raw stdio channels.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 03 Mar 2014 23:21:24 +0900 |
parents | 9524938c8ff8 |
children | c1a52dd56eb4 |
files | mercurial/commands.py mercurial/commandserver.py tests/test-commandserver.py tests/test-commandserver.py.out |
diffstat | 4 files changed, 38 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Mon Mar 03 23:11:17 2014 +0900 +++ b/mercurial/commands.py Mon Mar 03 23:21:24 2014 +0900 @@ -5168,7 +5168,6 @@ s.serve_forever() if opts["cmdserver"]: - checkrepo() s = commandserver.server(ui, repo, opts["cmdserver"]) return s.serve()
--- a/mercurial/commandserver.py Mon Mar 03 23:11:17 2014 +0900 +++ b/mercurial/commandserver.py Mon Mar 03 23:21:24 2014 +0900 @@ -142,11 +142,15 @@ else: logfile = open(logpath, 'a') - # the ui here is really the repo ui so take its baseui so we don't end - # up with its local configuration - self.ui = repo.baseui - self.repo = repo - self.repoui = repo.ui + if repo: + # the ui here is really the repo ui so take its baseui so we don't + # end up with its local configuration + self.ui = repo.baseui + self.repo = repo + self.repoui = repo.ui + else: + self.ui = ui + self.repo = self.repoui = None if mode == 'pipe': self.cerr = channeledoutput(sys.stderr, sys.stdout, 'e') @@ -183,12 +187,13 @@ # copy the uis so changes (e.g. --config or --verbose) don't # persist between requests copiedui = self.ui.copy() - self.repo.baseui = copiedui - # clone ui without using ui.copy because this is protected - repoui = self.repoui.__class__(self.repoui) - repoui.copy = copiedui.copy # redo copy protection - self.repo.ui = self.repo.dirstate._ui = repoui - self.repo.invalidateall() + if self.repo: + self.repo.baseui = copiedui + # clone ui without using ui.copy because this is protected + repoui = self.repoui.__class__(self.repoui) + repoui.copy = copiedui.copy # redo copy protection + self.repo.ui = self.repo.dirstate._ui = repoui + self.repo.invalidateall() req = dispatch.request(args[:], copiedui, self.repo, self.cin, self.cout, self.cerr)
--- a/tests/test-commandserver.py Mon Mar 03 23:11:17 2014 +0900 +++ b/tests/test-commandserver.py Mon Mar 03 23:21:24 2014 +0900 @@ -294,6 +294,11 @@ # repo.mq should be recreated to point to new queue runcommand(server, ['qqueue', '--active']) +def startwithoutrepo(server): + readchannel(server) + runcommand(server, ['init', 'repo2']) + runcommand(server, ['id', '-R', 'repo2']) + if __name__ == '__main__': os.system('hg init repo') os.chdir('repo') @@ -329,3 +334,7 @@ hgrc.write('[extensions]\nmq=\n') hgrc.close() check(mqoutsidechanges) + + os.chdir('..') + check(hellomessage) + check(startwithoutrepo)
--- a/tests/test-commandserver.py.out Mon Mar 03 23:11:17 2014 +0900 +++ b/tests/test-commandserver.py.out Mon Mar 03 23:21:24 2014 +0900 @@ -237,3 +237,16 @@ patch queue now empty runcommand qqueue --active foo + +testing hellomessage: + +o, 'capabilities: getencoding runcommand\nencoding: ***' + runcommand id +abort: there is no Mercurial repository here (.hg not found) + [255] + +testing startwithoutrepo: + + runcommand init repo2 + runcommand id -R repo2 +000000000000 tip