Пример #1
0
def createTag(db, user, repository, name, sha1):
    sha1 = gitutils.getTaggedCommit(repository, sha1)

    if sha1:
        cursor = db.cursor()
        cursor.execute("INSERT INTO tags (name, repository, sha1) VALUES (%s, %s, %s)",
                       (name, repository.id, sha1))
Пример #2
0
def updateTag(repository_name, name, old_sha1, new_sha1):
    repository = gitutils.Repository.fromName(db, repository_name)

    sha1 = gitutils.getTaggedCommit(repository, new_sha1)

    cursor = db.cursor()
    cursor.execute("UPDATE tags SET sha1=%s WHERE name=%s AND repository=%s",
                   (sha1, name, repository.id))
Пример #3
0
def createTag(repository_name, name, sha1):
    repository = gitutils.Repository.fromName(db, repository_name)

    sha1 = gitutils.getTaggedCommit(repository, sha1)

    cursor = db.cursor()
    cursor.execute("INSERT INTO tags (name, repository, sha1) VALUES (%s, %s, %s)",
                   (name, repository.id, sha1))
Пример #4
0
def updateTag(db, user, repository, name, old_sha1, new_sha1):
    sha1 = gitutils.getTaggedCommit(repository, new_sha1)
    cursor = db.cursor()

    if sha1:
        cursor.execute("UPDATE tags SET sha1=%s WHERE name=%s AND repository=%s",
                       (sha1, name, repository.id))
    else:
        cursor.execute("DELETE FROM tags WHERE name=%s AND repository=%s",
                       (name, repository.id))
Пример #5
0
def createTag(repository_name, name, sha1):
    repository = gitutils.Repository.fromName(db, repository_name)

    sha1 = gitutils.getTaggedCommit(repository, sha1)

    if sha1:
        cursor = db.cursor()
        cursor.execute(
            "INSERT INTO tags (name, repository, sha1) VALUES (%s, %s, %s)",
            (name, repository.id, sha1))
Пример #6
0
 def revparse(item):
     if re.match("^[0-9a-f]+$", item):
         cursor.execute(
             "SELECT sha1 FROM commits JOIN changesets ON (changesets.child=commits.id) JOIN reviewchangesets ON (reviewchangesets.changeset=changesets.id) WHERE reviewchangesets.review=%s AND commits.sha1 LIKE %s",
             (review_id, item + "%"))
         try:
             return cursor.fetchone()[0]
         except:
             return gitutils.getTaggedCommit(
                 repository,
                 repository.revparse(item))
Пример #7
0
def updateTag(repository_name, name, old_sha1, new_sha1):
    repository = gitutils.Repository.fromName(db, repository_name)

    sha1 = gitutils.getTaggedCommit(repository, new_sha1)
    cursor = db.cursor()

    if sha1:
        processCommits(repository.name, sha1)

        cursor.execute("UPDATE tags SET sha1=%s WHERE name=%s AND repository=%s",
                       (sha1, name, repository.id))
    else:
        cursor.execute("DELETE FROM tags WHERE name=%s AND repository=%s",
                       (name, repository.id))
Пример #8
0
 def revparsePlain(item):
     try: return gitutils.getTaggedCommit(repository, repository.revparse(item))
     except: raise
