Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit a28e76b

Browse files
author
epriestley
committed
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
1 parent 79a6dfd commit a28e76b

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@
3636

3737
# Python extension compiled files.
3838
/support/hg/arc-hg.pyc
39+
/support/hg/__pycache__/

support/hg/arc-hg.py

+26-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
from __future__ import absolute_import
2+
import sys
3+
4+
is_python_3 = sys.version_info[0] >= 3
5+
6+
if is_python_3:
7+
def arc_items(dict):
8+
return dict.items()
9+
else:
10+
def arc_items(dict):
11+
return dict.iteritems()
212

313
import os
414
import json
@@ -19,8 +29,8 @@
1929
command = registrar.command(cmdtable)
2030

2131
@command(
22-
"arc-ls-markers",
23-
[('', 'output', '',
32+
b'arc-ls-markers',
33+
[(b'', b'output', b'',
2434
_('file to output refs to'), _('FILE')),
2535
] + cmdutil.remoteopts,
2636
_('[--output FILENAME] [SOURCE]'))
@@ -42,6 +52,16 @@ def lsmarkers(ui, repo, source=None, **opts):
4252
else:
4353
markers = remotemarkers(ui, repo, source, opts)
4454

55+
for m in markers:
56+
if m['name'] != None:
57+
m['name'] = m['name'].decode('utf-8')
58+
59+
if m['node'] != None:
60+
m['node'] = m['node'].decode('utf-8')
61+
62+
if m['description'] != None:
63+
m['description'] = m['description'].decode('utf-8')
64+
4565
json_opts = {
4666
'indent': 2,
4767
'sort_keys': True,
@@ -54,14 +74,15 @@ def lsmarkers(ui, repo, source=None, **opts):
5474
with open(output_file, 'w+') as f:
5575
json.dump(markers, f, **json_opts)
5676
else:
57-
print json.dumps(markers, output_file, **json_opts)
77+
json_data = json.dumps(markers, **json_opts)
78+
print(json_data)
5879

5980
return 0
6081

6182
def localmarkers(ui, repo):
6283
markers = []
6384

64-
active_node = repo['.'].node()
85+
active_node = repo[b'.'].node()
6586
all_heads = set(repo.heads())
6687
current_name = repo.dirstate.branch()
6788
saw_current = False
@@ -117,7 +138,7 @@ def localmarkers(ui, repo):
117138
bookmarks = repo._bookmarks
118139
active_bookmark = repo._activebookmark
119140

120-
for bookmark_name, bookmark_node in bookmarks.iteritems():
141+
for bookmark_name, bookmark_node in arc_items(bookmarks):
121142
is_active = (active_bookmark == bookmark_name)
122143
description = repo[bookmark_node].description()
123144

0 commit comments

Comments
 (0)