Mercurial > hg > mercurial-crew-with-dirclash
comparison 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 |
comparison
equal
deleted
inserted
replaced
2351:075d2ddc4639 | 2352:61909dfb316d |
---|---|
11 # 26-May-2006 - Updated | 11 # 26-May-2006 - Updated |
12 # 24-May-2006 - First implementation | 12 # 24-May-2006 - First implementation |
13 # ----------------------------------------------------------------------------- | 13 # ----------------------------------------------------------------------------- |
14 | 14 |
15 import os, sys | 15 import os, sys |
16 import tempfile | |
16 import xml.dom.minidom as xml_dom | 17 import xml.dom.minidom as xml_dom |
18 from time import strptime, mktime | |
17 | 19 |
18 DARCS_REPO = None | 20 DARCS_REPO = None |
19 HG_REPO = None | 21 HG_REPO = None |
20 | 22 |
21 USAGE = """\ | 23 USAGE = """\ |
23 | 25 |
24 Converts the given Darcs repository to a new Mercurial repository. The given | 26 Converts the given Darcs repository to a new Mercurial repository. The given |
25 HGREPO must not exist, as it will be created and filled up (this will avoid | 27 HGREPO must not exist, as it will be created and filled up (this will avoid |
26 overwriting valuable data. | 28 overwriting valuable data. |
27 | 29 |
28 """ % (os.path.basename(__file__)) | 30 """ % (os.path.basename(sys.argv[0])) |
29 | 31 |
30 # ------------------------------------------------------------------------------ | 32 # ------------------------------------------------------------------------------ |
31 # | 33 # |
32 # Utilities | 34 # Utilities |
33 # | 35 # |
68 comm = filter(lambda n:n.nodeName == "comment", patch_node.childNodes) | 70 comm = filter(lambda n:n.nodeName == "comment", patch_node.childNodes) |
69 if not name:continue | 71 if not name:continue |
70 else: name = name[0].childNodes[0].data | 72 else: name = name[0].childNodes[0].data |
71 if not comm: comm = "" | 73 if not comm: comm = "" |
72 else: comm = comm[0].childNodes[0].data | 74 else: comm = comm[0].childNodes[0].data |
73 res.append([name, comm]) | 75 author = patch_node.getAttribute("author") |
74 return res | 76 date = patch_node.getAttribute("date") |
77 yield author, date, name, comm | |
75 | 78 |
76 def darcs_pull(hg_repo, darcs_repo, change): | 79 def darcs_pull(hg_repo, darcs_repo, change): |
77 cmd("darcs pull '%s' --all --patches='%s'" % (darcs_repo, change), hg_repo) | 80 cmd("darcs pull '%s' --all --patches='%s'" % (darcs_repo, change), hg_repo) |
78 | 81 |
79 # ------------------------------------------------------------------------------ | 82 # ------------------------------------------------------------------------------ |
80 # | 83 # |
81 # Mercurial interface | 84 # Mercurial interface |
82 # | 85 # |
83 # ------------------------------------------------------------------------------ | 86 # ------------------------------------------------------------------------------ |
84 | 87 |
85 def hg_commit( hg_repo, text ): | 88 def hg_commit( hg_repo, text, author, date ): |
86 writefile("/tmp/msg", text) | 89 fd, tmpfile = tempfile.mkstemp(prefix="darcs2hg_") |
87 cmd("hg add -X _darcs *", hg_repo) | 90 writefile(tmpfile, text) |
88 cmd("hg commit -l /tmp/msg", hg_repo) | 91 cmd("hg add -X _darcs", hg_repo) |
89 os.unlink("/tmp/msg") | 92 cmd("hg remove -X _darcs --after", hg_repo) |
93 cmd("hg commit -l %s -u '%s' -d '%s 0'" % (tmpfile, author, date), hg_repo) | |
94 os.unlink(tmpfile) | |
90 | 95 |
91 # ------------------------------------------------------------------------------ | 96 # ------------------------------------------------------------------------------ |
92 # | 97 # |
93 # Main | 98 # Main |
94 # | 99 # |
113 print "Given HG repository must not exist. It will be created" | 118 print "Given HG repository must not exist. It will be created" |
114 sys.exit(-1) | 119 sys.exit(-1) |
115 cmd("hg init '%s'" % (hg_repo)) | 120 cmd("hg init '%s'" % (hg_repo)) |
116 cmd("darcs initialize", hg_repo) | 121 cmd("darcs initialize", hg_repo) |
117 # Get the changes from the Darcs repository | 122 # Get the changes from the Darcs repository |
118 for summary, description in darcs_changes(darcs_repo): | 123 for author, date, summary, description in darcs_changes(darcs_repo): |
119 text = summary + "\n" + description | 124 text = summary + "\n" + description |
120 darcs_pull(hg_repo, darcs_repo, summary) | 125 darcs_pull(hg_repo, darcs_repo, summary) |
121 hg_commit(hg_repo, text) | 126 epoch = int(mktime(strptime(date, '%Y%m%d%H%M%S'))) |
127 hg_commit(hg_repo, text, author, epoch) | |
122 | 128 |
123 # EOF | 129 # EOF |
124 | 130 |