Пример #9
0
    def process(self, db, user, repository_name, remote, branch, upstream="refs/heads/master"):
        repository = gitutils.Repository.fromName(db, repository_name)

        cursor = db.cursor()

        # Check if any other repository is currently tracking branches from this
        # remote.  If that's the case, then the user most likely either selected
        # the wrong repository or entered the wrong remote.
        cursor.execute("""SELECT repositories.name
                            FROM repositories
                            JOIN trackedbranches ON (trackedbranches.repository=repositories.id)
                           WHERE repositories.id!=%s
                             AND trackedbranches.remote=%s""",
                       (repository.id, remote))
        for (other_name,) in cursor:
            raise OperationFailure(
                code="badremote",
                title="Bad remote!",
                message=("The remote <code>%s</code> appears to be related to "
                         "another repository on this server (<code>%s</code>).  "
                         "You most likely shouldn't be importing branches from "
                         "it into the selected repository (<code>%s</code>)."
                         % (htmlutils.htmlify(remote), htmlutils.htmlify(other_name),
                            htmlutils.htmlify(repository_name))),
                is_html=True)

        if not branch.startswith("refs/"):
            branch = "refs/heads/%s" % branch

        try:
            head_sha1 = repository.fetchTemporaryFromRemote(remote, branch)
        except gitutils.GitReferenceError:
            raise OperationFailure(
                code="refnotfound",
                title="Remote ref not found!",
                message=("Could not find the ref <code>%s</code> in the repository <code>%s</code>."
                         % (htmlutils.htmlify(branch), htmlutils.htmlify(remote))),
                is_html=True)
        except gitutils.GitCommandError as error:
            if error.output.splitlines()[0].endswith("does not appear to be a git repository"):
                raise OperationFailure(
                    code="invalidremote",
                    title="Invalid remote!",
                    message=("<code>%s</code> does not appear to be a valid Git repository."
                             % htmlutils.htmlify(remote)),
                    is_html=True)
            else:
                raise

        if upstream.startswith("refs/"):
            try:
                upstream_sha1 = repository.fetchTemporaryFromRemote(remote, upstream)
            except gitutils.GitReferenceError:
                raise OperationFailure(
                    code="refnotfound",
                    title="Remote ref not found!",
                    message=("Could not find the ref <code>%s</code> in the repository <code>%s</code>."
                             % (htmlutils.htmlify(upstream), htmlutils.htmlify(remote))),
                    is_html=True)
        else:
            try:
                upstream_sha1 = repository.revparse(upstream)
            except gitutils.GitReferenceError:
                raise OperationFailure(
                    code="refnotfound",
                    title="Local ref not found!",
                    message=("Could not find the ref <code>%s</code> in the repository <code>%s</code>."
                             % (htmlutils.htmlify(upstream), htmlutils.htmlify(str(repository)))),
                    is_html=True)

        try:
            resolved_upstream_sha1 = gitutils.getTaggedCommit(repository, upstream_sha1)
        except gitutils.GitReferenceError:
            resolved_upstream_sha1 = None

        if not resolved_upstream_sha1:
            raise OperationFailure(
                code="missingcommit",
                title="Upstream commit is missing!",
                message=("<p>Could not find the commit <code>%s</code> in the "
                         "repository <code>%s</code>.</p>"
                         "<p>Since it would have been fetched along with the "
                         "branch if it actually was a valid upstream commit, "
                         "this means it's not valid.</p>"
                         % (htmlutils.htmlify(upstream_sha1), htmlutils.htmlify(str(repository)))),
                is_html=True)

        commit_sha1s = repository.revlist(included=[head_sha1], excluded=[resolved_upstream_sha1])

        if not commit_sha1s:
            raise OperationFailure(
                code="emptybranch",
                title="Branch contains no commits!",
                message=("All commits referenced by <code>%s</code> are reachable from <code>%s</code>."
                         % (htmlutils.htmlify(branch), htmlutils.htmlify(upstream))),
                is_html=True)

        cursor.execute("SELECT id FROM commits WHERE sha1=ANY (%s)", (commit_sha1s,))

        return OperationResult(commit_ids=[commit_id for (commit_id,) in cursor],
                               head_sha1=head_sha1, upstream_sha1=resolved_upstream_sha1)
Пример #10
0
    def process(self,
                db,
                user,
                repository_name,
                remote,
                branch,
                upstream="refs/heads/master"):
        repository = gitutils.Repository.fromName(db, repository_name)

        cursor = db.cursor()

        # Check if any other repository is currently tracking branches from this
        # remote.  If that's the case, then the user most likely either selected
        # the wrong repository or entered the wrong remote.
        cursor.execute(
            """SELECT repositories.name
                            FROM repositories
                            JOIN trackedbranches ON (trackedbranches.repository=repositories.id)
                           WHERE repositories.id!=%s
                             AND trackedbranches.remote=%s""",
            (repository.id, remote))
        for (other_name, ) in cursor:
            raise OperationFailure(
                code="badremote",
                title="Bad remote!",
                message=(
                    "The remote <code>%s</code> appears to be related to "
                    "another repository on this server (<code>%s</code>).  "
                    "You most likely shouldn't be importing branches from "
                    "it into the selected repository (<code>%s</code>)." %
                    (htmlutils.htmlify(remote), htmlutils.htmlify(other_name),
                     htmlutils.htmlify(repository_name))),
                is_html=True)

        if not branch.startswith("refs/"):
            branch = "refs/heads/%s" % branch

        try:
            with repository.fetchTemporaryFromRemote(remote, branch) as sha1:
                head_sha1 = repository.keepalive(sha1)
        except gitutils.GitReferenceError as error:
            if error.repository:
                raise OperationFailure(
                    code="refnotfound",
                    title="Remote ref not found!",
                    message=
                    ("Could not find the ref <code>%s</code> in the repository <code>%s</code>."
                     % (htmlutils.htmlify(
                         error.ref), htmlutils.htmlify(error.repository))),
                    is_html=True)
            else:
                raise OperationFailure(
                    code="invalidref",
                    title="Invalid ref!",
                    message=("The specified ref is invalid: <code>%s</code>." %
                             htmlutils.htmlify(error.ref)),
                    is_html=True)
        except gitutils.GitCommandError as error:
            if error.output.splitlines()[0].endswith(
                    "does not appear to be a git repository"):
                raise OperationFailure(
                    code="invalidremote",
                    title="Invalid remote!",
                    message=
                    ("<code>%s</code> does not appear to be a valid Git repository."
                     % htmlutils.htmlify(remote)),
                    is_html=True)
            else:
                raise

        if upstream.startswith("refs/"):
            try:
                with repository.fetchTemporaryFromRemote(remote,
                                                         upstream) as sha1:
                    upstream_sha1 = repository.keepalive(sha1)
            except gitutils.GitReferenceError:
                raise OperationFailure(
                    code="refnotfound",
                    title="Remote ref not found!",
                    message=
                    ("Could not find the ref <code>%s</code> in the repository <code>%s</code>."
                     %
                     (htmlutils.htmlify(upstream), htmlutils.htmlify(remote))),
                    is_html=True)
        else:
            try:
                upstream_sha1 = repository.revparse(upstream)
            except gitutils.GitReferenceError:
                raise OperationFailure(
                    code="refnotfound",
                    title="Local ref not found!",
                    message=
                    ("Could not find the ref <code>%s</code> in the repository <code>%s</code>."
                     % (htmlutils.htmlify(upstream),
                        htmlutils.htmlify(str(repository)))),
                    is_html=True)

        try:
            resolved_upstream_sha1 = gitutils.getTaggedCommit(
                repository, upstream_sha1)
        except gitutils.GitReferenceError:
            resolved_upstream_sha1 = None

        if not resolved_upstream_sha1:
            raise OperationFailure(
                code="missingcommit",
                title="Upstream commit is missing!",
                message=("<p>Could not find the commit <code>%s</code> in the "
                         "repository <code>%s</code>.</p>"
                         "<p>Since it would have been fetched along with the "
                         "branch if it actually was a valid upstream commit, "
                         "this means it's not valid.</p>" %
                         (htmlutils.htmlify(upstream_sha1),
                          htmlutils.htmlify(str(repository)))),
                is_html=True)

        commit_sha1s = repository.revlist(included=[head_sha1],
                                          excluded=[resolved_upstream_sha1])

        if not commit_sha1s:
            raise OperationFailure(
                code="emptybranch",
                title="Branch contains no commits!",
                message=
                ("All commits referenced by <code>%s</code> are reachable from <code>%s</code>."
                 % (htmlutils.htmlify(branch), htmlutils.htmlify(upstream))),
                is_html=True)

        cursor.execute("SELECT id FROM commits WHERE sha1=ANY (%s)",
                       (commit_sha1s, ))

        return OperationResult(
            commit_ids=[commit_id for (commit_id, ) in cursor],
            head_sha1=head_sha1,
            upstream_sha1=resolved_upstream_sha1)
Пример #11
0
 def revparse(item):
     if re.match("^[0-9a-f]+$", item):
         cursor.execute("SELECT sha1 FROM commits JOIN changesets ON (changesets.child=commits.id) JOIN reviewchangesets ON (reviewchangesets.changeset=changesets.id) WHERE reviewchangesets.review=%s AND commits.sha1 LIKE %s", (review_id, item + "%"))
         try: return cursor.fetchone()[0]
         except: return gitutils.getTaggedCommit(repository, repository.revparse(item))