##// 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 --sourcesort try to preserve source revisions order, only
61 --sourcesort try to preserve source revisions order, only
62 supported by Mercurial sources.
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 If ``REVMAP`` isn't given, it will be put in a default location
68 If ``REVMAP`` isn't given, it will be put in a default location
65 (``<dest>/.hg/shamap`` by default). The ``REVMAP`` is a simple
69 (``<dest>/.hg/shamap`` by default). The ``REVMAP`` is a simple
66 text file that maps each source commit ID to the destination ID
70 text file that maps each source commit ID to the destination ID
@@ -318,7 +322,8 b' cmdtable = {'
318 _('change branch names while converting'), _('FILE')),
322 _('change branch names while converting'), _('FILE')),
319 ('', 'branchsort', None, _('try to sort changesets by branches')),
323 ('', 'branchsort', None, _('try to sort changesets by branches')),
320 ('', 'datesort', None, _('try to sort changesets by date')),
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 _('hg convert [OPTION]... SOURCE [DEST [REVMAP]]')),
327 _('hg convert [OPTION]... SOURCE [DEST [REVMAP]]')),
323 "debugsvnlog":
328 "debugsvnlog":
324 (debugsvnlog,
329 (debugsvnlog,
@@ -145,6 +145,11 b' class converter_source(object):'
145 """
145 """
146 return False
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 def lookuprev(self, rev):
153 def lookuprev(self, rev):
149 """If rev is a meaningful revision reference in source, return
154 """If rev is a meaningful revision reference in source, return
150 the referenced identifier in the same format used by getcommit().
155 the referenced identifier in the same format used by getcommit().
@@ -227,6 +227,14 b' class converter(object):'
227 return sorted(nodes, key=keyfn)[0]
227 return sorted(nodes, key=keyfn)[0]
228 return picknext
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 def makedatesorter():
238 def makedatesorter():
231 """Sort revisions by date."""
239 """Sort revisions by date."""
232 dates = {}
240 dates = {}
@@ -246,6 +254,8 b' class converter(object):'
246 picknext = makedatesorter()
254 picknext = makedatesorter()
247 elif sortmode == 'sourcesort':
255 elif sortmode == 'sourcesort':
248 picknext = makesourcesorter()
256 picknext = makesourcesorter()
257 elif sortmode == 'closesort':
258 picknext = makeclosesorter()
249 else:
259 else:
250 raise util.Abort(_('unknown sort mode: %s') % sortmode)
260 raise util.Abort(_('unknown sort mode: %s') % sortmode)
251
261
@@ -446,13 +456,15 b' def convert(ui, src, dest=None, revmapfi'
446 shutil.rmtree(path, True)
456 shutil.rmtree(path, True)
447 raise
457 raise
448
458
449 sortmodes = ('branchsort', 'datesort', 'sourcesort')
459 sortmodes = ('branchsort', 'datesort', 'sourcesort', 'closesort')
450 sortmode = [m for m in sortmodes if opts.get(m)]
460 sortmode = [m for m in sortmodes if opts.get(m)]
451 if len(sortmode) > 1:
461 if len(sortmode) > 1:
452 raise util.Abort(_('more than one sort mode specified'))
462 raise util.Abort(_('more than one sort mode specified'))
453 sortmode = sortmode and sortmode[0] or defaultsort
463 sortmode = sortmode and sortmode[0] or defaultsort
454 if sortmode == 'sourcesort' and not srcc.hasnativeorder():
464 if sortmode == 'sourcesort' and not srcc.hasnativeorder():
455 raise util.Abort(_('--sourcesort is not supported by this data source'))
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 fmap = opts.get('filemap')
469 fmap = opts.get('filemap')
458 if fmap:
470 if fmap:
@@ -386,6 +386,9 b' class mercurial_source(converter_source)'
386 def hasnativeorder(self):
386 def hasnativeorder(self):
387 return True
387 return True
388
388
389 def hasnativeclose(self):
390 return True
391
389 def lookuprev(self, rev):
392 def lookuprev(self, rev):
390 try:
393 try:
391 return hex(self.repo.lookup(rev))
394 return hex(self.repo.lookup(rev))
@@ -38,6 +38,26 b''
38 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
38 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
39 $ echo b >> b
39 $ echo b >> b
40 $ hg ci -m b1 -d '9 0'
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 $ cd ..
61 $ cd ..
42
62
43 convert with datesort
63 convert with datesort
@@ -47,27 +67,39 b' convert with datesort'
47 scanning source...
67 scanning source...
48 sorting...
68 sorting...
49 converting...
69 converting...
50 8 a0
70 12 a0
51 7 a1
71 11 a1
52 6 a2
72 10 a2
53 5 a3
73 9 a3
54 4 a4
74 8 a4
55 3 b0
75 7 b0
56 2 a5
76 6 a5
57 1 a6
77 5 a6
58 0 b1
78 4 b1
79 3 c0
80 2 a7x
81 1 b2x
82 0 c1
59
83
60 graph converted repo
84 graph converted repo
61
85
62 $ hg -R t-datesort glog --template '{rev} "{desc}"\n'
86 $ hg -R t-datesort glog --template '{rev} "{desc}"\n'
63 o 8 "b1"
87 o 12 "c1"
64 |
88 |\
65 | o 7 "a6"
89 | o 11 "b2x"
66 | |
90 | |
67 | o 6 "a5"
91 | | o 10 "a7x"
68 | |
92 | | |
69 o | 5 "b0"
93 o | | 9 "c0"
70 | |
94 | | |
95 | o | 8 "b1"
96 | | |
97 | | o 7 "a6"
98 | | |
99 | | o 6 "a5"
100 | | |
101 | o | 5 "b0"
102 |/ /
71 | o 4 "a4"
103 | o 4 "a4"
72 | |
104 | |
73 | o 3 "a3"
105 | o 3 "a3"
@@ -86,29 +118,41 b' convert with datesort (default mode)'
86 scanning source...
118 scanning source...
87 sorting...
119 sorting...
88 converting...
120 converting...
89 8 a0
121 12 a0
90 7 a1
122 11 a1
91 6 a2
123 10 a2
92 5 a3
124 9 a3
93 4 b0
125 8 b0
94 3 a4
126 7 a4
95 2 a5
127 6 a5
96 1 a6
128 5 a6
97 0 b1
129 4 b1
130 3 c0
131 2 a7x
132 1 b2x
133 0 c1
98
134
99 graph converted repo
135 graph converted repo
100
136
101 $ hg -R t-sourcesort glog --template '{rev} "{desc}"\n'
137 $ hg -R t-sourcesort glog --template '{rev} "{desc}"\n'
102 o 8 "b1"
138 o 12 "c1"
103 |
139 |\
104 | o 7 "a6"
140 | o 11 "b2x"
105 | |
141 | |
106 | o 6 "a5"
142 | | o 10 "a7x"
107 | |
143 | | |
108 | o 5 "a4"
144 o | | 9 "c0"
109 | |
145 | | |
110 o | 4 "b0"
146 | o | 8 "b1"
111 | |
147 | | |
148 | | o 7 "a6"
149 | | |
150 | | o 6 "a5"
151 | | |
152 | | o 5 "a4"
153 | | |
154 | o | 4 "b0"
155 |/ /
112 | o 3 "a3"
156 | o 3 "a3"
113 | |
157 | |
114 | o 2 "a2"
158 | o 2 "a2"
@@ -117,3 +161,54 b' graph converted repo'
117 |/
161 |/
118 o 0 "a0"
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 larger than the same ones generated by --branchsort.
46 larger than the same ones generated by --branchsort.
47 --sourcesort try to preserve source revisions order, only supported by
47 --sourcesort try to preserve source revisions order, only supported by
48 Mercurial sources.
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 If "REVMAP" isn't given, it will be put in a default location
52 If "REVMAP" isn't given, it will be put in a default location
51 ("<dest>/.hg/shamap" by default). The "REVMAP" is a simple text file that
53 ("<dest>/.hg/shamap" by default). The "REVMAP" is a simple text file that
@@ -268,6 +270,7 b''
268 --branchsort try to sort changesets by branches
270 --branchsort try to sort changesets by branches
269 --datesort try to sort changesets by date
271 --datesort try to sort changesets by date
270 --sourcesort preserve source changesets order
272 --sourcesort preserve source changesets order
273 --closesort try to reorder closed revisions
271
274
272 use "hg -v help convert" to show the global options
275 use "hg -v help convert" to show the global options
273 $ hg init a
276 $ hg init a
General Comments 0
You need to be logged in to leave comments. Login now