def archivelist(ui, nodeid, url): allowed = ui.configlist("web", "allow_archive", untrusted=True) for i in [('zip', '.zip'), ('gz', '.tar.gz'), ('bz2', '.tar.bz2')]: if i[0] in allowed or ui.configbool("web", "allow" + i[0], untrusted=True): yield {"type" : i[0], "extension": i[1], "node": nodeid, "url": url}
def archivelist(ui, nodeid, url): allowed = ui.configlist("web", "allow_archive", untrusted=True) archives = [] for i in [('zip', '.zip'), ('gz', '.tar.gz'), ('bz2', '.tar.bz2')]: if i[0] in allowed or ui.configbool("web", "allow" + i[0], untrusted=True): archives.append({"type" : i[0], "extension": i[1], "node": nodeid, "url": url}) return archives
def getdiff(ui, repo, r, parent, opts): '''return diff for the specified revision''' output = "" if opts.get('git') or ui.configbool('diff', 'git'): # Git diffs don't include the revision numbers with each file, so # we have to put them in the header instead. output += "# Node ID " + node.hex(r.node()) + "\n" output += "# Parent " + node.hex(parent.node()) + "\n" diffopts = patch.diffopts(ui, opts) for chunk in patch.diff(repo, parent.node(), r.node(), opts=diffopts): output += chunk return output
def _subtreelist(ui, repo, opts): l = opts.get('subtrees') if l: del opts['subtrees'] cansplit = ui.configbool('trees', 'splitargs', True) return _expandsubtrees(ui, cansplit and _splitsubtrees(l) or l) l = [] try: keys = repo.listkeys(_ns(ui, opts)) for i in xrange(0, len(keys)): l.append(keys[str(i)]) except: pass return l
def create_allowed(ui, req): """Check allow_create and deny_create config options of a repo's ui object to determine user permissions. By default, with neither option set (or both empty), deny all users to create new repos. There are two ways a user can be denied create access: (1) deny_create is not empty, and the user is unauthenticated or deny_create contains user (or *), and (2) allow_create is not empty and the user is not in allow_create. Return True if user is allowed to read the repo, else return False. This is modeled on (copied almost verbatim) hg's read_allowed function.""" user = req.env.get("REMOTE_USER") # enforce that you can only push using POST requests # if req.env['REQUEST_METHOD'] != 'POST': # msg = 'push requires POST request' # raise ErrorResponse(HTTP_METHOD_NOT_ALLOWED, msg) # require ssl by default for pushing, auth info cannot be sniffed # and replayed scheme = req.env.get("wsgi.url_scheme") if ui.configbool("web", "push_ssl", True) and scheme != "https": raise ErrorResponse(HTTP_FORBIDDEN, "ssl required") deny = ui.configlist("web", "deny_push") if deny and (not user or deny == ["*"] or user in deny): raise ErrorResponse(HTTP_UNAUTHORIZED, "push not authorized") allow = ui.configlist("web", "allow_push") result = allow and (allow == ["*"] or user in allow) if not result: raise ErrorResponse(HTTP_UNAUTHORIZED, "push not authorized") deny_create = ui.configlist("web", "deny_create", untrusted=True) if deny_create and (not user or deny_create == ["*"] or user in deny_create): raise ErrorResponse(HTTP_UNAUTHORIZED, "create not authorized") allow_create = ui.configlist("web", "allow_create", untrusted=True) result = (allow_create == ["*"]) or (user in allow_create) if not result: raise ErrorResponse(HTTP_UNAUTHORIZED, "create not authorized") return True
def saveremotebranches(self, remote, bm): real = {} bfile = self.join("remotebranches") olddata = [] existed = os.path.exists(bfile) if existed: f = open(bfile) olddata = [l for l in f if not l.split(" ", 1)[1].startswith(remote)] f = open(bfile, "w") if existed: f.write("".join(olddata)) for branch, nodes in bm.iteritems(): for n in nodes: f.write("%s %s/%s\n" % (node.hex(n), remote, branch)) alias_default = ui.configbool("remotebranches", "alias.default") if remote != "default" and branch == "default" and alias_default: f.write("%s %s\n" % (node.hex(n), remote)) real[branch] = [node.hex(x) for x in nodes] f.close()
def saveremotebranches(self, remote, bm): real = {} bfile = self.join('remotebranches') olddata = [] existed = os.path.exists(bfile) if existed: f = open(bfile) olddata = [l for l in f if not l.split(' ', 1)[1].startswith(remote)] f = open(bfile, 'w') if existed: f.write(''.join(olddata)) for branch, nodes in bm.iteritems(): for n in nodes: f.write('%s %s/%s\n' % (node.hex(n), remote, branch)) alias_default = ui.configbool('remotebranches', 'alias.default') if remote != 'default' and branch == 'default' and alias_default: f.write('%s %s\n' % (node.hex(n), remote)) real[branch] = [node.hex(x) for x in nodes] f.close()
def saveremotebranches(self, remote, bm): real = {} bfile = self.join('remotebranches') olddata = [] existed = os.path.exists(bfile) if existed: f = open(bfile) olddata = [ l for l in f if not l.split(' ', 1)[1].startswith(remote) ] f = open(bfile, 'w') if existed: f.write(''.join(olddata)) for branch, nodes in bm.iteritems(): for n in nodes: f.write('%s %s/%s\n' % (node.hex(n), remote, branch)) alias_default = ui.configbool('remotebranches', 'alias.default') if remote != 'default' and branch == 'default' and alias_default: f.write('%s %s\n' % (node.hex(n), remote)) real[branch] = [node.hex(x) for x in nodes] f.close()
def send_review(ui, repo, c, parentc, diff, parentdiff, opts): files = None if opts['attachbundle']: tmpfile = tempfile.NamedTemporaryFile(prefix='review_', suffix='.hgbundle', delete=False) tmpfile.close() if opts['old_server']: ui.status('postreview using old server compatibility mode (bundle format v1)\n') # request explicit 'v1' bundle format for our old creaky reviewboard server (running mercurial 2.0.x) # because it would be unable to read new 'v2' bundle format that mercurial 3.x uses bundle(ui, repo, tmpfile.name, dest=None, base=(parentc.rev(),), rev=(c.rev(),), type='bzip2-v1') else: bundle(ui, repo, tmpfile.name, dest=None, base=(parentc.rev(),), rev=(c.rev(),)) f = open(tmpfile.name,'rb') files = {BUNDLE_ATTACHMENT_CAPTION: {'filename': tmpfile.name, 'content': f.read()}} f.close() os.remove(tmpfile.name) fields = createfields(ui, repo, c, parentc, opts) request_id = opts['existing'] if request_id: update_review(request_id, ui, fields, diff, parentdiff, opts, files) else: request_id = new_review(ui, fields, diff, parentdiff, opts, files) request_url = '%s/%s/%s/' % (find_server(ui, opts), "r", request_id) if not request_url.startswith('http'): request_url = 'http://%s' % request_url msg = 'review request draft saved: %s\n' if opts['publish']: msg = 'review request published: %s\n' ui.status(msg % request_url) if ui.configbool('reviewboard', 'launch_webbrowser'): launch_webbrowser(ui, request_url)
password = opts.get('password') or ui.config('reviewboard', 'password') if password: ui.status('password: %s\n' % '**********') try: reviewboard = make_rbclient(server, username, password, proxy=proxy, apiver=opts.get('apiver'), trace=opts.get('apitrace')) except Exception, e: raise util.Abort(_(str(e))) if request_id: try: reviewboard.update_request(request_id, fields=fields, diff=diff, parentdiff=parentdiff, publish=opts.get('publish') or not ui.configbool('reviewboard', 'explicit_publish_update')) except ReviewBoardError, msg: raise util.Abort(_(str(msg))) else: repo_id = None repo_name = None submit_as = opts.get('submit_as') if repo_id_opt: try: repo_id = str(int(repo_id_opt)) except ValueError: repo_name = repo_id_opt if not repo_id: try:
password, proxy=proxy, apiver=opts.get('apiver'), trace=opts.get('apitrace')) except Exception, e: raise util.Abort(_(str(e))) if request_id: try: reviewboard.update_request( request_id, fields=fields, diff=diff, parentdiff=parentdiff, publish=opts.get('publish') or not ui.configbool('reviewboard', 'explicit_publish_update')) except ReviewBoardError, msg: raise util.Abort(_(str(msg))) else: repo_id = None repo_name = None submit_as = opts.get('submit_as') if repo_id_opt: try: repo_id = str(int(repo_id_opt)) except ValueError: repo_name = repo_id_opt if not repo_id: try: