/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to shamap.py

Use str text factory rather than encoding/decoding each time.

Show diffs side-by-side

added added

removed removed

Lines of Context:
173
173
            if not mapdbs().has_key(path):
174
174
                mapdbs()[path] = sqlite3.connect(path)
175
175
            self.db = mapdbs()[path]
 
176
        self.db.text_factory = str
176
177
        self.db.executescript("""
177
178
        create table if not exists commits(sha1 text, revid text, tree_sha text);
178
179
        create index if not exists commit_sha1 on commits(sha1);
198
199
    def lookup_commit(self, revid):
199
200
        row = self.db.execute("select sha1 from commits where revid = ?", (revid,)).fetchone()
200
201
        if row is not None:
201
 
            return row[0].encode("utf-8")
 
202
            return row[0]
202
203
        raise KeyError
203
204
 
204
205
    def commit_write_group(self):
210
211
        for sha, type, type_data in entries:
211
212
            assert isinstance(type_data[0], str)
212
213
            assert isinstance(type_data[1], str)
213
 
            entry = (sha.decode("utf-8"), type_data[0].decode("utf-8"), 
214
 
                     type_data[1].decode("utf-8"))
 
214
            entry = (sha, type_data[0], type_data[1])
215
215
            if type == "tree":
216
216
                trees.append(entry)
217
217
            elif type == "blob":
240
240
        row = self.db.execute("select sha1 from trees where fileid = ? and revid = ?", (fileid,revid)).fetchone()
241
241
        if row is None:
242
242
            raise KeyError((fileid, revid))
243
 
        return row[0].encode("utf-8")
 
243
        return row[0]
244
244
 
245
245
    def lookup_blob(self, fileid, revid):
246
246
        row = self.db.execute("select sha1 from blobs where fileid = ? and revid = ?", (fileid, revid)).fetchone()
247
247
        if row is None:
248
248
            raise KeyError((fileid, revid))
249
 
        return row[0].encode("utf-8")
 
249
        return row[0]
250
250
 
251
251
    def lookup_git_sha(self, sha):
252
252
        """Lookup a Git sha in the database.
256
256
            revision: revid, tree sha
257
257
        """
258
258
        def format(type, row):
259
 
            return (type, (row[0].encode("utf-8"), row[1].encode("utf-8")))
 
259
            return (type, (row[0], row[1]))
260
260
        row = self.db.execute("select revid, tree_sha from commits where sha1 = ?", (sha,)).fetchone()
261
261
        if row is not None:
262
262
            return format("commit", row)
271
271
    def revids(self):
272
272
        """List the revision ids known."""
273
273
        for row in self.db.execute("select revid from commits").fetchall():
274
 
            yield row[0].encode("utf-8")
 
274
            yield row[0]
275
275
 
276
276
    def sha1s(self):
277
277
        """List the SHA1s."""
278
278
        for table in ("blobs", "commits", "trees"):
279
279
            for row in self.db.execute("select sha1 from %s" % table).fetchall():
280
 
                yield row[0].encode("utf-8")
 
280
                yield row[0]
281
281
 
282
282
 
283
283
TDB_MAP_VERSION = 2