Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Bug fix: Resolves part of issue #5

Default repository under Trac is not always id 1, so it needs
to be handled carefully as the directory can be defined in
trac.ini or in repository table.

Also some improvements to error handling have been done.
  • Loading branch information...
commit 277186816e619511f60f72da65e2fe4202985cef 1 parent be644c7
Miguel Araujo authored October 22, 2010

Showing 1 changed file with 22 additions and 5 deletions. Show diff stats Hide diff stats

  1. 27  mercurialchangeset/admin.py
27  mercurialchangeset/admin.py
@@ -34,6 +34,7 @@ def __init__ (self):
34 34
         self.db = self.env.get_db_cnx()
35 35
         self.cursor = self.db.cursor()
36 36
         self.hg_encoding = locale.getpreferredencoding() or 'UTF-8' 
  37
+        self.default = False
37 38
 
38 39
     # IAdminCommandProvider methods
39 40
     # ---------------------------------------
@@ -85,8 +86,19 @@ def get_repository_id(self, repository):
85 86
         multi-repository since v0.12. However, in lower versions of Trac, by simply
86 87
         using 'default' as repository name, it should work just fine :)
87 88
         """
  89
+        # The default repository is the one that has no "name" value in repository table
88 90
         if (repository == "default"):
89  
-            return 1
  91
+            sql_string = """
  92
+                SELECT id
  93
+                 FROM repository 
  94
+                 WHERE name = 'name' AND value = '';
  95
+            """
  96
+            self.cursor.execute(sql_string)
  97
+            row = self.cursor.fetchone()
  98
+            # Default is an special situation, we need to handle different
  99
+            # Default dir could be specified in repository table or in trac.ini
  100
+            self.default = True
  101
+            return row[0]
90 102
 
91 103
         # The repository can be a path to the root of the repository
92 104
         if os.path.isdir(repository):
@@ -134,9 +146,13 @@ def get_mercurial_repository(self, repository_id):
134 146
         given by the trac-admin parameter. 
135 147
         """
136 148
         try:
137  
-            if (repository_id == 1):
  149
+            repository_dir = None
  150
+            if (self.default):
138 151
                 repository_dir = self.config.get("trac", "repository_dir", False)
139  
-            else:
  152
+
  153
+            # If repository is "default" but the dir is not in config then
  154
+            # repository_dir will be False, so we look in repository table
  155
+            if not self.default or repository_dir is False:
140 156
                 sql_string = """
141 157
                     SELECT value
142 158
                      FROM repository
@@ -152,8 +168,9 @@ def get_mercurial_repository(self, repository_id):
152 168
 
153 169
             return hg.repository(ui.ui(), repository_dir)
154 170
 
155  
-        except repo.RepoError:
156  
-            printout("[E] Impossible to connect to Mercurial repository at", repository_dir)
  171
+        except Exception, error:
  172
+            printout("Error:", error)
  173
+            printout("Error: Impossible to connect to Mercurial repository at", repository_dir)
157 174
             sys.exit(1)
158 175
 
159 176
     def initialize_repository(self, repository):

0 notes on commit 2771868

Please sign in to comment.
Something went wrong with that request. Please try again.