[PATCH 6 of 6 remotenames-ext] remotenames: do not expect repo._remotenames to be set unconditionally

Ryan McElroy rm at fb.com
Mon Feb 19 06:53:43 EST 2018


# HG changeset patch
# User Ryan McElroy <rmcelroy at fb.com>
# Date 1519041052 28800
#      Mon Feb 19 03:50:52 2018 -0800
# Node ID 97562271ac3533d9d1b323611fc9057989727b5d
# Parent  0cf83d6117fa918a8a9f6da6bd9747e09241de2a
remotenames: do not expect repo._remotenames to be set unconditionally

There are cases when a local repo communicates to another local repo
where one of the repos has remotenames enabled and the other does not that lead
to crashes. We fix these cases by checking repo objects for _remotenames before
accessing that member variables.

diff --git a/remotenames.py b/remotenames.py
--- a/remotenames.py
+++ b/remotenames.py
@@ -242,6 +242,11 @@ def exfindcommonheads(orig, ui, local, r
     return (common, True, srvheadhashes)
 
 def pullremotenames(repo, remote, bookmarks):
+    # when working between multiple local repos which do not all have
+    # remotenames enabled, do this work only for those with it enabled
+    if not util.safehasattr(repo, '_remotenames'):
+        return
+
     path = activepath(repo.ui, remote)
     if path:
         # on a push, we don't want to keep obsolete heads since
@@ -1694,6 +1699,11 @@ def precachedistance(repo):
         precachedistance = False
         precachecurrent = False
     """
+    # when working between multiple local repos which do not all have
+    # remotenames enabled, do this work only for those with it enabled
+    if not util.safehasattr(repo, '_remotenames'):
+        return
+
     # to avoid stale namespaces, let's reload
     repo._remotenames.clearnames()
 
diff --git a/tests/test-remotenames-on-and-off.t b/tests/test-remotenames-on-and-off.t
--- a/tests/test-remotenames-on-and-off.t
+++ b/tests/test-remotenames-on-and-off.t
@@ -46,19 +46,28 @@ Ensure no crashes when working from repo
 Check for crashes when working from repo with remotenames off
   $ cd off
 
-  $ hg pull ../on 2>&1 | grep Error
-  AttributeError: 'localrepository' object has no attribute '_remotenames'
+  $ hg pull ../on
+  pulling from ../on
+  searching for changes
+  no changes found
 
   $ cat >> .hg/hgrc <<EOF
   > [paths]
   > default = $TESTTMP/on
   > EOF
 
-  $ hg pull 2>&1 | grep Error
-  AttributeError: 'localrepository' object has no attribute '_remotenames'
+  $ hg pull
+  pulling from $TESTTMP/on
+  searching for changes
+  no changes found
 
-  $ hg push 2>&1 | grep Error
-  AttributeError: 'localrepository' object has no attribute '_remotenames'
+  $ hg push
+  pushing to $TESTTMP/on
+  searching for changes
+  no changes found
+  [1]
 
-  $ hg pull --rebase 2>&1 | grep Error
-  AttributeError: 'localrepository' object has no attribute '_remotenames'
+  $ hg pull --rebase
+  pulling from $TESTTMP/on
+  searching for changes
+  no changes found


More information about the Mercurial-devel mailing list