{"thread":{"id":"61162","subject":"[PATCH] contrib: drop hg-to-git script","startedAt":"2024-03-20T09:48:25Z","lastAt":"2024-03-23T18:49:32Z","messageCount":8,"participants":["Jeff King","Junio C Hamano","Johannes Schindelin","Stelian Pop"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"491006","messageId":"20240320094824.GA2445978@coredump.intra.peff.net","threadId":"61162","inReplyTo":null,"subject":"[PATCH] contrib: drop hg-to-git script","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2024-03-20T09:48:24Z","receivedAt":"2024-03-20T09:48:25Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"The hg-to-git script is full of command injection vulnerabilities\nagainst malicious branch and tag names. It's also old and largely\nunmaintained; the last commit was over 4 years ago, and the last code\nchange before that was from 2013. Users are better off with a modern\nremote-helper tool like cinnabar or remote-hg.\n\nSo rather than spending time to fix it, let's just get rid of it.\n\nReported-by: Matthew Rollings <admin@stealthcopter.com>\nSigned-off-by: Jeff King <peff@peff.net>\n---\nThis was reported to the security list in December. I suggested there\nthat we should just get rid of it, but there was no follow-up. Until\nnow. ;) Speak now if anybody wants to volunteer to fix the script\ninstead.\n\n contrib/hg-to-git/hg-to-git.py  | 254 --------------------------------\n contrib/hg-to-git/hg-to-git.txt |  21 ---\n 2 files changed, 275 deletions(-)\n delete mode 100755 contrib/hg-to-git/hg-to-git.py\n delete mode 100644 contrib/hg-to-git/hg-to-git.txt\n\ndiff --git a/contrib/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py\ndeleted file mode 100755\nindex 7eb1b24cc7..0000000000\n--- a/contrib/hg-to-git/hg-to-git.py\n+++ /dev/null\n@@ -1,254 +0,0 @@\n-#!/usr/bin/env python\n-\n-\"\"\" hg-to-git.py - A Mercurial to GIT converter\n-\n-    Copyright (C)2007 Stelian Pop <stelian@popies.net>\n-\n-    This program is free software; you can redistribute it and/or modify\n-    it under the terms of the GNU General Public License as published by\n-    the Free Software Foundation; either version 2, or (at your option)\n-    any later version.\n-\n-    This program is distributed in the hope that it will be useful,\n-    but WITHOUT ANY WARRANTY; without even the implied warranty of\n-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n-    GNU General Public License for more details.\n-\n-    You should have received a copy of the GNU General Public License\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 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-\n-# Maps hg version -> git version\n-hgvers = {}\n-# List of children for each hg revision\n-hgchildren = {}\n-# List of parents for each hg revision\n-hgparents = {}\n-# Current branch for each hg revision\n-hgbranch = {}\n-# Number of new changesets converted from hg\n-hgnewcsets = 0\n-\n-#------------------------------------------------------------------------------\n-\n-def usage():\n-\n-        print(\"\"\"\\\n-%s: [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-\n-required:\n-    hgprj:  name of the HG project to import (directory)\n-\"\"\" % sys.argv[0])\n-\n-#------------------------------------------------------------------------------\n-\n-def getgitenv(user, date):\n-    env = ''\n-    elems = re.compile('(.*?)\\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-        env += 'export GIT_AUTHOR_EMAIL=\"%s\" ;' % elems.group(2)\n-        env += 'export GIT_COMMITTER_EMAIL=\"%s\" ;' % elems.group(2)\n-    else:\n-        env += 'export GIT_AUTHOR_NAME=\"%s\" ;' % user\n-        env += 'export GIT_COMMITTER_NAME=\"%s\" ;' % user\n-        env += 'export GIT_AUTHOR_EMAIL= ;'\n-        env += 'export GIT_COMMITTER_EMAIL= ;'\n-\n-    env += 'export GIT_AUTHOR_DATE=\"%s\" ;' % date\n-    env += 'export GIT_COMMITTER_DATE=\"%s\" ;' % date\n-    return env\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-    for o, a in opts:\n-        if o in ('-s', '--gitstate'):\n-            state = a\n-            state = os.path.abspath(state)\n-        if o in ('-n', '--nrepack'):\n-            opt_nrepack = int(a)\n-        if o in ('-v', '--verbose'):\n-            verbose = True\n-    if len(args) != 1:\n-        raise Exception('params')\n-except:\n-    usage()\n-    sys.exit(1)\n-\n-hgprj = args[0]\n-os.chdir(hgprj)\n-\n-if state:\n-    if os.path.exists(state):\n-        if verbose:\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-\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-\n-# Calculate the branches\n-if verbose:\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-    if prnts[0] != '':\n-        parent = prnts[0].strip()\n-    else:\n-        parent = str(cset - 1)\n-    hgchildren[parent] += ( str(cset), )\n-    if len(prnts) > 1:\n-        mparent = prnts[1].strip()\n-        hgchildren[mparent] += ( str(cset), )\n-    else:\n-        mparent = None\n-\n-    hgparents[str(cset)] = (parent, mparent)\n-\n-    if mparent:\n-        # For merge changesets, take either one, preferably the 'master' branch\n-        if hgbranch[mparent] == 'master':\n-            hgbranch[str(cset)] = 'master'\n-        else:\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-        if hgchildren[parent][0] == str(cset):\n-            hgbranch[str(cset)] = hgbranch[parent]\n-        else:\n-            hgbranch[str(cset)] = \"branch-\" + str(cset)\n-\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 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-    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-    (fdcomment, filecomment) = tempfile.mkstemp()\n-    csetcomment = os.popen('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-    if parent:\n-        print('parent:', parent)\n-    if mparent:\n-        print('mparent:', mparent)\n-    if tag:\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-        else:\n-            print('checking out branch', hgbranch[str(cset)])\n-            os.system('git checkout %s' % hgbranch[str(cset)])\n-\n-    # merge\n-    if mparent:\n-        if hgbranch[parent] == hgbranch[str(cset)]:\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-\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-\n-    # repopulate with checkouted files\n-    os.system('hg update -C %d' % cset)\n-\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-\n-    # commit\n-    os.system(getgitenv(user, date) + 'git commit --allow-empty --allow-empty-message -a -F %s' % filecomment)\n-    os.unlink(filecomment)\n-\n-    # tag\n-    if tag and tag != 'tip':\n-        os.system(getgitenv(user, date) + 'git tag %s' % tag)\n-\n-    # delete branch if not used anymore...\n-    if mparent and len(hgchildren[str(cset)]):\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-    hgvers[str(cset)] = vvv\n-\n-if hgnewcsets >= opt_nrepack and opt_nrepack != -1:\n-    os.system('git repack -a -d')\n-\n-# write the state for incrementals\n-if state:\n-    if verbose:\n-        print('Writing state')\n-    f = open(state, 'w')\n-    pickle.dump(hgvers, f)\n-\n-# vim: et ts=8 sw=4 sts=4\ndiff --git a/contrib/hg-to-git/hg-to-git.txt b/contrib/hg-to-git/hg-to-git.txt\ndeleted file mode 100644\nindex 91f8fe6410..0000000000\n--- a/contrib/hg-to-git/hg-to-git.txt\n+++ /dev/null\n@@ -1,21 +0,0 @@\n-hg-to-git.py is able to convert a Mercurial repository into a git one,\n-and preserves the branches in the process (unlike tailor)\n-\n-hg-to-git.py can probably be greatly improved (it's a rather crude\n-combination of shell and python) but it does already work quite well for\n-me. Features:\n-\t- supports incremental conversion\n-\t  (for keeping a git repo in sync with a hg one)\n-        - supports hg branches\n-        - converts hg tags\n-\n-Note that the git repository will be created 'in place' (at the same\n-location as the source hg repo). You will have to manually remove the\n-'.hg' directory after the conversion.\n-\n-Also note that the incremental conversion uses 'simple' hg changesets\n-identifiers (ordinals, as opposed to SHA-1 ids), and since these ids\n-are not stable across different repositories the hg-to-git.py state file\n-is forever tied to one hg repository.\n-\n-Stelian Pop <stelian@popies.net>\n-- \n2.44.0.650.g4615f65fe0\n"},{"id":"491015","messageId":"xmqqa5mthsrw.fsf@gitster.g","threadId":"61162","inReplyTo":"20240320094824.GA2445978@coredump.intra.peff.net","subject":"Re: [PATCH] contrib: drop hg-to-git script","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-03-20T14:39:15Z","receivedAt":"2024-03-20T14:39:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> The hg-to-git script is full of command injection vulnerabilities\n> against malicious branch and tag names. It's also old and largely\n> unmaintained; the last commit was over 4 years ago, and the last code\n> change before that was from 2013. Users are better off with a modern\n> remote-helper tool like cinnabar or remote-hg.\n>\n> So rather than spending time to fix it, let's just get rid of it.\n>\n> Reported-by: Matthew Rollings <admin@stealthcopter.com>\n> Signed-off-by: Jeff King <peff@peff.net>\n> ---\n> This was reported to the security list in December. I suggested there\n> that we should just get rid of it, but there was no follow-up. Until\n> now. ;) Speak now if anybody wants to volunteer to fix the script\n> instead.\n\nThanks, will queue.\n\n>\n>  contrib/hg-to-git/hg-to-git.py  | 254 --------------------------------\n>  contrib/hg-to-git/hg-to-git.txt |  21 ---\n>  2 files changed, 275 deletions(-)\n>  delete mode 100755 contrib/hg-to-git/hg-to-git.py\n>  delete mode 100644 contrib/hg-to-git/hg-to-git.txt\n>\n> diff --git a/contrib/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py\n> deleted file mode 100755\n> index 7eb1b24cc7..0000000000\n> --- a/contrib/hg-to-git/hg-to-git.py\n> +++ /dev/null\n> @@ -1,254 +0,0 @@\n> -#!/usr/bin/env python\n> -\n> -\"\"\" hg-to-git.py - A Mercurial to GIT converter\n> -\n> -    Copyright (C)2007 Stelian Pop <stelian@popies.net>\n> -\n> -    This program is free software; you can redistribute it and/or modify\n> -    it under the terms of the GNU General Public License as published by\n> -    the Free Software Foundation; either version 2, or (at your option)\n> -    any later version.\n> -\n> -    This program is distributed in the hope that it will be useful,\n> -    but WITHOUT ANY WARRANTY; without even the implied warranty of\n> -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n> -    GNU General Public License for more details.\n> -\n> -    You should have received a copy of the GNU General Public License\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 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> -\n> -# Maps hg version -> git version\n> -hgvers = {}\n> -# List of children for each hg revision\n> -hgchildren = {}\n> -# List of parents for each hg revision\n> -hgparents = {}\n> -# Current branch for each hg revision\n> -hgbranch = {}\n> -# Number of new changesets converted from hg\n> -hgnewcsets = 0\n> -\n> -#------------------------------------------------------------------------------\n> -\n> -def usage():\n> -\n> -        print(\"\"\"\\\n> -%s: [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> -\n> -required:\n> -    hgprj:  name of the HG project to import (directory)\n> -\"\"\" % sys.argv[0])\n> -\n> -#------------------------------------------------------------------------------\n> -\n> -def getgitenv(user, date):\n> -    env = ''\n> -    elems = re.compile('(.*?)\\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> -        env += 'export GIT_AUTHOR_EMAIL=\"%s\" ;' % elems.group(2)\n> -        env += 'export GIT_COMMITTER_EMAIL=\"%s\" ;' % elems.group(2)\n> -    else:\n> -        env += 'export GIT_AUTHOR_NAME=\"%s\" ;' % user\n> -        env += 'export GIT_COMMITTER_NAME=\"%s\" ;' % user\n> -        env += 'export GIT_AUTHOR_EMAIL= ;'\n> -        env += 'export GIT_COMMITTER_EMAIL= ;'\n> -\n> -    env += 'export GIT_AUTHOR_DATE=\"%s\" ;' % date\n> -    env += 'export GIT_COMMITTER_DATE=\"%s\" ;' % date\n> -    return env\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> -    for o, a in opts:\n> -        if o in ('-s', '--gitstate'):\n> -            state = a\n> -            state = os.path.abspath(state)\n> -        if o in ('-n', '--nrepack'):\n> -            opt_nrepack = int(a)\n> -        if o in ('-v', '--verbose'):\n> -            verbose = True\n> -    if len(args) != 1:\n> -        raise Exception('params')\n> -except:\n> -    usage()\n> -    sys.exit(1)\n> -\n> -hgprj = args[0]\n> -os.chdir(hgprj)\n> -\n> -if state:\n> -    if os.path.exists(state):\n> -        if verbose:\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> -\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> -\n> -# Calculate the branches\n> -if verbose:\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> -    if prnts[0] != '':\n> -        parent = prnts[0].strip()\n> -    else:\n> -        parent = str(cset - 1)\n> -    hgchildren[parent] += ( str(cset), )\n> -    if len(prnts) > 1:\n> -        mparent = prnts[1].strip()\n> -        hgchildren[mparent] += ( str(cset), )\n> -    else:\n> -        mparent = None\n> -\n> -    hgparents[str(cset)] = (parent, mparent)\n> -\n> -    if mparent:\n> -        # For merge changesets, take either one, preferably the 'master' branch\n> -        if hgbranch[mparent] == 'master':\n> -            hgbranch[str(cset)] = 'master'\n> -        else:\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> -        if hgchildren[parent][0] == str(cset):\n> -            hgbranch[str(cset)] = hgbranch[parent]\n> -        else:\n> -            hgbranch[str(cset)] = \"branch-\" + str(cset)\n> -\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 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> -    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> -    (fdcomment, filecomment) = tempfile.mkstemp()\n> -    csetcomment = os.popen('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> -    if parent:\n> -        print('parent:', parent)\n> -    if mparent:\n> -        print('mparent:', mparent)\n> -    if tag:\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> -        else:\n> -            print('checking out branch', hgbranch[str(cset)])\n> -            os.system('git checkout %s' % hgbranch[str(cset)])\n> -\n> -    # merge\n> -    if mparent:\n> -        if hgbranch[parent] == hgbranch[str(cset)]:\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> -\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> -\n> -    # repopulate with checkouted files\n> -    os.system('hg update -C %d' % cset)\n> -\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> -\n> -    # commit\n> -    os.system(getgitenv(user, date) + 'git commit --allow-empty --allow-empty-message -a -F %s' % filecomment)\n> -    os.unlink(filecomment)\n> -\n> -    # tag\n> -    if tag and tag != 'tip':\n> -        os.system(getgitenv(user, date) + 'git tag %s' % tag)\n> -\n> -    # delete branch if not used anymore...\n> -    if mparent and len(hgchildren[str(cset)]):\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> -    hgvers[str(cset)] = vvv\n> -\n> -if hgnewcsets >= opt_nrepack and opt_nrepack != -1:\n> -    os.system('git repack -a -d')\n> -\n> -# write the state for incrementals\n> -if state:\n> -    if verbose:\n> -        print('Writing state')\n> -    f = open(state, 'w')\n> -    pickle.dump(hgvers, f)\n> -\n> -# vim: et ts=8 sw=4 sts=4\n> diff --git a/contrib/hg-to-git/hg-to-git.txt b/contrib/hg-to-git/hg-to-git.txt\n> deleted file mode 100644\n> index 91f8fe6410..0000000000\n> --- a/contrib/hg-to-git/hg-to-git.txt\n> +++ /dev/null\n> @@ -1,21 +0,0 @@\n> -hg-to-git.py is able to convert a Mercurial repository into a git one,\n> -and preserves the branches in the process (unlike tailor)\n> -\n> -hg-to-git.py can probably be greatly improved (it's a rather crude\n> -combination of shell and python) but it does already work quite well for\n> -me. Features:\n> -\t- supports incremental conversion\n> -\t  (for keeping a git repo in sync with a hg one)\n> -        - supports hg branches\n> -        - converts hg tags\n> -\n> -Note that the git repository will be created 'in place' (at the same\n> -location as the source hg repo). You will have to manually remove the\n> -'.hg' directory after the conversion.\n> -\n> -Also note that the incremental conversion uses 'simple' hg changesets\n> -identifiers (ordinals, as opposed to SHA-1 ids), and since these ids\n> -are not stable across different repositories the hg-to-git.py state file\n> -is forever tied to one hg repository.\n> -\n> -Stelian Pop <stelian@popies.net>\n"},{"id":"491221","messageId":"01de5e16-a4ee-47df-03e6-67f5f0d601a7@gmx.de","threadId":"61162","inReplyTo":"20240320094824.GA2445978@coredump.intra.peff.net","subject":"Re: [PATCH] contrib: drop hg-to-git script","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2024-03-22T07:31:28Z","receivedAt":"2024-03-22T07:31:41Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Jeff,\n\nI Cc:ed Mat (who reported the issue) and Stelian (who added this script in\n2007 and whose email address hopefully still works).\n\nWhile I have no objection to dropping this script, I am reluctant to drop\nit without leaving anything helpful in place. I am thinking about\nsomething like a `README.md` that would contain helpful information for\nany interested reader. I am not good writing such things, so I asked\nCopilot, and it came up with this:\n\n\tThe `hg-to-git` script, which was used to integrate Mercurial\n\trepositories into Git, has been dropped due to lack of\n\tmaintenance. There have been many past endeavors to integrate\n\tMercurial repositories into Git, but not all of them have been\n\tsuccessful. For those who are interested in this topic, there is\n\tstill an active project called Cinnabar, which can be found on\n\tGitHub. You can learn more about it by visiting the Cinnabar\n\trepository at https://github.com/glandium/git-cinnabar.\n\nCiao,\nJohannes\n\nOn Wed, 20 Mar 2024, Jeff King wrote:\n\n> The hg-to-git script is full of command injection vulnerabilities\n> against malicious branch and tag names. It's also old and largely\n> unmaintained; the last commit was over 4 years ago, and the last code\n> change before that was from 2013. Users are better off with a modern\n> remote-helper tool like cinnabar or remote-hg.\n>\n> So rather than spending time to fix it, let's just get rid of it.\n>\n> Reported-by: Matthew Rollings <admin@stealthcopter.com>\n> Signed-off-by: Jeff King <peff@peff.net>\n> ---\n> This was reported to the security list in December. I suggested there\n> that we should just get rid of it, but there was no follow-up. Until\n> now. ;) Speak now if anybody wants to volunteer to fix the script\n> instead.\n>\n>  contrib/hg-to-git/hg-to-git.py  | 254 --------------------------------\n>  contrib/hg-to-git/hg-to-git.txt |  21 ---\n>  2 files changed, 275 deletions(-)\n>  delete mode 100755 contrib/hg-to-git/hg-to-git.py\n>  delete mode 100644 contrib/hg-to-git/hg-to-git.txt\n>\n> diff --git a/contrib/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py\n> deleted file mode 100755\n> index 7eb1b24cc7..0000000000\n> --- a/contrib/hg-to-git/hg-to-git.py\n> +++ /dev/null\n> @@ -1,254 +0,0 @@\n> -#!/usr/bin/env python\n> -\n> -\"\"\" hg-to-git.py - A Mercurial to GIT converter\n> -\n> -    Copyright (C)2007 Stelian Pop <stelian@popies.net>\n> -\n> -    This program is free software; you can redistribute it and/or modify\n> -    it under the terms of the GNU General Public License as published by\n> -    the Free Software Foundation; either version 2, or (at your option)\n> -    any later version.\n> -\n> -    This program is distributed in the hope that it will be useful,\n> -    but WITHOUT ANY WARRANTY; without even the implied warranty of\n> -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n> -    GNU General Public License for more details.\n> -\n> -    You should have received a copy of the GNU General Public License\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 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> -\n> -# Maps hg version -> git version\n> -hgvers = {}\n> -# List of children for each hg revision\n> -hgchildren = {}\n> -# List of parents for each hg revision\n> -hgparents = {}\n> -# Current branch for each hg revision\n> -hgbranch = {}\n> -# Number of new changesets converted from hg\n> -hgnewcsets = 0\n> -\n> -#------------------------------------------------------------------------------\n> -\n> -def usage():\n> -\n> -        print(\"\"\"\\\n> -%s: [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> -\n> -required:\n> -    hgprj:  name of the HG project to import (directory)\n> -\"\"\" % sys.argv[0])\n> -\n> -#------------------------------------------------------------------------------\n> -\n> -def getgitenv(user, date):\n> -    env = ''\n> -    elems = re.compile('(.*?)\\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> -        env += 'export GIT_AUTHOR_EMAIL=\"%s\" ;' % elems.group(2)\n> -        env += 'export GIT_COMMITTER_EMAIL=\"%s\" ;' % elems.group(2)\n> -    else:\n> -        env += 'export GIT_AUTHOR_NAME=\"%s\" ;' % user\n> -        env += 'export GIT_COMMITTER_NAME=\"%s\" ;' % user\n> -        env += 'export GIT_AUTHOR_EMAIL= ;'\n> -        env += 'export GIT_COMMITTER_EMAIL= ;'\n> -\n> -    env += 'export GIT_AUTHOR_DATE=\"%s\" ;' % date\n> -    env += 'export GIT_COMMITTER_DATE=\"%s\" ;' % date\n> -    return env\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> -    for o, a in opts:\n> -        if o in ('-s', '--gitstate'):\n> -            state = a\n> -            state = os.path.abspath(state)\n> -        if o in ('-n', '--nrepack'):\n> -            opt_nrepack = int(a)\n> -        if o in ('-v', '--verbose'):\n> -            verbose = True\n> -    if len(args) != 1:\n> -        raise Exception('params')\n> -except:\n> -    usage()\n> -    sys.exit(1)\n> -\n> -hgprj = args[0]\n> -os.chdir(hgprj)\n> -\n> -if state:\n> -    if os.path.exists(state):\n> -        if verbose:\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> -\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> -\n> -# Calculate the branches\n> -if verbose:\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> -    if prnts[0] != '':\n> -        parent = prnts[0].strip()\n> -    else:\n> -        parent = str(cset - 1)\n> -    hgchildren[parent] += ( str(cset), )\n> -    if len(prnts) > 1:\n> -        mparent = prnts[1].strip()\n> -        hgchildren[mparent] += ( str(cset), )\n> -    else:\n> -        mparent = None\n> -\n> -    hgparents[str(cset)] = (parent, mparent)\n> -\n> -    if mparent:\n> -        # For merge changesets, take either one, preferably the 'master' branch\n> -        if hgbranch[mparent] == 'master':\n> -            hgbranch[str(cset)] = 'master'\n> -        else:\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> -        if hgchildren[parent][0] == str(cset):\n> -            hgbranch[str(cset)] = hgbranch[parent]\n> -        else:\n> -            hgbranch[str(cset)] = \"branch-\" + str(cset)\n> -\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 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> -    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> -    (fdcomment, filecomment) = tempfile.mkstemp()\n> -    csetcomment = os.popen('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> -    if parent:\n> -        print('parent:', parent)\n> -    if mparent:\n> -        print('mparent:', mparent)\n> -    if tag:\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> -        else:\n> -            print('checking out branch', hgbranch[str(cset)])\n> -            os.system('git checkout %s' % hgbranch[str(cset)])\n> -\n> -    # merge\n> -    if mparent:\n> -        if hgbranch[parent] == hgbranch[str(cset)]:\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> -\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> -\n> -    # repopulate with checkouted files\n> -    os.system('hg update -C %d' % cset)\n> -\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> -\n> -    # commit\n> -    os.system(getgitenv(user, date) + 'git commit --allow-empty --allow-empty-message -a -F %s' % filecomment)\n> -    os.unlink(filecomment)\n> -\n> -    # tag\n> -    if tag and tag != 'tip':\n> -        os.system(getgitenv(user, date) + 'git tag %s' % tag)\n> -\n> -    # delete branch if not used anymore...\n> -    if mparent and len(hgchildren[str(cset)]):\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> -    hgvers[str(cset)] = vvv\n> -\n> -if hgnewcsets >= opt_nrepack and opt_nrepack != -1:\n> -    os.system('git repack -a -d')\n> -\n> -# write the state for incrementals\n> -if state:\n> -    if verbose:\n> -        print('Writing state')\n> -    f = open(state, 'w')\n> -    pickle.dump(hgvers, f)\n> -\n> -# vim: et ts=8 sw=4 sts=4\n> diff --git a/contrib/hg-to-git/hg-to-git.txt b/contrib/hg-to-git/hg-to-git.txt\n> deleted file mode 100644\n> index 91f8fe6410..0000000000\n> --- a/contrib/hg-to-git/hg-to-git.txt\n> +++ /dev/null\n> @@ -1,21 +0,0 @@\n> -hg-to-git.py is able to convert a Mercurial repository into a git one,\n> -and preserves the branches in the process (unlike tailor)\n> -\n> -hg-to-git.py can probably be greatly improved (it's a rather crude\n> -combination of shell and python) but it does already work quite well for\n> -me. Features:\n> -\t- supports incremental conversion\n> -\t  (for keeping a git repo in sync with a hg one)\n> -        - supports hg branches\n> -        - converts hg tags\n> -\n> -Note that the git repository will be created 'in place' (at the same\n> -location as the source hg repo). You will have to manually remove the\n> -'.hg' directory after the conversion.\n> -\n> -Also note that the incremental conversion uses 'simple' hg changesets\n> -identifiers (ordinals, as opposed to SHA-1 ids), and since these ids\n> -are not stable across different repositories the hg-to-git.py state file\n> -is forever tied to one hg repository.\n> -\n> -Stelian Pop <stelian@popies.net>\n> --\n> 2.44.0.650.g4615f65fe0\n>\n>\n"},{"id":"491223","messageId":"37e4cd61-b370-437e-bd42-f98f47d3ad32@popies.net","threadId":"61162","inReplyTo":"01de5e16-a4ee-47df-03e6-67f5f0d601a7@gmx.de","subject":"Re: [PATCH] contrib: drop hg-to-git script","fromName":"Stelian Pop","fromEmail":"stelian@popies.net","sentAt":"2024-03-22T08:36:23Z","receivedAt":"2024-03-22T08:45:23Z","isPatch":true,"sender":{"key":"stelian@popies.net","avatar":"https://gravatar.com/avatar/c99e49c3b3d851deb85e4557b368712c890a09985211f183bd151f8ab6357c03?d=mp&s=160"},"body":"Hi everyone,\n\nFWIW, I have no objection to this removal !\n\nSigned-off-by: Stelian Pop <stelian@popies.net>\n\n\nBest,\n\nStelian.\n\nLe 22/03/2024 à 08:31, Johannes Schindelin a écrit :\n> Hi Jeff,\n> \n> I Cc:ed Mat (who reported the issue) and Stelian (who added this script in\n> 2007 and whose email address hopefully still works).\n> \n> While I have no objection to dropping this script, I am reluctant to drop\n> it without leaving anything helpful in place. I am thinking about\n> something like a `README.md` that would contain helpful information for\n> any interested reader. I am not good writing such things, so I asked\n> Copilot, and it came up with this:\n> \n> \tThe `hg-to-git` script, which was used to integrate Mercurial\n> \trepositories into Git, has been dropped due to lack of\n> \tmaintenance. There have been many past endeavors to integrate\n> \tMercurial repositories into Git, but not all of them have been\n> \tsuccessful. For those who are interested in this topic, there is\n> \tstill an active project called Cinnabar, which can be found on\n> \tGitHub. You can learn more about it by visiting the Cinnabar\n> \trepository at https://github.com/glandium/git-cinnabar.\n> \n> Ciao,\n> Johannes\n> \n> On Wed, 20 Mar 2024, Jeff King wrote:\n> \n>> The hg-to-git script is full of command injection vulnerabilities\n>> against malicious branch and tag names. It's also old and largely\n>> unmaintained; the last commit was over 4 years ago, and the last code\n>> change before that was from 2013. Users are better off with a modern\n>> remote-helper tool like cinnabar or remote-hg.\n>>\n>> So rather than spending time to fix it, let's just get rid of it.\n>>\n>> Reported-by: Matthew Rollings <admin@stealthcopter.com>\n>> Signed-off-by: Jeff King <peff@peff.net>\n>> ---\n>> This was reported to the security list in December. I suggested there\n>> that we should just get rid of it, but there was no follow-up. Until\n>> now. ;) Speak now if anybody wants to volunteer to fix the script\n>> instead.\n>>\n>>   contrib/hg-to-git/hg-to-git.py  | 254 --------------------------------\n>>   contrib/hg-to-git/hg-to-git.txt |  21 ---\n>>   2 files changed, 275 deletions(-)\n>>   delete mode 100755 contrib/hg-to-git/hg-to-git.py\n>>   delete mode 100644 contrib/hg-to-git/hg-to-git.txt\n>>\n>> diff --git a/contrib/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py\n>> deleted file mode 100755\n>> index 7eb1b24cc7..0000000000\n>> --- a/contrib/hg-to-git/hg-to-git.py\n>> +++ /dev/null\n>> @@ -1,254 +0,0 @@\n>> -#!/usr/bin/env python\n>> -\n>> -\"\"\" hg-to-git.py - A Mercurial to GIT converter\n>> -\n>> -    Copyright (C)2007 Stelian Pop <stelian@popies.net>\n>> -\n>> -    This program is free software; you can redistribute it and/or modify\n>> -    it under the terms of the GNU General Public License as published by\n>> -    the Free Software Foundation; either version 2, or (at your option)\n>> -    any later version.\n>> -\n>> -    This program is distributed in the hope that it will be useful,\n>> -    but WITHOUT ANY WARRANTY; without even the implied warranty of\n>> -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n>> -    GNU General Public License for more details.\n>> -\n>> -    You should have received a copy of the GNU General Public License\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 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>> -\n>> -# Maps hg version -> git version\n>> -hgvers = {}\n>> -# List of children for each hg revision\n>> -hgchildren = {}\n>> -# List of parents for each hg revision\n>> -hgparents = {}\n>> -# Current branch for each hg revision\n>> -hgbranch = {}\n>> -# Number of new changesets converted from hg\n>> -hgnewcsets = 0\n>> -\n>> -#------------------------------------------------------------------------------\n>> -\n>> -def usage():\n>> -\n>> -        print(\"\"\"\\\n>> -%s: [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>> -\n>> -required:\n>> -    hgprj:  name of the HG project to import (directory)\n>> -\"\"\" % sys.argv[0])\n>> -\n>> -#------------------------------------------------------------------------------\n>> -\n>> -def getgitenv(user, date):\n>> -    env = ''\n>> -    elems = re.compile('(.*?)\\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>> -        env += 'export GIT_AUTHOR_EMAIL=\"%s\" ;' % elems.group(2)\n>> -        env += 'export GIT_COMMITTER_EMAIL=\"%s\" ;' % elems.group(2)\n>> -    else:\n>> -        env += 'export GIT_AUTHOR_NAME=\"%s\" ;' % user\n>> -        env += 'export GIT_COMMITTER_NAME=\"%s\" ;' % user\n>> -        env += 'export GIT_AUTHOR_EMAIL= ;'\n>> -        env += 'export GIT_COMMITTER_EMAIL= ;'\n>> -\n>> -    env += 'export GIT_AUTHOR_DATE=\"%s\" ;' % date\n>> -    env += 'export GIT_COMMITTER_DATE=\"%s\" ;' % date\n>> -    return env\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>> -    for o, a in opts:\n>> -        if o in ('-s', '--gitstate'):\n>> -            state = a\n>> -            state = os.path.abspath(state)\n>> -        if o in ('-n', '--nrepack'):\n>> -            opt_nrepack = int(a)\n>> -        if o in ('-v', '--verbose'):\n>> -            verbose = True\n>> -    if len(args) != 1:\n>> -        raise Exception('params')\n>> -except:\n>> -    usage()\n>> -    sys.exit(1)\n>> -\n>> -hgprj = args[0]\n>> -os.chdir(hgprj)\n>> -\n>> -if state:\n>> -    if os.path.exists(state):\n>> -        if verbose:\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>> -\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>> -\n>> -# Calculate the branches\n>> -if verbose:\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>> -    if prnts[0] != '':\n>> -        parent = prnts[0].strip()\n>> -    else:\n>> -        parent = str(cset - 1)\n>> -    hgchildren[parent] += ( str(cset), )\n>> -    if len(prnts) > 1:\n>> -        mparent = prnts[1].strip()\n>> -        hgchildren[mparent] += ( str(cset), )\n>> -    else:\n>> -        mparent = None\n>> -\n>> -    hgparents[str(cset)] = (parent, mparent)\n>> -\n>> -    if mparent:\n>> -        # For merge changesets, take either one, preferably the 'master' branch\n>> -        if hgbranch[mparent] == 'master':\n>> -            hgbranch[str(cset)] = 'master'\n>> -        else:\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>> -        if hgchildren[parent][0] == str(cset):\n>> -            hgbranch[str(cset)] = hgbranch[parent]\n>> -        else:\n>> -            hgbranch[str(cset)] = \"branch-\" + str(cset)\n>> -\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 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>> -    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>> -    (fdcomment, filecomment) = tempfile.mkstemp()\n>> -    csetcomment = os.popen('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>> -    if parent:\n>> -        print('parent:', parent)\n>> -    if mparent:\n>> -        print('mparent:', mparent)\n>> -    if tag:\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>> -        else:\n>> -            print('checking out branch', hgbranch[str(cset)])\n>> -            os.system('git checkout %s' % hgbranch[str(cset)])\n>> -\n>> -    # merge\n>> -    if mparent:\n>> -        if hgbranch[parent] == hgbranch[str(cset)]:\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>> -\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>> -\n>> -    # repopulate with checkouted files\n>> -    os.system('hg update -C %d' % cset)\n>> -\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>> -\n>> -    # commit\n>> -    os.system(getgitenv(user, date) + 'git commit --allow-empty --allow-empty-message -a -F %s' % filecomment)\n>> -    os.unlink(filecomment)\n>> -\n>> -    # tag\n>> -    if tag and tag != 'tip':\n>> -        os.system(getgitenv(user, date) + 'git tag %s' % tag)\n>> -\n>> -    # delete branch if not used anymore...\n>> -    if mparent and len(hgchildren[str(cset)]):\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>> -    hgvers[str(cset)] = vvv\n>> -\n>> -if hgnewcsets >= opt_nrepack and opt_nrepack != -1:\n>> -    os.system('git repack -a -d')\n>> -\n>> -# write the state for incrementals\n>> -if state:\n>> -    if verbose:\n>> -        print('Writing state')\n>> -    f = open(state, 'w')\n>> -    pickle.dump(hgvers, f)\n>> -\n>> -# vim: et ts=8 sw=4 sts=4\n>> diff --git a/contrib/hg-to-git/hg-to-git.txt b/contrib/hg-to-git/hg-to-git.txt\n>> deleted file mode 100644\n>> index 91f8fe6410..0000000000\n>> --- a/contrib/hg-to-git/hg-to-git.txt\n>> +++ /dev/null\n>> @@ -1,21 +0,0 @@\n>> -hg-to-git.py is able to convert a Mercurial repository into a git one,\n>> -and preserves the branches in the process (unlike tailor)\n>> -\n>> -hg-to-git.py can probably be greatly improved (it's a rather crude\n>> -combination of shell and python) but it does already work quite well for\n>> -me. Features:\n>> -\t- supports incremental conversion\n>> -\t  (for keeping a git repo in sync with a hg one)\n>> -        - supports hg branches\n>> -        - converts hg tags\n>> -\n>> -Note that the git repository will be created 'in place' (at the same\n>> -location as the source hg repo). You will have to manually remove the\n>> -'.hg' directory after the conversion.\n>> -\n>> -Also note that the incremental conversion uses 'simple' hg changesets\n>> -identifiers (ordinals, as opposed to SHA-1 ids), and since these ids\n>> -are not stable across different repositories the hg-to-git.py state file\n>> -is forever tied to one hg repository.\n>> -\n>> -Stelian Pop <stelian@popies.net>\n>> --\n>> 2.44.0.650.g4615f65fe0\n>>\n>>\n\n-- \nStelian Pop <stelian@popies.net>\n\n"},{"id":"491249","messageId":"xmqqjzlu2r8n.fsf@gitster.g","threadId":"61162","inReplyTo":"01de5e16-a4ee-47df-03e6-67f5f0d601a7@gmx.de","subject":"Re: [PATCH] contrib: drop hg-to-git script","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-03-22T15:58:16Z","receivedAt":"2024-03-22T15:58:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> While I have no objection to dropping this script, I am reluctant to drop\n> it without leaving anything helpful in place. I am thinking about\n> something like a `README.md` that would contain helpful information for\n> any interested reader.\n\nYears ago, I lost the illusion that our tree is the place for all\nusers who want to improve their Git experience to come and they try\nto find related software in our contrib/ section.\n\nThose with specific needs (e.g., \"A project uses Mercuial; I want\nits history in Git because I am used to it more\") will never come to\nour contrib/ as their first place to look, but they may still find\nus in https://letmegooglethat.com/?q=mercurial+to+git if we left an\notherwise empty directory there.\n\nThose with curiosity without specific needs (e.g., \"what kind of\ninteresting enhancements around Git are there\") are unlikely to come\nto our contrib/ section either, as it offers too small a collection,\nbut more importantly, a directory with README and nothing else is\none more place they have to look at for no interesting information.\nIf we want to be really helpful to these folks, we need a curated\ncollection that is properly maintained.\n\nWhile some directories under contrib/ may have been well maintained,\nI do not think we have been good stewards for most directories in\nthere that do not have upstream author's involvement in maintaining\nthem.  If 6 months down the road a better alternative for cinnabar\nor remote-hg appears, I doubt anybody will update such a README file\nto add mention of it.  Even if it did, I highly doubt anybody will\ncome to our contrib/ area to find out about it---they will find out\nabout it elsewhere.\n\nI am aware that we have precedence.  contrib/hooks/multimail and\ncontrib/emacs are two examples that lost almost everything but still\nhave tombstone README.  But these README are not kept up to date to\nhelp their intended audiences.  The only people it _might_ help to\nhave such tombstone README are those who say \"Oh, I thought we had\nHg to git in contrib/---what happened to it?\" and they are better\nserved by \"git log contrib/\" that will find the commit that explains\nwhy we decided to drop it back when we did.\n\n>> The hg-to-git script is full of command injection vulnerabilities\n>> against malicious branch and tag names. It's also old and largely\n>> unmaintained; the last commit was over 4 years ago, and the last code\n>> change before that was from 2013. Users are better off with a modern\n>> remote-helper tool like cinnabar or remote-hg.\n\nThe approach will not give them any false expectation that the\n\"modern tool\" are updated in the historical record to tell them\nabout better alternative that appeared after hg-to-git was removed,\nunlike tombstone README that we _could_ be maintaining but without\nany intention to do so.\n\nSo, I dunno.  I very much appreciate your desire to be helpful to\nthe users, but in this case the effort is misguided and not being\nhelping the users very much.  \n\nIf we were a major part of the sources for Git related information\nand there were little external information, READMEs that are\nsomewhat stale were much much better than no READMEs at all.  But\nsuch days are over a decade ago and having README that we plan to\nlet go stale has dubious value, I would have to say.\n"},{"id":"491251","messageId":"xmqqy1aa1acf.fsf@gitster.g","threadId":"61162","inReplyTo":"37e4cd61-b370-437e-bd42-f98f47d3ad32@popies.net","subject":"Re: [PATCH] contrib: drop hg-to-git script","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-03-22T16:48:32Z","receivedAt":"2024-03-22T16:48:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stelian Pop <stelian@popies.net> writes:\n\n> Hi everyone,\n>\n> FWIW, I have no objection to this removal !\n>\n> Signed-off-by: Stelian Pop <stelian@popies.net>\n\nThanks.\n"},{"id":"491286","messageId":"20240322234354.GC2049941@coredump.intra.peff.net","threadId":"61162","inReplyTo":"xmqqjzlu2r8n.fsf@gitster.g","subject":"Re: [PATCH] contrib: drop hg-to-git script","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2024-03-22T23:43:54Z","receivedAt":"2024-03-22T23:43:55Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Mar 22, 2024 at 08:58:16AM -0700, Junio C Hamano wrote:\n\n> Those with specific needs (e.g., \"A project uses Mercuial; I want\n> its history in Git because I am used to it more\") will never come to\n> our contrib/ as their first place to look, but they may still find\n> us in https://letmegooglethat.com/?q=mercurial+to+git if we left an\n> otherwise empty directory there.\n\nThanks, I was going to write something similar, but you did it much\nbetter than I would have. :)\n\nI was curious what results such a search _would_ turn up these days. The\ntop hits for me (keeping in mind that sometimes search results are\npersonalized, of course) are:\n\n  - https://git-scm.com/book/en/v2/Git-and-Other-Systems-Migrating-to-Git\n\n    which suggests hg-fast-export to git-fast-import for a one-time\n    conversion.\n\n  - https://docs.github.com/en/migrations/importing-source-code/using-the-command-line-to-import-source-code/importing-a-mercurial-repository\n\n    which does likewise.\n\n  - https://www.alexpage.de/guides/convert-a-mercurial-hg-repository-to-git/\n\n    which suggests using hg-git to push into the Git repository.\n\nI suggested remote-hg or cinnabar, which is what I would have turned to.\nBut I guess those are more about continuous interoperability rather than\na one-shot conversion (and of course are based on fast-export/import\nunder the hood anyway).\n\nAnyway, the important takeaway to me is that searches are not likely to\nend up at contrib/hg-to-git, with people wondering where it went. They\nwill point directly to the alternatives.\n\n-Peff\n"},{"id":"491310","messageId":"xmqqh6gwwzpi.fsf@gitster.g","threadId":"61162","inReplyTo":"20240322234354.GC2049941@coredump.intra.peff.net","subject":"Re: [PATCH] contrib: drop hg-to-git script","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-03-23T18:49:29Z","receivedAt":"2024-03-23T18:49:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> Anyway, the important takeaway to me is that searches are not likely to\n> end up at contrib/hg-to-git, with people wondering where it went. They\n> will point directly to the alternatives.\n\nAnd what is most attractive is that the list of alternatives they\nwill see in there searches will be updated as new and better ones\nappear, unlike contrib/hg-to-git/README that we would need to\nconciously maintain, which we are unlikely to do.\n\nWe might want to see if there are other contrib/ ones with only\ntombstone READMEs and remove them as a part of spring (in the\nnorthern hemisphere) cleaning, #leftoverbits, citing what we\ndiscussed in this thread as the rationale.\n\nThanks.\n"}]}