<commit_before>#
# Copyright (c) 2004-2005 rPath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.opensource.org/licenses/cpl.php.
#
# This program is distributed in the hope that it will be useful, but
# without any waranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#

from conary import versions
from conary.dbstore import idtable
from conary.repository.errors import DuplicateBranch
from conary.repository.netrepos import schema

class BranchTable(idtable.IdTable):
    def addId(self, branch):
        assert(isinstance(branch, versions.Branch))
        cu = self.db.cursor()
        cu.execute("INSERT INTO Branches VALUES (NULL, ?)",
		   branch.asString())
	return cu.lastrowid

    def getId(self, theId):
	return versions.VersionFromString(idtable.IdTable.getId(self, theId))

    def __getitem__(self, branch):
        assert(isinstance(branch, versions.Branch))
	return idtable.IdTable.__getitem__(self, branch.asString())

    def get(self, branch, defValue):
        assert(isinstance(branch, versions.Branch))
	return idtable.IdTable.get(self, branch.asString(), defValue)

    def __delitem__(self, branch):
        assert(isinstance(branch, versions.Branch))
	idtable.IdTable.__delitem__(self, branch.asString())

    def has_key(self, branch):
        assert(isinstance(branch, versions.Branch))
	return idtable.IdTable.has_key(self, branch.asString())

    def iterkeys(self):
	raise NotImplementedError

    def iteritems(self):
	raise NotImplementedError

    def __init__(self, db):
        idtable.IdTable.__init__(self, db, "Branches", "branchId", "branch")

class LabelTable(idtable.IdTable):

    def addId(self, label):
	idtable.IdTable.addId(self, label.asString())

    def __getitem__(self, label):
	return idtable.IdTable.__getitem__(self, label.asString())

    def get(self, label, defValue):
	return idtable.IdTable.get(self, label.asString(), defValue)

    def __delitem__(self, label):
	idtable.IdTable.__delitem__(self, label.asString())

    def has_key(self, label):
	return idtable.IdTable.has_key(self, label.asString())

    def iterkeys(self):
	raise NotImplementedError

    def iteritems(self):
	raise NotImplementedError

    def __init__(self, db):
        idtable.IdTable.__init__(self, db, 'Labels', 'labelId', 'label')

class LatestTable:
    def __init__(self, db):
        self.db = db
        schema.createLatest(db)

    def __setitem__(self, key, val):
	(first, second, third) = key

        cu = self.db.cursor()
        cu.execute("INSERT OR REPLACE INTO Latest VALUES (?, ?, ?, ?)",
                   (first, second, third, val))

    def get(self, key, defValue):
	(first, second, third) = key

        cu = self.db.cursor()

        cu.execute("SELECT versionId FROM Latest WHERE itemId=? AND branchId=?"
                            "AND flavorId=?",
		   (first, second, third))
	item = cu.fetchone()
	if not item:
	    return defValue
	return item[0]

class LabelMap(idtable.IdPairSet):
    def __init__(self, db):
	idtable.IdPairMapping.__init__(self, db, 'LabelMap',
		                       'itemId', 'labelId', 'branchId')
	cu = db.cursor()
        cu.execute("SELECT name FROM sqlite_master WHERE type='index'")
        tables = [ x[0] for x in cu ]
        if "LabelMapLabelIdx" not in tables:
	    cu.execute("CREATE INDEX LabelMapLabelIdx on LabelMap(labelId)")

    def branchesByItem(self, itemId):
	return self.getByFirst(itemId)

class Nodes:<commit_msg>eliminate sqlite dependency from the creation of LabelMap<commit_after>#
# Copyright (c) 2004-2005 rPath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.opensource.org/licenses/cpl.php.
#
# This program is distributed in the hope that it will be useful, but
# without any waranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#

from conary import versions
from conary.dbstore import idtable
from conary.repository.errors import DuplicateBranch
from conary.repository.netrepos import schema

class BranchTable(idtable.IdTable):
    def addId(self, branch):
        assert(isinstance(branch, versions.Branch))
        cu = self.db.cursor()
        cu.execute("INSERT INTO Branches VALUES (NULL, ?)",
		   branch.asString())
	return cu.lastrowid

    def getId(self, theId):
	return versions.VersionFromString(idtable.IdTable.getId(self, theId))

    def __getitem__(self, branch):
        assert(isinstance(branch, versions.Branch))
	return idtable.IdTable.__getitem__(self, branch.asString())

    def get(self, branch, defValue):
        assert(isinstance(branch, versions.Branch))
	return idtable.IdTable.get(self, branch.asString(), defValue)

    def __delitem__(self, branch):
        assert(isinstance(branch, versions.Branch))
	idtable.IdTable.__delitem__(self, branch.asString())

    def has_key(self, branch):
        assert(isinstance(branch, versions.Branch))
	return idtable.IdTable.has_key(self, branch.asString())

    def iterkeys(self):
	raise NotImplementedError

    def iteritems(self):
	raise NotImplementedError

    def __init__(self, db):
        idtable.IdTable.__init__(self, db, "Branches", "branchId", "branch")

class LabelTable(idtable.IdTable):

    def addId(self, label):
	idtable.IdTable.addId(self, label.asString())

    def __getitem__(self, label):
	return idtable.IdTable.__getitem__(self, label.asString())

    def get(self, label, defValue):
	return idtable.IdTable.get(self, label.asString(), defValue)

    def __delitem__(self, label):
	idtable.IdTable.__delitem__(self, label.asString())

    def has_key(self, label):
	return idtable.IdTable.has_key(self, label.asString())

    def iterkeys(self):
	raise NotImplementedError

    def iteritems(self):
	raise NotImplementedError

    def __init__(self, db):
        idtable.IdTable.__init__(self, db, 'Labels', 'labelId', 'label')

class LatestTable:
    def __init__(self, db):
        self.db = db
        schema.createLatest(db)

    def __setitem__(self, key, val):
	(first, second, third) = key

        cu = self.db.cursor()
        cu.execute("INSERT OR REPLACE INTO Latest VALUES (?, ?, ?, ?)",
                   (first, second, third, val))

    def get(self, key, defValue):
	(first, second, third) = key

        cu = self.db.cursor()

        cu.execute("SELECT versionId FROM Latest WHERE itemId=? AND branchId=?"
                            "AND flavorId=?",
		   (first, second, third))
	item = cu.fetchone()
	if not item:
	    return defValue
	return item[0]

class LabelMap(idtable.IdPairSet):
    def __init__(self, db):
        exists = 1
        if "LabelMap" not in db.tables:
            exists = 0
	idtable.IdPairMapping.__init__(self, db, 'LabelMap',
		                       'itemId', 'labelId', 'branchId')
        if not exists:
            cu = db.cursor()
	    cu.execute("CREATE INDEX LabelMapItemIdx  ON LabelMap(labelId)")
	    cu.execute("CREATE INDEX LabelMapLabelIdx ON LabelMap(labelId)")

    def branchesByItem(self, itemId):
	return self.getByFirst(itemId)

class Nodes:
{'fraction_non_alphanumeric': 0.11109645071909223, 'fraction_numerical': 0.0032985882042485815, 'mean_word_length': 3.580060422960725, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6706349', 'n_tokens_mistral': 2378, 'n_tokens_neox': 2292, 'n_words': 656}