Commits

Anonymous committed 70eb022

fix comparison of repo URLs

  • Participants
  • Parent commits c92b214
  • Branches trunk

Comments (0)

Files changed (3)

 * Editable freeze URLs now always use revision hash/id rather than tip or
   branch names which could move.
 
+* Fixed comparison of repo URLs so incidental differences such as
+  presence/absence of final slashes or quoted/unquoted special
+  characters don't trigger "ignore/switch/wipe/backup" choice.
+
 0.4
 ---
 
         assert not location.rstrip('/').endswith(self.dirname), 'Bad directory: %s' % location
         return self.get_url(location), self.get_revision(location)
 
+    def normalize_url(self, url):
+        """
+        Normalize a URL for comparison by unquoting it and removing any trailing slash.
+        """
+        return urllib.unquote(url).rstrip('/')
+
+    def compare_urls(self, url1, url2):
+        """
+        Compare two repo URLs for identity, ignoring incidental differences.
+        """
+        return (self.normalize_url(url1) == self.normalize_url(url2))
+    
     def parse_vcs_bundle_file(self, content):
         """
         Takes the contents of the bundled text file that explains how to revert
         if os.path.exists(os.path.join(dest, self.dirname)):
             existing_url = self.get_info(dest)[0]
             checkout = False
-            if existing_url == url:
+            if self.compare_urls(existing_url, url):
                 logger.info('Checkout in %s exists, and has correct URL (%s)'
                             % (display_path(dest), url))
                 logger.notify('Updating checkout %s%s'
             existing_url = self.get_url(dest)
             rev_options = self.check_rev_options(rev, dest, rev_options)
             clone = False
-            if existing_url == url:
+            if self.compare_urls(existing_url, url):
                 logger.info('Clone in %s exists, and has correct URL (%s)'
                             % (display_path(dest), url))
                 logger.notify('Updating clone %s%s'
         if os.path.exists(os.path.join(dest, '.hg')):
             existing_url = self.get_url(dest)
             clone = False
-            if existing_url == url:
+            if self.compare_urls(existing_url, url):
                 logger.info('Clone in %s exists, and has correct URL (%s)'
                             % (display_path(dest), url))
                 logger.notify('Updating clone %s%s'
         if os.path.exists(os.path.join(dest, '.bzr')):
             existing_url = self.get_url(dest)
             branch = False
-            if existing_url == url:
+            if self.compare_urls(existing_url, url):
                 logger.info('Checkout in %s exists, and has correct URL (%s)'
                             % (display_path(dest), url))
                 logger.notify('Updating branch %s%s'

tests/test_basic.txt

     >>> assert 'src/django-registration' in result.files_created
     >>> assert 'src/django-registration/.hg' in result.files_created
 
+Presence or absence of final slash is also normalized::
+
+    >>> result = run_pip('install', '-e', 'hg+http://bitbucket.org/ubernostrum/django-registration#egg=django-registration', expect_error=True)
+    >>> assert 'pip-log.txt' not in result.files_created, result.files_created['pip-log.txt'].bytes
+
 Checking out from Bazaar::
 
     >>> reset_env()
-    >>> result = run_pip('install', '-e', 'bzr+http://bazaar.launchpad.net/%7Ejezdez/pip-test/test/#egg=pip-test', expect_error=True)
+    >>> result = run_pip('install', '-e', 'bzr+http://bazaar.launchpad.net/%7Ejezdez/pip-test/test/@1#egg=pip-test', expect_error=True)
     >>> egg_link = result.files_created[lib_py + 'site-packages/pip-test.egg-link']
     >>> # FIXME: I don't understand why there's a trailing . here:
     >>> egg_link.bytes
     >>> assert (lib_py + 'site-packages/easy-install.pth') in result.files_updated
     >>> assert 'src/pip-test' in result.files_created
     >>> assert 'src/pip-test/.bzr' in result.files_created
+
+Urlquoted characters are normalized for repo URL comparison::
+
+    >>> result = run_pip('install', '-e', 'bzr+http://bazaar.launchpad.net/~jezdez/pip-test/test#egg=pip-test', expect_error=True)
+    >>> assert 'pip-log.txt' not in result.files_created, result.files_created['pip-log.txt'].bytes
+