convert: refactor head calculation for hg sources
authorMads Kiilerich <madski@unity3d.com>
Thu, 03 Oct 2013 18:01:21 +0200
changeset 19890 9057855d8749
parent 19889 3828b3e09462
child 19891 e271970b9821
convert: refactor head calculation for hg sources
hgext/convert/hg.py
--- a/hgext/convert/hg.py	Fri Jul 19 14:20:11 2013 +0200
+++ b/hgext/convert/hg.py	Thu Oct 03 18:01:21 2013 +0200
@@ -260,11 +260,15 @@
                                  % startnode)
             startrev = self.repo.changelog.rev(startnode)
             children = {startnode: 1}
-            for rev in self.repo.changelog.descendants([startrev]):
-                children[self.repo.changelog.node(rev)] = 1
+            for r in self.repo.changelog.descendants([startrev]):
+                children[self.repo.changelog.node(r)] = 1
             self.keep = children.__contains__
         else:
             self.keep = util.always
+        if rev:
+            self._heads = [self.repo[rev].node()]
+        else:
+            self._heads = self.repo.heads()
 
     def changectx(self, rev):
         if self.lastrev != rev:
@@ -276,11 +280,7 @@
         return [p for p in ctx.parents() if p and self.keep(p.node())]
 
     def getheads(self):
-        if self.rev:
-            heads = [self.repo[self.rev].node()]
-        else:
-            heads = self.repo.heads()
-        return [hex(h) for h in heads if self.keep(h)]
+        return [hex(h) for h in self._heads if self.keep(h)]
 
     def getfile(self, name, rev):
         try: