pull: close peer repo on completion (issue2491) (issue2797) stable
authorPiotr Klecha <pklecha@forcom.com.pl>
Tue, 25 Feb 2014 21:26:25 +0100
branchstable
changeset 20576 7f865a94691e
parent 20575 3d77e567de56
child 20577 de48422df393
pull: close peer repo on completion (issue2491) (issue2797) When pulling changes from a compressed bundle Mercurial first uncompresses it to a temporary file in .hg directory. This file will not be deleted unless the bundlerepo (other) is explicitly closed. This is similar to cleanup that occurs after incoming.
mercurial/commands.py
tests/test-bundle.t
--- a/mercurial/commands.py	Thu Feb 27 00:24:06 2014 +0100
+++ b/mercurial/commands.py	Tue Feb 25 21:26:25 2014 +0100
@@ -4605,47 +4605,50 @@
     """
     source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch'))
     other = hg.peer(repo, opts, source)
-    ui.status(_('pulling from %s\n') % util.hidepassword(source))
-    revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get('rev'))
-
-    remotebookmarks = other.listkeys('bookmarks')
-
-    if opts.get('bookmark'):
-        if not revs:
-            revs = []
-        for b in opts['bookmark']:
-            if b not in remotebookmarks:
-                raise util.Abort(_('remote bookmark %s not found!') % b)
-            revs.append(remotebookmarks[b])
-
-    if revs:
+    try:
+        ui.status(_('pulling from %s\n') % util.hidepassword(source))
+        revs, checkout = hg.addbranchrevs(repo, other, branches,
+                                          opts.get('rev'))
+
+        remotebookmarks = other.listkeys('bookmarks')
+
+        if opts.get('bookmark'):
+            if not revs:
+                revs = []
+            for b in opts['bookmark']:
+                if b not in remotebookmarks:
+                    raise util.Abort(_('remote bookmark %s not found!') % b)
+                revs.append(remotebookmarks[b])
+
+        if revs:
+            try:
+                revs = [other.lookup(rev) for rev in revs]
+            except error.CapabilityError:
+                err = _("other repository doesn't support revision lookup, "
+                        "so a rev cannot be specified.")
+                raise util.Abort(err)
+
+        modheads = repo.pull(other, heads=revs, force=opts.get('force'))
+        bookmarks.updatefromremote(ui, repo, remotebookmarks, source)
+        if checkout:
+            checkout = str(repo.changelog.rev(other.lookup(checkout)))
+        repo._subtoppath = source
         try:
-            revs = [other.lookup(rev) for rev in revs]
-        except error.CapabilityError:
-            err = _("other repository doesn't support revision lookup, "
-                    "so a rev cannot be specified.")
-            raise util.Abort(err)
-
-    modheads = repo.pull(other, heads=revs, force=opts.get('force'))
-    bookmarks.updatefromremote(ui, repo, remotebookmarks, source)
-    if checkout:
-        checkout = str(repo.changelog.rev(other.lookup(checkout)))
-    repo._subtoppath = source
-    try:
-        ret = postincoming(ui, repo, modheads, opts.get('update'), checkout)
-
+            ret = postincoming(ui, repo, modheads, opts.get('update'), checkout)
+
+        finally:
+            del repo._subtoppath
+
+        # update specified bookmarks
+        if opts.get('bookmark'):
+            marks = repo._bookmarks
+            for b in opts['bookmark']:
+                # explicit pull overrides local bookmark if any
+                ui.status(_("importing bookmark %s\n") % b)
+                marks[b] = repo[remotebookmarks[b]].node()
+            marks.write()
     finally:
-        del repo._subtoppath
-
-    # update specified bookmarks
-    if opts.get('bookmark'):
-        marks = repo._bookmarks
-        for b in opts['bookmark']:
-            # explicit pull overrides local bookmark if any
-            ui.status(_("importing bookmark %s\n") % b)
-            marks[b] = repo[remotebookmarks[b]].node()
-        marks.write()
-
+        other.close()
     return ret
 
 @command('^push',
--- a/tests/test-bundle.t	Thu Feb 27 00:24:06 2014 +0100
+++ b/tests/test-bundle.t	Tue Feb 25 21:26:25 2014 +0100
@@ -84,6 +84,11 @@
   searching for changes
   no changes found
 
+Verify that there are no leaked temporary files after pull (issue2797)
+
+  $ ls test/.hg | grep .hg10un
+  [1]
+
 Pull full.hg into empty (using --cwd)
 
   $ hg --cwd empty pull ../full.hg