##// END OF EJS Templates
convert: add closesort algorithm to mercurial sources...
Constantine Linnick -
r18819:05acdf8e default
parent child Browse files
Show More
@@ -61,6 +61,10 b' def convert(ui, src, dest=None, revmapfi'
61 61 --sourcesort try to preserve source revisions order, only
62 62 supported by Mercurial sources.
63 63
64 --closesort try to move closed revisions as close as possible
65 to parent branches, only supported by Mercurial
66 sources.
67
64 68 If ``REVMAP`` isn't given, it will be put in a default location
65 69 (``<dest>/.hg/shamap`` by default). The ``REVMAP`` is a simple
66 70 text file that maps each source commit ID to the destination ID
@@ -318,7 +322,8 b' cmdtable = {'
318 322 _('change branch names while converting'), _('FILE')),
319 323 ('', 'branchsort', None, _('try to sort changesets by branches')),
320 324 ('', 'datesort', None, _('try to sort changesets by date')),
321 ('', 'sourcesort', None, _('preserve source changesets order'))],
325 ('', 'sourcesort', None, _('preserve source changesets order')),
326 ('', 'closesort', None, _('try to reorder closed revisions'))],
322 327 _('hg convert [OPTION]... SOURCE [DEST [REVMAP]]')),
323 328 "debugsvnlog":
324 329 (debugsvnlog,
@@ -145,6 +145,11 b' class converter_source(object):'
145 145 """
146 146 return False
147 147
148 def hasnativeclose(self):
149 """Return true if this source has ability to close branch.
150 """
151 return False
152
148 153 def lookuprev(self, rev):
149 154 """If rev is a meaningful revision reference in source, return
150 155 the referenced identifier in the same format used by getcommit().
@@ -227,6 +227,14 b' class converter(object):'
227 227 return sorted(nodes, key=keyfn)[0]
228 228 return picknext
229 229
230 def makeclosesorter():
231 """Close order sort."""
232 keyfn = lambda n: ('close' not in self.commitcache[n].extra,
233 self.commitcache[n].sortkey)
234 def picknext(nodes):
235 return sorted(nodes, key=keyfn)[0]
236 return picknext
237
230 238 def makedatesorter():
231 239 """Sort revisions by date."""
232 240 dates = {}
@@ -246,6 +254,8 b' class converter(object):'
246 254 picknext = makedatesorter()
247 255 elif sortmode == 'sourcesort':
248 256 picknext = makesourcesorter()
257 elif sortmode == 'closesort':
258 picknext = makeclosesorter()
249 259 else:
250 260 raise util.Abort(_('unknown sort mode: %s') % sortmode)
251 261
@@ -446,13 +456,15 b' def convert(ui, src, dest=None, revmapfi'
446 456 shutil.rmtree(path, True)
447 457 raise
448 458
449 sortmodes = ('branchsort', 'datesort', 'sourcesort')
459 sortmodes = ('branchsort', 'datesort', 'sourcesort', 'closesort')
450 460 sortmode = [m for m in sortmodes if opts.get(m)]
451 461 if len(sortmode) > 1:
452 462 raise util.Abort(_('more than one sort mode specified'))
453 463 sortmode = sortmode and sortmode[0] or defaultsort
454 464 if sortmode == 'sourcesort' and not srcc.hasnativeorder():
455 465 raise util.Abort(_('--sourcesort is not supported by this data source'))
466 if sortmode == 'closesort' and not srcc.hasnativeclose():
467 raise util.Abort(_('--closesort is not supported by this data source'))
456 468
457 469 fmap = opts.get('filemap')
458 470 if fmap:
@@ -386,6 +386,9 b' class mercurial_source(converter_source)'
386 386 def hasnativeorder(self):
387 387 return True
388 388
389 def hasnativeclose(self):
390 return True
391
389 392 def lookuprev(self, rev):
390 393 try:
391 394 return hex(self.repo.lookup(rev))
@@ -38,6 +38,26 b''
38 38 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
39 39 $ echo b >> b
40 40 $ hg ci -m b1 -d '9 0'
41 $ hg up -C 0
42 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
43 $ echo c >> c
44 $ hg branch branchc
45 marked working directory as branch branchc
46 (branches are permanent and global, did you want a bookmark?)
47 $ hg ci -Am c0 -d '10 0'
48 adding c
49 $ hg up -C brancha
50 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
51 $ hg ci --close-branch -m a7x -d '11 0'
52 $ hg up -C branchb
53 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
54 $ hg ci --close-branch -m b2x -d '12 0'
55 $ hg up -C branchc
56 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
57 $ hg merge branchb
58 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
59 (branch merge, don't forget to commit)
60 $ hg ci -m c1 -d '13 0'
41 61 $ cd ..
42 62
43 63 convert with datesort
@@ -47,27 +67,39 b' convert with datesort'
47 67 scanning source...
48 68 sorting...
49 69 converting...
50 8 a0
51 7 a1
52 6 a2
53 5 a3
54 4 a4
55 3 b0
56 2 a5
57 1 a6
58 0 b1
70 12 a0
71 11 a1
72 10 a2
73 9 a3
74 8 a4
75 7 b0
76 6 a5
77 5 a6
78 4 b1
79 3 c0
80 2 a7x
81 1 b2x
82 0 c1
59 83
60 84 graph converted repo
61 85
62 86 $ hg -R t-datesort glog --template '{rev} "{desc}"\n'
63 o 8 "b1"
64 |
65 | o 7 "a6"
87 o 12 "c1"
88 |\
89 | o 11 "b2x"
66 90 | |
67 | o 6 "a5"
68 | |
69 o | 5 "b0"
70 | |
91 | | o 10 "a7x"
92 | | |
93 o | | 9 "c0"
94 | | |
95 | o | 8 "b1"
96 | | |
97 | | o 7 "a6"
98 | | |
99 | | o 6 "a5"
100 | | |
101 | o | 5 "b0"
102 |/ /
71 103 | o 4 "a4"
72 104 | |
73 105 | o 3 "a3"
@@ -86,29 +118,41 b' convert with datesort (default mode)'
86 118 scanning source...
87 119 sorting...
88 120 converting...
89 8 a0
90 7 a1
91 6 a2
92 5 a3
93 4 b0
94 3 a4
95 2 a5
96 1 a6
97 0 b1
121 12 a0
122 11 a1
123 10 a2
124 9 a3
125 8 b0
126 7 a4
127 6 a5
128 5 a6
129 4 b1
130 3 c0
131 2 a7x
132 1 b2x
133 0 c1
98 134
99 135 graph converted repo
100 136
101 137 $ hg -R t-sourcesort glog --template '{rev} "{desc}"\n'
102 o 8 "b1"
103 |
104 | o 7 "a6"
138 o 12 "c1"
139 |\
140 | o 11 "b2x"
105 141 | |
106 | o 6 "a5"
107 | |
108 | o 5 "a4"
109 | |
110 o | 4 "b0"
111 | |
142 | | o 10 "a7x"
143 | | |
144 o | | 9 "c0"
145 | | |
146 | o | 8 "b1"
147 | | |
148 | | o 7 "a6"
149 | | |
150 | | o 6 "a5"
151 | | |
152 | | o 5 "a4"
153 | | |
154 | o | 4 "b0"
155 |/ /
112 156 | o 3 "a3"
113 157 | |
114 158 | o 2 "a2"
@@ -117,3 +161,54 b' graph converted repo'
117 161 |/
118 162 o 0 "a0"
119 163
164
165 convert with closesort
166
167 $ hg convert --closesort t t-closesort
168 initializing destination t-closesort repository
169 scanning source...
170 sorting...
171 converting...
172 12 a0
173 11 a1
174 10 a2
175 9 a3
176 8 b0
177 7 a4
178 6 a5
179 5 a6
180 4 a7x
181 3 b1
182 2 b2x
183 1 c0
184 0 c1
185
186 graph converted repo
187
188 $ hg -R t-closesort glog --template '{rev} "{desc}"\n'
189 o 12 "c1"
190 |\
191 | o 11 "c0"
192 | |
193 o | 10 "b2x"
194 | |
195 o | 9 "b1"
196 | |
197 | | o 8 "a7x"
198 | | |
199 | | o 7 "a6"
200 | | |
201 | | o 6 "a5"
202 | | |
203 | | o 5 "a4"
204 | | |
205 o | | 4 "b0"
206 |/ /
207 | o 3 "a3"
208 | |
209 | o 2 "a2"
210 | |
211 | o 1 "a1"
212 |/
213 o 0 "a0"
214
@@ -46,6 +46,8 b''
46 46 larger than the same ones generated by --branchsort.
47 47 --sourcesort try to preserve source revisions order, only supported by
48 48 Mercurial sources.
49 --closesort try to move closed revisions as close as possible to parent
50 branches, only supported by Mercurial sources.
49 51
50 52 If "REVMAP" isn't given, it will be put in a default location
51 53 ("<dest>/.hg/shamap" by default). The "REVMAP" is a simple text file that
@@ -268,6 +270,7 b''
268 270 --branchsort try to sort changesets by branches
269 271 --datesort try to sort changesets by date
270 272 --sourcesort preserve source changesets order
273 --closesort try to reorder closed revisions
271 274
272 275 use "hg -v help convert" to show the global options
273 276 $ hg init a
General Comments 0
You need to be logged in to leave comments. Login now