/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
 
19
21
from dulwich.index import (
20
22
    Index,
21
23
    )
25
27
    inventory,
26
28
    lockable_files,
27
29
    lockdir,
 
30
    osutils,
28
31
    transport,
29
32
    urlutils,
30
33
    workingtree,
31
34
    )
 
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
 
32
45
 
33
46
class GitWorkingTree(workingtree.WorkingTree):
34
47
    """A Git working tree."""
40
53
        self._branch = branch
41
54
        self._transport = bzrdir.transport
42
55
 
43
 
        self.controldir = urlutils.join(self.repository._git.path, 'bzr')
 
56
        self.controldir = urlutils.join(self.repository._git._controldir, 'bzr')
44
57
 
45
58
        try:
46
59
            os.makedirs(self.controldir)
56
69
        self.index = Index(os.path.join(self.repository._git.controldir(), 
57
70
            "index"))
58
71
        self.views = self._make_views()
 
72
        self._detect_case_handling()
59
73
 
60
74
    def unlock(self):
61
75
        # non-implementation specific cleanup
70
84
    def is_control_filename(self, path):
71
85
        return os.path.basename(path) == ".git"
72
86
 
73
 
    def _get_inventory(self):
74
 
        return inventory.Inventory()
75
 
 
76
87
    def _reset_data(self):
77
 
        pass
 
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)
78
92
 
79
 
    inventory = property(_get_inventory,
80
 
                         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']
81
98
 
82
99
 
83
100
class GitWorkingTreeFormat(workingtree.WorkingTreeFormat):