changeset 11195:46bb49134498 stable

convert/svn: close gettags() log stream (issue2196)
author Aaron Digulla <digulla@hepe.com>
date Wed, 19 May 2010 22:09:58 +0200
parents 6798536454e6
children 573bef78763f ed71cb07d7b2
files hgext/convert/subversion.py
diffstat 1 files changed, 68 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/subversion.py	Wed May 19 22:04:41 2010 +0200
+++ b/hgext/convert/subversion.py	Wed May 19 22:09:58 2010 +0200
@@ -448,76 +448,79 @@
         pendings = []
         tagspath = self.tags
         start = svn.ra.get_latest_revnum(self.ra)
-        for entry in self._getlog([self.tags], start, self.startrev):
-            origpaths, revnum, author, date, message = entry
-            copies = [(e.copyfrom_path, e.copyfrom_rev, p) for p, e
-                      in origpaths.iteritems() if e.copyfrom_path]
-            # Apply moves/copies from more specific to general
-            copies.sort(reverse=True)
+        stream = self._getlog([self.tags], start, self.startrev)
+        try:
+            for entry in stream:
+                origpaths, revnum, author, date, message = entry
+                copies = [(e.copyfrom_path, e.copyfrom_rev, p) for p, e
+                          in origpaths.iteritems() if e.copyfrom_path]
+                # Apply moves/copies from more specific to general
+                copies.sort(reverse=True)
 
-            srctagspath = tagspath
-            if copies and copies[-1][2] == tagspath:
-                # Track tags directory moves
-                srctagspath = copies.pop()[0]
+                srctagspath = tagspath
+                if copies and copies[-1][2] == tagspath:
+                    # Track tags directory moves
+                    srctagspath = copies.pop()[0]
 
-            for source, sourcerev, dest in copies:
-                if not dest.startswith(tagspath + '/'):
-                    continue
-                for tag in pendings:
-                    if tag[0].startswith(dest):
-                        tagpath = source + tag[0][len(dest):]
-                        tag[:2] = [tagpath, sourcerev]
-                        break
-                else:
-                    pendings.append([source, sourcerev, dest])
+                for source, sourcerev, dest in copies:
+                    if not dest.startswith(tagspath + '/'):
+                        continue
+                    for tag in pendings:
+                        if tag[0].startswith(dest):
+                            tagpath = source + tag[0][len(dest):]
+                            tag[:2] = [tagpath, sourcerev]
+                            break
+                    else:
+                        pendings.append([source, sourcerev, dest])
 
-            # Filter out tags with children coming from different
-            # parts of the repository like:
-            # /tags/tag.1 (from /trunk:10)
-            # /tags/tag.1/foo (from /branches/foo:12)
-            # Here/tags/tag.1 discarded as well as its children.
-            # It happens with tools like cvs2svn. Such tags cannot
-            # be represented in mercurial.
-            addeds = dict((p, e.copyfrom_path) for p, e
-                          in origpaths.iteritems()
-                          if e.action == 'A' and e.copyfrom_path)
-            badroots = set()
-            for destroot in addeds:
-                for source, sourcerev, dest in pendings:
-                    if (not dest.startswith(destroot + '/')
-                        or source.startswith(addeds[destroot] + '/')):
-                        continue
-                    badroots.add(destroot)
-                    break
+                # Filter out tags with children coming from different
+                # parts of the repository like:
+                # /tags/tag.1 (from /trunk:10)
+                # /tags/tag.1/foo (from /branches/foo:12)
+                # Here/tags/tag.1 discarded as well as its children.
+                # It happens with tools like cvs2svn. Such tags cannot
+                # be represented in mercurial.
+                addeds = dict((p, e.copyfrom_path) for p, e
+                              in origpaths.iteritems()
+                              if e.action == 'A' and e.copyfrom_path)
+                badroots = set()
+                for destroot in addeds:
+                    for source, sourcerev, dest in pendings:
+                        if (not dest.startswith(destroot + '/')
+                            or source.startswith(addeds[destroot] + '/')):
+                            continue
+                        badroots.add(destroot)
+                        break
 
-            for badroot in badroots:
-                pendings = [p for p in pendings if p[2] != badroot
-                            and not p[2].startswith(badroot + '/')]
+                for badroot in badroots:
+                    pendings = [p for p in pendings if p[2] != badroot
+                                and not p[2].startswith(badroot + '/')]
 
-            # Tell tag renamings from tag creations
-            remainings = []
-            for source, sourcerev, dest in pendings:
-                tagname = dest.split('/')[-1]
-                if source.startswith(srctagspath):
-                    remainings.append([source, sourcerev, tagname])
-                    continue
-                if tagname in tags:
-                    # Keep the latest tag value
-                    continue
-                # From revision may be fake, get one with changes
-                try:
-                    tagid = self.latest(source, sourcerev)
-                    if tagid and tagname not in tags:
-                        tags[tagname] = tagid
-                except SvnPathNotFound:
-                    # It happens when we are following directories
-                    # we assumed were copied with their parents
-                    # but were really created in the tag
-                    # directory.
-                    pass
-            pendings = remainings
-            tagspath = srctagspath
-
+                # Tell tag renamings from tag creations
+                remainings = []
+                for source, sourcerev, dest in pendings:
+                    tagname = dest.split('/')[-1]
+                    if source.startswith(srctagspath):
+                        remainings.append([source, sourcerev, tagname])
+                        continue
+                    if tagname in tags:
+                        # Keep the latest tag value
+                        continue
+                    # From revision may be fake, get one with changes
+                    try:
+                        tagid = self.latest(source, sourcerev)
+                        if tagid and tagname not in tags:
+                            tags[tagname] = tagid
+                    except SvnPathNotFound:
+                        # It happens when we are following directories
+                        # we assumed were copied with their parents
+                        # but were really created in the tag
+                        # directory.
+                        pass
+                pendings = remainings
+                tagspath = srctagspath
+        finally:
+            stream.close()
         return tags
 
     def converted(self, rev, destrev):