Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple repository support #70

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions code_comments/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ def validate(self):

def href(self):
if self.is_comment_to_file:
href = self.req.href.browser(self.path, rev=self.revision, codecomment=self.id)
href = self.req.href.browser(self.reponame + '/' + self.path, rev=self.revision, codecomment=self.id)
elif self.is_comment_to_changeset:
href = self.req.href.changeset(self.revision, codecomment=self.id)
href = self.req.href.changeset(self.revision + '/' + self.reponame, codecomment=self.id)
elif self.is_comment_to_attachment:
href = self.req.href('/attachment/ticket/%d/%s' % (self.attachment_ticket, self.attachment_filename), codecomment=self.id)
if self.line and not self.is_comment_to_changeset:
Expand Down
15 changes: 14 additions & 1 deletion code_comments/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from trac.db.schema import Table, Column, Index
from trac.env import IEnvironmentSetupParticipant
from trac.db.api import DatabaseManager
from trac.versioncontrol.api import RepositoryManager

# Database version identifier for upgrades.
db_version = 3
db_version = 4

# Database schema
schema = {
Expand All @@ -18,6 +19,7 @@
Column('author'),
Column('time', type='int'),
Column('type'),
Column('reponame'),
Index(['path']),
Index(['author']),
],
Expand Down Expand Up @@ -101,9 +103,20 @@ def add_subscriptions_table(db):
cursor.execute(stmt)


def upgrade_from_3_to_4(env, db):
# Add the new column "reponame" and populate it with the name of the default repository.
@env.with_transaction()
def add_reponame_column(db):
cursor = db.cursor()
cursor.execute('ALTER TABLE code_comments ADD COLUMN reponame TEXT')
reponame = RepositoryManager(env).get_repository(None).reponame
cursor.execute('UPDATE code_comments SET reponame = %s', [reponame])


upgrade_map = {
2: upgrade_from_1_to_2,
3: upgrade_from_2_to_3,
4: upgrade_from_3_to_4,
}


Expand Down
3 changes: 2 additions & 1 deletion code_comments/htdocs/code-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ var underscore = _.noConflict();
title += ( displayLine ? 'line ' + displayLine + ' of ' : '' )
+ this.path + '@' + CodeComments.revision;
}
title += ' in ' + CodeComments.reponame;
return title;
},
close: function() {
Expand All @@ -213,7 +214,7 @@ var underscore = _.noConflict();
},
wait: true
};
this.collection.create({text: text, author: CodeComments.username, path: this.path, revision: CodeComments.revision, line: line, type: CodeComments.page}, options);
this.collection.create({text: text, author: CodeComments.username, path: this.path, reponame: CodeComments.reponame, revision: CodeComments.revision, line: line, type: CodeComments.page}, options);
},
previewThrottled: $.throttle(1500, function(e) { return this.preview(e); }),
preview: function(e) {
Expand Down
34 changes: 11 additions & 23 deletions code_comments/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def from_comment(cls, env, comment, user=None, notify=True):
sub['path'] = comment.path
else:
sub['path'] = ''
repo = RepositoryManager(env).get_repository(None)
repo = RepositoryManager(env).get_repository(comment.reponame)
try:
sub['repos'] = repo.reponame
try:
Expand Down Expand Up @@ -313,13 +313,6 @@ def for_request(cls, env, req, create=False):
"""
Return a **single** subscription for a HTTP request.
"""
reponame = req.args.get('reponame')
rm = RepositoryManager(env)
repos = rm.get_repository(reponame)

path = req.args.get('path') or ''
rev = req.args.get('rev') or repos.youngest_rev

dict_ = {
'user': req.authname,
'type': req.args.get('realm'),
Expand All @@ -329,19 +322,15 @@ def for_request(cls, env, req, create=False):
}

if dict_['type'] == 'attachment':
dict_['path'] = path
dict_['path'] = "/" + req.args.get('arg1') + "/" + req.args.get('arg2')

if dict_['type'] == 'changeset':
dict_['rev'] = path[1:]
dict_['repos'] = repos.reponame
dict_['rev'] = req.args.get('arg1')
dict_['repos'] = req.args.get('arg2')

if dict_['type'] == 'browser':
if len(path) == 0:
dict_['path'] = '/'
else:
dict_['path'] = path[1:]
dict_['rev'] = rev
dict_['repos'] = repos.reponame
dict_['path'] = '/' + req.args.get('arg2')
dict_['repos'] = req.args.get('arg1')

return cls._from_dict(env, dict_, create=create)

Expand Down Expand Up @@ -453,12 +442,11 @@ class SubscriptionModule(Component):
# IRequestHandler methods

def match_request(self, req):
match = re.match(r'\/subscription\/(\w+)(\/?.*)$', req.path_info)
match = re.match(r'\/subscription\/(\w+)\/(\w+)\/?(.*)$', req.path_info)
if match:
if match.group(1):
req.args['realm'] = match.group(1)
if match.group(2):
req.args['path'] = match.group(2)
req.args['realm'] = match.group(1)
req.args['arg1'] = match.group(2)
req.args['arg2'] = match.group(3)
return True

def process_request(self, req):
Expand All @@ -471,7 +459,7 @@ def process_request(self, req):
# ITemplateStreamFilter methods

def filter_stream(self, req, method, filename, stream, data):
if re.match(r'^/(changeset|browser|attachment).*', req.path_info):
if re.match(r'^\/(changeset|browser|attachment)\/\w+', req.path_info):
filter = Transformer('//h1')
stream |= filter.before(self._subscription_button(req.path_info))
return stream
Expand Down
6 changes: 3 additions & 3 deletions code_comments/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ def templates_js_data(self):
return data

def changeset_js_data(self, req, data):
return {'page': 'changeset', 'revision': data['new_rev'], 'path': '', 'selectorToInsertAfter': 'div.diff div.diff:last'}
return {'page': 'changeset', 'reponame': data['reponame'], 'revision': data['new_rev'], 'path': '', 'selectorToInsertAfter': 'div.diff div.diff:last'}

def browser_js_data(self, req, data):
return {'page': 'browser', 'revision': data['rev'], 'path': data['path'], 'selectorToInsertAfter': 'table.code'}
return {'page': 'browser', 'reponame': data['reponame'], 'revision': data['rev'], 'path': data['path'], 'selectorToInsertAfter': 'table.code'}

def attachment_js_data(self, req, data):
path = req.path_info.replace('/attachment/', 'attachment:/')
return {'page': 'attachment', 'revision': 0, 'path': path, 'selectorToInsertAfter': 'div#preview'}
return {'page': 'attachment', 'reponame': '', 'revision': 0, 'path': path, 'selectorToInsertAfter': 'div#preview'}

def template_js_data(self, name):
file_name = name + '.html'
Expand Down