diff hgsubversion/svnmeta.py @ 746:174f03c288d4

svnmeta: abort when no UUID given and none is stored on disk. Previously, not passing a UUID when instantiating an SVNMeta instance would cause it to succeed even if no UUID was previously known. First when the UUID was actually read would an exception be raised. This slight refactoring of _set_uuid() makes it so an exception is raised immediately. While at it, the exception message is changed to be slightly more accurate and helpful.
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Thu, 11 Nov 2010 21:32:22 +0100
parents 6252f0cc7b7a
children 34b25f6bc4ef
line wrap: on
line diff
--- a/hgsubversion/svnmeta.py
+++ b/hgsubversion/svnmeta.py
@@ -134,22 +134,19 @@ class SVNMeta(object):
             return self.__uuid
 
     def _set_uuid(self, uuid):
-        if not uuid:
-            return
-        elif os.path.isfile(os.path.join(self.meta_data_dir, 'uuid')):
+        if os.path.isfile(os.path.join(self.meta_data_dir, 'uuid')):
             stored_uuid = self._get_uuid()
             assert stored_uuid
-            if uuid != stored_uuid:
+            if uuid and uuid != stored_uuid:
                 raise hgutil.Abort('unable to operate on unrelated repository')
+        elif uuid:
+            f = open(os.path.join(self.meta_data_dir, 'uuid'), 'w')
+            f.write(uuid)
+            f.close()
+            self.__uuid = uuid
         else:
-            if uuid:
-                f = open(os.path.join(self.meta_data_dir, 'uuid'), 'w')
-                f.write(uuid)
-                f.close()
-            else:
-                raise hgutil.Abort('unable to operate on unrelated repository')
-
-        self.__uuid = uuid
+            raise hgutil.Abort("hgsubversion metadata unavailable; "
+                               "please run 'hg svn rebuildmeta'")
 
     uuid = property(_get_uuid, _set_uuid, None,
                     'Error-checked UUID of source Subversion repository.')