D3860: httppeer: fix use of uninitialized variable with devel logging

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Fri Jun 29 21:31:28 UTC 2018


martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  If the request fails, "res" was uninitialized.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3860

AFFECTED FILES
  mercurial/httppeer.py

CHANGE DETAILS

diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py
--- a/mercurial/httppeer.py
+++ b/mercurial/httppeer.py
@@ -306,6 +306,7 @@
 
         start = util.timer()
 
+    res = None
     try:
         res = opener.open(req)
     except urlerr.httperror as inst:
@@ -319,8 +320,9 @@
         raise IOError(None, inst)
     finally:
         if ui.debugflag and ui.configbool('devel', 'debug.peer-request'):
+            code = res.code if res else -1
             dbg(line % '  finished in %.4f seconds (%d)'
-                % (util.timer() - start, res.code))
+                % (util.timer() - start, code))
 
     # Insert error handlers for common I/O failures.
     _wraphttpresponse(res)



To: martinvonz, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list