Beispiel #1
0
    def fromId(db, branch_id, load_review=False, load_commits=True, repository=None, for_update=False, profiler=None):
        import gitutils

        cursor = db.cursor()
        cursor.execute("""SELECT name, repository, head, base, tail, branches.type, archived, review
                            FROM branches
                           WHERE branches.id=%s""",
                       (branch_id,),
                       for_update=for_update)
        row = cursor.fetchone()

        if not row: return None
        else:
            branch_name, repository_id, head_commit_id, base_branch_id, tail_commit_id, type, archived, review_id = row

            if profiler: profiler.check("Branch.fromId: basic")

            if repository is None:
                repository = gitutils.Repository.fromId(db, repository_id)

            assert repository.id == repository_id

            if profiler: profiler.check("Branch.fromId: repository")

            if load_commits:
                try: head_commit = gitutils.Commit.fromId(db, repository, head_commit_id)
                except: head_commit = None

                if profiler: profiler.check("Branch.fromId: head")
            else:
                head_commit = None

            if load_commits:
                base_branch = Branch.fromId(db, base_branch_id) if base_branch_id is not None else None

                if profiler: profiler.check("Branch.fromId: base")

                tail_commit = gitutils.Commit.fromId(db, repository, tail_commit_id) if tail_commit_id is not None else None

                if profiler: profiler.check("Branch.fromId: tail")
            else:
                base_branch = None
                tail_commit = None

            branch = Branch(branch_id, repository, branch_name, head_commit, base_branch, tail_commit, type, archived, review_id)

            if load_review:
                from dbutils import Review

                branch.review = Review.fromBranch(db, branch)

                if profiler: profiler.check("Branch.fromId: review")

            return branch
Beispiel #2
0
    def fromId(db, branch_id, load_review=False, repository=None, for_update=False, profiler=None):
        import gitutils

        cursor = db.cursor()
        cursor.execute("""SELECT name, repository, head, base, tail, branches.type, archived
                            FROM branches
                           WHERE branches.id=%s""",
                       (branch_id,),
                       for_update=for_update)
        row = cursor.fetchone()

        if not row: return None
        else:
            branch_name, repository_id, head_commit_id, base_branch_id, tail_commit_id, type, archived = row

            def commit_sha1(commit_id):
                cursor.execute("SELECT sha1 FROM commits WHERE id=%s", (commit_id,))
                return cursor.fetchone()[0]

            head_commit_sha1 = commit_sha1(head_commit_id)
            tail_commit_sha1 = (commit_sha1(tail_commit_id)
                                if tail_commit_id is not None else None)

            if profiler: profiler.check("Branch.fromId: basic")

            if repository is None:
                repository = gitutils.Repository.fromId(db, repository_id)

            assert repository.id == repository_id

            if profiler: profiler.check("Branch.fromId: repository")

            base_branch = (Branch.fromId(db, base_branch_id, repository=repository)
                           if base_branch_id is not None else None)

            if profiler: profiler.check("Branch.fromId: base")

            branch = Branch(branch_id, repository, branch_name, head_commit_sha1, base_branch, tail_commit_sha1, type, archived)

            if load_review:
                from dbutils import Review

                branch.review = Review.fromBranch(db, branch)

                if profiler: profiler.check("Branch.fromId: review")

            return branch
Beispiel #3
0
    def fromId(db, branch_id, load_review=False, load_commits=True, profiler=None):
        import gitutils

        cursor = db.cursor()
        cursor.execute("SELECT name, repository, head, base, tail, branches.type, review, reviews.id IS NOT NULL FROM branches LEFT OUTER JOIN reviews ON (branches.id=reviews.branch) WHERE branches.id=%s", [branch_id])
        row = cursor.fetchone()

        if not row: return None
        else:
            branch_name, repository_id, head_commit_id, base_branch_id, tail_commit_id, type, review_id, has_review = row

            if profiler: profiler.check("Branch.fromId: basic")

            repository = gitutils.Repository.fromId(db, repository_id)

            if profiler: profiler.check("Branch.fromId: repository")

            if load_commits:
                try: head_commit = gitutils.Commit.fromId(db, repository, head_commit_id)
                except: head_commit = None

                if profiler: profiler.check("Branch.fromId: head")
            else:
                head_commit = None

            if load_commits:
                base_branch = Branch.fromId(db, base_branch_id) if base_branch_id is not None else None

                if profiler: profiler.check("Branch.fromId: base")

                tail_commit = gitutils.Commit.fromId(db, repository, tail_commit_id) if tail_commit_id is not None else None

                if profiler: profiler.check("Branch.fromId: tail")
            else:
                base_branch = None
                tail_commit = None

            branch = Branch(branch_id, repository, branch_name, head_commit, base_branch, tail_commit, type, review_id)

            if has_review and load_review:
                from dbutils import Review

                branch.review = Review.fromBranch(db, branch)

                if profiler: profiler.check("Branch.fromId: review")

            return branch