bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.264.10
by Jelmer Vernooij
Yield inventory entries. |
1 |
# Copyright (C) 2008-2011 Jelmer Vernooij <jelmer@samba.org>
|
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
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.1594
by Jelmer Vernooij
Use absolute_import everywhere. |
20 |
from __future__ import absolute_import |
|
0.200.381
by Jelmer Vernooij
Support working trees properly, status and ls. |
21 |
|
|
0.200.385
by Jelmer Vernooij
Cope with removed files. |
22 |
from cStringIO import ( |
23 |
StringIO, |
|
24 |
)
|
|
|
0.200.1210
by Jelmer Vernooij
Implement GitWorkingTree._walkdirs. |
25 |
from collections import defaultdict |
|
0.239.4
by Jelmer Vernooij
Cope with nonexistent files and directories in get_file_sha1. |
26 |
import errno |
|
0.200.1538
by Jelmer Vernooij
More work on tree-reference support. |
27 |
from dulwich.errors import NotGitRepository |
|
0.200.1655
by Jelmer Vernooij
Basic support for git ignores. |
28 |
from dulwich.ignore import ( |
|
0.200.1658
by Jelmer Vernooij
Fix handling of ignores - return patterns that matched. |
29 |
IgnoreFilterManager, |
|
0.200.1655
by Jelmer Vernooij
Basic support for git ignores. |
30 |
)
|
|
0.200.1096
by Jelmer Vernooij
Implement GitWorkingTreeFormat.initialize. |
31 |
from dulwich.index import ( |
32 |
Index, |
|
|
0.200.1531
by Jelmer Vernooij
Don't trust index contents - verify against file timestamps. |
33 |
changes_from_tree, |
34 |
cleanup_mode, |
|
35 |
index_entry_from_stat, |
|
|
0.200.1096
by Jelmer Vernooij
Implement GitWorkingTreeFormat.initialize. |
36 |
)
|
|
0.200.1202
by Jelmer Vernooij
Implement has_or_had_id. |
37 |
from dulwich.object_store import ( |
38 |
tree_lookup_path, |
|
39 |
)
|
|
|
0.200.383
by Jelmer Vernooij
Simplify, support rewriting index based on inventory. |
40 |
from dulwich.objects import ( |
41 |
Blob, |
|
|
0.200.1538
by Jelmer Vernooij
More work on tree-reference support. |
42 |
S_IFGITLINK, |
|
0.200.948
by Jelmer Vernooij
Cope with empty inventories. |
43 |
ZERO_SHA, |
44 |
)
|
|
|
0.200.1538
by Jelmer Vernooij
More work on tree-reference support. |
45 |
from dulwich.repo import Repo |
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
46 |
import os |
|
0.264.10
by Jelmer Vernooij
Yield inventory entries. |
47 |
import posixpath |
|
0.200.1655
by Jelmer Vernooij
Basic support for git ignores. |
48 |
import re |
|
0.200.384
by Jelmer Vernooij
Fix reading of inventory from index. |
49 |
import stat |
|
0.200.1215
by Jelmer Vernooij
Implement GitWorkingTree.remove. |
50 |
import sys |
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
51 |
|
|
0.200.1641
by Jelmer Vernooij
Use relative imports where possible. |
52 |
from ... import ( |
|
0.200.382
by Jelmer Vernooij
Support flushing index. |
53 |
errors, |
|
0.262.1
by Jelmer Vernooij
Fix WorkingTree.conflicts(). |
54 |
conflicts as _mod_conflicts, |
|
0.200.1655
by Jelmer Vernooij
Basic support for git ignores. |
55 |
globbing, |
|
0.200.409
by Jelmer Vernooij
Support parsing .gitignore. |
56 |
ignores, |
|
0.200.1476
by Jelmer Vernooij
Cope with working tree refactoring. |
57 |
lock, |
|
0.200.381
by Jelmer Vernooij
Support working trees properly, status and ls. |
58 |
osutils, |
|
0.200.1215
by Jelmer Vernooij
Implement GitWorkingTree.remove. |
59 |
trace, |
|
0.200.519
by Jelmer Vernooij
Move imports down, might not be available in older bzr-git versions. |
60 |
tree, |
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
61 |
workingtree, |
62 |
)
|
|
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
63 |
from ...bzr import ( |
64 |
inventory, |
|
65 |
)
|
|
|
0.200.1680
by Jelmer Vernooij
Fix repo locks. |
66 |
from ...mutabletree import ( |
67 |
MutableTree, |
|
68 |
)
|
|
|
0.200.1641
by Jelmer Vernooij
Use relative imports where possible. |
69 |
|
70 |
||
71 |
from .dir import ( |
|
|
0.200.1096
by Jelmer Vernooij
Implement GitWorkingTreeFormat.initialize. |
72 |
LocalGitDir, |
73 |
)
|
|
|
0.200.1641
by Jelmer Vernooij
Use relative imports where possible. |
74 |
from .tree import ( |
|
0.200.622
by Jelmer Vernooij
Implement InterTree.iter_changes() as well. |
75 |
changes_from_git_changes, |
|
0.200.617
by Jelmer Vernooij
Add custom InterTree for use between git revision trees. |
76 |
tree_delta_from_git_changes, |
77 |
)
|
|
|
0.200.1641
by Jelmer Vernooij
Use relative imports where possible. |
78 |
from .mapping import ( |
|
0.200.971
by Chadrik
Fix 'bzr status' after 'bzr add' in native git working trees. |
79 |
GitFileIdMap, |
|
0.264.10
by Jelmer Vernooij
Yield inventory entries. |
80 |
mode_kind, |
|
0.200.971
by Chadrik
Fix 'bzr status' after 'bzr add' in native git working trees. |
81 |
)
|
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
82 |
|
|
0.200.409
by Jelmer Vernooij
Support parsing .gitignore. |
83 |
IGNORE_FILENAME = ".gitignore" |
84 |
||
85 |
||
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
86 |
class GitWorkingTree(workingtree.WorkingTree): |
87 |
"""A Git working tree.""" |
|
88 |
||
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
89 |
def __init__(self, controldir, repo, branch, index): |
90 |
self.basedir = controldir.root_transport.local_abspath('.').encode(osutils._fs_enc) |
|
91 |
self.controldir = controldir |
|
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
92 |
self.repository = repo |
|
0.200.1205
by Jelmer Vernooij
Implement GitWorkingTree.stored_kind. |
93 |
self.store = self.repository._git.object_store |
|
0.200.384
by Jelmer Vernooij
Fix reading of inventory from index. |
94 |
self.mapping = self.repository.get_mapping() |
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
95 |
self._branch = branch |
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
96 |
self._transport = controldir.transport |
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
97 |
self._format = GitWorkingTreeFormat() |
|
0.200.803
by Jelmer Vernooij
Default to non-bare repositories when initializing a control directory. |
98 |
self.index = index |
|
0.200.1242
by Jelmer Vernooij
Support directories better. |
99 |
self._versioned_dirs = None |
|
0.200.239
by Jelmer Vernooij
Provide views. |
100 |
self.views = self._make_views() |
|
0.200.1173
by Jelmer Vernooij
Provide GitWorkingTree._rules_searcher. |
101 |
self._rules_searcher = None |
|
0.200.381
by Jelmer Vernooij
Support working trees properly, status and ls. |
102 |
self._detect_case_handling() |
|
0.200.1202
by Jelmer Vernooij
Implement has_or_had_id. |
103 |
self._reset_data() |
104 |
self._fileid_map = self._basis_fileid_map.copy() |
|
|
0.200.1476
by Jelmer Vernooij
Cope with working tree refactoring. |
105 |
self._lock_mode = None |
106 |
self._lock_count = 0 |
|
107 |
||
|
0.200.1650
by Jelmer Vernooij
Implement GitWorkingTree.supports_tree_reference. |
108 |
def supports_tree_reference(self): |
109 |
return False |
|
110 |
||
|
0.200.1476
by Jelmer Vernooij
Cope with working tree refactoring. |
111 |
def lock_read(self): |
112 |
"""Lock the repository for read operations. |
|
113 |
||
|
0.200.1646
by Jelmer Vernooij
Rename bzrlib to breezy. |
114 |
:return: A breezy.lock.LogicalLockResult.
|
|
0.200.1476
by Jelmer Vernooij
Cope with working tree refactoring. |
115 |
"""
|
116 |
if not self._lock_mode: |
|
117 |
self._lock_mode = 'r' |
|
118 |
self._lock_count = 1 |
|
|
0.200.1525
by Jelmer Vernooij
Make sure to always use an up-to-date index. |
119 |
self.index.read() |
|
0.200.1476
by Jelmer Vernooij
Cope with working tree refactoring. |
120 |
else: |
121 |
self._lock_count += 1 |
|
122 |
self.branch.lock_read() |
|
123 |
return lock.LogicalLockResult(self.unlock) |
|
124 |
||
|
0.200.1477
by Jelmer Vernooij
Implement GitWorkingTree.lock_tree_write. |
125 |
def lock_tree_write(self): |
126 |
if not self._lock_mode: |
|
127 |
self._lock_mode = 'w' |
|
128 |
self._lock_count = 1 |
|
|
0.200.1525
by Jelmer Vernooij
Make sure to always use an up-to-date index. |
129 |
self.index.read() |
|
0.200.1477
by Jelmer Vernooij
Implement GitWorkingTree.lock_tree_write. |
130 |
elif self._lock_mode == 'r': |
131 |
raise errors.ReadOnlyError(self) |
|
132 |
else: |
|
133 |
self._lock_count +=1 |
|
134 |
self.branch.lock_read() |
|
135 |
return lock.LogicalLockResult(self.unlock) |
|
136 |
||
|
0.200.1476
by Jelmer Vernooij
Cope with working tree refactoring. |
137 |
def lock_write(self, token=None): |
138 |
if not self._lock_mode: |
|
139 |
self._lock_mode = 'w' |
|
140 |
self._lock_count = 1 |
|
|
0.200.1525
by Jelmer Vernooij
Make sure to always use an up-to-date index. |
141 |
self.index.read() |
|
0.200.1476
by Jelmer Vernooij
Cope with working tree refactoring. |
142 |
elif self._lock_mode == 'r': |
143 |
raise errors.ReadOnlyError(self) |
|
144 |
else: |
|
145 |
self._lock_count +=1 |
|
146 |
self.branch.lock_write() |
|
147 |
return lock.LogicalLockResult(self.unlock) |
|
148 |
||
149 |
def is_locked(self): |
|
150 |
return self._lock_count >= 1 |
|
151 |
||
152 |
def get_physical_lock_status(self): |
|
153 |
return False |
|
154 |
||
155 |
def unlock(self): |
|
156 |
if not self._lock_count: |
|
157 |
return lock.cant_unlock_not_held(self) |
|
|
0.200.1530
by Jelmer Vernooij
Fix lock order. |
158 |
self.branch.unlock() |
|
0.200.1476
by Jelmer Vernooij
Cope with working tree refactoring. |
159 |
self._cleanup() |
160 |
self._lock_count -= 1 |
|
161 |
if self._lock_count > 0: |
|
162 |
return
|
|
163 |
self._lock_mode = None |
|
|
0.200.173
by Jelmer Vernooij
Merge changes, open index. |
164 |
|
|
0.200.1658
by Jelmer Vernooij
Fix handling of ignores - return patterns that matched. |
165 |
def _cleanup(self): |
166 |
pass
|
|
167 |
||
|
0.200.1322
by Jelmer Vernooij
Add case detection. |
168 |
def _detect_case_handling(self): |
169 |
try: |
|
170 |
self._transport.stat(".git/cOnFiG") |
|
171 |
except errors.NoSuchFile: |
|
172 |
self.case_sensitive = True |
|
173 |
else: |
|
174 |
self.case_sensitive = False |
|
175 |
||
|
0.200.1315
by Jelmer Vernooij
Implement WorkingTree.merge_modified. |
176 |
def merge_modified(self): |
177 |
return {} |
|
178 |
||
|
0.200.1696
by Jelmer Vernooij
Fix set_merge_modified. |
179 |
def set_merge_modified(self, modified_hashes): |
|
0.200.1690
by Jelmer Vernooij
Implement WorkingTree.set_merge_modified. |
180 |
# TODO(jelmer)
|
181 |
pass
|
|
182 |
||
|
0.200.1220
by Jelmer Vernooij
Support set_parent_trees. |
183 |
def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False): |
184 |
self.set_parent_ids([p for p, t in parents_list]) |
|
185 |
||
|
0.200.1599
by Jelmer Vernooij
Implement GitWorkingTree.iter_children. |
186 |
def iter_children(self, file_id): |
187 |
dpath = self.id2path(file_id) + "/" |
|
188 |
if dpath in self.index: |
|
189 |
return
|
|
190 |
for path in self.index: |
|
191 |
if not path.startswith(dpath): |
|
192 |
continue
|
|
193 |
if "/" in path[len(dpath):]: |
|
194 |
# Not a direct child but something further down
|
|
195 |
continue
|
|
196 |
yield self.path2id(path) |
|
197 |
||
|
0.200.1663
by Jelmer Vernooij
Raise SettingFileIdUnsupported |
198 |
def _index_add_entry(self, path, kind): |
|
0.200.1525
by Jelmer Vernooij
Make sure to always use an up-to-date index. |
199 |
assert self._lock_mode is not None |
|
0.200.1206
by Jelmer Vernooij
Implement GitWorkingTree.all_file_ids. |
200 |
assert isinstance(path, basestring) |
|
0.264.2
by Jelmer Vernooij
Implement GitWorkingTree.{_add,__iter__,id2path}. |
201 |
if kind == "directory": |
202 |
# Git indexes don't contain directories
|
|
203 |
return
|
|
204 |
if kind == "file": |
|
205 |
blob = Blob() |
|
206 |
try: |
|
|
0.285.1
by Jelmer Vernooij
Swap arguments for tree methods. |
207 |
file, stat_val = self.get_file_with_stat(path) |
|
0.264.2
by Jelmer Vernooij
Implement GitWorkingTree.{_add,__iter__,id2path}. |
208 |
except (errors.NoSuchFile, IOError): |
209 |
# TODO: Rather than come up with something here, use the old index
|
|
210 |
file = StringIO() |
|
|
0.265.1
by Martin
Don't import posix module, the os wrapper exists for portability |
211 |
stat_val = os.stat_result( |
212 |
(stat.S_IFREG | 0644, 0, 0, 0, 0, 0, 0, 0, 0, 0)) |
|
|
0.264.2
by Jelmer Vernooij
Implement GitWorkingTree.{_add,__iter__,id2path}. |
213 |
blob.set_raw_string(file.read()) |
214 |
elif kind == "symlink": |
|
215 |
blob = Blob() |
|
216 |
try: |
|
217 |
stat_val = os.lstat(self.abspath(path)) |
|
218 |
except (errors.NoSuchFile, OSError): |
|
|
0.200.1636
by Jelmer Vernooij
Some formatting fixes. |
219 |
# TODO: Rather than come up with something here, use the
|
|
0.264.2
by Jelmer Vernooij
Implement GitWorkingTree.{_add,__iter__,id2path}. |
220 |
# old index
|
|
0.265.1
by Martin
Don't import posix module, the os wrapper exists for portability |
221 |
stat_val = os.stat_result( |
222 |
(stat.S_IFLNK, 0, 0, 0, 0, 0, 0, 0, 0, 0)) |
|
|
0.200.1321
by Jelmer Vernooij
More fixes for compatibility with bzr.dev testsuite. |
223 |
blob.set_raw_string( |
|
0.285.1
by Jelmer Vernooij
Swap arguments for tree methods. |
224 |
self.get_symlink_target(path).encode("utf-8")) |
|
0.264.2
by Jelmer Vernooij
Implement GitWorkingTree.{_add,__iter__,id2path}. |
225 |
else: |
226 |
raise AssertionError("unknown kind '%s'" % kind) |
|
227 |
# Add object to the repository if it didn't exist yet
|
|
|
0.200.1205
by Jelmer Vernooij
Implement GitWorkingTree.stored_kind. |
228 |
if not blob.id in self.store: |
229 |
self.store.add_object(blob) |
|
|
0.264.2
by Jelmer Vernooij
Implement GitWorkingTree.{_add,__iter__,id2path}. |
230 |
# Add an entry to the index or update the existing entry
|
231 |
flags = 0 # FIXME |
|
|
0.200.1242
by Jelmer Vernooij
Support directories better. |
232 |
encoded_path = path.encode("utf-8") |
|
0.200.1531
by Jelmer Vernooij
Don't trust index contents - verify against file timestamps. |
233 |
self.index[encoded_path] = index_entry_from_stat( |
234 |
stat_val, blob.id, flags) |
|
|
0.200.1242
by Jelmer Vernooij
Support directories better. |
235 |
if self._versioned_dirs is not None: |
236 |
self._ensure_versioned_dir(encoded_path) |
|
237 |
||
238 |
def _ensure_versioned_dir(self, dirname): |
|
|
0.200.1249
by Jelmer Vernooij
Fix file id for tree root |
239 |
if dirname in self._versioned_dirs: |
|
0.200.1242
by Jelmer Vernooij
Support directories better. |
240 |
return
|
|
0.200.1249
by Jelmer Vernooij
Fix file id for tree root |
241 |
if dirname != "": |
242 |
self._ensure_versioned_dir(posixpath.dirname(dirname)) |
|
|
0.200.1242
by Jelmer Vernooij
Support directories better. |
243 |
self._versioned_dirs.add(dirname) |
244 |
||
245 |
def _load_dirs(self): |
|
|
0.200.1525
by Jelmer Vernooij
Make sure to always use an up-to-date index. |
246 |
assert self._lock_mode is not None |
|
0.200.1242
by Jelmer Vernooij
Support directories better. |
247 |
self._versioned_dirs = set() |
248 |
for p in self.index: |
|
249 |
self._ensure_versioned_dir(posixpath.dirname(p)) |
|
|
0.264.2
by Jelmer Vernooij
Implement GitWorkingTree.{_add,__iter__,id2path}. |
250 |
|
|
0.200.1215
by Jelmer Vernooij
Implement GitWorkingTree.remove. |
251 |
def _unversion_path(self, path): |
|
0.200.1525
by Jelmer Vernooij
Make sure to always use an up-to-date index. |
252 |
assert self._lock_mode is not None |
|
0.200.1215
by Jelmer Vernooij
Implement GitWorkingTree.remove. |
253 |
encoded_path = path.encode("utf-8") |
254 |
try: |
|
255 |
del self.index[encoded_path] |
|
256 |
except KeyError: |
|
257 |
# A directory, perhaps?
|
|
258 |
for p in list(self.index): |
|
|
0.200.1692
by Jelmer Vernooij
Mark three more tests as xfail. |
259 |
if p.startswith(encoded_path+b"/"): |
|
0.200.1215
by Jelmer Vernooij
Implement GitWorkingTree.remove. |
260 |
del self.index[p] |
|
0.200.1242
by Jelmer Vernooij
Support directories better. |
261 |
# FIXME: remove empty directories
|
|
0.200.1215
by Jelmer Vernooij
Implement GitWorkingTree.remove. |
262 |
|
|
0.285.8
by Jelmer Vernooij
Fix more tests for swapped arguments. |
263 |
def unversion(self, paths, file_ids=None): |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
264 |
with self.lock_tree_write(): |
|
0.200.1690
by Jelmer Vernooij
Implement WorkingTree.set_merge_modified. |
265 |
for path in paths: |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
266 |
self._unversion_path(path) |
267 |
self.flush() |
|
|
0.200.1215
by Jelmer Vernooij
Implement GitWorkingTree.remove. |
268 |
|
|
0.200.1678
by Jelmer Vernooij
Fix tests. |
269 |
def update_basis_by_delta(self, revid, delta): |
270 |
# TODO(jelmer): This shouldn't be called, it's inventory specific.
|
|
271 |
pass
|
|
272 |
||
|
0.200.1243
by Jelmer Vernooij
Implement WorkingTree.check_state. |
273 |
def check_state(self): |
274 |
"""Check that the working state is/isn't valid.""" |
|
275 |
pass
|
|
276 |
||
|
0.200.1215
by Jelmer Vernooij
Implement GitWorkingTree.remove. |
277 |
def remove(self, files, verbose=False, to_file=None, keep_files=True, |
278 |
force=False): |
|
279 |
"""Remove nominated files from the working tree metadata. |
|
280 |
||
281 |
:param files: File paths relative to the basedir.
|
|
282 |
:param keep_files: If true, the files will also be kept.
|
|
283 |
:param force: Delete files and directories, even if they are changed
|
|
284 |
and even if the directories are not empty.
|
|
285 |
"""
|
|
|
0.200.1636
by Jelmer Vernooij
Some formatting fixes. |
286 |
all_files = set() # specified and nested files |
|
0.200.1215
by Jelmer Vernooij
Implement GitWorkingTree.remove. |
287 |
|
288 |
if isinstance(files, basestring): |
|
289 |
files = [files] |
|
290 |
||
291 |
if to_file is None: |
|
292 |
to_file = sys.stdout |
|
293 |
||
294 |
files = list(all_files) |
|
295 |
||
296 |
if len(files) == 0: |
|
297 |
return # nothing to do |
|
298 |
||
299 |
# Sort needed to first handle directory content before the directory
|
|
300 |
files.sort(reverse=True) |
|
301 |
||
302 |
def backup(file_to_backup): |
|
303 |
abs_path = self.abspath(file_to_backup) |
|
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
304 |
backup_name = self.controldir._available_backup_name(file_to_backup) |
|
0.200.1215
by Jelmer Vernooij
Implement GitWorkingTree.remove. |
305 |
osutils.rename(abs_path, self.abspath(backup_name)) |
306 |
return "removed %s (but kept a copy: %s)" % ( |
|
307 |
file_to_backup, backup_name) |
|
308 |
||
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
309 |
with self.lock_tree_write(): |
310 |
for f in files: |
|
311 |
fid = self.path2id(f) |
|
312 |
if not fid: |
|
313 |
message = "%s is not versioned." % (f,) |
|
314 |
else: |
|
315 |
abs_path = self.abspath(f) |
|
316 |
if verbose: |
|
317 |
# having removed it, it must be either ignored or unknown
|
|
318 |
if self.is_ignored(f): |
|
319 |
new_status = 'I' |
|
320 |
else: |
|
321 |
new_status = '?' |
|
322 |
# XXX: Really should be a more abstract reporter interface
|
|
323 |
kind_ch = osutils.kind_marker(self.kind(fid)) |
|
324 |
to_file.write(new_status + ' ' + f + kind_ch + '\n') |
|
325 |
# Unversion file
|
|
326 |
# FIXME: _unversion_path() is O(size-of-index) for directories
|
|
327 |
self._unversion_path(f) |
|
328 |
message = "removed %s" % (f,) |
|
329 |
if osutils.lexists(abs_path): |
|
330 |
if (osutils.isdir(abs_path) and |
|
331 |
len(os.listdir(abs_path)) > 0): |
|
332 |
if force: |
|
333 |
osutils.rmtree(abs_path) |
|
334 |
message = "deleted %s" % (f,) |
|
335 |
else: |
|
336 |
message = backup(f) |
|
337 |
else: |
|
338 |
if not keep_files: |
|
339 |
osutils.delete_any(abs_path) |
|
340 |
message = "deleted %s" % (f,) |
|
|
0.200.1215
by Jelmer Vernooij
Implement GitWorkingTree.remove. |
341 |
|
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
342 |
# print only one message (if any) per file.
|
343 |
if message is not None: |
|
344 |
trace.note(message) |
|
345 |
self.flush() |
|
|
0.200.1192
by Jelmer Vernooij
Implement path2id. |
346 |
|
|
0.264.2
by Jelmer Vernooij
Implement GitWorkingTree.{_add,__iter__,id2path}. |
347 |
def _add(self, files, ids, kinds): |
348 |
for (path, file_id, kind) in zip(files, ids, kinds): |
|
|
0.200.1201
by Jelmer Vernooij
Implement _set_root_id. |
349 |
if file_id is not None: |
|
0.200.1663
by Jelmer Vernooij
Raise SettingFileIdUnsupported |
350 |
raise workingtree.SettingFileIdUnsupported() |
351 |
self._index_add_entry(path, kind) |
|
|
0.200.1201
by Jelmer Vernooij
Implement _set_root_id. |
352 |
|
|
0.200.1240
by Jelmer Vernooij
Implement GitWorkingTree.smart_add. |
353 |
def smart_add(self, file_list, recurse=True, action=None, save=True): |
354 |
added = [] |
|
355 |
ignored = {} |
|
356 |
user_dirs = [] |
|
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
357 |
with self.lock_tree_write(): |
358 |
for filepath in osutils.canonical_relpaths(self.basedir, file_list): |
|
359 |
abspath = self.abspath(filepath) |
|
|
0.200.1240
by Jelmer Vernooij
Implement GitWorkingTree.smart_add. |
360 |
kind = osutils.file_kind(abspath) |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
361 |
if action is not None: |
362 |
file_id = action(self, None, filepath, kind) |
|
|
0.200.1240
by Jelmer Vernooij
Implement GitWorkingTree.smart_add. |
363 |
else: |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
364 |
file_id = None |
365 |
if kind in ("file", "symlink"): |
|
|
0.200.1308
by Jelmer Vernooij
Write index to disk after adding files. |
366 |
if save: |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
367 |
self._index_add_entry(filepath, kind) |
368 |
added.append(filepath) |
|
369 |
elif kind == "directory": |
|
370 |
if recurse: |
|
371 |
user_dirs.append(filepath) |
|
372 |
else: |
|
373 |
raise errors.BadFileKindError(filename=abspath, kind=kind) |
|
374 |
for user_dir in user_dirs: |
|
375 |
abs_user_dir = self.abspath(user_dir) |
|
376 |
for name in os.listdir(abs_user_dir): |
|
377 |
subp = os.path.join(user_dir, name) |
|
378 |
if self.is_control_filename(subp) or self.mapping.is_special_file(subp): |
|
379 |
continue
|
|
380 |
ignore_glob = self.is_ignored(subp) |
|
381 |
if ignore_glob is not None: |
|
382 |
ignored.setdefault(ignore_glob, []).append(subp) |
|
383 |
continue
|
|
384 |
abspath = self.abspath(subp) |
|
385 |
kind = osutils.file_kind(abspath) |
|
386 |
if kind == "directory": |
|
387 |
user_dirs.append(subp) |
|
388 |
else: |
|
389 |
if action is not None: |
|
390 |
file_id = action(self, None, filepath, kind) |
|
391 |
else: |
|
392 |
file_id = None |
|
393 |
if save: |
|
394 |
self._index_add_entry(subp, kind) |
|
395 |
if added and save: |
|
396 |
self.flush() |
|
397 |
return added, ignored |
|
|
0.200.1240
by Jelmer Vernooij
Implement GitWorkingTree.smart_add. |
398 |
|
|
0.200.1201
by Jelmer Vernooij
Implement _set_root_id. |
399 |
def _set_root_id(self, file_id): |
400 |
self._fileid_map.set_file_id("", file_id) |
|
|
0.264.2
by Jelmer Vernooij
Implement GitWorkingTree.{_add,__iter__,id2path}. |
401 |
|
|
0.200.1193
by Jelmer Vernooij
Implement GitWorkingTree.{move,rename_one}. |
402 |
def move(self, from_paths, to_dir=None, after=False): |
403 |
rename_tuples = [] |
|
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
404 |
with self.lock_tree_write(): |
405 |
to_abs = self.abspath(to_dir) |
|
406 |
if not os.path.isdir(to_abs): |
|
407 |
raise errors.BzrMoveFailedError('', to_dir, |
|
408 |
errors.NotADirectory(to_abs)) |
|
409 |
||
410 |
for from_rel in from_paths: |
|
411 |
from_tail = os.path.split(from_rel)[-1] |
|
412 |
to_rel = os.path.join(to_dir, from_tail) |
|
413 |
self.rename_one(from_rel, to_rel, after=after) |
|
414 |
rename_tuples.append((from_rel, to_rel)) |
|
415 |
self.flush() |
|
416 |
return rename_tuples |
|
417 |
||
|
0.200.1193
by Jelmer Vernooij
Implement GitWorkingTree.{move,rename_one}. |
418 |
def rename_one(self, from_rel, to_rel, after=False): |
|
0.200.1203
by Jelmer Vernooij
Fix per_workingtree.test_rename_one.TestRenameOne.test_rename_after_non_existant_non_ascii |
419 |
from_path = from_rel.encode("utf-8") |
420 |
to_path = to_rel.encode("utf-8") |
|
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
421 |
with self.lock_tree_write(): |
422 |
if not self.has_filename(to_rel): |
|
423 |
raise errors.BzrMoveFailedError(from_rel, to_rel, |
|
424 |
errors.NoSuchFile(to_rel)) |
|
425 |
if not from_path in self.index: |
|
426 |
raise errors.BzrMoveFailedError(from_rel, to_rel, |
|
427 |
errors.NotVersionedError(path=from_rel)) |
|
428 |
if not after: |
|
429 |
os.rename(self.abspath(from_rel), self.abspath(to_rel)) |
|
430 |
self.index[to_path] = self.index[from_path] |
|
431 |
del self.index[from_path] |
|
432 |
self.flush() |
|
|
0.200.1193
by Jelmer Vernooij
Implement GitWorkingTree.{move,rename_one}. |
433 |
|
|
0.264.1
by Jelmer Vernooij
Provide stubs using inventory for the moment.: |
434 |
def get_root_id(self): |
|
0.200.1192
by Jelmer Vernooij
Implement path2id. |
435 |
return self.path2id("") |
436 |
||
|
0.200.1242
by Jelmer Vernooij
Support directories better. |
437 |
def _has_dir(self, path): |
|
0.200.1368
by Jelmer Vernooij
There is always a tree root. |
438 |
if path == "": |
439 |
return True |
|
|
0.200.1242
by Jelmer Vernooij
Support directories better. |
440 |
if self._versioned_dirs is None: |
441 |
self._load_dirs() |
|
442 |
return path in self._versioned_dirs |
|
443 |
||
|
0.200.1192
by Jelmer Vernooij
Implement path2id. |
444 |
def path2id(self, path): |
|
0.200.1600
by Jelmer Vernooij
Cope with paths as lists of elements. |
445 |
if type(path) is list: |
446 |
path = u"/".join(path) |
|
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
447 |
with self.lock_read(): |
448 |
encoded_path = path.encode("utf-8") |
|
449 |
if self._is_versioned(encoded_path): |
|
450 |
return self._fileid_map.lookup_file_id(encoded_path) |
|
451 |
return None |
|
|
0.264.1
by Jelmer Vernooij
Provide stubs using inventory for the moment.: |
452 |
|
|
0.200.1328
by Jelmer Vernooij
More test fixes. |
453 |
def _iter_files_recursive(self, from_dir=None): |
454 |
if from_dir is None: |
|
455 |
from_dir = "" |
|
456 |
for (dirpath, dirnames, filenames) in os.walk(self.abspath(from_dir)): |
|
|
0.200.1302
by Jelmer Vernooij
Significantly improve performance of WorkingTree.extras(). |
457 |
dir_relpath = dirpath[len(self.basedir):].strip("/") |
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
458 |
if self.controldir.is_control_filename(dir_relpath): |
|
0.200.605
by Jelmer Vernooij
Ignore directories in WorkingTree.extras(). |
459 |
continue
|
|
0.200.615
by Jelmer Vernooij
Optimize WorkingTree.extras(). |
460 |
for filename in filenames: |
|
0.200.1328
by Jelmer Vernooij
More test fixes. |
461 |
if not self.mapping.is_special_file(filename): |
462 |
yield os.path.join(dir_relpath, filename) |
|
|
0.200.1327
by Jelmer Vernooij
Factor out all file browsing in extras. |
463 |
|
464 |
def extras(self): |
|
465 |
"""Yield all unversioned files in this WorkingTree. |
|
466 |
"""
|
|
|
0.200.1676
by Jelmer Vernooij
Fix typo. |
467 |
with self.lock_read(): |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
468 |
return set(self._iter_files_recursive()) - set(self.index) |
|
0.200.605
by Jelmer Vernooij
Ignore directories in WorkingTree.extras(). |
469 |
|
|
0.200.382
by Jelmer Vernooij
Support flushing index. |
470 |
def flush(self): |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
471 |
with self.lock_tree_write(): |
472 |
# TODO: Maybe this should only write on dirty ?
|
|
473 |
if self._lock_mode != 'w': |
|
474 |
raise errors.NotWriteLocked(self) |
|
475 |
self.index.write() |
|
|
0.200.382
by Jelmer Vernooij
Support flushing index. |
476 |
|
|
0.264.1
by Jelmer Vernooij
Provide stubs using inventory for the moment.: |
477 |
def __iter__(self): |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
478 |
with self.lock_read(): |
479 |
for path in self.index: |
|
480 |
yield self.path2id(path) |
|
481 |
self._load_dirs() |
|
482 |
for path in self._versioned_dirs: |
|
483 |
yield self.path2id(path) |
|
|
0.264.1
by Jelmer Vernooij
Provide stubs using inventory for the moment.: |
484 |
|
|
0.200.1202
by Jelmer Vernooij
Implement has_or_had_id. |
485 |
def has_or_had_id(self, file_id): |
486 |
if self.has_id(file_id): |
|
487 |
return True |
|
488 |
if self.had_id(file_id): |
|
489 |
return True |
|
490 |
return False |
|
491 |
||
492 |
def had_id(self, file_id): |
|
493 |
path = self._basis_fileid_map.lookup_file_id(file_id) |
|
494 |
try: |
|
495 |
head = self.repository._git.head() |
|
496 |
except KeyError: |
|
497 |
# Assume no if basis is not accessible
|
|
498 |
return False |
|
|
0.200.1205
by Jelmer Vernooij
Implement GitWorkingTree.stored_kind. |
499 |
if head == ZERO_SHA: |
500 |
return False |
|
|
0.200.1202
by Jelmer Vernooij
Implement has_or_had_id. |
501 |
root_tree = self.store[head].tree |
502 |
try: |
|
503 |
tree_lookup_path(self.store.__getitem__, root_tree, path) |
|
504 |
except KeyError: |
|
505 |
return False |
|
506 |
else: |
|
507 |
return True |
|
508 |
||
|
0.200.1198
by Jelmer Vernooij
Implement GitWorkingTree.has_id. |
509 |
def has_id(self, file_id): |
510 |
try: |
|
511 |
self.id2path(file_id) |
|
512 |
except errors.NoSuchId: |
|
513 |
return False |
|
514 |
else: |
|
515 |
return True |
|
516 |
||
|
0.264.1
by Jelmer Vernooij
Provide stubs using inventory for the moment.: |
517 |
def id2path(self, file_id): |
|
0.200.1532
by Jelmer Vernooij
Cope with float timestamps. |
518 |
assert type(file_id) is str, "file id not a string: %r" % file_id |
|
0.200.1411
by Jelmer Vernooij
Fix control files. |
519 |
file_id = osutils.safe_utf8(file_id) |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
520 |
with self.lock_read(): |
521 |
path = self._fileid_map.lookup_path(file_id) |
|
522 |
# FIXME: What about directories?
|
|
523 |
if self._is_versioned(path): |
|
524 |
return path.decode("utf-8") |
|
525 |
raise errors.NoSuchId(self, file_id) |
|
|
0.264.1
by Jelmer Vernooij
Provide stubs using inventory for the moment.: |
526 |
|
|
0.285.1
by Jelmer Vernooij
Swap arguments for tree methods. |
527 |
def get_file_mtime(self, path, file_id=None): |
|
0.200.1200
by Jelmer Vernooij
Support GitWorkingTree.get_file_mtime. |
528 |
"""See Tree.get_file_mtime.""" |
|
0.285.1
by Jelmer Vernooij
Swap arguments for tree methods. |
529 |
try: |
530 |
return os.lstat(self.abspath(path)).st_mtime |
|
531 |
except OSError, (num, msg): |
|
532 |
if num == errno.ENOENT: |
|
533 |
raise errors.NoSuchFile(path) |
|
534 |
raise
|
|
|
0.200.1200
by Jelmer Vernooij
Support GitWorkingTree.get_file_mtime. |
535 |
|
|
0.200.1655
by Jelmer Vernooij
Basic support for git ignores. |
536 |
def is_ignored(self, filename): |
537 |
r"""Check whether the filename matches an ignore pattern. |
|
538 |
||
539 |
If the file is ignored, returns the pattern which caused it to
|
|
540 |
be ignored, otherwise None. So this can simply be used as a
|
|
541 |
boolean if desired."""
|
|
542 |
if getattr(self, '_global_ignoreglobster', None) is None: |
|
543 |
ignore_globs = set() |
|
544 |
ignore_globs.update(ignores.get_runtime_ignores()) |
|
545 |
ignore_globs.update(ignores.get_user_ignores()) |
|
546 |
self._global_ignoreglobster = globbing.ExceptionGlobster(ignore_globs) |
|
|
0.200.1656
by Jelmer Vernooij
Report proper patterns, ignore files. |
547 |
match = self._global_ignoreglobster.match(filename) |
548 |
if match is not None: |
|
549 |
return match |
|
|
0.200.1655
by Jelmer Vernooij
Basic support for git ignores. |
550 |
if osutils.file_kind(self.abspath(filename)) == 'directory': |
551 |
filename += b'/' |
|
|
0.200.1658
by Jelmer Vernooij
Fix handling of ignores - return patterns that matched. |
552 |
ignore_manager = self._get_ignore_manager() |
553 |
ps = list(ignore_manager.find_matching(filename)) |
|
554 |
if not ps: |
|
555 |
return None |
|
556 |
if not ps[-1].is_exclude: |
|
557 |
return None |
|
558 |
return bytes(ps[-1]) |
|
559 |
||
560 |
def _get_ignore_manager(self): |
|
561 |
ignoremanager = getattr(self, '_ignoremanager', None) |
|
562 |
if ignoremanager is not None: |
|
563 |
return ignoremanager |
|
564 |
||
565 |
ignore_manager = IgnoreFilterManager.from_repo(self.repository._git) |
|
566 |
self._ignoremanager = ignore_manager |
|
567 |
return ignore_manager |
|
|
0.200.409
by Jelmer Vernooij
Support parsing .gitignore. |
568 |
|
|
0.200.508
by Jelmer Vernooij
Skip inventory caching bits. |
569 |
def set_last_revision(self, revid): |
570 |
self._change_last_revision(revid) |
|
571 |
||
|
0.200.379
by Jelmer Vernooij
Re-enable working tree support. |
572 |
def _reset_data(self): |
|
0.248.3
by Jelmer Vernooij
Handle working trees without valid HEAD branch. |
573 |
try: |
574 |
head = self.repository._git.head() |
|
575 |
except KeyError, name: |
|
|
0.200.1308
by Jelmer Vernooij
Write index to disk after adding files. |
576 |
raise errors.NotBranchError("branch %s at %s" % (name, |
577 |
self.repository.base)) |
|
|
0.200.948
by Jelmer Vernooij
Cope with empty inventories. |
578 |
if head == ZERO_SHA: |
|
0.200.1202
by Jelmer Vernooij
Implement has_or_had_id. |
579 |
self._basis_fileid_map = GitFileIdMap({}, self.mapping) |
|
0.200.948
by Jelmer Vernooij
Cope with empty inventories. |
580 |
else: |
|
0.200.1308
by Jelmer Vernooij
Write index to disk after adding files. |
581 |
self._basis_fileid_map = self.mapping.get_fileid_map( |
582 |
self.store.__getitem__, self.store[head].tree) |
|
|
0.200.379
by Jelmer Vernooij
Re-enable working tree support. |
583 |
|
|
0.285.1
by Jelmer Vernooij
Swap arguments for tree methods. |
584 |
def get_file_verifier(self, path, file_id=None, stat_value=None): |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
585 |
with self.lock_read(): |
586 |
try: |
|
587 |
return ("GIT", self.index[path][-2]) |
|
588 |
except KeyError: |
|
589 |
if self._has_dir(path): |
|
590 |
return ("GIT", None) |
|
|
0.285.1
by Jelmer Vernooij
Swap arguments for tree methods. |
591 |
raise errors.NoSuchFile(path) |
|
0.200.1302
by Jelmer Vernooij
Significantly improve performance of WorkingTree.extras(). |
592 |
|
|
0.285.1
by Jelmer Vernooij
Swap arguments for tree methods. |
593 |
def get_file_sha1(self, path, file_id=None, stat_value=None): |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
594 |
with self.lock_read(): |
595 |
abspath = self.abspath(path).encode(osutils._fs_enc) |
|
596 |
try: |
|
597 |
return osutils.sha_file_by_name(abspath) |
|
598 |
except OSError, (num, msg): |
|
599 |
if num in (errno.EISDIR, errno.ENOENT): |
|
600 |
return None |
|
601 |
raise
|
|
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
602 |
|
|
0.200.610
by Jelmer Vernooij
Support retrieving basis tree properly. |
603 |
def revision_tree(self, revid): |
604 |
return self.repository.revision_tree(revid) |
|
605 |
||
|
0.200.1242
by Jelmer Vernooij
Support directories better. |
606 |
def _is_versioned(self, path): |
|
0.200.1525
by Jelmer Vernooij
Make sure to always use an up-to-date index. |
607 |
assert self._lock_mode is not None |
|
0.200.1242
by Jelmer Vernooij
Support directories better. |
608 |
return (path in self.index or self._has_dir(path)) |
609 |
||
|
0.200.1239
by Jelmer Vernooij
Implement GitWorkingTree.filter_unversioned_files. |
610 |
def filter_unversioned_files(self, files): |
|
0.200.1316
by Jelmer Vernooij
Fix filter_unversioned_files. |
611 |
return set([p for p in files if not self._is_versioned(p.encode("utf-8"))]) |
|
0.200.1239
by Jelmer Vernooij
Implement GitWorkingTree.filter_unversioned_files. |
612 |
|
|
0.264.11
by Jelmer Vernooij
Completer implementation of iter_entries_by_dir and list_files. |
613 |
def _get_dir_ie(self, path, parent_id): |
|
0.200.1192
by Jelmer Vernooij
Implement path2id. |
614 |
file_id = self.path2id(path) |
|
0.264.11
by Jelmer Vernooij
Completer implementation of iter_entries_by_dir and list_files. |
615 |
return inventory.InventoryDirectory(file_id, |
|
0.200.1190
by Jelmer Vernooij
Fix get_symlink_target call. |
616 |
posixpath.basename(path).strip("/"), parent_id) |
|
0.264.11
by Jelmer Vernooij
Completer implementation of iter_entries_by_dir and list_files. |
617 |
|
618 |
def _add_missing_parent_ids(self, path, dir_ids): |
|
619 |
if path in dir_ids: |
|
620 |
return [] |
|
621 |
parent = posixpath.dirname(path).strip("/") |
|
622 |
ret = self._add_missing_parent_ids(parent, dir_ids) |
|
623 |
parent_id = dir_ids[parent] |
|
624 |
ie = self._get_dir_ie(path, parent_id) |
|
625 |
dir_ids[path] = ie.file_id |
|
626 |
ret.append((path, ie)) |
|
627 |
return ret |
|
628 |
||
|
0.200.1321
by Jelmer Vernooij
More fixes for compatibility with bzr.dev testsuite. |
629 |
def _get_file_ie(self, name, path, value, parent_id): |
630 |
assert isinstance(name, unicode) |
|
|
0.200.1192
by Jelmer Vernooij
Implement path2id. |
631 |
assert isinstance(path, unicode) |
|
0.264.10
by Jelmer Vernooij
Yield inventory entries. |
632 |
assert isinstance(value, tuple) and len(value) == 10 |
633 |
(ctime, mtime, dev, ino, mode, uid, gid, size, sha, flags) = value |
|
|
0.200.1192
by Jelmer Vernooij
Implement path2id. |
634 |
file_id = self.path2id(path) |
|
0.264.10
by Jelmer Vernooij
Yield inventory entries. |
635 |
if type(file_id) != str: |
636 |
raise AssertionError |
|
637 |
kind = mode_kind(mode) |
|
|
0.200.1321
by Jelmer Vernooij
More fixes for compatibility with bzr.dev testsuite. |
638 |
ie = inventory.entry_factory[kind](file_id, name, parent_id) |
|
0.264.10
by Jelmer Vernooij
Yield inventory entries. |
639 |
if kind == 'symlink': |
|
0.285.1
by Jelmer Vernooij
Swap arguments for tree methods. |
640 |
ie.symlink_target = self.get_symlink_target(path, file_id) |
|
0.264.10
by Jelmer Vernooij
Yield inventory entries. |
641 |
else: |
|
0.285.1
by Jelmer Vernooij
Swap arguments for tree methods. |
642 |
data = self.get_file_text(path, file_id) |
|
0.264.10
by Jelmer Vernooij
Yield inventory entries. |
643 |
ie.text_sha1 = osutils.sha_string(data) |
644 |
ie.text_size = len(data) |
|
|
0.285.1
by Jelmer Vernooij
Swap arguments for tree methods. |
645 |
ie.executable = self.is_executable(path, file_id) |
|
0.264.10
by Jelmer Vernooij
Yield inventory entries. |
646 |
ie.revision = None |
647 |
return ie |
|
648 |
||
|
0.264.11
by Jelmer Vernooij
Completer implementation of iter_entries_by_dir and list_files. |
649 |
def _is_executable_from_path_and_stat_from_stat(self, path, stat_result): |
650 |
mode = stat_result.st_mode |
|
651 |
return bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode) |
|
652 |
||
|
0.285.1
by Jelmer Vernooij
Swap arguments for tree methods. |
653 |
def stored_kind(self, path, file_id=None): |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
654 |
with self.lock_read(): |
655 |
try: |
|
656 |
return mode_kind(self.index[path.encode("utf-8")][4]) |
|
657 |
except KeyError: |
|
658 |
# Maybe it's a directory?
|
|
659 |
if self._has_dir(path): |
|
660 |
return "directory" |
|
|
0.285.1
by Jelmer Vernooij
Swap arguments for tree methods. |
661 |
raise errors.NoSuchFile(path) |
|
0.200.1205
by Jelmer Vernooij
Implement GitWorkingTree.stored_kind. |
662 |
|
|
0.285.1
by Jelmer Vernooij
Swap arguments for tree methods. |
663 |
def is_executable(self, path, file_id=None): |
|
0.200.1539
by Jelmer Vernooij
Cope with new is_executable. |
664 |
if getattr(self, "_supports_executable", osutils.supports_executable)(): |
665 |
mode = os.lstat(self.abspath(path)).st_mode |
|
666 |
return bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode) |
|
667 |
else: |
|
|
0.264.11
by Jelmer Vernooij
Completer implementation of iter_entries_by_dir and list_files. |
668 |
basis_tree = self.basis_tree() |
669 |
if file_id in basis_tree: |
|
|
0.285.1
by Jelmer Vernooij
Swap arguments for tree methods. |
670 |
return basis_tree.is_executable(path, file_id) |
|
0.264.11
by Jelmer Vernooij
Completer implementation of iter_entries_by_dir and list_files. |
671 |
# Default to not executable
|
672 |
return False |
|
673 |
||
|
0.200.1539
by Jelmer Vernooij
Cope with new is_executable. |
674 |
def _is_executable_from_path_and_stat(self, path, stat_result): |
675 |
if getattr(self, "_supports_executable", osutils.supports_executable)(): |
|
676 |
return self._is_executable_from_path_and_stat_from_stat(path, stat_result) |
|
677 |
else: |
|
678 |
return self._is_executable_from_path_and_stat_from_basis(path, stat_result) |
|
|
0.264.11
by Jelmer Vernooij
Completer implementation of iter_entries_by_dir and list_files. |
679 |
|
|
0.264.10
by Jelmer Vernooij
Yield inventory entries. |
680 |
def list_files(self, include_root=False, from_dir=None, recursive=True): |
|
0.200.1321
by Jelmer Vernooij
More fixes for compatibility with bzr.dev testsuite. |
681 |
if from_dir is None: |
682 |
from_dir = "" |
|
|
0.264.11
by Jelmer Vernooij
Completer implementation of iter_entries_by_dir and list_files. |
683 |
dir_ids = {} |
|
0.200.1339
by Jelmer Vernooij
Some reformatting. |
684 |
fk_entries = {'directory': workingtree.TreeDirectory, |
685 |
'file': workingtree.TreeFile, |
|
686 |
'symlink': workingtree.TreeLink} |
|
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
687 |
with self.lock_read(): |
688 |
root_ie = self._get_dir_ie(u"", None) |
|
689 |
if include_root and not from_dir: |
|
690 |
yield "", "V", root_ie.kind, root_ie.file_id, root_ie |
|
691 |
dir_ids[u""] = root_ie.file_id |
|
692 |
if recursive: |
|
693 |
path_iterator = self._iter_files_recursive(from_dir) |
|
694 |
else: |
|
695 |
if from_dir is None: |
|
696 |
start = self.basedir |
|
697 |
else: |
|
698 |
start = os.path.join(self.basedir, from_dir) |
|
699 |
path_iterator = sorted([os.path.join(from_dir, name) for name in |
|
700 |
os.listdir(start) if not self.controldir.is_control_filename(name) |
|
701 |
and not self.mapping.is_special_file(name)]) |
|
702 |
for path in path_iterator: |
|
703 |
try: |
|
704 |
value = self.index[path] |
|
705 |
except KeyError: |
|
706 |
value = None |
|
707 |
path = path.decode("utf-8") |
|
708 |
parent, name = posixpath.split(path) |
|
709 |
for dir_path, dir_ie in self._add_missing_parent_ids(parent, dir_ids): |
|
710 |
yield dir_path, "V", dir_ie.kind, dir_ie.file_id, dir_ie |
|
711 |
if value is not None: |
|
712 |
ie = self._get_file_ie(name, path, value, dir_ids[parent]) |
|
713 |
yield path, "V", ie.kind, ie.file_id, ie |
|
714 |
else: |
|
715 |
kind = osutils.file_kind(self.abspath(path)) |
|
716 |
ie = fk_entries[kind]() |
|
717 |
yield path, ("I" if self.is_ignored(path) else "?"), kind, None, ie |
|
|
0.264.10
by Jelmer Vernooij
Yield inventory entries. |
718 |
|
|
0.200.1206
by Jelmer Vernooij
Implement GitWorkingTree.all_file_ids. |
719 |
def all_file_ids(self): |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
720 |
with self.lock_read(): |
721 |
ids = {u"": self.path2id("")} |
|
722 |
for path in self.index: |
|
723 |
if self.mapping.is_special_file(path): |
|
724 |
continue
|
|
725 |
path = path.decode("utf-8") |
|
726 |
parent = posixpath.dirname(path).strip("/") |
|
727 |
for e in self._add_missing_parent_ids(parent, ids): |
|
728 |
pass
|
|
729 |
ids[path] = self.path2id(path) |
|
730 |
return set(ids.values()) |
|
|
0.200.1206
by Jelmer Vernooij
Implement GitWorkingTree.all_file_ids. |
731 |
|
|
0.200.1374
by Jelmer Vernooij
Implement GitWorkingTree._directory_is_tree_reference. |
732 |
def _directory_is_tree_reference(self, path): |
733 |
# FIXME: Check .gitsubmodules for path
|
|
734 |
return False |
|
735 |
||
|
0.264.9
by Jelmer Vernooij
Implement basic GitWorkingTree.iter_entries_by_dir. |
736 |
def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False): |
737 |
# FIXME: Is return order correct?
|
|
|
0.200.1252
by Jelmer Vernooij
Support specific_file_ids in GitWorkingTree.iter_entries_by_dir. |
738 |
if yield_parents: |
739 |
raise NotImplementedError(self.iter_entries_by_dir) |
|
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
740 |
with self.lock_read(): |
741 |
if specific_file_ids is not None: |
|
742 |
specific_paths = [ |
|
743 |
self.id2path(file_id) for file_id in specific_file_ids] |
|
744 |
if specific_paths in ([u""], []): |
|
745 |
specific_paths = None |
|
746 |
else: |
|
747 |
specific_paths = set(specific_paths) |
|
748 |
else: |
|
|
0.200.1252
by Jelmer Vernooij
Support specific_file_ids in GitWorkingTree.iter_entries_by_dir. |
749 |
specific_paths = None |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
750 |
root_ie = self._get_dir_ie(u"", None) |
751 |
if specific_paths is None: |
|
752 |
yield u"", root_ie |
|
753 |
dir_ids = {u"": root_ie.file_id} |
|
754 |
for path, value in self.index.iteritems(): |
|
755 |
if self.mapping.is_special_file(path): |
|
756 |
continue
|
|
757 |
path = path.decode("utf-8") |
|
758 |
if specific_paths is not None and not path in specific_paths: |
|
759 |
continue
|
|
760 |
(parent, name) = posixpath.split(path) |
|
761 |
try: |
|
762 |
file_ie = self._get_file_ie(name, path, value, None) |
|
763 |
except IOError: |
|
764 |
continue
|
|
765 |
for (dir_path, dir_ie) in self._add_missing_parent_ids(parent, |
|
766 |
dir_ids): |
|
767 |
yield dir_path, dir_ie |
|
768 |
file_ie.parent_id = self.path2id(parent) |
|
769 |
yield path, file_ie |
|
|
0.264.9
by Jelmer Vernooij
Implement basic GitWorkingTree.iter_entries_by_dir. |
770 |
|
|
0.200.619
by Jelmer Vernooij
Provide dummy WorkingTree.conflicts() implementation rather than spending a lot of time not finding any conflicts. |
771 |
def conflicts(self): |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
772 |
with self.lock_read(): |
773 |
# FIXME:
|
|
774 |
return _mod_conflicts.ConflictList() |
|
|
0.200.619
by Jelmer Vernooij
Provide dummy WorkingTree.conflicts() implementation rather than spending a lot of time not finding any conflicts. |
775 |
|
|
0.200.1328
by Jelmer Vernooij
More test fixes. |
776 |
def get_canonical_inventory_path(self, path): |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
777 |
with self.lock_read(): |
778 |
for p in self.index: |
|
779 |
if p.lower() == path.lower(): |
|
780 |
return p |
|
781 |
else: |
|
782 |
return path |
|
|
0.200.1328
by Jelmer Vernooij
More test fixes. |
783 |
|
|
0.200.1705
by Jelmer Vernooij
Fix walkdirs. |
784 |
def walkdirs(self, prefix=""): |
785 |
"""Walk the directories of this tree. |
|
786 |
||
787 |
returns a generator which yields items in the form:
|
|
788 |
((curren_directory_path, fileid),
|
|
789 |
[(file1_path, file1_name, file1_kind, (lstat), file1_id,
|
|
790 |
file1_kind), ... ])
|
|
791 |
||
792 |
This API returns a generator, which is only valid during the current
|
|
793 |
tree transaction - within a single lock_read or lock_write duration.
|
|
794 |
||
795 |
If the tree is not locked, it may cause an error to be raised,
|
|
796 |
depending on the tree implementation.
|
|
797 |
"""
|
|
798 |
disk_top = self.abspath(prefix) |
|
799 |
if disk_top.endswith('/'): |
|
800 |
disk_top = disk_top[:-1] |
|
801 |
top_strip_len = len(disk_top) + 1 |
|
802 |
inventory_iterator = self._walkdirs(prefix) |
|
803 |
disk_iterator = osutils.walkdirs(disk_top, prefix) |
|
804 |
try: |
|
805 |
current_disk = next(disk_iterator) |
|
806 |
disk_finished = False |
|
807 |
except OSError as e: |
|
808 |
if not (e.errno == errno.ENOENT or |
|
809 |
(sys.platform == 'win32' and e.errno == ERROR_PATH_NOT_FOUND)): |
|
810 |
raise
|
|
811 |
current_disk = None |
|
812 |
disk_finished = True |
|
813 |
try: |
|
814 |
current_inv = next(inventory_iterator) |
|
815 |
inv_finished = False |
|
816 |
except StopIteration: |
|
817 |
current_inv = None |
|
818 |
inv_finished = True |
|
819 |
while not inv_finished or not disk_finished: |
|
820 |
if current_disk: |
|
821 |
((cur_disk_dir_relpath, cur_disk_dir_path_from_top), |
|
822 |
cur_disk_dir_content) = current_disk |
|
823 |
else: |
|
824 |
((cur_disk_dir_relpath, cur_disk_dir_path_from_top), |
|
825 |
cur_disk_dir_content) = ((None, None), None) |
|
826 |
if not disk_finished: |
|
827 |
# strip out .bzr dirs
|
|
828 |
if (cur_disk_dir_path_from_top[top_strip_len:] == '' and |
|
829 |
len(cur_disk_dir_content) > 0): |
|
830 |
# osutils.walkdirs can be made nicer -
|
|
831 |
# yield the path-from-prefix rather than the pathjoined
|
|
832 |
# value.
|
|
833 |
bzrdir_loc = bisect_left(cur_disk_dir_content, |
|
834 |
('.bzr', '.bzr')) |
|
835 |
if (bzrdir_loc < len(cur_disk_dir_content) |
|
836 |
and self.controldir.is_control_filename( |
|
837 |
cur_disk_dir_content[bzrdir_loc][0])): |
|
838 |
# we dont yield the contents of, or, .bzr itself.
|
|
839 |
del cur_disk_dir_content[bzrdir_loc] |
|
840 |
if inv_finished: |
|
841 |
# everything is unknown
|
|
842 |
direction = 1 |
|
843 |
elif disk_finished: |
|
844 |
# everything is missing
|
|
845 |
direction = -1 |
|
846 |
else: |
|
847 |
direction = cmp(current_inv[0][0], cur_disk_dir_relpath) |
|
848 |
if direction > 0: |
|
849 |
# disk is before inventory - unknown
|
|
850 |
dirblock = [(relpath, basename, kind, stat, None, None) for |
|
851 |
relpath, basename, kind, stat, top_path in |
|
852 |
cur_disk_dir_content] |
|
853 |
yield (cur_disk_dir_relpath, None), dirblock |
|
854 |
try: |
|
855 |
current_disk = next(disk_iterator) |
|
856 |
except StopIteration: |
|
857 |
disk_finished = True |
|
858 |
elif direction < 0: |
|
859 |
# inventory is before disk - missing.
|
|
860 |
dirblock = [(relpath, basename, 'unknown', None, fileid, kind) |
|
861 |
for relpath, basename, dkind, stat, fileid, kind in |
|
862 |
current_inv[1]] |
|
863 |
yield (current_inv[0][0], current_inv[0][1]), dirblock |
|
864 |
try: |
|
865 |
current_inv = next(inventory_iterator) |
|
866 |
except StopIteration: |
|
867 |
inv_finished = True |
|
868 |
else: |
|
869 |
# versioned present directory
|
|
870 |
# merge the inventory and disk data together
|
|
871 |
dirblock = [] |
|
872 |
for relpath, subiterator in itertools.groupby(sorted( |
|
873 |
current_inv[1] + cur_disk_dir_content, |
|
874 |
key=operator.itemgetter(0)), operator.itemgetter(1)): |
|
875 |
path_elements = list(subiterator) |
|
876 |
if len(path_elements) == 2: |
|
877 |
inv_row, disk_row = path_elements |
|
878 |
# versioned, present file
|
|
879 |
dirblock.append((inv_row[0], |
|
880 |
inv_row[1], disk_row[2], |
|
881 |
disk_row[3], inv_row[4], |
|
882 |
inv_row[5])) |
|
883 |
elif len(path_elements[0]) == 5: |
|
884 |
# unknown disk file
|
|
885 |
dirblock.append((path_elements[0][0], |
|
886 |
path_elements[0][1], path_elements[0][2], |
|
887 |
path_elements[0][3], None, None)) |
|
888 |
elif len(path_elements[0]) == 6: |
|
889 |
# versioned, absent file.
|
|
890 |
dirblock.append((path_elements[0][0], |
|
891 |
path_elements[0][1], 'unknown', None, |
|
892 |
path_elements[0][4], path_elements[0][5])) |
|
893 |
else: |
|
894 |
raise NotImplementedError('unreachable code') |
|
895 |
yield current_inv[0], dirblock |
|
896 |
try: |
|
897 |
current_inv = next(inventory_iterator) |
|
898 |
except StopIteration: |
|
899 |
inv_finished = True |
|
900 |
try: |
|
901 |
current_disk = next(disk_iterator) |
|
902 |
except StopIteration: |
|
903 |
disk_finished = True |
|
904 |
||
905 |
def walkdirs(self, prefix=""): |
|
|
0.200.1210
by Jelmer Vernooij
Implement GitWorkingTree._walkdirs. |
906 |
if prefix != "": |
907 |
prefix += "/" |
|
908 |
per_dir = defaultdict(list) |
|
909 |
for path, value in self.index.iteritems(): |
|
|
0.200.1328
by Jelmer Vernooij
More test fixes. |
910 |
if self.mapping.is_special_file(path): |
911 |
continue
|
|
|
0.200.1210
by Jelmer Vernooij
Implement GitWorkingTree._walkdirs. |
912 |
if not path.startswith(prefix): |
913 |
continue
|
|
914 |
(dirname, child_name) = posixpath.split(path) |
|
915 |
dirname = dirname.decode("utf-8") |
|
916 |
dir_file_id = self.path2id(dirname) |
|
917 |
assert isinstance(value, tuple) and len(value) == 10 |
|
918 |
(ctime, mtime, dev, ino, mode, uid, gid, size, sha, flags) = value |
|
|
0.265.1
by Martin
Don't import posix module, the os wrapper exists for portability |
919 |
stat_result = os.stat_result((mode, ino, |
|
0.200.1211
by Jelmer Vernooij
Fix statresult. |
920 |
dev, 1, uid, gid, size, |
921 |
0, mtime, ctime)) |
|
|
0.200.1210
by Jelmer Vernooij
Implement GitWorkingTree._walkdirs. |
922 |
per_dir[(dirname, dir_file_id)].append( |
923 |
(path.decode("utf-8"), child_name.decode("utf-8"), |
|
924 |
mode_kind(mode), stat_result, |
|
925 |
self.path2id(path.decode("utf-8")), |
|
926 |
mode_kind(mode))) |
|
927 |
return per_dir.iteritems() |
|
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
928 |
|
|
0.200.1542
by Jelmer Vernooij
Refactor iter_changes. |
929 |
def _lookup_entry(self, path, update_index=False): |
|
0.200.1543
by Jelmer Vernooij
Support symlinks. |
930 |
assert type(path) == str |
|
0.200.1542
by Jelmer Vernooij
Refactor iter_changes. |
931 |
entry = self.index[path] |
932 |
index_mode = entry[-6] |
|
933 |
index_sha = entry[-2] |
|
934 |
disk_path = os.path.join(self.basedir, path) |
|
|
0.284.1
by Jelmer Vernooij
Raise KeyError when file was removed. |
935 |
try: |
936 |
disk_stat = os.lstat(disk_path) |
|
937 |
except OSError, (num, msg): |
|
938 |
if num in (errno.EISDIR, errno.ENOENT): |
|
939 |
raise KeyError(path) |
|
940 |
raise
|
|
|
0.200.1542
by Jelmer Vernooij
Refactor iter_changes. |
941 |
disk_mtime = disk_stat.st_mtime |
942 |
if isinstance(entry[1], tuple): |
|
943 |
index_mtime = entry[1][0] |
|
944 |
else: |
|
945 |
index_mtime = int(entry[1]) |
|
946 |
mtime_delta = (disk_mtime - index_mtime) |
|
947 |
disk_mode = cleanup_mode(disk_stat.st_mode) |
|
948 |
if mtime_delta > 0 or disk_mode != index_mode: |
|
949 |
if stat.S_ISDIR(disk_mode): |
|
950 |
try: |
|
951 |
subrepo = Repo(disk_path) |
|
952 |
except NotGitRepository: |
|
953 |
return (None, None) |
|
954 |
else: |
|
955 |
disk_mode = S_IFGITLINK |
|
956 |
git_id = subrepo.head() |
|
|
0.200.1543
by Jelmer Vernooij
Support symlinks. |
957 |
elif stat.S_ISLNK(disk_mode): |
|
0.200.1545
by Jelmer Vernooij
Some more test fixes. |
958 |
blob = Blob.from_string(os.readlink(disk_path).encode('utf-8')) |
|
0.200.1543
by Jelmer Vernooij
Support symlinks. |
959 |
git_id = blob.id |
960 |
elif stat.S_ISREG(disk_mode): |
|
|
0.200.1542
by Jelmer Vernooij
Refactor iter_changes. |
961 |
with open(disk_path, 'r') as f: |
962 |
blob = Blob.from_string(f.read()) |
|
963 |
git_id = blob.id |
|
|
0.200.1543
by Jelmer Vernooij
Support symlinks. |
964 |
else: |
965 |
raise AssertionError |
|
|
0.200.1542
by Jelmer Vernooij
Refactor iter_changes. |
966 |
if update_index: |
967 |
flags = 0 # FIXME |
|
|
0.200.1545
by Jelmer Vernooij
Some more test fixes. |
968 |
self.index[path] = index_entry_from_stat(disk_stat, git_id, flags, disk_mode) |
|
0.200.1542
by Jelmer Vernooij
Refactor iter_changes. |
969 |
return (git_id, disk_mode) |
970 |
return (index_sha, index_mode) |
|
971 |
||
|
0.200.1677
by Jelmer Vernooij
Mark shelving as unsupported. |
972 |
def get_shelf_manager(self): |
973 |
raise workingtree.ShelvingUnsupported(self) |
|
974 |
||
|
0.200.1678
by Jelmer Vernooij
Fix tests. |
975 |
def store_uncommitted(self): |
976 |
raise errors.StoringUncommittedNotSupported(self) |
|
977 |
||
|
0.200.1703
by Jelmer Vernooij
Implement apply_inventory_delta. |
978 |
def apply_inventory_delta(self, changes): |
979 |
for (old_path, new_path, file_id, ie) in changes: |
|
980 |
if old_path is not None: |
|
981 |
del self.index[old_path.encode('utf-8')] |
|
982 |
if new_path is not None and ie.kind != 'directory': |
|
983 |
self._index_add_entry(new_path, ie.kind) |
|
984 |
||
|
0.200.1308
by Jelmer Vernooij
Write index to disk after adding files. |
985 |
|
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
986 |
class GitWorkingTreeFormat(workingtree.WorkingTreeFormat): |
987 |
||
|
0.200.1206
by Jelmer Vernooij
Implement GitWorkingTree.all_file_ids. |
988 |
_tree_class = GitWorkingTree |
989 |
||
|
0.200.1295
by Jelmer Vernooij
Mark working trees as not supporting directories. |
990 |
supports_versioned_directories = False |
991 |
||
|
0.200.1661
by Jelmer Vernooij
Set supports_setting_file_ids to False. |
992 |
supports_setting_file_ids = False |
993 |
||
|
0.200.1677
by Jelmer Vernooij
Mark shelving as unsupported. |
994 |
supports_store_uncommitted = False |
995 |
||
|
0.200.656
by Jelmer Vernooij
Implement GitWorkingTreeFormat._matchingbzrdir. |
996 |
@property
|
|
0.200.1665
by Jelmer Vernooij
Rename _matchingbzrdir to _matchingcnotroldir. |
997 |
def _matchingcontroldir(self): |
|
0.200.1641
by Jelmer Vernooij
Use relative imports where possible. |
998 |
from .dir import LocalGitControlDirFormat |
|
0.200.1013
by Jelmer Vernooij
More renames. |
999 |
return LocalGitControlDirFormat() |
|
0.200.656
by Jelmer Vernooij
Implement GitWorkingTreeFormat._matchingbzrdir. |
1000 |
|
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
1001 |
def get_format_description(self): |
1002 |
return "Git Working Tree" |
|
|
0.200.616
by Jelmer Vernooij
Provide custom intertree implementation for GitRevisionTree->GitWorkingTree. |
1003 |
|
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
1004 |
def initialize(self, a_controldir, revision_id=None, from_branch=None, |
|
0.200.1096
by Jelmer Vernooij
Implement GitWorkingTreeFormat.initialize. |
1005 |
accelerator_tree=None, hardlink=False): |
1006 |
"""See WorkingTreeFormat.initialize().""" |
|
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
1007 |
if not isinstance(a_controldir, LocalGitDir): |
1008 |
raise errors.IncompatibleFormat(self, a_controldir) |
|
1009 |
index = Index(a_controldir.root_transport.local_abspath(".git/index")) |
|
|
0.200.1096
by Jelmer Vernooij
Implement GitWorkingTreeFormat.initialize. |
1010 |
index.write() |
|
0.200.1680
by Jelmer Vernooij
Fix repo locks. |
1011 |
wt = GitWorkingTree( |
1012 |
a_controldir, a_controldir.open_repository(), |
|
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
1013 |
a_controldir.open_branch(), index) |
|
0.200.1680
by Jelmer Vernooij
Fix repo locks. |
1014 |
for hook in MutableTree.hooks['post_build_tree']: |
1015 |
hook(wt) |
|
1016 |
return wt |
|
|
0.200.1096
by Jelmer Vernooij
Implement GitWorkingTreeFormat.initialize. |
1017 |
|
|
0.200.616
by Jelmer Vernooij
Provide custom intertree implementation for GitRevisionTree->GitWorkingTree. |
1018 |
|
1019 |
class InterIndexGitTree(tree.InterTree): |
|
1020 |
"""InterTree that works between a Git revision tree and an index.""" |
|
1021 |
||
1022 |
def __init__(self, source, target): |
|
1023 |
super(InterIndexGitTree, self).__init__(source, target) |
|
1024 |
self._index = target.index |
|
1025 |
||
1026 |
@classmethod
|
|
1027 |
def is_compatible(cls, source, target): |
|
|
0.200.1641
by Jelmer Vernooij
Use relative imports where possible. |
1028 |
from .repository import GitRevisionTree |
|
0.200.1636
by Jelmer Vernooij
Some formatting fixes. |
1029 |
return (isinstance(source, GitRevisionTree) and |
|
0.200.616
by Jelmer Vernooij
Provide custom intertree implementation for GitRevisionTree->GitWorkingTree. |
1030 |
isinstance(target, GitWorkingTree)) |
1031 |
||
1032 |
def compare(self, want_unchanged=False, specific_files=None, |
|
1033 |
extra_trees=None, require_versioned=False, include_root=False, |
|
1034 |
want_unversioned=False): |
|
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
1035 |
with self.lock_read(): |
1036 |
# FIXME: Handle include_root
|
|
1037 |
changes = changes_between_git_tree_and_index( |
|
1038 |
self.source.store, self.source.tree, |
|
1039 |
self.target, want_unchanged=want_unchanged, |
|
1040 |
want_unversioned=want_unversioned) |
|
1041 |
source_fileid_map = self.source._fileid_map |
|
1042 |
target_fileid_map = self.target._fileid_map |
|
1043 |
ret = tree_delta_from_git_changes(changes, self.target.mapping, |
|
1044 |
(source_fileid_map, target_fileid_map), |
|
1045 |
specific_file=specific_files, require_versioned=require_versioned) |
|
1046 |
if want_unversioned: |
|
1047 |
for e in self.target.extras(): |
|
1048 |
ret.unversioned.append((e, None, |
|
1049 |
osutils.file_kind(self.target.abspath(e)))) |
|
1050 |
return ret |
|
|
0.200.616
by Jelmer Vernooij
Provide custom intertree implementation for GitRevisionTree->GitWorkingTree. |
1051 |
|
|
0.200.622
by Jelmer Vernooij
Implement InterTree.iter_changes() as well. |
1052 |
def iter_changes(self, include_unchanged=False, specific_files=None, |
|
0.200.1207
by Jelmer Vernooij
Fix some formatting. |
1053 |
pb=None, extra_trees=[], require_versioned=True, |
1054 |
want_unversioned=False): |
|
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
1055 |
with self.lock_read(): |
1056 |
changes = changes_between_git_tree_and_index( |
|
1057 |
self.source.store, self.source.tree, |
|
1058 |
self.target, want_unchanged=include_unchanged, |
|
1059 |
want_unversioned=want_unversioned) |
|
1060 |
return changes_from_git_changes( |
|
1061 |
changes, self.target.mapping, specific_file=specific_files) |
|
|
0.200.616
by Jelmer Vernooij
Provide custom intertree implementation for GitRevisionTree->GitWorkingTree. |
1062 |
|
|
0.200.1179
by Jelmer Vernooij
Avoid using verifiers for natively imported revisions, save a lot of time. |
1063 |
|
|
0.200.616
by Jelmer Vernooij
Provide custom intertree implementation for GitRevisionTree->GitWorkingTree. |
1064 |
tree.InterTree.register_optimiser(InterIndexGitTree) |
|
0.200.1529
by Jelmer Vernooij
Add changes_between_tree_and_index. |
1065 |
|
1066 |
||
|
0.200.1542
by Jelmer Vernooij
Refactor iter_changes. |
1067 |
def changes_between_git_tree_and_index(object_store, tree, target, |
|
0.200.1529
by Jelmer Vernooij
Add changes_between_tree_and_index. |
1068 |
want_unchanged=False, want_unversioned=False, update_index=False): |
1069 |
"""Determine the changes between a git tree and a working tree with index. |
|
1070 |
||
1071 |
"""
|
|
|
0.200.1538
by Jelmer Vernooij
More work on tree-reference support. |
1072 |
|
|
0.200.1542
by Jelmer Vernooij
Refactor iter_changes. |
1073 |
names = target.index._byname.keys() |
1074 |
for (name, mode, sha) in changes_from_tree(names, target._lookup_entry, |
|
|
0.200.1531
by Jelmer Vernooij
Don't trust index contents - verify against file timestamps. |
1075 |
object_store, tree, want_unchanged=want_unchanged): |
|
0.200.1538
by Jelmer Vernooij
More work on tree-reference support. |
1076 |
if name == (None, None): |
1077 |
continue
|
|
|
0.200.1531
by Jelmer Vernooij
Don't trust index contents - verify against file timestamps. |
1078 |
yield (name, mode, sha) |