Mercurial > hg
diff contrib/darcs2hg.py @ 2352:61909dfb316d
various fixes to darcs conversion script
1. removed files were missed
2. hidden files in top directory were not added/removed correctly
3. suppressed spurious warning on adding new files.
4. hg changeset now checked in with original author and date
5. __file__ not supported by pdb.py
author | TK Soh <teekaysoh@yahoo.com> |
---|---|
date | Mon, 29 May 2006 16:46:31 +0800 |
parents | 88c881bda888 |
children | 5ec2dded1bda |
line wrap: on
line diff
--- a/contrib/darcs2hg.py Sat May 27 20:45:22 2006 -0700 +++ b/contrib/darcs2hg.py Mon May 29 16:46:31 2006 +0800 @@ -13,7 +13,9 @@ # ----------------------------------------------------------------------------- import os, sys +import tempfile import xml.dom.minidom as xml_dom +from time import strptime, mktime DARCS_REPO = None HG_REPO = None @@ -25,7 +27,7 @@ HGREPO must not exist, as it will be created and filled up (this will avoid overwriting valuable data. -""" % (os.path.basename(__file__)) +""" % (os.path.basename(sys.argv[0])) # ------------------------------------------------------------------------------ # @@ -70,8 +72,9 @@ else: name = name[0].childNodes[0].data if not comm: comm = "" else: comm = comm[0].childNodes[0].data - res.append([name, comm]) - return res + author = patch_node.getAttribute("author") + date = patch_node.getAttribute("date") + yield author, date, name, comm def darcs_pull(hg_repo, darcs_repo, change): cmd("darcs pull '%s' --all --patches='%s'" % (darcs_repo, change), hg_repo) @@ -82,11 +85,13 @@ # # ------------------------------------------------------------------------------ -def hg_commit( hg_repo, text ): - writefile("/tmp/msg", text) - cmd("hg add -X _darcs *", hg_repo) - cmd("hg commit -l /tmp/msg", hg_repo) - os.unlink("/tmp/msg") +def hg_commit( hg_repo, text, author, date ): + fd, tmpfile = tempfile.mkstemp(prefix="darcs2hg_") + writefile(tmpfile, text) + cmd("hg add -X _darcs", hg_repo) + cmd("hg remove -X _darcs --after", hg_repo) + cmd("hg commit -l %s -u '%s' -d '%s 0'" % (tmpfile, author, date), hg_repo) + os.unlink(tmpfile) # ------------------------------------------------------------------------------ # @@ -115,10 +120,11 @@ cmd("hg init '%s'" % (hg_repo)) cmd("darcs initialize", hg_repo) # Get the changes from the Darcs repository - for summary, description in darcs_changes(darcs_repo): + for author, date, summary, description in darcs_changes(darcs_repo): text = summary + "\n" + description darcs_pull(hg_repo, darcs_repo, summary) - hg_commit(hg_repo, text) + epoch = int(mktime(strptime(date, '%Y%m%d%H%M%S'))) + hg_commit(hg_repo, text, author, epoch) # EOF