diff --git a/rhodecode/controllers/changeset.py b/rhodecode/controllers/changeset.py --- a/rhodecode/controllers/changeset.py +++ b/rhodecode/controllers/changeset.py @@ -98,15 +98,13 @@ class ChangesetController(BaseRepoContro c.cut_off = False # defines if cut off limit is reached c.comments = [] - for cs in c.cs_ranges: - c.comments.extend(ChangesetComment.query()\ - .filter(ChangesetComment.repo_id == c.rhodecode_db_repo.repo_id)\ - .filter(ChangesetComment.commit_id == cs.raw_id)\ - .filter(ChangesetComment.line_no == None)\ - .filter(ChangesetComment.f_path == None).all()) # Iterate over ranges (default changeset view is always one changeset) for changeset in c.cs_ranges: + c.comments.extend(ChangesetCommentsModel()\ + .get_comments(c.rhodecode_db_repo.repo_id, + changeset.raw_id)) + c.changes[changeset.raw_id] = [] try: changeset_parent = changeset.parents[0] @@ -272,7 +270,7 @@ class ChangesetController(BaseRepoContro ccmodel.create(text=request.POST.get('text'), repo_id=c.rhodecode_db_repo.repo_id, user_id=c.rhodecode_user.user_id, - commit_id=revision, f_path=request.POST.get('f_path'), + revision=revision, f_path=request.POST.get('f_path'), line_no = request.POST.get('line')) return redirect(h.url('changeset_home', repo_name=repo_name, diff --git a/rhodecode/model/comment.py b/rhodecode/model/comment.py --- a/rhodecode/model/comment.py +++ b/rhodecode/model/comment.py @@ -29,6 +29,7 @@ import traceback from rhodecode.model import BaseModel from rhodecode.model.db import ChangesetComment +from sqlalchemy.util.compat import defaultdict log = logging.getLogger(__name__) @@ -36,7 +37,7 @@ log = logging.getLogger(__name__) class ChangesetCommentsModel(BaseModel): - def create(self, text, repo_id, user_id, commit_id, f_path=None, + def create(self, text, repo_id, user_id, revision, f_path=None, line_no=None): """ Creates new comment for changeset @@ -44,7 +45,7 @@ class ChangesetCommentsModel(BaseModel): :param text: :param repo_id: :param user_id: - :param commit_id: + :param revision: :param f_path: :param line_no: """ @@ -52,7 +53,7 @@ class ChangesetCommentsModel(BaseModel): comment = ChangesetComment() comment.repo_id = repo_id comment.user_id = user_id - comment.commit_id = commit_id + comment.revision = revision comment.text = text comment.f_path = f_path comment.line_no = line_no @@ -71,3 +72,22 @@ class ChangesetCommentsModel(BaseModel): self.sa.delete(comment) self.sa.commit() return comment + + + def get_comments(self, repo_id, revision): + return ChangesetComment.query()\ + .filter(ChangesetComment.repo_id == repo_id)\ + .filter(ChangesetComment.revision == revision)\ + .filter(ChangesetComment.line_no == None)\ + .filter(ChangesetComment.f_path == None).all() + + def get_comments_for_file(self, repo_id, f_path, raw_id): + comments = self.sa.query(ChangesetComment)\ + .filter(ChangesetComment.repo_id == repo_id)\ + .filter(ChangesetComment.commit_id == raw_id)\ + .filter(ChangesetComment.f_path == f_path).all() + + d = defaultdict(list) + for co in comments: + d[co.line_no].append(co) + return d.items() diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -1100,7 +1100,7 @@ class ChangesetComment(Base, BaseModel): __table_args__ = ({'extend_existing':True},) comment_id = Column('comment_id', Integer(), nullable=False, primary_key=True) repo_id = Column('repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False) - commit_id = Column('commit_id', String(100), nullable=False) + revision = Column('revision', String(40), nullable=False) line_no = Column('line_no', Integer(), nullable=True) f_path = Column('f_path', String(1000), nullable=True) user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), nullable=False) diff --git a/rhodecode/templates/changeset/changeset_file_comment.html b/rhodecode/templates/changeset/changeset_file_comment.html --- a/rhodecode/templates/changeset/changeset_file_comment.html +++ b/rhodecode/templates/changeset/changeset_file_comment.html @@ -10,7 +10,7 @@ ${co.author.username} ${_('commented on')} - ${h.short_id(co.commit_id)} + ${h.short_id(co.revision)} %if co.f_path: ${_(' in file ')} ${co.f_path}:L${co.line_no}