##// END OF EJS Templates
py3: add b'' annotations in some places where they will be needed later...
Mads Kiilerich -
r7958:45bfab30 default
parent child Browse files
Show More
@@ -162,7 +162,7 b' def setup_configuration(app):'
162 162
163 163 load_rcextensions(root_path=config['here'])
164 164
165 repos_path = make_ui().configitems('paths')[0][1]
165 repos_path = make_ui().configitems(b'paths')[0][1]
166 166 config['base_path'] = repos_path
167 167 set_app_settings(config)
168 168
@@ -108,20 +108,26 b' class CompareController(BaseRepoControll'
108 108 hgrepo = other_repo._repo
109 109
110 110 ancestors = [hgrepo[ancestor].hex() for ancestor in
111 hgrepo.revs("id(%s) & ::id(%s)", other_rev, org_rev)]
111 hgrepo.revs(b"id(%s) & ::id(%s)", other_rev, org_rev)]
112 112 if ancestors:
113 113 log.debug("shortcut found: %s is already an ancestor of %s", other_rev, org_rev)
114 114 else:
115 115 log.debug("no shortcut found: %s is not an ancestor of %s", other_rev, org_rev)
116 116 ancestors = [hgrepo[ancestor].hex() for ancestor in
117 hgrepo.revs("heads(::id(%s) & ::id(%s))", org_rev, other_rev)] # FIXME: expensive!
117 hgrepo.revs(b"heads(::id(%s) & ::id(%s))", org_rev, other_rev)] # FIXME: expensive!
118 118
119 other_revs = hgrepo.revs("ancestors(id(%s)) and not ancestors(id(%s)) and not id(%s)",
120 other_rev, org_rev, org_rev)
121 other_changesets = [other_repo.get_changeset(rev) for rev in other_revs]
122 org_revs = hgrepo.revs("ancestors(id(%s)) and not ancestors(id(%s)) and not id(%s)",
123 org_rev, other_rev, other_rev)
124 org_changesets = [org_repo.get_changeset(hgrepo[rev].hex()) for rev in org_revs]
119 other_changesets = [
120 other_repo.get_changeset(rev)
121 for rev in hgrepo.revs(
122 b"ancestors(id(%s)) and not ancestors(id(%s)) and not id(%s)",
123 other_rev, org_rev, org_rev)
124 ]
125 org_changesets = [
126 org_repo.get_changeset(hgrepo[rev].hex())
127 for rev in hgrepo.revs(
128 b"ancestors(id(%s)) and not ancestors(id(%s)) and not id(%s)",
129 org_rev, other_rev, other_rev)
130 ]
125 131
126 132 elif alias == 'git':
127 133 if org_repo != other_repo:
@@ -97,7 +97,7 b' class PullrequestsController(BaseRepoCon'
97 97 # including branches of children could be nice too
98 98 peerbranches = set()
99 99 for i in repo._repo.revs(
100 "sort(parents(branch(id(%s)) and merge()) - branch(id(%s)), -rev)",
100 b"sort(parents(branch(id(%s)) and merge()) - branch(id(%s)), -rev)",
101 101 branch_rev, branch_rev
102 102 ):
103 103 for abranch in repo.get_changeset(i).branches:
@@ -236,7 +236,7 b' def get_gitdiff(filenode_old, filenode_n'
236 236 context = context or 3
237 237 submodules = [o for o in [filenode_new, filenode_old] if isinstance(o, SubModuleNode)]
238 238 if submodules:
239 return ''
239 return b''
240 240
241 241 for filenode in (filenode_old, filenode_new):
242 242 if not isinstance(filenode, FileNode):
@@ -261,7 +261,7 b' def get_diff(scm_instance, rev1, rev2, p'
261 261 ignore_whitespace=ignore_whitespace, context=context)
262 262 except MemoryError:
263 263 h.flash('MemoryError: Diff is too big', category='error')
264 return ''
264 return b''
265 265
266 266
267 267 NEW_FILENODE = 1
@@ -279,7 +279,7 b' class DiffProcessor(object):'
279 279 mentioned in the diff together with a dict of meta information that
280 280 can be used to render it in a HTML template.
281 281 """
282 _diff_git_re = re.compile('^diff --git', re.MULTILINE)
282 _diff_git_re = re.compile(b'^diff --git', re.MULTILINE)
283 283
284 284 def __init__(self, diff, vcs='hg', diff_limit=None, inline_diff=True):
285 285 """
@@ -480,7 +480,7 b' def _escaper(string):'
480 480 return _escape_re.sub(substitute, safe_unicode(string))
481 481
482 482
483 _git_header_re = re.compile(r"""
483 _git_header_re = re.compile(br"""
484 484 ^diff[ ]--git[ ]a/(?P<a_path>.+?)[ ]b/(?P<b_path>.+?)\n
485 485 (?:^old[ ]mode[ ](?P<old_mode>\d+)\n
486 486 ^new[ ]mode[ ](?P<new_mode>\d+)(?:\n|$))?
@@ -497,7 +497,7 b' def _escaper(string):'
497 497 """, re.VERBOSE | re.MULTILINE)
498 498
499 499
500 _hg_header_re = re.compile(r"""
500 _hg_header_re = re.compile(br"""
501 501 ^diff[ ]--git[ ]a/(?P<a_path>.+?)[ ]b/(?P<b_path>.+?)\n
502 502 (?:^old[ ]mode[ ](?P<old_mode>\d+)\n
503 503 ^new[ ]mode[ ](?P<new_mode>\d+)(?:\n|$))?
@@ -542,7 +542,7 b' def _get_header(vcs, diff_chunk):'
542 542 rest = diff_chunk[match.end():]
543 543 if rest and _header_next_check.match(rest):
544 544 raise Exception('cannot parse %s diff header: %r followed by %r' % (vcs, diff_chunk[:match.end()], rest[:1000]))
545 diff_lines = (_escaper(m.group(0)) for m in re.finditer(r'.*\n|.+$', rest)) # don't split on \r as str.splitlines do
545 diff_lines = (_escaper(m.group(0)) for m in re.finditer(br'.*\n|.+$', rest)) # don't split on \r as str.splitlines do
546 546 return meta_info, diff_lines
547 547
548 548
@@ -110,7 +110,7 b' def log_push_action(ui, repo, node, node'
110 110 cahes! The function should perhaps be renamed.
111 111 """
112 112 _h = binascii.hexlify
113 revs = [_h(repo[r].node()) for r in revrange(repo, [node + ':' + node_last])]
113 revs = [_h(repo[r].node()) for r in revrange(repo, [b'%s:%s' % (node, node_last)])]
114 114 process_pushed_raw_ids(revs)
115 115 return 0
116 116
@@ -363,8 +363,9 b' def handle_git_post_receive(repo_path, g'
363 363 if push_ref['old_rev'] == EmptyChangeset().raw_id:
364 364 # update the symbolic ref if we push new repo
365 365 if scm_repo.is_empty():
366 scm_repo._repo.refs.set_symbolic_ref('HEAD',
367 'refs/heads/%s' % push_ref['name'])
366 scm_repo._repo.refs.set_symbolic_ref(
367 b'HEAD',
368 b'refs/heads/%s' % push_ref['name'])
368 369
369 370 # build exclude list without the ref
370 371 cmd = ['for-each-ref', '--format=%(refname)', 'refs/heads/*']
@@ -88,8 +88,8 b' def parse_pub_key(ssh_key):'
88 88 except TypeError:
89 89 raise SshKeyParseError(_("Incorrect SSH key - failed to decode base64 part %r") % keyvalue)
90 90
91 if not decoded.startswith('\x00\x00\x00' + chr(len(keytype)) + str(keytype) + '\x00'):
92 raise SshKeyParseError(_("Incorrect SSH key - base64 part is not %r as claimed but %r") % (str(keytype), str(decoded[4:].split('\0', 1)[0])))
91 if not decoded.startswith(b'\x00\x00\x00' + chr(len(keytype)) + str(keytype) + b'\x00'):
92 raise SshKeyParseError(_("Incorrect SSH key - base64 part is not %r as claimed but %r") % (str(keytype), str(decoded[4:].split(b'\0', 1)[0])))
93 93
94 94 return keytype, decoded, comment
95 95
@@ -337,21 +337,21 b' def make_ui(repo_path=None):'
337 337 sa = meta.Session()
338 338 for ui_ in sa.query(Ui).all():
339 339 if ui_.ui_active:
340 ui_val = '' if ui_.ui_value is None else safe_str(ui_.ui_value)
340 ui_val = b'' if ui_.ui_value is None else safe_str(ui_.ui_value)
341 341 log.debug('config from db: [%s] %s=%r', ui_.ui_section,
342 342 ui_.ui_key, ui_val)
343 343 baseui.setconfig(safe_str(ui_.ui_section), safe_str(ui_.ui_key),
344 344 ui_val)
345 345
346 346 # force set push_ssl requirement to False, Kallithea handles that
347 baseui.setconfig('web', 'push_ssl', False)
348 baseui.setconfig('web', 'allow_push', '*')
347 baseui.setconfig(b'web', b'push_ssl', False)
348 baseui.setconfig(b'web', b'allow_push', b'*')
349 349 # prevent interactive questions for ssh password / passphrase
350 ssh = baseui.config('ui', 'ssh', default='ssh')
351 baseui.setconfig('ui', 'ssh', '%s -oBatchMode=yes -oIdentitiesOnly=yes' % ssh)
350 ssh = baseui.config(b'ui', b'ssh', default=b'ssh')
351 baseui.setconfig(b'ui', b'ssh', b'%s -oBatchMode=yes -oIdentitiesOnly=yes' % ssh)
352 352 # push / pull hooks
353 baseui.setconfig('hooks', 'changegroup.kallithea_log_push_action', 'python:kallithea.lib.hooks.log_push_action')
354 baseui.setconfig('hooks', 'outgoing.kallithea_log_pull_action', 'python:kallithea.lib.hooks.log_pull_action')
353 baseui.setconfig(b'hooks', b'changegroup.kallithea_log_push_action', b'python:kallithea.lib.hooks.log_push_action')
354 baseui.setconfig(b'hooks', b'outgoing.kallithea_log_pull_action', b'python:kallithea.lib.hooks.log_pull_action')
355 355
356 356 if repo_path is not None:
357 357 hgrc_path = os.path.join(repo_path, '.hg', 'hgrc')
@@ -244,7 +244,7 b' class GitChangeset(BaseChangeset):'
244 244 # Only used to feed diffstat
245 245 rev1 = self.parents[0] if self.parents else self.repository.EMPTY_CHANGESET
246 246 rev2 = self
247 return ''.join(self.repository.get_diff(rev1, rev2,
247 return b''.join(self.repository.get_diff(rev1, rev2,
248 248 ignore_whitespace=ignore_whitespace,
249 249 context=context))
250 250
@@ -418,7 +418,7 b' class GitChangeset(BaseChangeset):'
418 418 obj_path = name
419 419 if objects.S_ISGITLINK(stat):
420 420 root_tree = self.repository._repo[self._tree_id]
421 cf = ConfigFile.from_file(BytesIO(self.repository._repo.get_object(root_tree['.gitmodules'][1]).data))
421 cf = ConfigFile.from_file(BytesIO(self.repository._repo.get_object(root_tree[b'.gitmodules'][1]).data))
422 422 url = cf.get(('submodule', obj_path), 'url')
423 423 dirnodes.append(SubModuleNode(obj_path, url=url, changeset=id,
424 424 alias=als))
@@ -457,7 +457,7 b' class GitChangeset(BaseChangeset):'
457 457 _GL = lambda m: m and objects.S_ISGITLINK(m)
458 458 if _GL(self._stat_modes.get(path)):
459 459 tree = self.repository._repo[self._tree_id]
460 cf = ConfigFile.from_file(BytesIO(self.repository._repo.get_object(tree['.gitmodules'][1]).data))
460 cf = ConfigFile.from_file(BytesIO(self.repository._repo.get_object(tree[b'.gitmodules'][1]).data))
461 461 url = cf.get(('submodule', path), 'url')
462 462 node = SubModuleNode(path, url=url, changeset=id_,
463 463 alias=self.repository.alias)
@@ -39,7 +39,7 b' class GitInMemoryChangeset(BaseInMemoryC'
39 39 repo = self.repository._repo
40 40 object_store = repo.object_store
41 41
42 ENCODING = "UTF-8" # TODO: should probably be kept in sync with safe_unicode/safe_bytes and vcs/conf/settings.py DEFAULT_ENCODINGS
42 ENCODING = b"UTF-8" # TODO: should probably be kept in sync with safe_unicode/safe_bytes and vcs/conf/settings.py DEFAULT_ENCODINGS
43 43
44 44 # Create tree and populates it with blobs
45 45 commit_tree = self.parents[0] and repo[self.parents[0]._commit.tree] or \
@@ -47,7 +47,7 b' class GitInMemoryChangeset(BaseInMemoryC'
47 47 for node in self.added + self.changed:
48 48 # Compute subdirs if needed
49 49 dirpath, nodename = posixpath.split(node.path)
50 dirnames = safe_str(dirpath).split('/') if dirpath else []
50 dirnames = safe_str(dirpath).split(b'/') if dirpath else []
51 51 parent = commit_tree
52 52 ancestors = [('', parent)]
53 53
@@ -100,7 +100,7 b' class GitInMemoryChangeset(BaseInMemoryC'
100 100 for tree in new_trees:
101 101 object_store.add_object(tree)
102 102 for node in self.removed:
103 paths = node.path.split('/')
103 paths = node.path.split(b'/')
104 104 tree = commit_tree
105 105 trees = [tree]
106 106 # Traverse deep into the forest...
@@ -146,10 +146,9 b' class GitInMemoryChangeset(BaseInMemoryC'
146 146
147 147 object_store.add_object(commit)
148 148
149 ref = 'refs/heads/%s' % branch
149 # Update vcs repository object & recreate dulwich repo
150 ref = b'refs/heads/%s' % branch
150 151 repo.refs[ref] = commit.id
151
152 # Update vcs repository object & recreate dulwich repo
153 152 self.repository.revisions.append(commit.id)
154 153 # invalidate parsed refs after commit
155 154 self.repository._parsed_refs = self.repository._get_parsed_refs()
@@ -123,8 +123,8 b' class GitRepository(BaseRepository):'
123 123 raise RepositoryError(msg)
124 124
125 125 try:
126 stdout = ''.join(p.output)
127 stderr = ''.join(p.error)
126 stdout = b''.join(p.output)
127 stderr = b''.join(p.error)
128 128 finally:
129 129 p.close()
130 130 # TODO: introduce option to make commands fail if they have any stderr output?
@@ -170,12 +170,12 b' class GitRepository(BaseRepository):'
170 170 handlers = []
171 171 url_obj = hg_url(url)
172 172 test_uri, authinfo = url_obj.authinfo()
173 url_obj.passwd = '*****'
174 cleaned_uri = str(url_obj)
175
176 173 if not test_uri.endswith('info/refs'):
177 174 test_uri = test_uri.rstrip('/') + '/info/refs'
178 175
176 url_obj.passwd = b'*****'
177 cleaned_uri = str(url_obj)
178
179 179 if authinfo:
180 180 # create a password manager
181 181 passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
@@ -252,7 +252,7 b' class GitRepository(BaseRepository):'
252 252 def _get_all_revisions2(self):
253 253 # alternate implementation using dulwich
254 254 includes = [x[1][0] for x in self._parsed_refs.iteritems()
255 if x[1][1] != 'T']
255 if x[1][1] != b'T']
256 256 return [c.commit.id for c in self._repo.get_walker(include=includes)]
257 257
258 258 def _get_revision(self, revision):
@@ -282,7 +282,7 b' class GitRepository(BaseRepository):'
282 282
283 283 # get by branch/tag name
284 284 _ref_revision = self._parsed_refs.get(revision)
285 if _ref_revision: # and _ref_revision[1] in ['H', 'RH', 'T']:
285 if _ref_revision: # and _ref_revision[1] in [b'H', b'RH', b'T']:
286 286 return _ref_revision[0]
287 287
288 288 if revision in self.revisions:
@@ -355,9 +355,7 b' class GitRepository(BaseRepository):'
355 355
356 356 @LazyProperty
357 357 def description(self):
358 undefined_description = u'unknown'
359 _desc = self._repo.get_description()
360 return safe_unicode(_desc or undefined_description)
358 return safe_unicode(self._repo.get_description() or b'unknown')
361 359
362 360 @LazyProperty
363 361 def contact(self):
@@ -370,7 +368,7 b' class GitRepository(BaseRepository):'
370 368 return {}
371 369 sortkey = lambda ctx: ctx[0]
372 370 _branches = [(x[0], x[1][0])
373 for x in self._parsed_refs.iteritems() if x[1][1] == 'H']
371 for x in self._parsed_refs.iteritems() if x[1][1] == b'H']
374 372 return OrderedDict(sorted(_branches, key=sortkey, reverse=False))
375 373
376 374 @LazyProperty
@@ -387,7 +385,7 b' class GitRepository(BaseRepository):'
387 385
388 386 sortkey = lambda ctx: ctx[0]
389 387 _tags = [(x[0], x[1][0])
390 for x in self._parsed_refs.iteritems() if x[1][1] == 'T']
388 for x in self._parsed_refs.iteritems() if x[1][1] == b'T']
391 389 return OrderedDict(sorted(_tags, key=sortkey, reverse=True))
392 390
393 391 def tag(self, name, user, revision=None, message=None, date=None,
@@ -408,7 +406,7 b' class GitRepository(BaseRepository):'
408 406 changeset = self.get_changeset(revision)
409 407 message = message or "Added tag %s for commit %s" % (name,
410 408 changeset.raw_id)
411 self._repo.refs["refs/tags/%s" % name] = changeset._commit.id
409 self._repo.refs[b"refs/tags/%s" % name] = changeset._commit.id
412 410
413 411 self._parsed_refs = self._get_parsed_refs()
414 412 self.tags = self._get_tags()
@@ -451,15 +449,15 b' class GitRepository(BaseRepository):'
451 449 # cache the property
452 450 _repo = self._repo
453 451 refs = _repo.get_refs()
454 keys = [('refs/heads/', 'H'),
455 ('refs/remotes/origin/', 'RH'),
456 ('refs/tags/', 'T')]
452 keys = [(b'refs/heads/', b'H'),
453 (b'refs/remotes/origin/', b'RH'),
454 (b'refs/tags/', b'T')]
457 455 _refs = {}
458 456 for ref, sha in refs.iteritems():
459 457 for k, type_ in keys:
460 458 if ref.startswith(k):
461 459 _key = ref[len(k):]
462 if type_ == 'T':
460 if type_ == b'T':
463 461 obj = _repo.get_object(sha)
464 462 if isinstance(obj, Tag):
465 463 sha = _repo.get_object(sha).object[1]
@@ -472,10 +470,10 b' class GitRepository(BaseRepository):'
472 470 heads = {}
473 471
474 472 for key, val in refs.items():
475 for ref_key in ['refs/heads/', 'refs/remotes/origin/']:
473 for ref_key in [b'refs/heads/', b'refs/remotes/origin/']:
476 474 if key.startswith(ref_key):
477 475 n = key[len(ref_key):]
478 if n not in ['HEAD']:
476 if n not in [b'HEAD']:
479 477 heads[n] = val
480 478
481 479 return heads if reverse else dict((y, x) for x, y in heads.iteritems())
@@ -627,9 +625,9 b' class GitRepository(BaseRepository):'
627 625 # If we used 'show' command, strip first few lines (until actual diff
628 626 # starts)
629 627 if rev1 == self.EMPTY_CHANGESET:
630 parts = stdout.split('\ndiff ', 1)
628 parts = stdout.split(b'\ndiff ', 1)
631 629 if len(parts) > 1:
632 stdout = 'diff ' + parts[1]
630 stdout = b'diff ' + parts[1]
633 631 return stdout
634 632
635 633 @LazyProperty
@@ -7,7 +7,7 b' from kallithea.lib.vcs.exceptions import'
7 7 class GitWorkdir(BaseWorkdir):
8 8
9 9 def get_branch(self):
10 headpath = self.repository._repo.refs.refpath('HEAD')
10 headpath = self.repository._repo.refs.refpath(b'HEAD')
11 11 try:
12 12 content = open(headpath).read()
13 13 match = re.match(r'^ref: refs/heads/(?P<branch>.+)\n$', content)
@@ -20,7 +20,7 b' class GitWorkdir(BaseWorkdir):'
20 20 raise RepositoryError("Couldn't compute workdir's branch")
21 21
22 22 def get_changeset(self):
23 wk_dir_id = self.repository._repo.refs.as_dict().get('HEAD')
23 wk_dir_id = self.repository._repo.refs.as_dict().get(b'HEAD')
24 24 return self.repository.get_changeset(wk_dir_id)
25 25
26 26 def checkout_branch(self, branch=None):
@@ -194,7 +194,7 b' class MercurialChangeset(BaseChangeset):'
194 194
195 195 def diff(self):
196 196 # Only used to feed diffstat
197 return ''.join(self._ctx.diff())
197 return b''.join(self._ctx.diff())
198 198
199 199 def _fix_path(self, path):
200 200 """
@@ -236,7 +236,7 b' class MercurialChangeset(BaseChangeset):'
236 236 Returns stat mode of the file at the given ``path``.
237 237 """
238 238 fctx = self._get_filectx(path)
239 if 'x' in fctx.flags():
239 if b'x' in fctx.flags():
240 240 return 0o100755
241 241 else:
242 242 return 0o100644
@@ -36,7 +36,7 b' class MercurialInMemoryChangeset(BaseInM'
36 36
37 37 if branch is None:
38 38 branch = MercurialRepository.DEFAULT_BRANCH_NAME
39 kwargs['branch'] = branch
39 kwargs[b'branch'] = branch
40 40
41 41 def filectxfn(_repo, memctx, path):
42 42 """
@@ -79,7 +79,7 b' class MercurialInMemoryChangeset(BaseInM'
79 79
80 80 commit_ctx = memctx(repo=self.repository._repo,
81 81 parents=parents,
82 text='',
82 text=b'',
83 83 files=self.get_paths(),
84 84 filectxfn=filectxfn,
85 85 user=author,
@@ -221,8 +221,7 b' class MercurialRepository(BaseRepository'
221 221 ))
222 222
223 223 def _get_all_revisions(self):
224
225 return [self._repo[x].hex() for x in self._repo.filtered('visible').changelog.revs()]
224 return [self._repo[x].hex() for x in self._repo.filtered(b'visible').changelog.revs()]
226 225
227 226 def get_diff(self, rev1, rev2, path='', ignore_whitespace=False,
228 227 context=3):
@@ -262,7 +261,7 b' class MercurialRepository(BaseRepository'
262 261 else:
263 262 file_filter = None
264 263
265 return ''.join(patch.diff(self._repo, rev1, rev2, match=file_filter,
264 return b''.join(patch.diff(self._repo, rev1, rev2, match=file_filter,
266 265 opts=diffopts(git=True,
267 266 showfunc=True,
268 267 ignorews=ignore_whitespace,
@@ -280,23 +279,23 b' class MercurialRepository(BaseRepository'
280 279 when the return code is non 200
281 280 """
282 281 # check first if it's not an local url
283 if os.path.isdir(url) or url.startswith('file:'):
282 if os.path.isdir(url) or url.startswith(b'file:'):
284 283 return True
285 284
286 if url.startswith('ssh:'):
285 if url.startswith(b'ssh:'):
287 286 # in case of invalid uri or authentication issues, sshpeer will
288 287 # throw an exception.
289 sshpeer.instance(repoui or ui.ui(), url, False).lookup('tip')
288 sshpeer.instance(repoui or ui.ui(), url, False).lookup(b'tip')
290 289 return True
291 290
292 291 url_prefix = None
293 if '+' in url[:url.find('://')]:
294 url_prefix, url = url.split('+', 1)
292 if b'+' in url[:url.find(b'://')]:
293 url_prefix, url = url.split(b'+', 1)
295 294
296 295 handlers = []
297 296 url_obj = hg_url(url)
298 297 test_uri, authinfo = url_obj.authinfo()
299 url_obj.passwd = '*****'
298 url_obj.passwd = b'*****'
300 299 cleaned_uri = str(url_obj)
301 300
302 301 if authinfo:
@@ -328,7 +327,7 b' class MercurialRepository(BaseRepository'
328 327 if not url_prefix: # skip svn+http://... (and git+... too)
329 328 # now check if it's a proper hg repo
330 329 try:
331 httppeer.instance(repoui or ui.ui(), url, False).lookup('tip')
330 httppeer.instance(repoui or ui.ui(), url, False).lookup(b'tip')
332 331 except Exception as e:
333 332 raise urllib2.URLError(
334 333 "url [%s] does not look like an hg repo org_exc: %s"
@@ -374,15 +373,13 b' class MercurialRepository(BaseRepository'
374 373
375 374 @LazyProperty
376 375 def description(self):
377 undefined_description = u'unknown'
378 _desc = self._repo.ui.config('web', 'description', None, untrusted=True)
379 return safe_unicode(_desc or undefined_description)
376 _desc = self._repo.ui.config(b'web', b'description', None, untrusted=True)
377 return safe_unicode(_desc or b'unknown')
380 378
381 379 @LazyProperty
382 380 def contact(self):
383 undefined_contact = u'Unknown'
384 381 return safe_unicode(get_contact(self._repo.ui.config)
385 or undefined_contact)
382 or b'Unknown')
386 383
387 384 @LazyProperty
388 385 def last_change(self):
@@ -413,7 +410,7 b' class MercurialRepository(BaseRepository'
413 410 raise EmptyRepositoryError("There are no changesets yet")
414 411
415 412 if revision in [-1, None]:
416 revision = 'tip'
413 revision = b'tip'
417 414 elif isinstance(revision, unicode):
418 415 revision = safe_bytes(revision)
419 416
@@ -461,13 +458,13 b' class MercurialRepository(BaseRepository'
461 458 return self._get_revision(revision)
462 459
463 460 def _get_archives(self, archive_name='tip'):
464 allowed = self.baseui.configlist("web", "allow_archive",
461 allowed = self.baseui.configlist(b"web", b"allow_archive",
465 462 untrusted=True)
466 for i in [('zip', '.zip'), ('gz', '.tar.gz'), ('bz2', '.tar.bz2')]:
467 if i[0] in allowed or self._repo.ui.configbool("web",
468 "allow" + i[0],
463 for name, ext in [(b'zip', '.zip'), (b'gz', '.tar.gz'), (b'bz2', '.tar.bz2')]:
464 if name in allowed or self._repo.ui.configbool(b"web",
465 b"allow" + name,
469 466 untrusted=True):
470 yield {"type": i[0], "extension": i[1], "node": archive_name}
467 yield {"type": name, "extension": ext, "node": archive_name}
471 468
472 469 def _get_url(self, url):
473 470 """
@@ -525,18 +522,18 b' class MercurialRepository(BaseRepository'
525 522 # filter branches
526 523 filter_ = []
527 524 if branch_name:
528 filter_.append('branch("%s")' % safe_str(branch_name))
525 filter_.append(b'branch("%s")' % safe_str(branch_name))
529 526 if start_date:
530 filter_.append('date(">%s")' % start_date)
527 filter_.append(b'date(">%s")' % start_date)
531 528 if end_date:
532 filter_.append('date("<%s")' % end_date)
529 filter_.append(b'date("<%s")' % end_date)
533 530 if filter_ or max_revisions:
534 531 if filter_:
535 revspec = ' and '.join(filter_)
532 revspec = b' and '.join(filter_)
536 533 else:
537 revspec = 'all()'
534 revspec = b'all()'
538 535 if max_revisions:
539 revspec = 'limit(%s, %s)' % (revspec, max_revisions)
536 revspec = b'limit(%s, %d)' % (revspec, max_revisions)
540 537 revisions = scmutil.revrange(self._repo, [revspec])
541 538 else:
542 539 revisions = self.revisions
@@ -58,8 +58,8 b' class MercurialSshHandler(BaseSshHandler'
58 58 # Note: we want a repo with config based on .hg/hgrc and can thus not use self.db_repo.scm_instance._repo.ui
59 59 baseui = make_ui(repo_path=self.db_repo.repo_full_path)
60 60 if not self.allow_push:
61 baseui.setconfig('hooks', 'pretxnopen._ssh_reject', 'python:kallithea.lib.hooks.rejectpush')
62 baseui.setconfig('hooks', 'prepushkey._ssh_reject', 'python:kallithea.lib.hooks.rejectpush')
61 baseui.setconfig(b'hooks', b'pretxnopen._ssh_reject', b'python:kallithea.lib.hooks.rejectpush')
62 baseui.setconfig(b'hooks', b'prepushkey._ssh_reject', b'python:kallithea.lib.hooks.rejectpush')
63 63
64 64 repo = hg.repository(baseui, safe_str(self.db_repo.repo_full_path))
65 65 log.debug("Starting Mercurial sshserver for %s", self.db_repo.repo_full_path)
@@ -367,11 +367,11 b' class SubprocessIOChunker(object):'
367 367 and returncode != 0
368 368 ): # and it failed
369 369 bg_out.stop()
370 out = ''.join(bg_out)
370 out = b''.join(bg_out)
371 371 bg_err.stop()
372 err = ''.join(bg_err)
373 if (err.strip() == 'fatal: The remote end hung up unexpectedly' and
374 out.startswith('0034shallow ')
372 err = b''.join(bg_err)
373 if (err.strip() == b'fatal: The remote end hung up unexpectedly' and
374 out.startswith(b'0034shallow ')
375 375 ):
376 376 # hack inspired by https://github.com/schacon/grack/pull/7
377 377 bg_out = iter([out])
@@ -261,7 +261,7 b' class CreatePullRequestAction(object):'
261 261
262 262 if self.org_repo.scm_instance.alias == 'git':
263 263 # create a ref under refs/pull/ so that commits don't get garbage-collected
264 self.org_repo.scm_instance._repo["refs/pull/%d/head" % pr.pull_request_id] = safe_str(self.org_rev)
264 self.org_repo.scm_instance._repo[b"refs/pull/%d/head" % pr.pull_request_id] = safe_str(self.org_rev)
265 265
266 266 # reset state to under-review
267 267 from kallithea.model.changeset_status import ChangesetStatusModel
@@ -716,11 +716,11 b' class ScmModel(object):'
716 716 if not os.path.isdir(loc):
717 717 os.makedirs(loc)
718 718
719 tmpl_post = "#!%s\n" % self._get_git_hook_interpreter()
719 tmpl_post = b"#!%s\n" % self._get_git_hook_interpreter()
720 720 tmpl_post += pkg_resources.resource_string(
721 721 'kallithea', os.path.join('config', 'post_receive_tmpl.py')
722 722 )
723 tmpl_pre = "#!%s\n" % self._get_git_hook_interpreter()
723 tmpl_pre = b"#!%s\n" % self._get_git_hook_interpreter()
724 724 tmpl_pre += pkg_resources.resource_string(
725 725 'kallithea', os.path.join('config', 'pre_receive_tmpl.py')
726 726 )
@@ -750,7 +750,7 b' class ScmModel(object):'
750 750 log.debug('writing %s hook file !', h_type)
751 751 try:
752 752 with open(_hook_file, 'wb') as f:
753 tmpl = tmpl.replace('_TMPL_', kallithea.__version__)
753 tmpl = tmpl.replace(b'_TMPL_', kallithea.__version__)
754 754 f.write(tmpl)
755 755 os.chmod(_hook_file, 0o755)
756 756 except IOError as e:
@@ -2509,8 +2509,8 b' class _BaseTestApi(object):'
2509 2509 "revisions": self.TEST_PR_REVISIONS,
2510 2510 }
2511 2511 self._compare_ok(random_id, expected,
2512 given=re.sub(r"\d\d\d\d\-\d\d\-\d\dT\d\d\:\d\d\:\d\d",
2513 "2000-01-01T00:00:00", response.body))
2512 given=re.sub(br"\d\d\d\d\-\d\d\-\d\dT\d\d\:\d\d\:\d\d",
2513 b"2000-01-01T00:00:00", response.body))
2514 2514
2515 2515 def test_api_close_pullrequest(self):
2516 2516 pull_request_id = fixture.create_pullrequest(self, self.REPO, self.TEST_PR_SRC, self.TEST_PR_DST, u'close test')
@@ -156,7 +156,7 b' class TestController(object):'
156 156 'password': password,
157 157 '_session_csrf_secret_token': self.session_csrf_secret_token()})
158 158
159 if 'Invalid username or password' in response.body:
159 if b'Invalid username or password' in response.body:
160 160 pytest.fail('could not login using %s %s' % (username, password))
161 161
162 162 assert response.status == '302 Found'
@@ -423,7 +423,7 b' def create_test_index(repo_location, con'
423 423
424 424
425 425 def failing_test_hook(ui, repo, **kwargs):
426 ui.write("failing_test_hook failed\n")
426 ui.write(b"failing_test_hook failed\n")
427 427 return 1
428 428
429 429
@@ -432,5 +432,5 b' def exception_test_hook(ui, repo, **kwar'
432 432
433 433
434 434 def passing_test_hook(ui, repo, **kwargs):
435 ui.write("passing_test_hook succeeded\n")
435 ui.write(b"passing_test_hook succeeded\n")
436 436 return 0
@@ -219,7 +219,7 b' class TestAuthSettingsController(TestCon'
219 219 url=url(controller='admin/my_account', action='my_account'),
220 220 extra_environ={'REMOTE_USER': 'john'},
221 221 )
222 assert 'Log Out' not in response.normal_body
222 assert b'Log Out' not in response.normal_body
223 223
224 224 def test_crowd_save_settings(self):
225 225 self.log_user()
@@ -158,14 +158,14 b' class TestGistsController(TestController'
158 158 gist = _create_gist('gist-show-me', content='GIST CONTENT')
159 159 response = self.app.get(url('formatted_gist',
160 160 gist_id=gist.gist_access_id, format='raw'))
161 assert response.body == 'GIST CONTENT'
161 assert response.body == b'GIST CONTENT'
162 162
163 163 def test_show_as_raw_individual_file(self):
164 164 gist = _create_gist('gist-show-me-raw', content='GIST BODY')
165 165 response = self.app.get(url('formatted_gist_file',
166 166 gist_id=gist.gist_access_id, format='raw',
167 167 revision='tip', f_path='gist-show-me-raw'))
168 assert response.body == 'GIST BODY'
168 assert response.body == b'GIST BODY'
169 169
170 170 def test_edit(self):
171 171 response = self.app.get(url('edit_gist', gist_id=1))
@@ -229,7 +229,7 b' class TestGitRepository(object):'
229 229 def test_changeset10(self):
230 230
231 231 chset10 = self.repo.get_changeset(self.repo.revisions[9])
232 readme = """===
232 readme = b"""===
233 233 VCS
234 234 ===
235 235
@@ -649,11 +649,11 b' class TestGitSpecificWithRepo(_BackendTe'
649 649
650 650 def test_paths_slow_traversing(self):
651 651 cs = self.repo.get_changeset()
652 assert cs.get_node('foobar').get_node('static').get_node('js').get_node('admin').get_node('base.js').content == 'base'
652 assert cs.get_node('foobar').get_node('static').get_node('js').get_node('admin').get_node('base.js').content == b'base'
653 653
654 654 def test_paths_fast_traversing(self):
655 655 cs = self.repo.get_changeset()
656 assert cs.get_node('foobar/static/js/admin/base.js').content == 'base'
656 assert cs.get_node('foobar/static/js/admin/base.js').content == b'base'
657 657
658 658 def test_workdir_get_branch(self):
659 659 self.repo.run_git_command(['checkout', '-b', 'production'])
@@ -219,7 +219,7 b' class TestMercurialRepository(object):'
219 219 def test_changeset10(self):
220 220
221 221 chset10 = self.repo.get_changeset(10)
222 readme = """===
222 readme = b"""===
223 223 VCS
224 224 ===
225 225
@@ -82,8 +82,8 b' class InMemoryChangesetTestMixin(_Backen'
82 82 changeset = self.imc.commit(u'Initial', u'joe.doe@example.com')
83 83 assert isinstance(changeset.get_node('foo'), DirNode)
84 84 assert isinstance(changeset.get_node('foo/bar'), DirNode)
85 assert changeset.get_node('foo/bar/image.png').content == '\0'
86 assert changeset.get_node('foo/README.txt').content == 'readme!'
85 assert changeset.get_node('foo/bar/image.png').content == b'\0'
86 assert changeset.get_node('foo/README.txt').content == b'readme!'
87 87
88 88 # commit some more files again
89 89 to_add = [
@@ -95,11 +95,11 b' class InMemoryChangesetTestMixin(_Backen'
95 95 ]
96 96 self.imc.add(*to_add)
97 97 changeset = self.imc.commit(u'Another', u'joe.doe@example.com')
98 changeset.get_node('foo/bar/foobaz/bar').content == 'foo'
99 changeset.get_node('foo/bar/another/bar').content == 'foo'
100 changeset.get_node('foo/baz.txt').content == 'foo'
101 changeset.get_node('foobar/foobaz/file').content == 'foo'
102 changeset.get_node('foobar/barbaz').content == 'foo'
98 changeset.get_node('foo/bar/foobaz/bar').content == b'foo'
99 changeset.get_node('foo/bar/another/bar').content == b'foo'
100 changeset.get_node('foo/baz.txt').content == b'foo'
101 changeset.get_node('foobar/foobaz/file').content == b'foo'
102 changeset.get_node('foobar/barbaz').content == b'foo'
103 103
104 104 def test_add_non_ascii_files(self):
105 105 rev_count = len(self.repo.revisions)
@@ -154,7 +154,7 b' class InMemoryChangesetTestMixin(_Backen'
154 154 newtip = self.repo.get_changeset()
155 155 assert tip != newtip
156 156 assert tip.id != newtip.id
157 assert newtip.get_node('foo/bar/baz').content == 'My **changed** content'
157 assert newtip.get_node('foo/bar/baz').content == b'My **changed** content'
158 158
159 159 def test_change_non_ascii(self):
160 160 to_add = [
@@ -181,8 +181,8 b' class InMemoryChangesetTestMixin(_Backen'
181 181 assert tip != newtip
182 182 assert tip.id != newtip.id
183 183
184 assert newtip.get_node('ΕΌΓ³Ε‚wik/zwierzΔ…tko').content == 'My **changed** content'
185 assert newtip.get_node('ΕΌΓ³Ε‚wik/zwierzΔ…tko_uni').content == 'My **changed** content'
184 assert newtip.get_node('ΕΌΓ³Ε‚wik/zwierzΔ…tko').content == b'My **changed** content'
185 assert newtip.get_node('ΕΌΓ³Ε‚wik/zwierzΔ…tko_uni').content == b'My **changed** content'
186 186
187 187 def test_change_raise_empty_repository(self):
188 188 node = FileNode('foobar')
@@ -158,10 +158,10 b' class TestNodeBasic(object):'
158 158 tar_node = FileNode('test.tar.gz')
159 159
160 160 my_node2 = FileNode('myfile2')
161 my_node2._content = 'foobar'
161 my_node2._content = b'foobar'
162 162
163 163 my_node3 = FileNode('myfile3')
164 my_node3._content = '\0foobar'
164 my_node3._content = b'\0foobar'
165 165
166 166 assert py_node.mimetype == mimetypes.guess_type(py_node.name)[0]
167 167 assert py_node.get_mimetype() == mimetypes.guess_type(py_node.name)
@@ -110,7 +110,7 b' class TestGitRepositoryGetDiff(Repositor'
110 110
111 111 def test_initial_commit_diff(self):
112 112 initial_rev = self.repo.revisions[0]
113 assert self.repo.get_diff(self.repo.EMPTY_CHANGESET, initial_rev) == r'''diff --git a/foobar b/foobar
113 assert self.repo.get_diff(self.repo.EMPTY_CHANGESET, initial_rev) == br'''diff --git a/foobar b/foobar
114 114 new file mode 100644
115 115 index 0000000000000000000000000000000000000000..f6ea0495187600e7b2288c8ac19c5886383a4632
116 116 --- /dev/null
@@ -130,7 +130,7 b' index 0000000000000000000000000000000000'
130 130
131 131 def test_second_changeset_diff(self):
132 132 revs = self.repo.revisions
133 assert self.repo.get_diff(revs[0], revs[1]) == r'''diff --git a/foobar b/foobar
133 assert self.repo.get_diff(revs[0], revs[1]) == br'''diff --git a/foobar b/foobar
134 134 index f6ea0495187600e7b2288c8ac19c5886383a4632..389865bb681b358c9b102d79abd8d5f941e96551 100644
135 135 --- a/foobar
136 136 +++ b/foobar
@@ -151,7 +151,7 b' index 0000000000000000000000000000000000'
151 151
152 152 def test_third_changeset_diff(self):
153 153 revs = self.repo.revisions
154 assert self.repo.get_diff(revs[1], revs[2]) == r'''diff --git a/foobar b/foobar
154 assert self.repo.get_diff(revs[1], revs[2]) == br'''diff --git a/foobar b/foobar
155 155 deleted file mode 100644
156 156 index 389865bb681b358c9b102d79abd8d5f941e96551..0000000000000000000000000000000000000000
157 157 --- a/foobar
@@ -173,7 +173,7 b' index c11c37d41d33fb47741cff93fa5f9d798c'
173 173
174 174 def test_fourth_changeset_diff(self):
175 175 revs = self.repo.revisions
176 assert self.repo.get_diff(revs[2], revs[3]) == r'''diff --git a/README{ b/README{
176 assert self.repo.get_diff(revs[2], revs[3]) == br'''diff --git a/README{ b/README{
177 177 new file mode 100644
178 178 index 0000000000000000000000000000000000000000..cdc0c1b5d234feedb37bbac19cd1b6442061102d
179 179 --- /dev/null
@@ -189,7 +189,7 b' class TestHgRepositoryGetDiff(Repository'
189 189
190 190 def test_initial_commit_diff(self):
191 191 initial_rev = self.repo.revisions[0]
192 assert self.repo.get_diff(self.repo.EMPTY_CHANGESET, initial_rev) == r'''diff --git a/foobar b/foobar
192 assert self.repo.get_diff(self.repo.EMPTY_CHANGESET, initial_rev) == br'''diff --git a/foobar b/foobar
193 193 new file mode 100644
194 194 --- /dev/null
195 195 +++ b/foobar
@@ -207,7 +207,7 b' new file mode 100644'
207 207
208 208 def test_second_changeset_diff(self):
209 209 revs = self.repo.revisions
210 assert self.repo.get_diff(revs[0], revs[1]) == r'''diff --git a/foobar b/foobar
210 assert self.repo.get_diff(revs[0], revs[1]) == br'''diff --git a/foobar b/foobar
211 211 --- a/foobar
212 212 +++ b/foobar
213 213 @@ -1,1 +1,1 @@
@@ -226,7 +226,7 b' new file mode 100644'
226 226
227 227 def test_third_changeset_diff(self):
228 228 revs = self.repo.revisions
229 assert self.repo.get_diff(revs[1], revs[2]) == r'''diff --git a/foobar b/foobar
229 assert self.repo.get_diff(revs[1], revs[2]) == br'''diff --git a/foobar b/foobar
230 230 deleted file mode 100644
231 231 --- a/foobar
232 232 +++ /dev/null
@@ -246,7 +246,7 b' diff --git a/foobar3 b/foobar3'
246 246
247 247 def test_fourth_changeset_diff(self):
248 248 revs = self.repo.revisions
249 assert self.repo.get_diff(revs[2], revs[3]) == r'''diff --git a/README{ b/README{
249 assert self.repo.get_diff(revs[2], revs[3]) == br'''diff --git a/README{ b/README{
250 250 new file mode 100644
251 251 --- /dev/null
252 252 +++ b/README{
General Comments 0
You need to be logged in to leave comments. Login now