Show More
@@ -98,6 +98,33 b' def darcs_pull(hg_repo, darcs_repo, chas' | |||
|
98 | 98 | if not new_tip != old_tip + 1: |
|
99 | 99 | error("Darcs pull did not work as expected: " + res) |
|
100 | 100 | |
|
101 | def darcs_changes_summary(darcs_repo, chash): | |
|
102 | """Gets the changes from the darcs summary. This returns the chronological | |
|
103 | list of changes as (change_type, args). Eg. ('add_file', 'foo.txt') or | |
|
104 | ('move', ['foo.txt','bar.txt']).""" | |
|
105 | change = cmd("darcs changes --summary --xml-output --match=\"hash %s\"" % (chash), darcs_repo) | |
|
106 | doc = xml_dom.parseString(change) | |
|
107 | for patch_node in doc.childNodes[0].childNodes: | |
|
108 | summary_nodes = filter(lambda n: n.nodeName == "summary" and n.nodeType == n.ELEMENT_NODE, patch_node.childNodes) | |
|
109 | for summary_node in summary_nodes: | |
|
110 | change_nodes = filter(lambda n: n.nodeType == n.ELEMENT_NODE, summary_node.childNodes) | |
|
111 | for change_node in change_nodes: | |
|
112 | change = change_node.nodeName | |
|
113 | if change == 'modify_file': | |
|
114 | yield change, change_node.childNodes[0].data.strip() | |
|
115 | elif change == 'add_file': | |
|
116 | yield change, change_node.childNodes[0].data.strip() | |
|
117 | elif change == 'remove_file': | |
|
118 | yield change, change_node.childNodes[0].data.strip() | |
|
119 | elif change == 'add_directory': | |
|
120 | yield change, change_node.childNodes[0].data.strip() | |
|
121 | elif change == 'remove_directory': | |
|
122 | yield change, change_node.childNodes[0].data.strip() | |
|
123 | elif change == 'move': | |
|
124 | yield change, (change_node.getAttribute('from'), change_node.getAttribute('to')) | |
|
125 | else: | |
|
126 | error('Problem parsing summary xml: Unexpected element: ' + change_node.toxml()) | |
|
127 | ||
|
101 | 128 | # ------------------------------------------------------------------------------ |
|
102 | 129 | # |
|
103 | 130 | # Mercurial interface |
@@ -127,6 +154,27 b' def hg_tip( hg_repo ):' | |||
|
127 | 154 | tip = tip.split("\n")[0].split(":")[1].strip() |
|
128 | 155 | return int(tip) |
|
129 | 156 | |
|
157 | def hg_rename( hg_repo, from_file, to_file ): | |
|
158 | cmd("hg rename --after \"%s\" \"%s\"" % (from_file, to_file), hg_repo); | |
|
159 | ||
|
160 | def hg_handle_change( hg_repo, change, arg ): | |
|
161 | """Processes a change event as output by darcs_changes_summary. These | |
|
162 | consist of file move/rename/add/delete commands.""" | |
|
163 | if change == 'modify_file': | |
|
164 | pass | |
|
165 | elif change == 'add_file': | |
|
166 | pass | |
|
167 | elif change =='remove_file': | |
|
168 | pass | |
|
169 | elif change == 'add_directory': | |
|
170 | pass | |
|
171 | elif change == 'remove_directory': | |
|
172 | pass | |
|
173 | elif change == 'move': | |
|
174 | hg_rename(hg_repo, arg[0], arg[1]) | |
|
175 | else: | |
|
176 | error('Unknown change type ' + change + ': ' + arg) | |
|
177 | ||
|
130 | 178 | # ------------------------------------------------------------------------------ |
|
131 | 179 | # |
|
132 | 180 | # Main |
@@ -167,11 +215,13 b' if __name__ == "__main__":' | |||
|
167 | 215 | print "(skipping)" |
|
168 | 216 | else: |
|
169 | 217 | text = summary + "\n" + description |
|
170 | darcs_pull(hg_repo, darcs_repo, chash) | |
|
171 | 218 | # The commit hash has a date like 20021020201112 |
|
172 | 219 | # --------------------------------YYYYMMDDHHMMSS |
|
173 | 220 | date = chash.split("-")[0] |
|
174 | 221 | epoch = int(mktime(strptime(date, '%Y%m%d%H%M%S'))) |
|
222 | darcs_pull(hg_repo, darcs_repo, chash) | |
|
223 | for change, arg in darcs_changes_summary(darcs_repo, chash): | |
|
224 | hg_handle_change(hg_repo, change, arg) | |
|
175 | 225 | hg_commit(hg_repo, text, author, epoch) |
|
176 | 226 | change_number += 1 |
|
177 | 227 | print "Darcs repository (_darcs) was not deleted. You can keep or remove it." |
General Comments 0
You need to be logged in to leave comments.
Login now