* [PATCH 0/3] Make hg-to-git contrib script Python 3 compatible
@ 2019-04-01 18:52 Jelle van der Waa
2019-04-01 18:52 ` [PATCH 1/3] contrib: hg-to-git: make print python " Jelle van der Waa
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Jelle van der Waa @ 2019-04-01 18:52 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Todd Zullinger
This patch series makes hg-to-git Python 3 compatible and was tested
that it still works with Python 2.7. I'm not sure which Python version
in minimally supported for these Git contrib scripts.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] contrib: hg-to-git: make print python 3 compatible
2019-04-01 18:52 [PATCH 0/3] Make hg-to-git contrib script Python 3 compatible Jelle van der Waa
@ 2019-04-01 18:52 ` Jelle van der Waa
2019-04-01 18:52 ` [PATCH 2/3] contrib: hg-to-git: has_key is removed in Python 3 Jelle van der Waa
2019-04-01 18:52 ` [PATCH 3/3] contrib: hg-to-git: convert data to bytes for os.write Jelle van der Waa
2 siblings, 0 replies; 4+ messages in thread
From: Jelle van der Waa @ 2019-04-01 18:52 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Todd Zullinger, Jelle van der Waa
From: Jelle van der Waa <jelle@vdwaa.nl>
Python 3 made print a function, keep Python 2 compatibility with a
future import of print_function.
Signed-off-by: Jelle van der Waa <jelle@vdwaa.nl>
---
contrib/hg-to-git/hg-to-git.py | 47 +++++++++++++++++-----------------
1 file changed, 24 insertions(+), 23 deletions(-)
diff --git a/contrib/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py
index de3f81667e..f898d6f23e 100755
--- a/contrib/hg-to-git/hg-to-git.py
+++ b/contrib/hg-to-git/hg-to-git.py
@@ -17,6 +17,7 @@
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
"""
+from __future__ import print_function
import os, os.path, sys
import tempfile, pickle, getopt
@@ -42,7 +43,7 @@
def usage():
- print """\
+ print("""\
%s: [OPTIONS] <hgprj>
options:
@@ -54,7 +55,7 @@ def usage():
required:
hgprj: name of the HG project to import (directory)
-""" % sys.argv[0]
+""" % sys.argv[0])
#------------------------------------------------------------------------------
@@ -104,22 +105,22 @@ def getgitenv(user, date):
if state:
if os.path.exists(state):
if verbose:
- print 'State does exist, reading'
+ print('State does exist, reading')
f = open(state, 'r')
hgvers = pickle.load(f)
else:
- print 'State does not exist, first run'
+ print('State does not exist, first run')
sock = os.popen('hg tip --template "{rev}"')
tip = sock.read()
if sock.close():
sys.exit(1)
if verbose:
- print 'tip is', tip
+ print('tip is', tip)
# Calculate the branches
if verbose:
- print 'analysing the branches...'
+ print('analysing the branches...')
hgchildren["0"] = ()
hgparents["0"] = (None, None)
hgbranch["0"] = "master"
@@ -155,7 +156,7 @@ def getgitenv(user, date):
hgbranch[str(cset)] = "branch-" + str(cset)
if not hgvers.has_key("0"):
- print 'creating repository'
+ print('creating repository')
os.system('git init')
# loop through every hg changeset
@@ -180,27 +181,27 @@ def getgitenv(user, date):
os.write(fdcomment, csetcomment)
os.close(fdcomment)
- print '-----------------------------------------'
- print 'cset:', cset
- print 'branch:', hgbranch[str(cset)]
- print 'user:', user
- print 'date:', date
- print 'comment:', csetcomment
+ print('-----------------------------------------')
+ print('cset:', cset)
+ print('branch:', hgbranch[str(cset)])
+ print('user:', user)
+ print('date:', date)
+ print('comment:', csetcomment)
if parent:
- print 'parent:', parent
+ print('parent:', parent)
if mparent:
- print 'mparent:', mparent
+ print('mparent:', mparent)
if tag:
- print 'tag:', tag
- print '-----------------------------------------'
+ print('tag:', tag)
+ print('-----------------------------------------')
# checkout the parent if necessary
if cset != 0:
if hgbranch[str(cset)] == "branch-" + str(cset):
- print 'creating new branch', hgbranch[str(cset)]
+ print('creating new branch', hgbranch[str(cset)])
os.system('git checkout -b %s %s' % (hgbranch[str(cset)], hgvers[parent]))
else:
- print 'checking out branch', hgbranch[str(cset)]
+ print('checking out branch', hgbranch[str(cset)])
os.system('git checkout %s' % hgbranch[str(cset)])
# merge
@@ -209,7 +210,7 @@ def getgitenv(user, date):
otherbranch = hgbranch[mparent]
else:
otherbranch = hgbranch[parent]
- print 'merging', otherbranch, 'into', hgbranch[str(cset)]
+ print('merging', otherbranch, 'into', hgbranch[str(cset)])
os.system(getgitenv(user, date) + 'git merge --no-commit -s ours "" %s %s' % (hgbranch[str(cset)], otherbranch))
# remove everything except .git and .hg directories
@@ -233,12 +234,12 @@ def getgitenv(user, date):
# delete branch if not used anymore...
if mparent and len(hgchildren[str(cset)]):
- print "Deleting unused branch:", otherbranch
+ print("Deleting unused branch:", otherbranch)
os.system('git branch -d %s' % otherbranch)
# retrieve and record the version
vvv = os.popen('git show --quiet --pretty=format:%H').read()
- print 'record', cset, '->', vvv
+ print('record', cset, '->', vvv)
hgvers[str(cset)] = vvv
if hgnewcsets >= opt_nrepack and opt_nrepack != -1:
@@ -247,7 +248,7 @@ def getgitenv(user, date):
# write the state for incrementals
if state:
if verbose:
- print 'Writing state'
+ print('Writing state')
f = open(state, 'w')
pickle.dump(hgvers, f)
--
2.21.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] contrib: hg-to-git: has_key is removed in Python 3
2019-04-01 18:52 [PATCH 0/3] Make hg-to-git contrib script Python 3 compatible Jelle van der Waa
2019-04-01 18:52 ` [PATCH 1/3] contrib: hg-to-git: make print python " Jelle van der Waa
@ 2019-04-01 18:52 ` Jelle van der Waa
2019-04-01 18:52 ` [PATCH 3/3] contrib: hg-to-git: convert data to bytes for os.write Jelle van der Waa
2 siblings, 0 replies; 4+ messages in thread
From: Jelle van der Waa @ 2019-04-01 18:52 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Todd Zullinger, Jelle van der Waa
From: Jelle van der Waa <jelle@vdwaa.nl>
has_key was deprecated in Python 2 and finally removed in Python 3 in
favor of 'foo' in bar.
Signed-off-by: Jelle van der Waa <jelle@vdwaa.nl>
---
contrib/hg-to-git/hg-to-git.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/contrib/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py
index f898d6f23e..d504624c63 100755
--- a/contrib/hg-to-git/hg-to-git.py
+++ b/contrib/hg-to-git/hg-to-git.py
@@ -155,7 +155,7 @@ def getgitenv(user, date):
else:
hgbranch[str(cset)] = "branch-" + str(cset)
-if not hgvers.has_key("0"):
+if "0" not in hgvers:
print('creating repository')
os.system('git init')
@@ -163,7 +163,7 @@ def getgitenv(user, date):
for cset in range(int(tip) + 1):
# incremental, already seen
- if hgvers.has_key(str(cset)):
+ if str(cset) in hgvers:
continue
hgnewcsets += 1
--
2.21.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] contrib: hg-to-git: convert data to bytes for os.write
2019-04-01 18:52 [PATCH 0/3] Make hg-to-git contrib script Python 3 compatible Jelle van der Waa
2019-04-01 18:52 ` [PATCH 1/3] contrib: hg-to-git: make print python " Jelle van der Waa
2019-04-01 18:52 ` [PATCH 2/3] contrib: hg-to-git: has_key is removed in Python 3 Jelle van der Waa
@ 2019-04-01 18:52 ` Jelle van der Waa
2 siblings, 0 replies; 4+ messages in thread
From: Jelle van der Waa @ 2019-04-01 18:52 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Todd Zullinger, Jelle van der Waa
From: Jelle van der Waa <jelle@vdwaa.nl>
In Python 3 os.write wants bytes instead of a string, decode the str in
to bytes.
Signed-off-by: Jelle van der Waa <jelle@vdwaa.nl>
---
contrib/hg-to-git/hg-to-git.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/contrib/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py
index d504624c63..26c7300011 100755
--- a/contrib/hg-to-git/hg-to-git.py
+++ b/contrib/hg-to-git/hg-to-git.py
@@ -178,7 +178,7 @@ def getgitenv(user, date):
#get comment
(fdcomment, filecomment) = tempfile.mkstemp()
csetcomment = os.popen('hg log -r %d --template "{desc}"' % cset).read().strip()
- os.write(fdcomment, csetcomment)
+ os.write(fdcomment, csetcomment.encode())
os.close(fdcomment)
print('-----------------------------------------')
--
2.21.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-04-01 18:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-01 18:52 [PATCH 0/3] Make hg-to-git contrib script Python 3 compatible Jelle van der Waa
2019-04-01 18:52 ` [PATCH 1/3] contrib: hg-to-git: make print python " Jelle van der Waa
2019-04-01 18:52 ` [PATCH 2/3] contrib: hg-to-git: has_key is removed in Python 3 Jelle van der Waa
2019-04-01 18:52 ` [PATCH 3/3] contrib: hg-to-git: convert data to bytes for os.write Jelle van der Waa
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).