##// END OF EJS Templates
convert: fix --datesort ordering...
Patrick Mezard -
r6100:49c69e1e default
parent child Browse files
Show More
@@ -0,0 +1,40 b''
1 #!/bin/sh
2
3 cat >> $HGRCPATH <<EOF
4 [extensions]
5 convert=
6 graphlog=
7 EOF
8
9 hg init t
10 cd t
11 echo a >> a
12 hg ci -Am a0 -d '1 0'
13 hg branch brancha
14 echo a >> a
15 hg ci -m a1 -d '2 0'
16 echo a >> a
17 hg ci -m a2 -d '3 0'
18 echo a >> a
19 hg ci -m a3 -d '4 0'
20 hg up -C 0
21 hg branch branchb
22 echo b >> b
23 hg ci -Am b0 -d '5 0'
24 hg up -C brancha
25 echo a >> a
26 hg ci -m a4 -d '6 0'
27 echo a >> a
28 hg ci -m a5 -d '7 0'
29 echo a >> a
30 hg ci -m a6 -d '8 0'
31 hg up -C branchb
32 echo b >> b
33 hg ci -m b1 -d '9 0'
34 cd ..
35
36 echo % convert with datesort
37 hg convert --datesort t t2
38 echo % graph converted repo
39 hg -R t2 glog --template '#rev# "#desc#"\n'
40
@@ -0,0 +1,40 b''
1 adding a
2 marked working directory as branch brancha
3 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
4 marked working directory as branch branchb
5 adding b
6 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
7 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
8 % convert with datesort
9 initializing destination t2 repository
10 scanning source...
11 sorting...
12 converting...
13 8 a0
14 7 a1
15 6 a2
16 5 a3
17 4 b0
18 3 a4
19 2 a5
20 1 a6
21 0 b1
22 % graph converted repo
23 o 8 "b1"
24 |
25 | o 7 "a6"
26 | |
27 | o 6 "a5"
28 | |
29 | o 5 "a4"
30 | |
31 o | 4 "b0"
32 | |
33 | o 3 "a3"
34 | |
35 | o 2 "a2"
36 | |
37 | o 1 "a1"
38 |/
39 o 0 "a0"
40
@@ -110,6 +110,7 b' class converter(object):'
110 110 visit = parents.keys()
111 111 seen = {}
112 112 children = {}
113 actives = []
113 114
114 115 while visit:
115 116 n = visit.pop(0)
@@ -118,49 +119,59 b' class converter(object):'
118 119 # Ensure that nodes without parents are present in the 'children'
119 120 # mapping.
120 121 children.setdefault(n, [])
122 hasparent = False
121 123 for p in parents[n]:
122 124 if not p in self.map:
123 125 visit.append(p)
126 hasparent = True
124 127 children.setdefault(p, []).append(n)
128 if not hasparent:
129 actives.append(n)
130
131 del seen
132 del visit
133
134 if self.opts.get('datesort'):
135 dates = {}
136 def getdate(n):
137 if n not in dates:
138 dates[n] = util.parsedate(self.commitcache[n].date)
139 return dates[n]
140
141 def picknext(nodes):
142 return min([(getdate(n), n) for n in nodes])[1]
143 else:
144 prev = [None]
145 def picknext(nodes):
146 # Return the first eligible child of the previously converted
147 # revision, or any of them.
148 next = nodes[0]
149 for n in nodes:
150 if prev[0] in parents[n]:
151 next = n
152 break
153 prev[0] = next
154 return next
125 155
126 156 s = []
127 removed = {}
128 visit = children.keys()
129 while visit:
130 n = visit.pop(0)
131 if n in removed: continue
132 dep = 0
133 if n in parents:
134 for p in parents[n]:
135 if p in self.map: continue
136 if p not in removed:
137 # we're still dependent
138 visit.append(n)
139 dep = 1
140 break
157 pendings = {}
158 while actives:
159 n = picknext(actives)
160 actives.remove(n)
161 s.append(n)
141 162
142 if not dep:
143 # all n's parents are in the list
144 removed[n] = 1
145 if n not in self.map:
146 s.append(n)
147 if n in children:
148 for c in children[n]:
149 visit.insert(0, c)
163 # Update dependents list
164 for c in children.get(n, []):
165 if c not in pendings:
166 pendings[c] = [p for p in parents[c] if p not in self.map]
167 pendings[c].remove(n)
168 if not pendings[c]:
169 # Parents are converted, node is eligible
170 actives.insert(0, c)
171 pendings[c] = None
150 172
151 if self.opts.get('datesort'):
152 depth = {}
153 for n in s:
154 depth[n] = 0
155 pl = [p for p in self.commitcache[n].parents
156 if p not in self.map]
157 if pl:
158 depth[n] = max([depth[p] for p in pl]) + 1
159
160 s = [(depth[n], util.parsedate(self.commitcache[n].date), n)
161 for n in s]
162 s.sort()
163 s = [e[2] for e in s]
173 if len(s) != len(parents):
174 raise util.Abort(_("not all revisions were sorted"))
164 175
165 176 return s
166 177
@@ -16,11 +16,11 b' 1 files updated, 0 files merged, 0 files'
16 16 (branch merge, don't forget to commit)
17 17 marked working directory as branch branch3
18 18 % incremental conversion
19 2 c1
20 pulling from branch0 into branch1
19 2 c2
20 pulling from branch0 into branch2
21 21 2 changesets found
22 1 c2
23 pulling from branch0 into branch2
22 1 c1
23 pulling from branch0 into branch1
24 24 2 changesets found
25 25 0 c3
26 26 pulling from branch2 into branch3
General Comments 0
You need to be logged in to leave comments. Login now