Permalink
Browse files

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...
1 parent be644c7 commit 277186816e619511f60f72da65e2fe4202985cef @maraujop committed Oct 22, 2010
Showing with 22 additions and 5 deletions.
  1. +22 −5 mercurialchangeset/admin.py
View
27 mercurialchangeset/admin.py
@@ -34,6 +34,7 @@ def __init__ (self):
self.db = self.env.get_db_cnx()
self.cursor = self.db.cursor()
self.hg_encoding = locale.getpreferredencoding() or 'UTF-8'
+ self.default = False
# IAdminCommandProvider methods
# ---------------------------------------
@@ -85,8 +86,19 @@ def get_repository_id(self, repository):
multi-repository since v0.12. However, in lower versions of Trac, by simply
using 'default' as repository name, it should work just fine :)
"""
+ # The default repository is the one that has no "name" value in repository table
if (repository == "default"):
- return 1
+ sql_string = """
+ SELECT id
+ FROM repository
+ WHERE name = 'name' AND value = '';
+ """
+ self.cursor.execute(sql_string)
+ row = self.cursor.fetchone()
+ # Default is an special situation, we need to handle different
+ # Default dir could be specified in repository table or in trac.ini
+ self.default = True
+ return row[0]
# The repository can be a path to the root of the repository
if os.path.isdir(repository):
@@ -134,9 +146,13 @@ def get_mercurial_repository(self, repository_id):
given by the trac-admin parameter.
"""
try:
- if (repository_id == 1):
+ repository_dir = None
+ if (self.default):
repository_dir = self.config.get("trac", "repository_dir", False)
- else:
+
+ # If repository is "default" but the dir is not in config then
+ # repository_dir will be False, so we look in repository table
+ if not self.default or repository_dir is False:
sql_string = """
SELECT value
FROM repository
@@ -152,8 +168,9 @@ def get_mercurial_repository(self, repository_id):
return hg.repository(ui.ui(), repository_dir)
- except repo.RepoError:
- printout("[E] Impossible to connect to Mercurial repository at", repository_dir)
+ except Exception, error:
+ printout("Error:", error)
+ printout("Error: Impossible to connect to Mercurial repository at", repository_dir)
sys.exit(1)
def initialize_repository(self, repository):

0 comments on commit 2771868

Please sign in to comment.