bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
1 |
# Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
|
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 |
||
|
0.200.381
by Jelmer Vernooij
Support working trees properly, status and ls. |
17 |
|
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
18 |
"""An adapter between a Git index and a Bazaar Working Tree"""
|
19 |
||
|
0.200.381
by Jelmer Vernooij
Support working trees properly, status and ls. |
20 |
|
|
0.200.292
by Jelmer Vernooij
Fix formatting. |
21 |
from dulwich.index import ( |
22 |
Index, |
|
23 |
)
|
|
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
24 |
import os |
25 |
||
26 |
from bzrlib import ( |
|
27 |
inventory, |
|
28 |
lockable_files, |
|
29 |
lockdir, |
|
|
0.200.381
by Jelmer Vernooij
Support working trees properly, status and ls. |
30 |
osutils, |
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
31 |
transport, |
32 |
urlutils, |
|
33 |
workingtree, |
|
34 |
)
|
|
|
0.200.381
by Jelmer Vernooij
Support working trees properly, status and ls. |
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 |
||
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
45 |
|
46 |
class GitWorkingTree(workingtree.WorkingTree): |
|
47 |
"""A Git working tree.""" |
|
48 |
||
49 |
def __init__(self, bzrdir, repo, branch): |
|
|
0.200.379
by Jelmer Vernooij
Re-enable working tree support. |
50 |
self.basedir = bzrdir.root_transport.local_abspath('.') |
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
51 |
self.bzrdir = bzrdir |
52 |
self.repository = repo |
|
53 |
self._branch = branch |
|
54 |
self._transport = bzrdir.transport |
|
55 |
||
|
0.200.381
by Jelmer Vernooij
Support working trees properly, status and ls. |
56 |
self.controldir = urlutils.join(self.repository._git._controldir, 'bzr') |
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
57 |
|
58 |
try: |
|
59 |
os.makedirs(self.controldir) |
|
60 |
os.makedirs(os.path.join(self.controldir, 'lock')) |
|
61 |
except OSError: |
|
62 |
pass
|
|
63 |
||
64 |
self._control_files = lockable_files.LockableFiles( |
|
65 |
transport.get_transport(self.controldir), 'lock', lockdir.LockDir) |
|
66 |
||
67 |
self._format = GitWorkingTreeFormat() |
|
68 |
||
|
0.200.173
by Jelmer Vernooij
Merge changes, open index. |
69 |
self.index = Index(os.path.join(self.repository._git.controldir(), |
70 |
"index")) |
|
|
0.200.239
by Jelmer Vernooij
Provide views. |
71 |
self.views = self._make_views() |
|
0.200.381
by Jelmer Vernooij
Support working trees properly, status and ls. |
72 |
self._detect_case_handling() |
|
0.200.173
by Jelmer Vernooij
Merge changes, open index. |
73 |
|
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
74 |
def unlock(self): |
|
0.200.224
by Jelmer Vernooij
Fix working tree locking. |
75 |
# non-implementation specific cleanup
|
76 |
self._cleanup() |
|
77 |
||
78 |
# reverse order of locking.
|
|
79 |
try: |
|
80 |
return self._control_files.unlock() |
|
81 |
finally: |
|
82 |
self.branch.unlock() |
|
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
83 |
|
84 |
def is_control_filename(self, path): |
|
85 |
return os.path.basename(path) == ".git" |
|
86 |
||
|
0.200.379
by Jelmer Vernooij
Re-enable working tree support. |
87 |
def _reset_data(self): |
|
0.200.381
by Jelmer Vernooij
Support working trees properly, status and ls. |
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) |
|
|
0.200.379
by Jelmer Vernooij
Re-enable working tree support. |
92 |
|
|
0.200.381
by Jelmer Vernooij
Support working trees properly, status and ls. |
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'] |
|
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
98 |
|
99 |
||
100 |
class GitWorkingTreeFormat(workingtree.WorkingTreeFormat): |
|
101 |
||
102 |
def get_format_description(self): |
|
103 |
return "Git Working Tree" |