comparison hgext/convert/convcmd.py @ 6130:516d8ffede7c

Merge with crew-stable
author Patrick Mezard <pmezard@gmail.com>
date Sat, 16 Feb 2008 12:46:28 +0100
parents e2cbdd931341 49c69e1e4aa2
children fddeeb00f8d1
comparison
equal deleted inserted replaced
6129:3d666e8e6398 6130:516d8ffede7c
100 '''Return an ordering such that every uncommitted changeset is 100 '''Return an ordering such that every uncommitted changeset is
101 preceeded by all its uncommitted ancestors.''' 101 preceeded by all its uncommitted ancestors.'''
102 visit = parents.keys() 102 visit = parents.keys()
103 seen = {} 103 seen = {}
104 children = {} 104 children = {}
105 actives = []
105 106
106 while visit: 107 while visit:
107 n = visit.pop(0) 108 n = visit.pop(0)
108 if n in seen: continue 109 if n in seen: continue
109 seen[n] = 1 110 seen[n] = 1
110 # Ensure that nodes without parents are present in the 'children' 111 # Ensure that nodes without parents are present in the 'children'
111 # mapping. 112 # mapping.
112 children.setdefault(n, []) 113 children.setdefault(n, [])
114 hasparent = False
113 for p in parents[n]: 115 for p in parents[n]:
114 if not p in self.map: 116 if not p in self.map:
115 visit.append(p) 117 visit.append(p)
118 hasparent = True
116 children.setdefault(p, []).append(n) 119 children.setdefault(p, []).append(n)
120 if not hasparent:
121 actives.append(n)
122
123 del seen
124 del visit
125
126 if self.opts.get('datesort'):
127 dates = {}
128 def getdate(n):
129 if n not in dates:
130 dates[n] = util.parsedate(self.commitcache[n].date)
131 return dates[n]
132
133 def picknext(nodes):
134 return min([(getdate(n), n) for n in nodes])[1]
135 else:
136 prev = [None]
137 def picknext(nodes):
138 # Return the first eligible child of the previously converted
139 # revision, or any of them.
140 next = nodes[0]
141 for n in nodes:
142 if prev[0] in parents[n]:
143 next = n
144 break
145 prev[0] = next
146 return next
117 147
118 s = [] 148 s = []
119 removed = {} 149 pendings = {}
120 visit = children.keys() 150 while actives:
121 while visit: 151 n = picknext(actives)
122 n = visit.pop(0) 152 actives.remove(n)
123 if n in removed: continue 153 s.append(n)
124 dep = 0 154
125 if n in parents: 155 # Update dependents list
126 for p in parents[n]: 156 for c in children.get(n, []):
127 if p in self.map: continue 157 if c not in pendings:
128 if p not in removed: 158 pendings[c] = [p for p in parents[c] if p not in self.map]
129 # we're still dependent 159 pendings[c].remove(n)
130 visit.append(n) 160 if not pendings[c]:
131 dep = 1 161 # Parents are converted, node is eligible
132 break 162 actives.insert(0, c)
133 163 pendings[c] = None
134 if not dep: 164
135 # all n's parents are in the list 165 if len(s) != len(parents):
136 removed[n] = 1 166 raise util.Abort(_("not all revisions were sorted"))
137 if n not in self.map:
138 s.append(n)
139 if n in children:
140 for c in children[n]:
141 visit.insert(0, c)
142
143 if self.opts.get('datesort'):
144 depth = {}
145 for n in s:
146 depth[n] = 0
147 pl = [p for p in self.commitcache[n].parents
148 if p not in self.map]
149 if pl:
150 depth[n] = max([depth[p] for p in pl]) + 1
151
152 s = [(depth[n], util.parsedate(self.commitcache[n].date), n)
153 for n in s]
154 s.sort()
155 s = [e[2] for e in s]
156 167
157 return s 168 return s
158 169
159 def writeauthormap(self): 170 def writeauthormap(self):
160 authorfile = self.authorfile 171 authorfile = self.authorfile