mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-21 22:32:41 +01:00
Allow "hg arc-ls-markers" to run under Python 2 or Python 3
Summary: Ref T13546. See PHI1805. Currently, the "arc-ls-markers" extension doesn't run under Python 3: - some stuff needs "b'...'" to mark it as a byte string; - "dict.iteritems()" is gone in Python 3, and "mercurial.pycompat" isn't always available; - in Python 3, "json" refuses to print byte strings; and - the compiler caching behavior in Python 3 has changed. Try to get these things working in the same way under Python 2 and Python 3. Test Plan: Ran this command (with `python` as Python 2, locally): ``` $ python /usr/local/bin/hg --config 'extensions.arc-hg=/Users/epriestley/dev/core/lib/arcanist/support/hg/arc-hg.py' arc-ls-markers -- ``` ...and this command: ``` $ python3 /usr/local/bin/hg --config 'extensions.arc-hg=/Users/epriestley/dev/core/lib/arcanist/support/hg/arc-hg.py' arc-ls-markers -- ``` ..and saw the same output in both cases (previously, `python3 ...` fataled in various ways). Maniphest Tasks: T13546 Differential Revision: https://secure.phabricator.com/D21392
This commit is contained in:
parent
79a6dfd7a9
commit
a28e76b7b3
2 changed files with 27 additions and 5 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -36,3 +36,4 @@
|
|||
|
||||
# Python extension compiled files.
|
||||
/support/hg/arc-hg.pyc
|
||||
/support/hg/__pycache__/
|
||||
|
|
|
@ -1,4 +1,14 @@
|
|||
from __future__ import absolute_import
|
||||
import sys
|
||||
|
||||
is_python_3 = sys.version_info[0] >= 3
|
||||
|
||||
if is_python_3:
|
||||
def arc_items(dict):
|
||||
return dict.items()
|
||||
else:
|
||||
def arc_items(dict):
|
||||
return dict.iteritems()
|
||||
|
||||
import os
|
||||
import json
|
||||
|
@ -19,8 +29,8 @@ cmdtable = {}
|
|||
command = registrar.command(cmdtable)
|
||||
|
||||
@command(
|
||||
"arc-ls-markers",
|
||||
[('', 'output', '',
|
||||
b'arc-ls-markers',
|
||||
[(b'', b'output', b'',
|
||||
_('file to output refs to'), _('FILE')),
|
||||
] + cmdutil.remoteopts,
|
||||
_('[--output FILENAME] [SOURCE]'))
|
||||
|
@ -42,6 +52,16 @@ def lsmarkers(ui, repo, source=None, **opts):
|
|||
else:
|
||||
markers = remotemarkers(ui, repo, source, opts)
|
||||
|
||||
for m in markers:
|
||||
if m['name'] != None:
|
||||
m['name'] = m['name'].decode('utf-8')
|
||||
|
||||
if m['node'] != None:
|
||||
m['node'] = m['node'].decode('utf-8')
|
||||
|
||||
if m['description'] != None:
|
||||
m['description'] = m['description'].decode('utf-8')
|
||||
|
||||
json_opts = {
|
||||
'indent': 2,
|
||||
'sort_keys': True,
|
||||
|
@ -54,14 +74,15 @@ def lsmarkers(ui, repo, source=None, **opts):
|
|||
with open(output_file, 'w+') as f:
|
||||
json.dump(markers, f, **json_opts)
|
||||
else:
|
||||
print json.dumps(markers, output_file, **json_opts)
|
||||
json_data = json.dumps(markers, **json_opts)
|
||||
print(json_data)
|
||||
|
||||
return 0
|
||||
|
||||
def localmarkers(ui, repo):
|
||||
markers = []
|
||||
|
||||
active_node = repo['.'].node()
|
||||
active_node = repo[b'.'].node()
|
||||
all_heads = set(repo.heads())
|
||||
current_name = repo.dirstate.branch()
|
||||
saw_current = False
|
||||
|
@ -117,7 +138,7 @@ def localmarkers(ui, repo):
|
|||
bookmarks = repo._bookmarks
|
||||
active_bookmark = repo._activebookmark
|
||||
|
||||
for bookmark_name, bookmark_node in bookmarks.iteritems():
|
||||
for bookmark_name, bookmark_node in arc_items(bookmarks):
|
||||
is_active = (active_bookmark == bookmark_name)
|
||||
description = repo[bookmark_node].description()
|
||||
|
||||
|
|
Loading…
Reference in a new issue