mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 06:42: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.
|
# Python extension compiled files.
|
||||||
/support/hg/arc-hg.pyc
|
/support/hg/arc-hg.pyc
|
||||||
|
/support/hg/__pycache__/
|
||||||
|
|
|
@ -1,4 +1,14 @@
|
||||||
from __future__ import absolute_import
|
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 os
|
||||||
import json
|
import json
|
||||||
|
@ -19,8 +29,8 @@ cmdtable = {}
|
||||||
command = registrar.command(cmdtable)
|
command = registrar.command(cmdtable)
|
||||||
|
|
||||||
@command(
|
@command(
|
||||||
"arc-ls-markers",
|
b'arc-ls-markers',
|
||||||
[('', 'output', '',
|
[(b'', b'output', b'',
|
||||||
_('file to output refs to'), _('FILE')),
|
_('file to output refs to'), _('FILE')),
|
||||||
] + cmdutil.remoteopts,
|
] + cmdutil.remoteopts,
|
||||||
_('[--output FILENAME] [SOURCE]'))
|
_('[--output FILENAME] [SOURCE]'))
|
||||||
|
@ -42,6 +52,16 @@ def lsmarkers(ui, repo, source=None, **opts):
|
||||||
else:
|
else:
|
||||||
markers = remotemarkers(ui, repo, source, opts)
|
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 = {
|
json_opts = {
|
||||||
'indent': 2,
|
'indent': 2,
|
||||||
'sort_keys': True,
|
'sort_keys': True,
|
||||||
|
@ -54,14 +74,15 @@ def lsmarkers(ui, repo, source=None, **opts):
|
||||||
with open(output_file, 'w+') as f:
|
with open(output_file, 'w+') as f:
|
||||||
json.dump(markers, f, **json_opts)
|
json.dump(markers, f, **json_opts)
|
||||||
else:
|
else:
|
||||||
print json.dumps(markers, output_file, **json_opts)
|
json_data = json.dumps(markers, **json_opts)
|
||||||
|
print(json_data)
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def localmarkers(ui, repo):
|
def localmarkers(ui, repo):
|
||||||
markers = []
|
markers = []
|
||||||
|
|
||||||
active_node = repo['.'].node()
|
active_node = repo[b'.'].node()
|
||||||
all_heads = set(repo.heads())
|
all_heads = set(repo.heads())
|
||||||
current_name = repo.dirstate.branch()
|
current_name = repo.dirstate.branch()
|
||||||
saw_current = False
|
saw_current = False
|
||||||
|
@ -117,7 +138,7 @@ def localmarkers(ui, repo):
|
||||||
bookmarks = repo._bookmarks
|
bookmarks = repo._bookmarks
|
||||||
active_bookmark = repo._activebookmark
|
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)
|
is_active = (active_bookmark == bookmark_name)
|
||||||
description = repo[bookmark_node].description()
|
description = repo[bookmark_node].description()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue