Ejemplo n.º 1
0
    def __init__(self, db, cnn, cursor, repoid):
        self.db = db
        self.cnn = cnn
        self.repoid = repoid

        self.icursor = ICursor(cursor, self.INTERVAL_SIZE)
        self.icursor.execute(statement(self.__query__, db.place_holder),
                             (repoid, ))
        self.rs = iter(self.icursor.fetchmany())
        self.prev_commit = -1
        self.current = None
Ejemplo n.º 2
0
 def get_patches(self, repo, repo_uri, repo_id, db, cursor):
     icursor = ICursor(cursor, self.INTERVAL_SIZE)
     # Get the patches from this repository
     query = """select p.commit_id, p.file_id, p.patch, s.rev
                 from patches p, scmlog s
                 where p.commit_id = s.id and
                 s.repository_id = ? and
                 p.patch is not NULL"""
     icursor.execute(statement(query, db.place_holder), (repo_id,))
     rs = icursor.fetchmany()
     while rs:
         for commit_id, file_id, patch_content, rev in rs:
             yield (commit_id, file_id, to_utf8(patch_content), rev)
         rs = icursor.fetchmany()
Ejemplo n.º 3
0
    def __init__(self, db, cnn, cursor, repoid):
        self.db = db
        self.cnn = cnn
        self.repoid = repoid

        self.icursor = ICursor(cursor, self.INTERVAL_SIZE)
        self.icursor.execute(statement(self.__query__, db.place_holder), (repoid,))
        self.rs = iter(self.icursor.fetchmany())
        self.prev_commit = -1
        self.current = None
Ejemplo n.º 4
0
        def patch_generator(repo, repo_uri, repo_id, db, cursor):
            icursor = ICursor(cursor, self.INTERVAL_SIZE)
            icursor.execute(
                statement("SELECT id, rev, composed_rev " + "from scmlog where repository_id = ?", db.place_holder),
                (repo_id,),
            )

            rs = icursor.fetchmany()

            while rs:
                for commit_id, revision, composed_rev in rs:
                    # Get the patch
                    pj = PatchJob(revision, commit_id)

                    path = uri_to_filename(repo_uri)
                    pj.run(repo, path or repo.get_uri())

                    # Yield the patch to hunks
                    yield (pj.commit_id, pj.data, pj.rev)

                rs = icursor.fetchmany()
Ejemplo n.º 5
0
 def get_patches(self, repo, repo_uri, repo_id, db, cursor):
     icursor = ICursor(cursor, self.INTERVAL_SIZE)
     # Get the patches from this repository
     query = """select p.commit_id, p.file_id, p.patch, s.rev
                 from patches p, scmlog s
                 where p.commit_id = s.id and
                 s.repository_id = ? and
                 p.patch is not NULL"""
     icursor.execute(statement(query, db.place_holder), (repo_id, ))
     rs = icursor.fetchmany()
     while rs:
         for commit_id, file_id, patch_content, rev in rs:
             yield (commit_id, file_id, to_utf8(patch_content), rev)
         rs = icursor.fetchmany()
Ejemplo n.º 6
0
        def patch_generator(repo, repo_uri, repo_id, db, cursor):
            icursor = ICursor(cursor, self.INTERVAL_SIZE)
            icursor.execute(statement("SELECT id, rev, composed_rev " + \
                                      "from scmlog where repository_id = ?",
                                      db.place_holder), (repo_id,))

            rs = icursor.fetchmany()

            while rs:
                for commit_id, revision, composed_rev in rs:
                    # Get the patch
                    pj = PatchJob(revision, commit_id)

                    path = uri_to_filename(repo_uri)
                    pj.run(repo, path or repo.get_uri())

                    p = DBPatch(db, commit_id, pj.data)
                    # Yield the patch to hunks
                    for file_id, patch in p.file_patches():
                        yield (pj.commit_id, file_id, patch, pj.rev)

                rs = icursor.fetchmany()
Ejemplo n.º 7
0
class FileRevs:

    INTERVAL_SIZE = 1000
    __query__ = '''select s.rev rev, s.id commit_id, af.file_id, af.action_type, s.composed_rev 
from scmlog s, action_files af where s.id = af.commit_id and s.repository_id = ? order by s.id'''
    # This query selects the newest entry for those cases with two filepaths
    # for the same file. See https://github.com/MetricsGrimoire/CVSAnalY/issues/3 for more info.
    __path_query__ = '''SELECT file_path FROM file_links,
(SELECT MAX(id) id FROM file_links WHERE file_id = ? AND commit_id <= ? ORDER BY commit_id DESC) fp
WHERE file_links.id = fp.id'''

    def __init__(self, db, cnn, cursor, repoid):
        self.db = db
        self.cnn = cnn
        self.repoid = repoid

        self.icursor = ICursor(cursor, self.INTERVAL_SIZE)
        self.icursor.execute(statement(self.__query__, db.place_holder),
                             (repoid, ))
        self.rs = iter(self.icursor.fetchmany())
        self.prev_commit = -1
        self.current = None

    def __iter__(self):
        return self

    def __get_next(self):
        try:
            t = self.rs.next()
        except StopIteration:
            self.rs = iter(self.icursor.fetchmany())
            if not self.rs:
                raise StopIteration
            t = self.rs.next()

        return t

    def next(self):
        if not self.rs:
            raise StopIteration

        while True:
            self.current = self.__get_next()
            revision, commit_id, file_id, action_type, composed = self.current

            if action_type in ('V', 'C'):
                if self.prev_commit != commit_id:
                    # Get the matrix for revision
                    self.prev_commit = commit_id
                    continue
            elif action_type == 'D':
                continue
            elif action_type in ('A', 'R'):
                if self.prev_commit != commit_id:
                    # Get the matrix for revision
                    self.prev_commit = commit_id

            return self.current

    def get_path(self):
        if not self.current:
            return None

        revision, commit_id, file_id, action_type, composed = self.current
        if composed:
            rev = revision.split("|")[0]
        else:
            rev = revision

        relative_path = self.__get_path_from_db(file_id, commit_id).strip("/")

        return relative_path

    def __get_path_from_db(self, file_id, commit_id):
        cursor = self.cnn.cursor()

        cursor.execute(statement(self.__path_query__, self.db.place_holder),
                       (file_id, commit_id))
        path = cursor.fetchone()[0]

        cursor.close()

        return "/" + path
Ejemplo n.º 8
0
class FileRevs:
    INTERVAL_SIZE = 1000
    __query__ = '''select s.rev rev, s.id commit_id, af.file_id, af.action_type, s.composed_rev
from scmlog s, action_files af where s.id = af.commit_id and s.repository_id = ? order by s.id'''
    # This query selects the newest entry for those cases with two filepaths
    # for the same file. See https://github.com/MetricsGrimoire/CVSAnalY/issues/3 for more info.
    __path_query__ = '''SELECT rev, file_path FROM file_links fl JOIN scmlog s
    ON fl.commit_id=s.id WHERE file_id = ? AND commit_id <= ? ORDER BY commit_id DESC, fl.id DESC'''

    def __init__(self, db, cnn, cursor, repoid):
        self.db = db
        self.cnn = cnn
        self.repoid = repoid

        self.icursor = ICursor(cursor, self.INTERVAL_SIZE)
        self.icursor.execute(statement(self.__query__, db.place_holder), (repoid,))
        self.rs = iter(self.icursor.fetchmany())
        self.prev_commit = -1
        self.current = None

    def __iter__(self):
        return self

    def __get_next(self):
        try:
            t = self.rs.next()
        except StopIteration:
            self.rs = iter(self.icursor.fetchmany())
            if not self.rs:
                raise StopIteration
            t = self.rs.next()

        return t

    def next(self):
        if not self.rs:
            raise StopIteration

        self.current = self.__get_next()
        return self.current

    def get_path(self, repo=None, repo_path=None):
        if not self.current:
            return None

        revision, commit_id, file_id, action_type, composed = self.current
        if composed:
            rev = revision.split("|")[0]
        else:
            rev = revision
        cursor = self.cnn.cursor()
        cursor.execute(statement(self.__path_query__, self.db.place_holder),
                       (file_id, commit_id))
        file_link = cursor.fetchone()
        relative_path = None
        if repo is None:
            relative_path = file_link[1]
        else:
            try:
                while file_link:
                    if repo.is_ancestor(repo_path, file_link[0], rev):
                        relative_path = file_link[1]
                        break
                    else:
                        file_link = cursor.fetchone()
            except CommandError as e:
                printerr(str(e) + '\n' + e.error)

        cursor.close()
        if relative_path is None:
            return None
        else:
            return relative_path.strip("/")
Ejemplo n.º 9
0
        commits = []

        try:
            self.__create_table (cnn)
        except TableAlreadyExists:
            cursor.execute (statement ("SELECT max(id) from patches", db.place_holder))
            id = cursor.fetchone ()[0]
            if id is not None:
                DBPatch.id_counter = id + 1

            commits = self.__get_patches_for_repository (repo_id, cursor)
        except Exception, e:
            raise ExtensionRunError (str (e))

        write_cursor = cnn.cursor ()
        icursor = ICursor (cursor, self.INTERVAL_SIZE)
        icursor.execute (statement ("SELECT id, rev, composed_rev from scmlog where repository_id = ?",
                                    db.place_holder), (repo_id,))
        rs = icursor.fetchmany ()
        while rs:
            for commit_id, revision, composed_rev in rs:
                if commit_id in commits:
                    continue

                if composed_rev:
                    rev = revision.split ("|")[0]
                else:
                    rev = revision

                p = DBPatch (None, commit_id, self.get_patch_for_commit (rev))
                write_cursor.execute (statement (DBPatch.__insert__, self.db.place_holder),
Ejemplo n.º 10
0
        try:
            self.__create_table(cnn)
        except TableAlreadyExists:
            cursor.execute(
                statement("SELECT max(id) from patches", db.place_holder))
            id = cursor.fetchone()[0]
            if id is not None:
                DBPatch.id_counter = id + 1

            commits = self.__get_patches_for_repository(repo_id, cursor)
        except Exception, e:
            raise ExtensionRunError(str(e))

        write_cursor = cnn.cursor()
        icursor = ICursor(cursor, self.INTERVAL_SIZE)
        icursor.execute(
            statement(
                "SELECT id, rev, composed_rev from scmlog where repository_id = ?",
                db.place_holder), (repo_id, ))
        rs = icursor.fetchmany()
        while rs:
            for commit_id, revision, composed_rev in rs:
                if commit_id in commits:
                    continue

                if composed_rev:
                    rev = revision.split("|")[0]
                else:
                    rev = revision
Ejemplo n.º 11
0
class FileRevs:

    INTERVAL_SIZE = 1000
    __query__ = '''select s.rev rev, s.id commit_id, af.file_id, af.action_type, s.composed_rev 
        from scmlog s, action_files af 
        where s.id = af.commit_id and s.repository_id = ? 
        order by s.date'''

    def __init__ (self, db, cnn, cursor, repoid):
        self.db = db
        self.cnn = cnn
        self.repoid = repoid

        self.icursor = ICursor (cursor, self.INTERVAL_SIZE)
        self.icursor.execute (statement (self.__query__, db.place_holder), (repoid,))
        self.rs = iter (self.icursor.fetchmany ())
        self.prev_commit = -1
        self.current = None

        self.fp = FilePaths (db)
        self.fp.update_all(repoid)

    def __iter__ (self):
        return self

    def __get_next (self):
        try:
            t = self.rs.next ()
        except StopIteration:
            self.rs = iter (self.icursor.fetchmany ())
            if not self.rs:
                raise StopIteration
            t = self.rs.next ()

        return t

    def next (self):
        if not self.rs:
            raise StopIteration

        while True:
            self.current = self.__get_next ()
            revision, commit_id, file_id, action_type, composed = self.current

            # Should not need to update_for_revision anymore, delete if OK
            # if action_type in ('V', 'C'):
            #     if self.prev_commit != commit_id:
            #         # Get the matrix for revision
            #         self.prev_commit = commit_id
            #         aux_cursor = self.cnn.cursor ()
            #         self.fp.update_for_revision (aux_cursor, commit_id, self.repoid)
            #         aux_cursor.close ()
            #         continue
            # elif action_type == 'D':
            #     continue
            # elif action_type in  ('A', 'R'):
            #     if self.prev_commit != commit_id:
            #         # Get the matrix for revision
            #         self.prev_commit = commit_id
            #         aux_cursor = self.cnn.cursor ()
            #         self.fp.update_for_revision (aux_cursor, commit_id, self.repoid)
            #         aux_cursor.close ()

            return self.current

    def get_path (self):
        if not self.current:
            return None

        revision, commit_id, file_id, action_type, composed = self.current
        if composed:
            rev = revision.split ("|")[0]
        else:
            rev = revision

        try:
            relative_path = self.fp.get_path (file_id, commit_id, self.repoid).strip ("/")
        except AttributeError, e:
            if self.fp.get_commit_id () != commit_id:
                # Commented out as update_for_all exists, delete if OK
                # aux_cursor = self.cnn.cursor ()
                #                 self.fp.update_for_revision (aux_cursor, commit_id, self.repoid)
                #                 aux_cursor.close ()

                relative_path = self.fp.get_path (file_id, commit_id, self.repoid).strip ("/")
            else:
                raise e

        return relative_path
Ejemplo n.º 12
0
class FileRevs:

    INTERVAL_SIZE = 1000
    __query__ = '''select s.rev rev, s.id commit_id, af.file_id, af.action_type, s.composed_rev 
from scmlog s, action_files af where s.id = af.commit_id and s.repository_id = ? order by s.id'''
    # This query selects the newest entry for those cases with two filepaths
    # for the same file. See https://github.com/MetricsGrimoire/CVSAnalY/issues/3 for more info.
    __path_query__ = '''SELECT file_path FROM file_links,
(SELECT MAX(id) id FROM file_links WHERE file_id = ? AND commit_id <= ? ORDER BY commit_id DESC) fp
WHERE file_links.id = fp.id'''

    def __init__ (self, db, cnn, cursor, repoid):
        self.db = db
        self.cnn = cnn
        self.repoid = repoid

        self.icursor = ICursor (cursor, self.INTERVAL_SIZE)
        self.icursor.execute (statement (self.__query__, db.place_holder), (repoid,))
        self.rs = iter (self.icursor.fetchmany ())
        self.prev_commit = -1
        self.current = None

    def __iter__ (self):
        return self

    def __get_next (self):
        try:
            t = self.rs.next ()
        except StopIteration:
            self.rs = iter (self.icursor.fetchmany ())
            if not self.rs:
                raise StopIteration
            t = self.rs.next ()

        return t

    def next (self):
        if not self.rs:
            raise StopIteration

        while True:
            self.current = self.__get_next ()
            revision, commit_id, file_id, action_type, composed = self.current

            if action_type in ('V', 'C'):
                if self.prev_commit != commit_id:
                    # Get the matrix for revision
                    self.prev_commit = commit_id
                    continue
            elif action_type == 'D':
                continue
            elif action_type in  ('A', 'R'):
                if self.prev_commit != commit_id:
                    # Get the matrix for revision
                    self.prev_commit = commit_id

            return self.current

    def get_path(self):
        if not self.current:
            return None

        revision, commit_id, file_id, action_type, composed = self.current
        if composed:
            rev = revision.split("|")[0]
        else:
            rev = revision

        relative_path = self.__get_path_from_db(file_id, commit_id).strip("/")

        return relative_path
    
    def __get_path_from_db(self, file_id, commit_id):
        cursor = self.cnn.cursor()

        cursor.execute(statement(self.__path_query__, self.db.place_holder),
                       (file_id, commit_id))
        path = cursor.fetchone()[0]

        cursor.close ()

        return "/" + path
Ejemplo n.º 13
0
class FileRevs:
    INTERVAL_SIZE = 1000
    __query__ = '''select s.rev rev, s.id commit_id, af.file_id, af.action_type, s.composed_rev
from scmlog s, action_files af where s.id = af.commit_id and s.repository_id = ? order by s.id'''
    # This query selects the newest entry for those cases with two filepaths
    # for the same file. See https://github.com/MetricsGrimoire/CVSAnalY/issues/3 for more info.
    __path_query__ = '''SELECT rev, file_path FROM file_links fl JOIN scmlog s
    ON fl.commit_id=s.id WHERE file_id = ? AND commit_id <= ? ORDER BY commit_id DESC, fl.id DESC'''

    def __init__(self, db, cnn, cursor, repoid):
        self.db = db
        self.cnn = cnn
        self.repoid = repoid

        self.icursor = ICursor(cursor, self.INTERVAL_SIZE)
        self.icursor.execute(statement(self.__query__, db.place_holder),
                             (repoid, ))
        self.rs = iter(self.icursor.fetchmany())
        self.prev_commit = -1
        self.current = None

    def __iter__(self):
        return self

    def __get_next(self):
        try:
            t = self.rs.next()
        except StopIteration:
            self.rs = iter(self.icursor.fetchmany())
            if not self.rs:
                raise StopIteration
            t = self.rs.next()

        return t

    def next(self):
        if not self.rs:
            raise StopIteration

        self.current = self.__get_next()
        return self.current

    def get_path(self, repo=None, repo_path=None):
        if not self.current:
            return None

        revision, commit_id, file_id, action_type, composed = self.current
        if composed:
            rev = revision.split("|")[0]
        else:
            rev = revision
        cursor = self.cnn.cursor()
        cursor.execute(statement(self.__path_query__, self.db.place_holder),
                       (file_id, commit_id))
        file_link = cursor.fetchone()
        relative_path = None
        if repo is None:
            relative_path = file_link[1]
        else:
            try:
                while file_link:
                    if repo.is_ancestor(repo_path, file_link[0], rev):
                        relative_path = file_link[1]
                        break
                    else:
                        file_link = cursor.fetchone()
            except CommandError as e:
                printerr(str(e) + '\n' + e.error)

        cursor.close()
        if relative_path is None:
            return None
        else:
            return relative_path.strip("/")
Ejemplo n.º 14
0
                repo_uri = uri

            read_cursor.execute(statement( \
                    "SELECT id from repositories where uri = ?", \
                    db.place_holder),(repo_uri,))
            repo_id = read_cursor.fetchone()[0]
        except NotImplementedError:
            raise ExtensionRunError( \
                    "Content extension is not supported for %s repos" \
                    %(repo.get_type()))
        except Exception, e:
            raise ExtensionRunError( \
                    "Error creating repository %s. Exception: %s" \
                    %(repo.get_uri(), str(e)))
        
        icursor = ICursor(read_cursor, self.INTERVAL_SIZE)
        # Get the patches from this repository
        query = "select p.commit_id, p.patch, s.rev from patches p, scmlog s " + \
                "where p.commit_id = s.id and " + \
                "s.repository_id = ? and " + \
                "p.patch is not NULL"
        icursor.execute(statement(query, db.place_holder),(repo_id,))

        self.__prepare_table(connection)
        fp = FilePaths(db)
        fp.update_all(repo_id)
        
        rs = icursor.fetchmany()

        while rs:
            for commit_id, patch_content, rev in rs: