{"thread":{"id":"47853","subject":"[PATCH] make hg-to-git compatible with python2.x and 3.x","startedAt":"2018-02-15T11:18:36Z","lastAt":"2019-09-18T17:55:56Z","messageCount":11,"participants":["Hervé Beraud","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"339466","messageId":"01020161992fe7ce-b41bf370-1480-4efe-8980-0c52fb9b9be5-000000@eu-west-1.amazonses.com","threadId":"47853","inReplyTo":null,"subject":"[PATCH] make hg-to-git compatible with python2.x and 3.x","fromName":"Hervé Beraud","fromEmail":"herveberaud.pro@gmail.com","sentAt":"2018-02-15T11:18:29Z","receivedAt":"2018-02-15T11:18:36Z","isPatch":true,"sender":{"key":"herveberaud.pro@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1541489?v=4"},"body":"---\n contrib/hg-to-git/hg-to-git.py | 140 ++++++++++++++++++++++++-----------------\n 1 file changed, 83 insertions(+), 57 deletions(-)\n\ndiff --git a/contrib/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py\nindex de3f81667ed97..9b0842c3883dc 100755\n--- a/contrib/hg-to-git/hg-to-git.py\n+++ b/contrib/hg-to-git/hg-to-git.py\n@@ -18,14 +18,19 @@\n     along with this program; if not, see <http://www.gnu.org/licenses/>.\n \"\"\"\n \n-import os, os.path, sys\n-import tempfile, pickle, getopt\n+import os\n+import os.path\n+import sys\n+import tempfile\n+import pickle\n+import getopt\n+import textwrap\n import re\n \n if sys.hexversion < 0x02030000:\n-   # The behavior of the pickle module changed significantly in 2.3\n-   sys.stderr.write(\"hg-to-git.py: requires Python 2.3 or later.\\n\")\n-   sys.exit(1)\n+    # The behavior of the pickle module changed significantly in 2.3\n+    sys.stderr.write(\"hg-to-git.py: requires Python 2.3 or later.\\n\")\n+    sys.exit(1)\n \n # Maps hg version -> git version\n hgvers = {}\n@@ -38,29 +43,31 @@\n # Number of new changesets converted from hg\n hgnewcsets = 0\n \n-#------------------------------------------------------------------------------\n+# -----------------------------------------------------------------------------\n+\n \n def usage():\n \n-        print \"\"\"\\\n-%s: [OPTIONS] <hgprj>\n+    print(textwrap.dedent(\"\"\"\\\n+        {0}: [OPTIONS] <hgprj>\n \n-options:\n-    -s, --gitstate=FILE: name of the state to be saved/read\n-                         for incrementals\n-    -n, --nrepack=INT:   number of changesets that will trigger\n-                         a repack (default=0, -1 to deactivate)\n-    -v, --verbose:       be verbose\n+        options:\n+            -s, --gitstate=FILE: name of the state to be saved/read\n+                                 for incrementals\n+            -n, --nrepack=INT:   number of changesets that will trigger\n+                                 a repack (default=0, -1 to deactivate)\n+            -v, --verbose:       be verbose\n \n-required:\n-    hgprj:  name of the HG project to import (directory)\n-\"\"\" % sys.argv[0]\n+        required:\n+            hgprj:  name of the HG project to import (directory)\n+    \"\"\").format(sys.argv[0]))\n+\n+# -----------------------------------------------------------------------------\n \n-#------------------------------------------------------------------------------\n \n def getgitenv(user, date):\n     env = ''\n-    elems = re.compile('(.*?)\\s+<(.*)>').match(user)\n+    elems = re.compile(r'(.*?)\\s+<(.*)>').match(user)\n     if elems:\n         env += 'export GIT_AUTHOR_NAME=\"%s\" ;' % elems.group(1)\n         env += 'export GIT_COMMITTER_NAME=\"%s\" ;' % elems.group(1)\n@@ -76,14 +83,16 @@ def getgitenv(user, date):\n     env += 'export GIT_COMMITTER_DATE=\"%s\" ;' % date\n     return env\n \n-#------------------------------------------------------------------------------\n+# -----------------------------------------------------------------------------\n+\n \n state = ''\n opt_nrepack = 0\n verbose = False\n \n try:\n-    opts, args = getopt.getopt(sys.argv[1:], 's:t:n:v', ['gitstate=', 'tempdir=', 'nrepack=', 'verbose'])\n+    options = ['gitstate=', 'tempdir=', 'nrepack=', 'verbose']\n+    opts, args = getopt.getopt(sys.argv[1:], 's:t:n:v', options)\n     for o, a in opts:\n         if o in ('-s', '--gitstate'):\n             state = a\n@@ -94,7 +103,7 @@ def getgitenv(user, date):\n             verbose = True\n     if len(args) != 1:\n         raise Exception('params')\n-except:\n+except Exception:\n     usage()\n     sys.exit(1)\n \n@@ -104,37 +113,38 @@ def getgitenv(user, date):\n if state:\n     if os.path.exists(state):\n         if verbose:\n-            print 'State does exist, reading'\n+            print('State does exist, reading')\n         f = open(state, 'r')\n         hgvers = pickle.load(f)\n     else:\n-        print 'State does not exist, first run'\n+        print('State does not exist, first run')\n \n sock = os.popen('hg tip --template \"{rev}\"')\n tip = sock.read()\n if sock.close():\n     sys.exit(1)\n if verbose:\n-    print 'tip is', tip\n+    print('tip is', tip)\n \n # Calculate the branches\n if verbose:\n-    print 'analysing the branches...'\n+    print('analysing the branches...')\n hgchildren[\"0\"] = ()\n hgparents[\"0\"] = (None, None)\n hgbranch[\"0\"] = \"master\"\n for cset in range(1, int(tip) + 1):\n     hgchildren[str(cset)] = ()\n-    prnts = os.popen('hg log -r %d --template \"{parents}\"' % cset).read().strip().split(' ')\n+    prnts = os.popen(\n+        'hg log -r %d --template \"{parents}\"' % cset).read().strip().split(' ')\n     prnts = map(lambda x: x[:x.find(':')], prnts)\n     if prnts[0] != '':\n         parent = prnts[0].strip()\n     else:\n         parent = str(cset - 1)\n-    hgchildren[parent] += ( str(cset), )\n+    hgchildren[parent] += (str(cset), )\n     if len(prnts) > 1:\n         mparent = prnts[1].strip()\n-        hgchildren[mparent] += ( str(cset), )\n+        hgchildren[mparent] += (str(cset), )\n     else:\n         mparent = None\n \n@@ -148,59 +158,65 @@ def getgitenv(user, date):\n             hgbranch[str(cset)] = hgbranch[parent]\n     else:\n         # Normal changesets\n-        # For first children, take the parent branch, for the others create a new branch\n+        # For first children, take the parent branch,\n+        # for the others create a new branch\n         if hgchildren[parent][0] == str(cset):\n             hgbranch[str(cset)] = hgbranch[parent]\n         else:\n             hgbranch[str(cset)] = \"branch-\" + str(cset)\n \n-if not hgvers.has_key(\"0\"):\n-    print 'creating repository'\n+if \"0\" not in hgvers:\n+    print('creating repository')\n     os.system('git init')\n \n # loop through every hg changeset\n for cset in range(int(tip) + 1):\n \n     # incremental, already seen\n-    if hgvers.has_key(str(cset)):\n+    if str(cset) in hgvers:\n         continue\n     hgnewcsets += 1\n \n     # get info\n-    log_data = os.popen('hg log -r %d --template \"{tags}\\n{date|date}\\n{author}\\n\"' % cset).readlines()\n+    log_data = os.popen(\n+        'hg log -r %d --template \"{tags}\\n{date|date}\\n{author}\\n\"' % cset\n+    ).readlines()\n     tag = log_data[0].strip()\n     date = log_data[1].strip()\n     user = log_data[2].strip()\n     parent = hgparents[str(cset)][0]\n     mparent = hgparents[str(cset)][1]\n \n-    #get comment\n+    # get comment\n     (fdcomment, filecomment) = tempfile.mkstemp()\n-    csetcomment = os.popen('hg log -r %d --template \"{desc}\"' % cset).read().strip()\n+    csetcomment = os.popen(\n+        'hg log -r %d --template \"{desc}\"' % cset).read().strip()\n     os.write(fdcomment, csetcomment)\n     os.close(fdcomment)\n \n-    print '-----------------------------------------'\n-    print 'cset:', cset\n-    print 'branch:', hgbranch[str(cset)]\n-    print 'user:', user\n-    print 'date:', date\n-    print 'comment:', csetcomment\n+    print('-----------------------------------------')\n+    print('cset:', cset)\n+    print('branch:', hgbranch[str(cset)])\n+    print('user:', user)\n+    print('date:', date)\n+    print('comment:', csetcomment)\n     if parent:\n-\tprint 'parent:', parent\n+        print('parent:', parent)\n     if mparent:\n-        print 'mparent:', mparent\n+        print('mparent:', mparent)\n     if tag:\n-        print 'tag:', tag\n-    print '-----------------------------------------'\n+        print('tag:', tag)\n+    print('-----------------------------------------')\n \n     # checkout the parent if necessary\n     if cset != 0:\n         if hgbranch[str(cset)] == \"branch-\" + str(cset):\n-            print 'creating new branch', hgbranch[str(cset)]\n-            os.system('git checkout -b %s %s' % (hgbranch[str(cset)], hgvers[parent]))\n+            print('creating new branch', hgbranch[str(cset)])\n+            os.system(\n+                'git checkout -b %s %s' % (hgbranch[str(cset)], hgvers[parent])\n+            )\n         else:\n-            print 'checking out branch', hgbranch[str(cset)]\n+            print('checking out branch', hgbranch[str(cset)])\n             os.system('git checkout %s' % hgbranch[str(cset)])\n \n     # merge\n@@ -209,11 +225,18 @@ def getgitenv(user, date):\n             otherbranch = hgbranch[mparent]\n         else:\n             otherbranch = hgbranch[parent]\n-        print 'merging', otherbranch, 'into', hgbranch[str(cset)]\n-        os.system(getgitenv(user, date) + 'git merge --no-commit -s ours \"\" %s %s' % (hgbranch[str(cset)], otherbranch))\n+        print('merging', otherbranch, 'into', hgbranch[str(cset)])\n+        mrg = 'git merge --no-commit -s ours \"\" %s %s' % (\n+            hgbranch[str(cset)], otherbranch)\n+        os.system(getgitenv(user, date) + mrg)\n \n     # remove everything except .git and .hg directories\n-    os.system('find . \\( -path \"./.hg\" -o -path \"./.git\" \\) -prune -o ! -name \".\" -print | xargs rm -rf')\n+    xargs_rm = 'xargs rm -rf'\n+    ignore_path = r'\\( -path \"./.hg\" -o -path \"./.git\" \\)'\n+    rm_all = r'find . {0} -prune -o ! -name \".\" -print | {1}'.format(\n+        ignore_path,\n+        xargs_rm)\n+    os.system(rm_all)\n \n     # repopulate with checkouted files\n     os.system('hg update -C %d' % cset)\n@@ -221,10 +244,13 @@ def getgitenv(user, date):\n     # add new files\n     os.system('git ls-files -x .hg --others | git update-index --add --stdin')\n     # delete removed files\n-    os.system('git ls-files -x .hg --deleted | git update-index --remove --stdin')\n+    rm_f = 'git ls-files -x .hg --deleted | git update-index --remove --stdin'\n+    os.system(rm_f)\n \n     # commit\n-    os.system(getgitenv(user, date) + 'git commit --allow-empty --allow-empty-message -a -F %s' % filecomment)\n+    commit = 'git commit --allow-empty --allow-empty-message -a -F {}'.format(\n+        filecomment)\n+    os.system(getgitenv(user, date) + commit)\n     os.unlink(filecomment)\n \n     # tag\n@@ -233,12 +259,12 @@ def getgitenv(user, date):\n \n     # delete branch if not used anymore...\n     if mparent and len(hgchildren[str(cset)]):\n-        print \"Deleting unused branch:\", otherbranch\n+        print(\"Deleting unused branch:\", otherbranch)\n         os.system('git branch -d %s' % otherbranch)\n \n     # retrieve and record the version\n     vvv = os.popen('git show --quiet --pretty=format:%H').read()\n-    print 'record', cset, '->', vvv\n+    print('record', cset, '->', vvv)\n     hgvers[str(cset)] = vvv\n \n if hgnewcsets >= opt_nrepack and opt_nrepack != -1:\n@@ -247,7 +273,7 @@ def getgitenv(user, date):\n # write the state for incrementals\n if state:\n     if verbose:\n-        print 'Writing state'\n+        print('Writing state')\n     f = open(state, 'w')\n     pickle.dump(hgvers, f)\n \n\n--\nhttps://github.com/git/git/pull/458\n"},{"id":"339516","messageId":"xmqq4lmh9abk.fsf@gitster-ct.c.googlers.com","threadId":"47853","inReplyTo":"01020161992fe7ce-b41bf370-1480-4efe-8980-0c52fb9b9be5-000000@eu-west-1.amazonses.com","subject":"Re: [PATCH] make hg-to-git compatible with python2.x and 3.x","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-02-15T22:06:55Z","receivedAt":"2018-02-15T22:07:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Hervé Beraud <herveberaud.pro@gmail.com> writes:\n\n> ---\n\nThanks for posting, but this is way under-justified, even for\nsomething in contrib/ area.  \n\nAre all changes in this patch necessary to \"make it compatible with\nboth Python 2 and 3\", or are some parts do not contribute directly\nto the objective but are good changes to suit your personal taste,\nmatch BCP styles, etc.?  I am guessing it is the latter (e.g. with\nPython 3, you cannot use print without invoking it as a function,\nbut os.system() can still accept a literal command line string, so\nintroducing variable \"rm_f\" that gets assigned a literal string only\nonce to pass it to os.system() does not have anything to do with the\nPython2to3 transition), and if that is the case, it makes sense to\nsplit this into at least 2 patches, i.e. prelimiary clean-up,\nfollowed by changes required to run it with Python3.  It also is OK\nto make it a 3-patch series, in which case you would limit the\npreliminary clean-up to minimum uncontroversial changes and follow\nup with an optional update to suit personal taste at the very end.\n\nAlso, the submission needs to be signed-off for us to be able to\nuse.  Please see Documentation/SubmittingPatches for details.\n\nThanks.\n\n>  contrib/hg-to-git/hg-to-git.py | 140 ++++++++++++++++++++++++-----------------\n>  1 file changed, 83 insertions(+), 57 deletions(-)\n>\n> diff --git a/contrib/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py\n> ...\n>      os.system('git ls-files -x .hg --others | git update-index --add --stdin')\n>      # delete removed files\n> -    os.system('git ls-files -x .hg --deleted | git update-index --remove --stdin')\n> +    rm_f = 'git ls-files -x .hg --deleted | git update-index --remove --stdin'\n> +    os.system(rm_f)\n>  ... \n> @@ -247,7 +273,7 @@ def getgitenv(user, date):\n>  # write the state for incrementals\n>  if state:\n>      if verbose:\n> -        print 'Writing state'\n> +        print('Writing state')\n>      f = open(state, 'w')\n>      pickle.dump(hgvers, f)\n>  \n>\n> --\n> https://github.com/git/git/pull/458\n"},{"id":"339715","messageId":"01020161b421939a-4ad52aaa-dda8-4250-9bce-71f0ede1a199-000000@eu-west-1.amazonses.com","threadId":"47853","inReplyTo":"01020161992fe7ce-b41bf370-1480-4efe-8980-0c52fb9b9be5-000000@eu-west-1.amazonses.com","subject":"[PATCH] make hg-to-git compatible with python2.x and 3.x","fromName":"Hervé Beraud","fromEmail":"herveberaud.pro@gmail.com","sentAt":"2018-02-20T16:52:34Z","receivedAt":"2018-02-20T16:52:43Z","isPatch":true,"sender":{"key":"herveberaud.pro@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1541489?v=4"},"body":"Signed-off-by: Hervé Beraud <herveberaud.pro@gmail.com>\n---\n contrib/hg-to-git/hg-to-git.py | 52 +++++++++++++++++++++---------------------\n 1 file changed, 26 insertions(+), 26 deletions(-)\n\ndiff --git a/contrib/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py\nindex de3f81667ed97..8fa7698df5c20 100755\n--- a/contrib/hg-to-git/hg-to-git.py\n+++ b/contrib/hg-to-git/hg-to-git.py\n@@ -42,7 +42,7 @@\n \n def usage():\n \n-        print \"\"\"\\\n+        print(\"\"\"\\\n %s: [OPTIONS] <hgprj>\n \n options:\n@@ -54,7 +54,7 @@ def usage():\n \n required:\n     hgprj:  name of the HG project to import (directory)\n-\"\"\" % sys.argv[0]\n+\"\"\" % sys.argv[0])\n \n #------------------------------------------------------------------------------\n \n@@ -104,29 +104,29 @@ def getgitenv(user, date):\n if state:\n     if os.path.exists(state):\n         if verbose:\n-            print 'State does exist, reading'\n+            print('State does exist, reading')\n         f = open(state, 'r')\n         hgvers = pickle.load(f)\n     else:\n-        print 'State does not exist, first run'\n+        print('State does not exist, first run')\n \n sock = os.popen('hg tip --template \"{rev}\"')\n tip = sock.read()\n if sock.close():\n     sys.exit(1)\n if verbose:\n-    print 'tip is', tip\n+    print('tip is', tip)\n \n # Calculate the branches\n if verbose:\n-    print 'analysing the branches...'\n+    print('analysing the branches...')\n hgchildren[\"0\"] = ()\n hgparents[\"0\"] = (None, None)\n hgbranch[\"0\"] = \"master\"\n for cset in range(1, int(tip) + 1):\n     hgchildren[str(cset)] = ()\n     prnts = os.popen('hg log -r %d --template \"{parents}\"' % cset).read().strip().split(' ')\n-    prnts = map(lambda x: x[:x.find(':')], prnts)\n+    prnts = [x[:x.find(':')] for x in prnts]\n     if prnts[0] != '':\n         parent = prnts[0].strip()\n     else:\n@@ -154,15 +154,15 @@ def getgitenv(user, date):\n         else:\n             hgbranch[str(cset)] = \"branch-\" + str(cset)\n \n-if not hgvers.has_key(\"0\"):\n-    print 'creating repository'\n+if \"0\" not in hgvers:\n+    print('creating repository')\n     os.system('git init')\n \n # loop through every hg changeset\n for cset in range(int(tip) + 1):\n \n     # incremental, already seen\n-    if hgvers.has_key(str(cset)):\n+    if str(cset) in hgvers:\n         continue\n     hgnewcsets += 1\n \n@@ -180,27 +180,27 @@ def getgitenv(user, date):\n     os.write(fdcomment, csetcomment)\n     os.close(fdcomment)\n \n-    print '-----------------------------------------'\n-    print 'cset:', cset\n-    print 'branch:', hgbranch[str(cset)]\n-    print 'user:', user\n-    print 'date:', date\n-    print 'comment:', csetcomment\n+    print('-----------------------------------------')\n+    print('cset:', cset)\n+    print('branch:', hgbranch[str(cset)])\n+    print('user:', user)\n+    print('date:', date)\n+    print('comment:', csetcomment)\n     if parent:\n-\tprint 'parent:', parent\n+\tprint('parent:', parent)\n     if mparent:\n-        print 'mparent:', mparent\n+        print('mparent:', mparent)\n     if tag:\n-        print 'tag:', tag\n-    print '-----------------------------------------'\n+        print('tag:', tag)\n+    print('-----------------------------------------')\n \n     # checkout the parent if necessary\n     if cset != 0:\n         if hgbranch[str(cset)] == \"branch-\" + str(cset):\n-            print 'creating new branch', hgbranch[str(cset)]\n+            print('creating new branch', hgbranch[str(cset)])\n             os.system('git checkout -b %s %s' % (hgbranch[str(cset)], hgvers[parent]))\n         else:\n-            print 'checking out branch', hgbranch[str(cset)]\n+            print('checking out branch', hgbranch[str(cset)])\n             os.system('git checkout %s' % hgbranch[str(cset)])\n \n     # merge\n@@ -209,7 +209,7 @@ def getgitenv(user, date):\n             otherbranch = hgbranch[mparent]\n         else:\n             otherbranch = hgbranch[parent]\n-        print 'merging', otherbranch, 'into', hgbranch[str(cset)]\n+        print('merging', otherbranch, 'into', hgbranch[str(cset)])\n         os.system(getgitenv(user, date) + 'git merge --no-commit -s ours \"\" %s %s' % (hgbranch[str(cset)], otherbranch))\n \n     # remove everything except .git and .hg directories\n@@ -233,12 +233,12 @@ def getgitenv(user, date):\n \n     # delete branch if not used anymore...\n     if mparent and len(hgchildren[str(cset)]):\n-        print \"Deleting unused branch:\", otherbranch\n+        print(\"Deleting unused branch:\", otherbranch)\n         os.system('git branch -d %s' % otherbranch)\n \n     # retrieve and record the version\n     vvv = os.popen('git show --quiet --pretty=format:%H').read()\n-    print 'record', cset, '->', vvv\n+    print('record', cset, '->', vvv)\n     hgvers[str(cset)] = vvv\n \n if hgnewcsets >= opt_nrepack and opt_nrepack != -1:\n@@ -247,7 +247,7 @@ def getgitenv(user, date):\n # write the state for incrementals\n if state:\n     if verbose:\n-        print 'Writing state'\n+        print('Writing state')\n     f = open(state, 'w')\n     pickle.dump(hgvers, f)\n \n\n--\nhttps://github.com/git/git/pull/458\n"},{"id":"339728","messageId":"xmqqwoz7324d.fsf@gitster-ct.c.googlers.com","threadId":"47853","inReplyTo":"01020161b421939a-4ad52aaa-dda8-4250-9bce-71f0ede1a199-000000@eu-west-1.amazonses.com","subject":"Re: [PATCH] make hg-to-git compatible with python2.x and 3.x","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-02-20T19:14:10Z","receivedAt":"2018-02-20T19:14:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Hervé Beraud <herveberaud.pro@gmail.com> writes:\n\n> Signed-off-by: Hervé Beraud <herveberaud.pro@gmail.com>\n> ---\n>  contrib/hg-to-git/hg-to-git.py | 52 +++++++++++++++++++++---------------------\n>  1 file changed, 26 insertions(+), 26 deletions(-)\n\nI think you shrunk the scope of the change, but I feel that it is\nstill a bit under-explained.  Let me try to write a proposed commit\nlog message and ask you to see if I understood the idea behind the\nchanges correctly:\n\n    Rewrite features that are no longer supported (or recommended)\n    in Python 3 in the script so that it can be used with both\n    Python 2 and 3, namely:\n\n    - print is not a statement; use print() function instead.\n    - dict.has_key(key) is no more; use \"key in dict\" instead.\n    - map(lambda ..., collection) is not liked; use list comprehension.\n\nHopefully this would also serve as an illustration of the kind of\nthings we want in our log message.\n\nI am not sure about the change from map(lambda ...) to list\ncomprehension, though.  Not that I have a preference for or against\n(I am not a Python person), but I do not know if this is a change\nnecessary to run with Python 3 or if it is merely more preferred to\nuse list comprehension.\n\nThanks.\n\n> diff --git a/contrib/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py\n> index de3f81667ed97..8fa7698df5c20 100755\n> --- a/contrib/hg-to-git/hg-to-git.py\n> +++ b/contrib/hg-to-git/hg-to-git.py\n> @@ -42,7 +42,7 @@\n>  \n>  def usage():\n>  \n> -        print \"\"\"\\\n> +        print(\"\"\"\\\n>  %s: [OPTIONS] <hgprj>\n>  \n>  options:\n> @@ -54,7 +54,7 @@ def usage():\n>  \n>  required:\n>      hgprj:  name of the HG project to import (directory)\n> -\"\"\" % sys.argv[0]\n> +\"\"\" % sys.argv[0])\n>  \n>  #------------------------------------------------------------------------------\n>  \n> @@ -104,29 +104,29 @@ def getgitenv(user, date):\n>  if state:\n>      if os.path.exists(state):\n>          if verbose:\n> -            print 'State does exist, reading'\n> +            print('State does exist, reading')\n>          f = open(state, 'r')\n>          hgvers = pickle.load(f)\n>      else:\n> -        print 'State does not exist, first run'\n> +        print('State does not exist, first run')\n>  \n>  sock = os.popen('hg tip --template \"{rev}\"')\n>  tip = sock.read()\n>  if sock.close():\n>      sys.exit(1)\n>  if verbose:\n> -    print 'tip is', tip\n> +    print('tip is', tip)\n>  \n>  # Calculate the branches\n>  if verbose:\n> -    print 'analysing the branches...'\n> +    print('analysing the branches...')\n>  hgchildren[\"0\"] = ()\n>  hgparents[\"0\"] = (None, None)\n>  hgbranch[\"0\"] = \"master\"\n>  for cset in range(1, int(tip) + 1):\n>      hgchildren[str(cset)] = ()\n>      prnts = os.popen('hg log -r %d --template \"{parents}\"' % cset).read().strip().split(' ')\n> -    prnts = map(lambda x: x[:x.find(':')], prnts)\n> +    prnts = [x[:x.find(':')] for x in prnts]\n>      if prnts[0] != '':\n>          parent = prnts[0].strip()\n>      else:\n> @@ -154,15 +154,15 @@ def getgitenv(user, date):\n>          else:\n>              hgbranch[str(cset)] = \"branch-\" + str(cset)\n>  \n> -if not hgvers.has_key(\"0\"):\n> -    print 'creating repository'\n> +if \"0\" not in hgvers:\n> +    print('creating repository')\n>      os.system('git init')\n>  \n>  # loop through every hg changeset\n>  for cset in range(int(tip) + 1):\n>  \n>      # incremental, already seen\n> -    if hgvers.has_key(str(cset)):\n> +    if str(cset) in hgvers:\n>          continue\n>      hgnewcsets += 1\n>  \n> @@ -180,27 +180,27 @@ def getgitenv(user, date):\n>      os.write(fdcomment, csetcomment)\n>      os.close(fdcomment)\n>  \n> -    print '-----------------------------------------'\n> -    print 'cset:', cset\n> -    print 'branch:', hgbranch[str(cset)]\n> -    print 'user:', user\n> -    print 'date:', date\n> -    print 'comment:', csetcomment\n> +    print('-----------------------------------------')\n> +    print('cset:', cset)\n> +    print('branch:', hgbranch[str(cset)])\n> +    print('user:', user)\n> +    print('date:', date)\n> +    print('comment:', csetcomment)\n>      if parent:\n> -\tprint 'parent:', parent\n> +\tprint('parent:', parent)\n>      if mparent:\n> -        print 'mparent:', mparent\n> +        print('mparent:', mparent)\n>      if tag:\n> -        print 'tag:', tag\n> -    print '-----------------------------------------'\n> +        print('tag:', tag)\n> +    print('-----------------------------------------')\n>  \n>      # checkout the parent if necessary\n>      if cset != 0:\n>          if hgbranch[str(cset)] == \"branch-\" + str(cset):\n> -            print 'creating new branch', hgbranch[str(cset)]\n> +            print('creating new branch', hgbranch[str(cset)])\n>              os.system('git checkout -b %s %s' % (hgbranch[str(cset)], hgvers[parent]))\n>          else:\n> -            print 'checking out branch', hgbranch[str(cset)]\n> +            print('checking out branch', hgbranch[str(cset)])\n>              os.system('git checkout %s' % hgbranch[str(cset)])\n>  \n>      # merge\n> @@ -209,7 +209,7 @@ def getgitenv(user, date):\n>              otherbranch = hgbranch[mparent]\n>          else:\n>              otherbranch = hgbranch[parent]\n> -        print 'merging', otherbranch, 'into', hgbranch[str(cset)]\n> +        print('merging', otherbranch, 'into', hgbranch[str(cset)])\n>          os.system(getgitenv(user, date) + 'git merge --no-commit -s ours \"\" %s %s' % (hgbranch[str(cset)], otherbranch))\n>  \n>      # remove everything except .git and .hg directories\n> @@ -233,12 +233,12 @@ def getgitenv(user, date):\n>  \n>      # delete branch if not used anymore...\n>      if mparent and len(hgchildren[str(cset)]):\n> -        print \"Deleting unused branch:\", otherbranch\n> +        print(\"Deleting unused branch:\", otherbranch)\n>          os.system('git branch -d %s' % otherbranch)\n>  \n>      # retrieve and record the version\n>      vvv = os.popen('git show --quiet --pretty=format:%H').read()\n> -    print 'record', cset, '->', vvv\n> +    print('record', cset, '->', vvv)\n>      hgvers[str(cset)] = vvv\n>  \n>  if hgnewcsets >= opt_nrepack and opt_nrepack != -1:\n> @@ -247,7 +247,7 @@ def getgitenv(user, date):\n>  # write the state for incrementals\n>  if state:\n>      if verbose:\n> -        print 'Writing state'\n> +        print('Writing state')\n>      f = open(state, 'w')\n>      pickle.dump(hgvers, f)\n>  \n>\n> --\n> https://github.com/git/git/pull/458\n"},{"id":"339729","messageId":"xmqqsh9v31wa.fsf@gitster-ct.c.googlers.com","threadId":"47853","inReplyTo":"xmqqwoz7324d.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH] make hg-to-git compatible with python2.x and 3.x","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-02-20T19:19:01Z","receivedAt":"2018-02-20T19:19:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n>     - map(lambda ..., collection) is not liked; use list comprehension.\n> ...\n> I am not sure about the change from map(lambda ...) to list\n> comprehension, though.  Not that I have a preference for or against\n> (I am not a Python person), but I do not know if this is a change\n> necessary to run with Python 3 or if it is merely more preferred to\n> use list comprehension.\n> ...\n>> -    prnts = map(lambda x: x[:x.find(':')], prnts)\n>> +    prnts = [x[:x.find(':')] for x in prnts]\n\nWell, I should have dug this myself a bit more [*1*] before hitting\n[SEND].  This change is required because map() no longer returns a\nlist.  So the bullet item in the proposed commit log message in my\nearlier message should be updated to say that instead--it was unclear\nto me so I phrased as if it was a mere preference, but it actually\nis a required change.\n\n\n[Footnote]\n\n*1* Well, it would have been ideal if the original patch had enough\n    information from the beginning to make this kind of \"digging\"\n    unnecessary ;-)\n\n\n\n\n"},{"id":"382488","messageId":"0102016d3f74d202-d5b32dd4-0098-4ad0-8ac7-5fde254f7796-000000@eu-west-1.amazonses.com","threadId":"47853","inReplyTo":"01020161b421939a-4ad52aaa-dda8-4250-9bce-71f0ede1a199-000000@eu-west-1.amazonses.com","subject":"[PATCH] Rewrite feature to render hg-to-git compatible with python2.x and 3.x","fromName":"Hervé Beraud","fromEmail":"herveberaud.pro@gmail.com","sentAt":"2019-09-17T13:41:23Z","receivedAt":"2019-09-17T13:41:27Z","isPatch":true,"sender":{"key":"herveberaud.pro@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1541489?v=4"},"body":"Rewrite features that are no longer supported (or recommended)\nin Python 3 in the script so that it can be used with both\nPython 2 and 3, namely:\n\n- print is not a statement; use print() function instead.\n- dict.has_key(key) is no more; use \"key in dict\" instead.\n- map(lambda ..., collection) is not liked; use list comprehension.\n\nThese changes introduce a syntaxe compatible with the both versions of\npython.\n\nPython 2 is EOL at the end of 2019, the major part of distros\nand systems now come with python 3  is the default version so\nthese address the situation to render this script compatible with\nthe latest versions of python.\n\nSigned-off-by: Hervé Beraud <herveberaud.pro@gmail.com>\n---\n contrib/hg-to-git/hg-to-git.py | 52 +++++++++++++++++-----------------\n 1 file changed, 26 insertions(+), 26 deletions(-)\n\ndiff --git a/contrib/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py\nindex de3f81667ed97..8fa7698df5c20 100755\n--- a/contrib/hg-to-git/hg-to-git.py\n+++ b/contrib/hg-to-git/hg-to-git.py\n@@ -42,7 +42,7 @@\n \n def usage():\n \n-        print \"\"\"\\\n+        print(\"\"\"\\\n %s: [OPTIONS] <hgprj>\n \n options:\n@@ -54,7 +54,7 @@ def usage():\n \n required:\n     hgprj:  name of the HG project to import (directory)\n-\"\"\" % sys.argv[0]\n+\"\"\" % sys.argv[0])\n \n #------------------------------------------------------------------------------\n \n@@ -104,29 +104,29 @@ def getgitenv(user, date):\n if state:\n     if os.path.exists(state):\n         if verbose:\n-            print 'State does exist, reading'\n+            print('State does exist, reading')\n         f = open(state, 'r')\n         hgvers = pickle.load(f)\n     else:\n-        print 'State does not exist, first run'\n+        print('State does not exist, first run')\n \n sock = os.popen('hg tip --template \"{rev}\"')\n tip = sock.read()\n if sock.close():\n     sys.exit(1)\n if verbose:\n-    print 'tip is', tip\n+    print('tip is', tip)\n \n # Calculate the branches\n if verbose:\n-    print 'analysing the branches...'\n+    print('analysing the branches...')\n hgchildren[\"0\"] = ()\n hgparents[\"0\"] = (None, None)\n hgbranch[\"0\"] = \"master\"\n for cset in range(1, int(tip) + 1):\n     hgchildren[str(cset)] = ()\n     prnts = os.popen('hg log -r %d --template \"{parents}\"' % cset).read().strip().split(' ')\n-    prnts = map(lambda x: x[:x.find(':')], prnts)\n+    prnts = [x[:x.find(':')] for x in prnts]\n     if prnts[0] != '':\n         parent = prnts[0].strip()\n     else:\n@@ -154,15 +154,15 @@ def getgitenv(user, date):\n         else:\n             hgbranch[str(cset)] = \"branch-\" + str(cset)\n \n-if not hgvers.has_key(\"0\"):\n-    print 'creating repository'\n+if \"0\" not in hgvers:\n+    print('creating repository')\n     os.system('git init')\n \n # loop through every hg changeset\n for cset in range(int(tip) + 1):\n \n     # incremental, already seen\n-    if hgvers.has_key(str(cset)):\n+    if str(cset) in hgvers:\n         continue\n     hgnewcsets += 1\n \n@@ -180,27 +180,27 @@ def getgitenv(user, date):\n     os.write(fdcomment, csetcomment)\n     os.close(fdcomment)\n \n-    print '-----------------------------------------'\n-    print 'cset:', cset\n-    print 'branch:', hgbranch[str(cset)]\n-    print 'user:', user\n-    print 'date:', date\n-    print 'comment:', csetcomment\n+    print('-----------------------------------------')\n+    print('cset:', cset)\n+    print('branch:', hgbranch[str(cset)])\n+    print('user:', user)\n+    print('date:', date)\n+    print('comment:', csetcomment)\n     if parent:\n-\tprint 'parent:', parent\n+\tprint('parent:', parent)\n     if mparent:\n-        print 'mparent:', mparent\n+        print('mparent:', mparent)\n     if tag:\n-        print 'tag:', tag\n-    print '-----------------------------------------'\n+        print('tag:', tag)\n+    print('-----------------------------------------')\n \n     # checkout the parent if necessary\n     if cset != 0:\n         if hgbranch[str(cset)] == \"branch-\" + str(cset):\n-            print 'creating new branch', hgbranch[str(cset)]\n+            print('creating new branch', hgbranch[str(cset)])\n             os.system('git checkout -b %s %s' % (hgbranch[str(cset)], hgvers[parent]))\n         else:\n-            print 'checking out branch', hgbranch[str(cset)]\n+            print('checking out branch', hgbranch[str(cset)])\n             os.system('git checkout %s' % hgbranch[str(cset)])\n \n     # merge\n@@ -209,7 +209,7 @@ def getgitenv(user, date):\n             otherbranch = hgbranch[mparent]\n         else:\n             otherbranch = hgbranch[parent]\n-        print 'merging', otherbranch, 'into', hgbranch[str(cset)]\n+        print('merging', otherbranch, 'into', hgbranch[str(cset)])\n         os.system(getgitenv(user, date) + 'git merge --no-commit -s ours \"\" %s %s' % (hgbranch[str(cset)], otherbranch))\n \n     # remove everything except .git and .hg directories\n@@ -233,12 +233,12 @@ def getgitenv(user, date):\n \n     # delete branch if not used anymore...\n     if mparent and len(hgchildren[str(cset)]):\n-        print \"Deleting unused branch:\", otherbranch\n+        print(\"Deleting unused branch:\", otherbranch)\n         os.system('git branch -d %s' % otherbranch)\n \n     # retrieve and record the version\n     vvv = os.popen('git show --quiet --pretty=format:%H').read()\n-    print 'record', cset, '->', vvv\n+    print('record', cset, '->', vvv)\n     hgvers[str(cset)] = vvv\n \n if hgnewcsets >= opt_nrepack and opt_nrepack != -1:\n@@ -247,7 +247,7 @@ def getgitenv(user, date):\n # write the state for incrementals\n if state:\n     if verbose:\n-        print 'Writing state'\n+        print('Writing state')\n     f = open(state, 'w')\n     pickle.dump(hgvers, f)\n \n\n--\nhttps://github.com/git/git/pull/458\n"},{"id":"382527","messageId":"xmqqd0fy7dra.fsf@gitster-ct.c.googlers.com","threadId":"47853","inReplyTo":"0102016d3f74d202-d5b32dd4-0098-4ad0-8ac7-5fde254f7796-000000@eu-west-1.amazonses.com","subject":"Re: [PATCH] Rewrite feature to render hg-to-git compatible with python2.x and 3.x","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-09-17T22:35:05Z","receivedAt":"2019-09-17T22:35:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Hervé Beraud <herveberaud.pro@gmail.com> writes:\n\n> Rewrite features that are no longer supported (or recommended)\n> in Python 3 in the script so that it can be used with both\n> Python 2 and 3, namely:\n>\n> - print is not a statement; use print() function instead.\n> - dict.has_key(key) is no more; use \"key in dict\" instead.\n> - map(lambda ..., collection) is not liked; use list comprehension.\n\nThe first two are must haves (iow, without them the code would not\nwork with Py3), but the last one sounds like a mere preference.  Is\nthere some authoritative source we can quote (e.g. \"PEPx says that\nwe should prefer X over Y\")?\n\n> These changes introduce a syntaxe compatible with the both versions of\n> python.\n>\n> Python 2 is EOL at the end of 2019, the major part of distros\n> and systems now come with python 3  is the default version so\n> these address the situation to render this script compatible with\n> the latest versions of python.\n\nThe explanation looks vaguely familiar.  I would have placed the\nbackground first, and then description of what is done next, perhaps\nlike:\n\n    Python 2 is EOL at the end of 2019, many distros and systems now\n    come with python 3 as their default version.\n\n    Rewrite features that are no longer supported (or recommended)\n    in Python 3 in the script so that it can be used with both\n    Python 2 and 3, namely:\n\n    - print is not a statement; use print() function instead.\n    - dict.has_key(key) is no more; use \"key in dict\" instead.\n    - map(lambda ..., collection) is not liked; use list comprehension.\n\nto make it even easier to read without unnecessary repetition, but\nwhat you wrote is clear enough already.\n\nThe patch text looked clearly done.  Nice.\n"},{"id":"382529","messageId":"xmqq4l1a7dio.fsf@gitster-ct.c.googlers.com","threadId":"47853","inReplyTo":"xmqqd0fy7dra.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH] Rewrite feature to render hg-to-git compatible with python2.x and 3.x","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-09-17T22:40:15Z","receivedAt":"2019-09-17T22:40:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\nOne more thing.\n\n> Subject: Re: [PATCH] Rewrite feature to render hg-to-git compatible with python2.x and 3.x\n\nOur commit titles typically begin with <area>: prefix, e.g.\n\n    Subject: hg-to-git: make it compatibile with both Python 3 and Python 2\n\nor something like that.\n"},{"id":"382543","messageId":"0102016d43812db5-722fe301-48f7-4b46-93e4-67dc2992629a-000000@eu-west-1.amazonses.com","threadId":"47853","inReplyTo":"0102016d3f74d202-d5b32dd4-0098-4ad0-8ac7-5fde254f7796-000000@eu-west-1.amazonses.com","subject":"[PATCH v2] hg-to-git: make it compatible with both python3 and python2","fromName":"Hervé Beraud","fromEmail":"herveberaud.pro@gmail.com","sentAt":"2019-09-18T08:33:22Z","receivedAt":"2019-09-18T08:33:27Z","isPatch":true,"sender":{"key":"herveberaud.pro@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1541489?v=4"},"body":"Python 2 is EOL at the end of 2019, many distros\nand systems now come with python 3 is the default version.\n\nThese changes introduce a syntaxe compatible with the both versions of\npython and so with the nearly future python standard.\n\nIntroduced changes:\n-------------------\n\nRewriting features that are no longer supported (or recommended)\nin Python 3 in the hg-to-git script.py so that it can be used with both\nPython 2 and 3, namely:\n\n- print is not a statement; use print() function instead.\n- dict.has_key(key) is no more; use \"key in dict\" instead.\n\nSigned-off-by: Hervé Beraud <herveberaud.pro@gmail.com>\n---\n contrib/hg-to-git/hg-to-git.py | 50 +++++++++++++++++-----------------\n 1 file changed, 25 insertions(+), 25 deletions(-)\n\ndiff --git a/contrib/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py\nindex de3f81667ed97..bb2822d4a5e17 100755\n--- a/contrib/hg-to-git/hg-to-git.py\n+++ b/contrib/hg-to-git/hg-to-git.py\n@@ -42,7 +42,7 @@\n \n def usage():\n \n-        print \"\"\"\\\n+        print(\"\"\"\\\n %s: [OPTIONS] <hgprj>\n \n options:\n@@ -54,7 +54,7 @@ def usage():\n \n required:\n     hgprj:  name of the HG project to import (directory)\n-\"\"\" % sys.argv[0]\n+\"\"\" % sys.argv[0])\n \n #------------------------------------------------------------------------------\n \n@@ -104,22 +104,22 @@ def getgitenv(user, date):\n if state:\n     if os.path.exists(state):\n         if verbose:\n-            print 'State does exist, reading'\n+            print('State does exist, reading')\n         f = open(state, 'r')\n         hgvers = pickle.load(f)\n     else:\n-        print 'State does not exist, first run'\n+        print('State does not exist, first run')\n \n sock = os.popen('hg tip --template \"{rev}\"')\n tip = sock.read()\n if sock.close():\n     sys.exit(1)\n if verbose:\n-    print 'tip is', tip\n+    print('tip is', tip)\n \n # Calculate the branches\n if verbose:\n-    print 'analysing the branches...'\n+    print('analysing the branches...')\n hgchildren[\"0\"] = ()\n hgparents[\"0\"] = (None, None)\n hgbranch[\"0\"] = \"master\"\n@@ -154,15 +154,15 @@ def getgitenv(user, date):\n         else:\n             hgbranch[str(cset)] = \"branch-\" + str(cset)\n \n-if not hgvers.has_key(\"0\"):\n-    print 'creating repository'\n+if \"0\" not in hgvers:\n+    print('creating repository')\n     os.system('git init')\n \n # loop through every hg changeset\n for cset in range(int(tip) + 1):\n \n     # incremental, already seen\n-    if hgvers.has_key(str(cset)):\n+    if str(cset) in hgvers:\n         continue\n     hgnewcsets += 1\n \n@@ -180,27 +180,27 @@ def getgitenv(user, date):\n     os.write(fdcomment, csetcomment)\n     os.close(fdcomment)\n \n-    print '-----------------------------------------'\n-    print 'cset:', cset\n-    print 'branch:', hgbranch[str(cset)]\n-    print 'user:', user\n-    print 'date:', date\n-    print 'comment:', csetcomment\n+    print('-----------------------------------------')\n+    print('cset:', cset)\n+    print('branch:', hgbranch[str(cset)])\n+    print('user:', user)\n+    print('date:', date)\n+    print('comment:', csetcomment)\n     if parent:\n-\tprint 'parent:', parent\n+\tprint('parent:', parent)\n     if mparent:\n-        print 'mparent:', mparent\n+        print('mparent:', mparent)\n     if tag:\n-        print 'tag:', tag\n-    print '-----------------------------------------'\n+        print('tag:', tag)\n+    print('-----------------------------------------')\n \n     # checkout the parent if necessary\n     if cset != 0:\n         if hgbranch[str(cset)] == \"branch-\" + str(cset):\n-            print 'creating new branch', hgbranch[str(cset)]\n+            print('creating new branch', hgbranch[str(cset)])\n             os.system('git checkout -b %s %s' % (hgbranch[str(cset)], hgvers[parent]))\n         else:\n-            print 'checking out branch', hgbranch[str(cset)]\n+            print('checking out branch', hgbranch[str(cset)])\n             os.system('git checkout %s' % hgbranch[str(cset)])\n \n     # merge\n@@ -209,7 +209,7 @@ def getgitenv(user, date):\n             otherbranch = hgbranch[mparent]\n         else:\n             otherbranch = hgbranch[parent]\n-        print 'merging', otherbranch, 'into', hgbranch[str(cset)]\n+        print('merging', otherbranch, 'into', hgbranch[str(cset)])\n         os.system(getgitenv(user, date) + 'git merge --no-commit -s ours \"\" %s %s' % (hgbranch[str(cset)], otherbranch))\n \n     # remove everything except .git and .hg directories\n@@ -233,12 +233,12 @@ def getgitenv(user, date):\n \n     # delete branch if not used anymore...\n     if mparent and len(hgchildren[str(cset)]):\n-        print \"Deleting unused branch:\", otherbranch\n+        print(\"Deleting unused branch:\", otherbranch)\n         os.system('git branch -d %s' % otherbranch)\n \n     # retrieve and record the version\n     vvv = os.popen('git show --quiet --pretty=format:%H').read()\n-    print 'record', cset, '->', vvv\n+    print('record', cset, '->', vvv)\n     hgvers[str(cset)] = vvv\n \n if hgnewcsets >= opt_nrepack and opt_nrepack != -1:\n@@ -247,7 +247,7 @@ def getgitenv(user, date):\n # write the state for incrementals\n if state:\n     if verbose:\n-        print 'Writing state'\n+        print('Writing state')\n     f = open(state, 'w')\n     pickle.dump(hgvers, f)\n \n\n--\nhttps://github.com/git/git/pull/458\n"},{"id":"382560","messageId":"xmqqsgot5xm7.fsf@gitster-ct.c.googlers.com","threadId":"47853","inReplyTo":"0102016d43812db5-722fe301-48f7-4b46-93e4-67dc2992629a-000000@eu-west-1.amazonses.com","subject":"Re: [PATCH v2] hg-to-git: make it compatible with both python3 and python2","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-09-18T17:21:20Z","receivedAt":"2019-09-18T17:21:35Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Hervé Beraud <herveberaud.pro@gmail.com> writes:\n\n> Python 2 is EOL at the end of 2019, many distros\n> and systems now come with python 3 is the default version.\n\nGrammo.  s/is the/as their/ or something like that to fix.\n\n> These changes introduce a syntaxe compatible with the both versions of\n> python and so with the nearly future python standard.\n>\n> Introduced changes:\n> -------------------\n\nLet's drop the above 5 lines.  A canonical form of log message for\nus is to begin with a brief background to make readers realize what\nis lacking in the current system (if needed -- and you've done a\ngood job to make the readers realize that we need to make sure we\nwork with Py3).  With readers' minds prepared to accept the need for\na change, then you give orders to the codebase to \"be like so\" in\nimperative mood.  E.g.\n\n    \tRewrite features used in hg-to-git that are no longer\n    \tsupported in Python 3, in such a way that an updated code\n    \tcan still be usable with Python 2.\n\n\t- print is not ...\n\t- dict.has_key(key) is no more; ...\n\nYou seem to have dropped the change from map() to list comprehention\nin this iteration.  I am not into Python deeply enough to care\neither way myself, and the original form with map() seems to work\nwith Python3 (evaluating it seems to result in a map object, instead\nof a list, to lazily yield the values, but we are not printing the\nresult of map() directly with print(), so it should be OK) so from\nmy point of view, the fewer things we have to defend/justify, the\nbetter ;-)\n\nWill queue.  Thanks.\n\n> Rewriting features that are no longer supported (or recommended)\n> in Python 3 in the hg-to-git script.py so that it can be used with both\n> Python 2 and 3, namely:\n>\n> - print is not a statement; use print() function instead.\n> - dict.has_key(key) is no more; use \"key in dict\" instead.\n>\n> Signed-off-by: Hervé Beraud <herveberaud.pro@gmail.com>\n> ---\n>  contrib/hg-to-git/hg-to-git.py | 50 +++++++++++++++++-----------------\n>  1 file changed, 25 insertions(+), 25 deletions(-)\n>\n> diff --git a/contrib/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py\n> index de3f81667ed97..bb2822d4a5e17 100755\n> --- a/contrib/hg-to-git/hg-to-git.py\n> +++ b/contrib/hg-to-git/hg-to-git.py\n> @@ -42,7 +42,7 @@\n>  \n>  def usage():\n>  \n> -        print \"\"\"\\\n> +        print(\"\"\"\\\n>  %s: [OPTIONS] <hgprj>\n>  \n>  options:\n> @@ -54,7 +54,7 @@ def usage():\n>  \n>  required:\n>      hgprj:  name of the HG project to import (directory)\n> -\"\"\" % sys.argv[0]\n> +\"\"\" % sys.argv[0])\n>  \n>  #------------------------------------------------------------------------------\n>  \n> @@ -104,22 +104,22 @@ def getgitenv(user, date):\n>  if state:\n>      if os.path.exists(state):\n>          if verbose:\n> -            print 'State does exist, reading'\n> +            print('State does exist, reading')\n>          f = open(state, 'r')\n>          hgvers = pickle.load(f)\n>      else:\n> -        print 'State does not exist, first run'\n> +        print('State does not exist, first run')\n>  \n>  sock = os.popen('hg tip --template \"{rev}\"')\n>  tip = sock.read()\n>  if sock.close():\n>      sys.exit(1)\n>  if verbose:\n> -    print 'tip is', tip\n> +    print('tip is', tip)\n>  \n>  # Calculate the branches\n>  if verbose:\n> -    print 'analysing the branches...'\n> +    print('analysing the branches...')\n>  hgchildren[\"0\"] = ()\n>  hgparents[\"0\"] = (None, None)\n>  hgbranch[\"0\"] = \"master\"\n> @@ -154,15 +154,15 @@ def getgitenv(user, date):\n>          else:\n>              hgbranch[str(cset)] = \"branch-\" + str(cset)\n>  \n> -if not hgvers.has_key(\"0\"):\n> -    print 'creating repository'\n> +if \"0\" not in hgvers:\n> +    print('creating repository')\n>      os.system('git init')\n>  \n>  # loop through every hg changeset\n>  for cset in range(int(tip) + 1):\n>  \n>      # incremental, already seen\n> -    if hgvers.has_key(str(cset)):\n> +    if str(cset) in hgvers:\n>          continue\n>      hgnewcsets += 1\n>  \n> @@ -180,27 +180,27 @@ def getgitenv(user, date):\n>      os.write(fdcomment, csetcomment)\n>      os.close(fdcomment)\n>  \n> -    print '-----------------------------------------'\n> -    print 'cset:', cset\n> -    print 'branch:', hgbranch[str(cset)]\n> -    print 'user:', user\n> -    print 'date:', date\n> -    print 'comment:', csetcomment\n> +    print('-----------------------------------------')\n> +    print('cset:', cset)\n> +    print('branch:', hgbranch[str(cset)])\n> +    print('user:', user)\n> +    print('date:', date)\n> +    print('comment:', csetcomment)\n>      if parent:\n> -\tprint 'parent:', parent\n> +\tprint('parent:', parent)\n>      if mparent:\n> -        print 'mparent:', mparent\n> +        print('mparent:', mparent)\n>      if tag:\n> -        print 'tag:', tag\n> -    print '-----------------------------------------'\n> +        print('tag:', tag)\n> +    print('-----------------------------------------')\n>  \n>      # checkout the parent if necessary\n>      if cset != 0:\n>          if hgbranch[str(cset)] == \"branch-\" + str(cset):\n> -            print 'creating new branch', hgbranch[str(cset)]\n> +            print('creating new branch', hgbranch[str(cset)])\n>              os.system('git checkout -b %s %s' % (hgbranch[str(cset)], hgvers[parent]))\n>          else:\n> -            print 'checking out branch', hgbranch[str(cset)]\n> +            print('checking out branch', hgbranch[str(cset)])\n>              os.system('git checkout %s' % hgbranch[str(cset)])\n>  \n>      # merge\n> @@ -209,7 +209,7 @@ def getgitenv(user, date):\n>              otherbranch = hgbranch[mparent]\n>          else:\n>              otherbranch = hgbranch[parent]\n> -        print 'merging', otherbranch, 'into', hgbranch[str(cset)]\n> +        print('merging', otherbranch, 'into', hgbranch[str(cset)])\n>          os.system(getgitenv(user, date) + 'git merge --no-commit -s ours \"\" %s %s' % (hgbranch[str(cset)], otherbranch))\n>  \n>      # remove everything except .git and .hg directories\n> @@ -233,12 +233,12 @@ def getgitenv(user, date):\n>  \n>      # delete branch if not used anymore...\n>      if mparent and len(hgchildren[str(cset)]):\n> -        print \"Deleting unused branch:\", otherbranch\n> +        print(\"Deleting unused branch:\", otherbranch)\n>          os.system('git branch -d %s' % otherbranch)\n>  \n>      # retrieve and record the version\n>      vvv = os.popen('git show --quiet --pretty=format:%H').read()\n> -    print 'record', cset, '->', vvv\n> +    print('record', cset, '->', vvv)\n>      hgvers[str(cset)] = vvv\n>  \n>  if hgnewcsets >= opt_nrepack and opt_nrepack != -1:\n> @@ -247,7 +247,7 @@ def getgitenv(user, date):\n>  # write the state for incrementals\n>  if state:\n>      if verbose:\n> -        print 'Writing state'\n> +        print('Writing state')\n>      f = open(state, 'w')\n>      pickle.dump(hgvers, f)\n>  \n>\n> --\n> https://github.com/git/git/pull/458\n"},{"id":"382566","messageId":"0102016d45842c54-616d4b1c-3410-4237-9da8-708c5b0daabd-000000@eu-west-1.amazonses.com","threadId":"47853","inReplyTo":"0102016d43812db5-722fe301-48f7-4b46-93e4-67dc2992629a-000000@eu-west-1.amazonses.com","subject":"[PATCH v3] hg-to-git: make it compatible with both python3 and python2","fromName":"Hervé Beraud","fromEmail":"herveberaud.pro@gmail.com","sentAt":"2019-09-18T17:55:53Z","receivedAt":"2019-09-18T17:55:56Z","isPatch":true,"sender":{"key":"herveberaud.pro@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1541489?v=4"},"body":"Python 2 is EOL at the end of 2019, many distros\nand systems now come with python 3 as their default version.\n\nThese changes introduce a syntaxe compatible with the both versions of\npython and so with the nearly future python standard.\n\nSigned-off-by: Hervé Beraud <herveberaud.pro@gmail.com>\n---\n contrib/hg-to-git/hg-to-git.py | 50 +++++++++++++++++-----------------\n 1 file changed, 25 insertions(+), 25 deletions(-)\n\ndiff --git a/contrib/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py\nindex de3f81667ed97..bb2822d4a5e17 100755\n--- a/contrib/hg-to-git/hg-to-git.py\n+++ b/contrib/hg-to-git/hg-to-git.py\n@@ -42,7 +42,7 @@\n \n def usage():\n \n-        print \"\"\"\\\n+        print(\"\"\"\\\n %s: [OPTIONS] <hgprj>\n \n options:\n@@ -54,7 +54,7 @@ def usage():\n \n required:\n     hgprj:  name of the HG project to import (directory)\n-\"\"\" % sys.argv[0]\n+\"\"\" % sys.argv[0])\n \n #------------------------------------------------------------------------------\n \n@@ -104,22 +104,22 @@ def getgitenv(user, date):\n if state:\n     if os.path.exists(state):\n         if verbose:\n-            print 'State does exist, reading'\n+            print('State does exist, reading')\n         f = open(state, 'r')\n         hgvers = pickle.load(f)\n     else:\n-        print 'State does not exist, first run'\n+        print('State does not exist, first run')\n \n sock = os.popen('hg tip --template \"{rev}\"')\n tip = sock.read()\n if sock.close():\n     sys.exit(1)\n if verbose:\n-    print 'tip is', tip\n+    print('tip is', tip)\n \n # Calculate the branches\n if verbose:\n-    print 'analysing the branches...'\n+    print('analysing the branches...')\n hgchildren[\"0\"] = ()\n hgparents[\"0\"] = (None, None)\n hgbranch[\"0\"] = \"master\"\n@@ -154,15 +154,15 @@ def getgitenv(user, date):\n         else:\n             hgbranch[str(cset)] = \"branch-\" + str(cset)\n \n-if not hgvers.has_key(\"0\"):\n-    print 'creating repository'\n+if \"0\" not in hgvers:\n+    print('creating repository')\n     os.system('git init')\n \n # loop through every hg changeset\n for cset in range(int(tip) + 1):\n \n     # incremental, already seen\n-    if hgvers.has_key(str(cset)):\n+    if str(cset) in hgvers:\n         continue\n     hgnewcsets += 1\n \n@@ -180,27 +180,27 @@ def getgitenv(user, date):\n     os.write(fdcomment, csetcomment)\n     os.close(fdcomment)\n \n-    print '-----------------------------------------'\n-    print 'cset:', cset\n-    print 'branch:', hgbranch[str(cset)]\n-    print 'user:', user\n-    print 'date:', date\n-    print 'comment:', csetcomment\n+    print('-----------------------------------------')\n+    print('cset:', cset)\n+    print('branch:', hgbranch[str(cset)])\n+    print('user:', user)\n+    print('date:', date)\n+    print('comment:', csetcomment)\n     if parent:\n-\tprint 'parent:', parent\n+\tprint('parent:', parent)\n     if mparent:\n-        print 'mparent:', mparent\n+        print('mparent:', mparent)\n     if tag:\n-        print 'tag:', tag\n-    print '-----------------------------------------'\n+        print('tag:', tag)\n+    print('-----------------------------------------')\n \n     # checkout the parent if necessary\n     if cset != 0:\n         if hgbranch[str(cset)] == \"branch-\" + str(cset):\n-            print 'creating new branch', hgbranch[str(cset)]\n+            print('creating new branch', hgbranch[str(cset)])\n             os.system('git checkout -b %s %s' % (hgbranch[str(cset)], hgvers[parent]))\n         else:\n-            print 'checking out branch', hgbranch[str(cset)]\n+            print('checking out branch', hgbranch[str(cset)])\n             os.system('git checkout %s' % hgbranch[str(cset)])\n \n     # merge\n@@ -209,7 +209,7 @@ def getgitenv(user, date):\n             otherbranch = hgbranch[mparent]\n         else:\n             otherbranch = hgbranch[parent]\n-        print 'merging', otherbranch, 'into', hgbranch[str(cset)]\n+        print('merging', otherbranch, 'into', hgbranch[str(cset)])\n         os.system(getgitenv(user, date) + 'git merge --no-commit -s ours \"\" %s %s' % (hgbranch[str(cset)], otherbranch))\n \n     # remove everything except .git and .hg directories\n@@ -233,12 +233,12 @@ def getgitenv(user, date):\n \n     # delete branch if not used anymore...\n     if mparent and len(hgchildren[str(cset)]):\n-        print \"Deleting unused branch:\", otherbranch\n+        print(\"Deleting unused branch:\", otherbranch)\n         os.system('git branch -d %s' % otherbranch)\n \n     # retrieve and record the version\n     vvv = os.popen('git show --quiet --pretty=format:%H').read()\n-    print 'record', cset, '->', vvv\n+    print('record', cset, '->', vvv)\n     hgvers[str(cset)] = vvv\n \n if hgnewcsets >= opt_nrepack and opt_nrepack != -1:\n@@ -247,7 +247,7 @@ def getgitenv(user, date):\n # write the state for incrementals\n if state:\n     if verbose:\n-        print 'Writing state'\n+        print('Writing state')\n     f = open(state, 'w')\n     pickle.dump(hgvers, f)\n \n\n--\nhttps://github.com/git/git/pull/458\n"}]}