From: Jelle van der Waa <jelle@vdwaa.nl>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Todd Zullinger <tmz@pobox.com>,
Jelle van der Waa <jelle@vdwaa.nl>
Subject: [PATCH 1/3] contrib: hg-to-git: make print python 3 compatible
Date: Mon, 1 Apr 2019 20:52:06 +0200 [thread overview]
Message-ID: <20190401185208.17031-2-jelle@vdwaa.nl> (raw)
In-Reply-To: <20190401185208.17031-1-jelle@vdwaa.nl>
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
next prev parent reply other threads:[~2019-04-01 18:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190401185208.17031-2-jelle@vdwaa.nl \
--to=jelle@vdwaa.nl \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=tmz@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).