示例#1
0
 def _q_lookup(self, request, revrange):
     current_user = request.user
     try:
         sha1, sha2 = revrange.split('...')
     except ValueError:
         raise TraversalError(
             'please provide valid start & end revisions: /compare/sha1...sha2'
         )  # noqa
     project = self.project
     commits = project.repo.get_commits(sha2, sha1)
     if commits is False:
         raise TraversalError()
     lasttime = commits and commits[0].author_time.strftime(
         "%Y-%m-%d %H:%M:%S") or 'UNKNOWN'
     grouped_commits = groupby(commits, lambda c: c.author_time.date())
     n_commits = len(commits)
     n_authors = len(set(c.author.username for c in commits))
     diff = project.repo.get_diff(sha2,
                                  from_ref=sha1,
                                  rename_detection=True)
     #diffs = project.git.get_3dot_diff(sha1, sha2)
     n_files = diff.length if diff else 0
     comments = []
     for ci in commits:
         comments.extend(Comment.gets_by_proj_and_ref(project.id, ci.sha))
     branches = project.repo.branches
     tags = project.repo.tags
     ref = project.default_branch
     n_comments = len(comments)
     ref_type = 'branch' if ref in branches else 'tag' \
                if ref in tags else 'tree'
     return st('compare.html', **locals())
示例#2
0
文件: compare.py 项目: 000fan000/code
 def _q_lookup(self, request, revrange):
     current_user = request.user
     try:
         sha1, sha2 = revrange.split('...')
     except ValueError:
         raise TraversalError(
             'please provide valid start & end revisions: /compare/sha1...sha2')  # noqa
     project = self.project
     commits = project.repo.get_commits(sha2, sha1)
     if commits is False:
         raise TraversalError()
     lasttime = commits and commits[0].author_time.strftime(
         "%Y-%m-%d %H:%M:%S") or 'UNKNOWN'
     grouped_commits = groupby(commits, lambda c: c.author_time.date())
     n_commits = len(commits)
     n_authors = len(set(c.author.username for c in commits))
     diff = project.repo.get_diff(sha2,
                                  from_ref=sha1,
                                  rename_detection=True)
     #diffs = project.git.get_3dot_diff(sha1, sha2)
     n_files = diff.length if diff else 0
     comments = []
     for ci in commits:
         comments.extend(Comment.gets_by_proj_and_ref(project.id, ci.sha))
     branches = project.repo.branches
     tags = project.repo.tags
     ref = project.default_branch
     n_comments = len(comments)
     ref_type = 'branch' if ref in branches else 'tag' \
                if ref in tags else 'tree'
     return st('compare.html', **locals())
示例#3
0
文件: commit.py 项目: 000fan000/code
    def source(self, request, sha1, path=None):
        current_user = request.user
        # guibog 20120815 some inherited templates need current user as user
        user = request.user
        project = self.project
        if sha1.count('.') == 1:
            sha, diff_type = sha1.split('.')
            resp = request.response
            resp.set_header("Content-Type", "text/plain")
            if diff_type == 'patch':
                text = project.repo.get_patch_file(sha)
                return text.encode('utf-8')
            elif diff_type == 'diff':
                text = project.repo.get_diff_file(sha)
                return text.encode('utf-8')

        ref = sha1
        if ref is None:
            ref = project.default_branch
        branches = project.repo.branches
        tags = project.repo.tags
        ref_type = ('branch' if ref in branches else 'tag'
                    if ref in tags else 'tree')

        comments = Comment.gets_by_proj_and_ref(project.id, ref)
        linecomments = CommitLineComment.gets_by_target_and_ref(project.id,
                                                                ref)

        whitespace = request.get_form_var('w', '0')
        if whitespace.isdigit() and int(whitespace) == 1:
            ignore_space = True
        else:
            ignore_space = False
        try:
            commit = project.repo.get_commit(sha1)
            # get_diff 默认与 parent diff
            diff = project.repo.get_diff(ref=sha1,
                                         ignore_space=ignore_space,
                                         rename_detection=True,
                                         linecomments=linecomments,
                                         paths=[path] if path else None)
            if not commit:
                raise TraversalError("not a valid commit ref")
        except IOError:
            raise TraversalError()

        return st('commit.html', **locals())
示例#4
0
    def source(self, request, sha1, path=None):
        current_user = request.user
        # guibog 20120815 some inherited templates need current user as user
        user = request.user
        project = self.project
        if sha1.count('.') == 1:
            sha, diff_type = sha1.split('.')
            resp = request.response
            resp.set_header("Content-Type", "text/plain")
            if diff_type == 'patch':
                text = project.repo.get_patch_file(sha)
                return text.encode('utf-8')
            elif diff_type == 'diff':
                text = project.repo.get_diff_file(sha)
                return text.encode('utf-8')

        ref = sha1
        if ref is None:
            ref = project.default_branch
        branches = project.repo.branches
        tags = project.repo.tags
        ref_type = ('branch'
                    if ref in branches else 'tag' if ref in tags else 'tree')

        comments = Comment.gets_by_proj_and_ref(project.id, ref)
        linecomments = CommitLineComment.gets_by_target_and_ref(
            project.id, ref)

        whitespace = request.get_form_var('w', '0')
        if whitespace.isdigit() and int(whitespace) == 1:
            ignore_space = True
        else:
            ignore_space = False
        try:
            commit = project.repo.get_commit(sha1)
            # get_diff 默认与 parent diff
            diff = project.repo.get_diff(ref=sha1,
                                         ignore_space=ignore_space,
                                         rename_detection=True,
                                         linecomments=linecomments,
                                         paths=[path] if path else None)
            if not commit:
                raise TraversalError("not a valid commit ref")
        except IOError:
            raise TraversalError()

        return st('commit.html', **locals())
示例#5
0
 def _pack(sha):
     return [(c.author, c.short_content)
             for c in Comment.gets_by_proj_and_ref(proj_id, sha)]
示例#6
0
文件: source.py 项目: leeccong/code
 def _pack(sha):
     return [(c.author, c.short_content) for c in Comment.gets_by_proj_and_ref(proj_id, sha)]