/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

  • Committer: Vincent Ladeuil
  • Date: 2007-06-24 15:16:40 UTC
  • mto: (2547.2.1 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 2550.
  • Revision ID: v.ladeuil+lp@free.fr-20070624151640-5tg62jb5g9tqvybd
Fix 121889 by working around urllib2 bug.

* tests/HTTPTestUtil.py:
(DigestAuthRequestHandler.send_header_auth_reqed): python-2.4.1
fail to decode the header without the quotes. The RFC do not
require them, python >= 2.4.4 handles them gracefully. Not a big
deal.

* tests/test_http.py:
(TestAuth.setUp): Add a comment in hope I will not running around
shouting: "Who takes my traces ? Gimme my traces !" when running
the only tests who capture their own traces without showing them.

* transport/http/_urllib2_wrappers.py (BasicAuthHandler,
DigestAuthHandler): Not directly related to the bug, bug good to
fix anyway, the digest auth should be preferred to the basic
one. To do so, the digest handler should be tried before the basic
one.

* builtins.py:
(cmd_selftest.run): Fix typo. Note to reviewers: No, it's not
related to the bug. No there are no tests for that. No I don't
intend to write some :) But I'll understand if you veto that
because you want to take care of it :D

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009 Canonical Ltd
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
17
 
"""Map from Git sha's to Bazaar objects."""
18
 
 
19
 
import bzrlib
20
 
 
21
 
from bzrlib.errors import NoSuchRevision
22
 
 
23
 
import os
24
 
 
25
 
 
26
 
def check_pysqlite_version(sqlite3):
27
 
    """Check that sqlite library is compatible.
28
 
 
29
 
    """
30
 
    if (sqlite3.sqlite_version_info[0] < 3 or 
31
 
            (sqlite3.sqlite_version_info[0] == 3 and 
32
 
             sqlite3.sqlite_version_info[1] < 3)):
33
 
        warning('Needs at least sqlite 3.3.x')
34
 
        raise bzrlib.errors.BzrError("incompatible sqlite library")
35
 
 
36
 
try:
37
 
    try:
38
 
        import sqlite3
39
 
        check_pysqlite_version(sqlite3)
40
 
    except (ImportError, bzrlib.errors.BzrError), e: 
41
 
        from pysqlite2 import dbapi2 as sqlite3
42
 
        check_pysqlite_version(sqlite3)
43
 
except:
44
 
    warning('Needs at least Python2.5 or Python2.4 with the pysqlite2 '
45
 
            'module')
46
 
    raise bzrlib.errors.BzrError("missing sqlite library")
47
 
 
48
 
 
49
 
class GitShaMap(object):
50
 
 
51
 
    def __init__(self, transport):
52
 
        self.transport = transport
53
 
        self.db = sqlite3.connect(
54
 
            os.path.join(self.transport.local_abspath("."), "git.db"))
55
 
        self.db.executescript("""
56
 
        create table if not exists commits(sha1 text, revid text, tree_sha text);
57
 
        create index if not exists commit_sha1 on commits(sha1);
58
 
        create table if not exists blobs(sha1 text, fileid text, revid text);
59
 
        create index if not exists blobs_sha1 on blobs(sha1);
60
 
        create table if not exists trees(sha1 text, fileid text, revid text);
61
 
        create index if not exists trees_sha1 on trees(sha1);
62
 
""")
63
 
 
64
 
    def _parent_lookup(self, revid):
65
 
        return self.db.execute("select sha1 from commits where revid = ?", (revid,)).fetchone()[0].encode("utf-8")
66
 
 
67
 
    def add_entry(self, sha, type, type_data):
68
 
        """Add a new entry to the database.
69
 
        """
70
 
        assert isinstance(type_data, tuple)
71
 
        assert isinstance(sha, str), "type was %r" % sha
72
 
        if type == "commit":
73
 
            self.db.execute("replace into commits (sha1, revid, tree_sha) values (?, ?, ?)", (sha, type_data[0], type_data[1]))
74
 
        elif type == "blob":
75
 
            self.db.execute("replace into blobs (sha1, fileid, revid) values (?, ?, ?)", (sha, type_data[0], type_data[1]))
76
 
        elif type == "tree":
77
 
            self.db.execute("replace into trees (sha1, fileid, revid) values (?, ?, ?)", (sha, type_data[0], type_data[1]))
78
 
        else:
79
 
            raise AssertionError("Unknown type %s" % type)
80
 
 
81
 
    def lookup_git_sha(self, sha):
82
 
        """Lookup a Git sha in the database.
83
 
 
84
 
        :param sha: Git object sha
85
 
        :return: (type, type_data) with type_data:
86
 
            revision: revid, tree sha
87
 
        """
88
 
        row = self.db.execute("select revid, tree_sha from commits where sha1 = ?", (sha,)).fetchone()
89
 
        if row is not None:
90
 
            return ("commit", row)
91
 
        row = self.db.execute("select fileid, revid from blobs where sha1 = ?", (sha,)).fetchone()
92
 
        if row is not None:
93
 
            return ("blob", row)
94
 
        row = self.db.execute("select fileid, revid from trees where sha1 = ?", (sha,)).fetchone()
95
 
        if row is not None:
96
 
            return ("tree", row)
97
 
        raise KeyError(sha)
98
 
 
99
 
    def revids(self):
100
 
        for row in self.db.execute("select revid from commits").fetchall():
101
 
            yield row[0]