/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 workingtree.py

Support working trees properly, status and ls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
 
17
 
17
18
"""An adapter between a Git index and a Bazaar Working Tree"""
18
19
 
 
20
 
 
21
from dulwich.index import (
 
22
    Index,
 
23
    )
19
24
import os
20
25
 
21
26
from bzrlib import (
22
27
    inventory,
23
28
    lockable_files,
24
29
    lockdir,
 
30
    osutils,
25
31
    transport,
26
32
    urlutils,
27
33
    workingtree,
28
34
    )
29
 
 
30
 
from dulwich.index import Index
 
35
from bzrlib.decorators import (
 
36
    needs_read_lock,
 
37
    needs_write_lock,
 
38
    )
 
39
 
 
40
 
 
41
def inventory_from_index(basis_inventory, index):
 
42
    inventory = basis_inventory.copy()
 
43
    return inventory
 
44
 
31
45
 
32
46
class GitWorkingTree(workingtree.WorkingTree):
33
47
    """A Git working tree."""
34
48
 
35
49
    def __init__(self, bzrdir, repo, branch):
36
 
        self.basedir = bzrdir.transport.base
 
50
        self.basedir = bzrdir.root_transport.local_abspath('.')
37
51
        self.bzrdir = bzrdir
38
52
        self.repository = repo
39
53
        self._branch = branch
40
54
        self._transport = bzrdir.transport
41
55
 
42
 
        self.controldir = urlutils.join(self.repository._git.path, 'bzr')
 
56
        self.controldir = urlutils.join(self.repository._git._controldir, 'bzr')
43
57
 
44
58
        try:
45
59
            os.makedirs(self.controldir)
54
68
 
55
69
        self.index = Index(os.path.join(self.repository._git.controldir(), 
56
70
            "index"))
 
71
        self.views = self._make_views()
 
72
        self._detect_case_handling()
57
73
 
58
74
    def unlock(self):
59
75
        # non-implementation specific cleanup
68
84
    def is_control_filename(self, path):
69
85
        return os.path.basename(path) == ".git"
70
86
 
71
 
    def _get_inventory(self):
72
 
        return inventory.Inventory()
 
87
    def _reset_data(self):
 
88
        self._inventory_is_modified = False
 
89
        basis_inv = self.repository.get_inventory(self.repository.get_mapping().revision_id_foreign_to_bzr(self.repository._git.head()))
 
90
        result = inventory_from_index(basis_inv, self.index)
 
91
        self._set_inventory(result, dirty=False)
73
92
 
74
 
    inventory = property(_get_inventory,
75
 
                         doc="Inventory of this Tree")
 
93
    @needs_read_lock
 
94
    def get_file_sha1(self, file_id, path=None, stat_value=None):
 
95
        if not path:
 
96
            path = self._inventory.id2path(file_id)
 
97
        return osutils.fingerprint_file(open(self.abspath(path).encode(osutils._fs_enc)))['sha1']
76
98
 
77
99
 
78
100
class GitWorkingTreeFormat(workingtree.WorkingTreeFormat):