bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.358.2
by Jelmer Vernooij
Refresh copyright headers, add my email. |
1 |
# Copyright (C) 2008-2018 Jelmer Vernooij <jelmer@jelmer.uk>
|
|
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
|
|
|
0.358.1
by Jelmer Vernooij
Fix FSF address. |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
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.1731
by Jelmer Vernooij
Add support for checking untracked changes. |
22 |
import itertools |
|
0.200.385
by Jelmer Vernooij
Cope with removed files. |
23 |
from cStringIO import ( |
24 |
StringIO, |
|
25 |
)
|
|
|
0.200.1210
by Jelmer Vernooij
Implement GitWorkingTree._walkdirs. |
26 |
from collections import defaultdict |
|
0.239.4
by Jelmer Vernooij
Cope with nonexistent files and directories in get_file_sha1. |
27 |
import errno |
|
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.415.2
by Jelmer Vernooij
Write index manually. |
31 |
from dulwich.file import GitFile, FileLocked |
|
0.200.1096
by Jelmer Vernooij
Implement GitWorkingTreeFormat.initialize. |
32 |
from dulwich.index import ( |
33 |
Index, |
|
|
0.415.2
by Jelmer Vernooij
Write index manually. |
34 |
SHA1Writer, |
|
0.371.1
by Jelmer Vernooij
Implement WorkingTree.reset_state(). |
35 |
build_index_from_tree, |
|
0.200.1531
by Jelmer Vernooij
Don't trust index contents - verify against file timestamps. |
36 |
changes_from_tree, |
37 |
cleanup_mode, |
|
|
0.200.1754
by Jelmer Vernooij
Avoid updating index when just comparing trees. |
38 |
commit_tree, |
|
0.391.6
by Jelmer Vernooij
Directly call index_entry_from_path. |
39 |
index_entry_from_path, |
|
0.200.1531
by Jelmer Vernooij
Don't trust index contents - verify against file timestamps. |
40 |
index_entry_from_stat, |
|
0.391.5
by Jelmer Vernooij
Use iter_fresh_entries directly. |
41 |
iter_fresh_entries, |
|
0.323.1
by Jelmer Vernooij
Fix iter_changes of untracked changes. |
42 |
blob_from_path_and_stat, |
|
0.369.1
by Jelmer Vernooij
Implement conflict handling. |
43 |
FLAG_STAGEMASK, |
|
0.429.10
by Jelmer Vernooij
use new read_submodule_head from dulwich. |
44 |
read_submodule_head, |
|
0.373.1
by Jelmer Vernooij
Fix WorkingTree.reset_state(). |
45 |
validate_path, |
|
0.415.2
by Jelmer Vernooij
Write index manually. |
46 |
write_index_dict, |
|
0.200.1096
by Jelmer Vernooij
Implement GitWorkingTreeFormat.initialize. |
47 |
)
|
|
0.200.1202
by Jelmer Vernooij
Implement has_or_had_id. |
48 |
from dulwich.object_store import ( |
49 |
tree_lookup_path, |
|
50 |
)
|
|
|
0.200.383
by Jelmer Vernooij
Simplify, support rewriting index based on inventory. |
51 |
from dulwich.objects import ( |
52 |
Blob, |
|
|
0.357.1
by Jelmer Vernooij
Fix some remove tests. |
53 |
Tree, |
|
0.200.1538
by Jelmer Vernooij
More work on tree-reference support. |
54 |
S_IFGITLINK, |
|
0.373.1
by Jelmer Vernooij
Fix WorkingTree.reset_state(). |
55 |
S_ISGITLINK, |
|
0.429.5
by Jelmer Vernooij
Fix tree_content_summary test. |
56 |
ZERO_SHA, |
57 |
)
|
|
58 |
from dulwich.repo import ( |
|
59 |
NotGitRepository, |
|
60 |
Repo as GitRepo, |
|
61 |
)
|
|
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
62 |
import os |
|
0.264.10
by Jelmer Vernooij
Yield inventory entries. |
63 |
import posixpath |
|
0.200.1655
by Jelmer Vernooij
Basic support for git ignores. |
64 |
import re |
|
0.200.384
by Jelmer Vernooij
Fix reading of inventory from index. |
65 |
import stat |
|
0.200.1215
by Jelmer Vernooij
Implement GitWorkingTree.remove. |
66 |
import sys |
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
67 |
|
|
0.200.1641
by Jelmer Vernooij
Use relative imports where possible. |
68 |
from ... import ( |
|
0.369.1
by Jelmer Vernooij
Implement conflict handling. |
69 |
conflicts as _mod_conflicts, |
|
0.200.382
by Jelmer Vernooij
Support flushing index. |
70 |
errors, |
|
0.200.1752
by Jelmer Vernooij
Don't traverse nested trees in WorkingTree.smart_add. |
71 |
controldir as _mod_controldir, |
|
0.200.1655
by Jelmer Vernooij
Basic support for git ignores. |
72 |
globbing, |
|
0.200.409
by Jelmer Vernooij
Support parsing .gitignore. |
73 |
ignores, |
|
0.200.1476
by Jelmer Vernooij
Cope with working tree refactoring. |
74 |
lock, |
|
0.380.1
by Jelmer Vernooij
Implement WorkingTree.pull. |
75 |
merge, |
|
0.200.381
by Jelmer Vernooij
Support working trees properly, status and ls. |
76 |
osutils, |
|
0.200.1720
by Jelmer Vernooij
Fix handling of pending merges. |
77 |
revision as _mod_revision, |
|
0.200.1215
by Jelmer Vernooij
Implement GitWorkingTree.remove. |
78 |
trace, |
|
0.200.1752
by Jelmer Vernooij
Don't traverse nested trees in WorkingTree.smart_add. |
79 |
transport as _mod_transport, |
|
0.200.519
by Jelmer Vernooij
Move imports down, might not be available in older bzr-git versions. |
80 |
tree, |
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
81 |
workingtree, |
82 |
)
|
|
|
0.383.1
by Jelmer Vernooij
Fix a bunch of locking issues. |
83 |
from ...decorators import ( |
84 |
only_raises, |
|
85 |
)
|
|
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
86 |
from ...bzr import ( |
87 |
inventory, |
|
88 |
)
|
|
|
0.200.1680
by Jelmer Vernooij
Fix repo locks. |
89 |
from ...mutabletree import ( |
|
0.429.2
by Jelmer Vernooij
Some more work on submodule support. |
90 |
BadReferenceTarget, |
|
0.200.1680
by Jelmer Vernooij
Fix repo locks. |
91 |
MutableTree, |
92 |
)
|
|
|
0.200.1641
by Jelmer Vernooij
Use relative imports where possible. |
93 |
|
94 |
||
95 |
from .dir import ( |
|
|
0.200.1096
by Jelmer Vernooij
Implement GitWorkingTreeFormat.initialize. |
96 |
LocalGitDir, |
97 |
)
|
|
|
0.200.1641
by Jelmer Vernooij
Use relative imports where possible. |
98 |
from .tree import ( |
|
0.200.622
by Jelmer Vernooij
Implement InterTree.iter_changes() as well. |
99 |
changes_from_git_changes, |
|
0.200.617
by Jelmer Vernooij
Add custom InterTree for use between git revision trees. |
100 |
tree_delta_from_git_changes, |
|
0.287.3
by Jelmer Vernooij
Some improvements to changes iterator. |
101 |
InterGitTrees, |
|
0.360.1
by Jelmer Vernooij
Implement GitMemoryTree. |
102 |
MutableGitIndexTree, |
|
0.200.617
by Jelmer Vernooij
Add custom InterTree for use between git revision trees. |
103 |
)
|
|
0.200.1641
by Jelmer Vernooij
Use relative imports where possible. |
104 |
from .mapping import ( |
|
0.200.971
by Chadrik
Fix 'bzr status' after 'bzr add' in native git working trees. |
105 |
GitFileIdMap, |
|
0.264.10
by Jelmer Vernooij
Yield inventory entries. |
106 |
mode_kind, |
|
0.200.971
by Chadrik
Fix 'bzr status' after 'bzr add' in native git working trees. |
107 |
)
|
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
108 |
|
|
0.200.409
by Jelmer Vernooij
Support parsing .gitignore. |
109 |
IGNORE_FILENAME = ".gitignore" |
110 |
||
111 |
||
|
0.360.1
by Jelmer Vernooij
Implement GitMemoryTree. |
112 |
class GitWorkingTree(MutableGitIndexTree,workingtree.WorkingTree): |
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
113 |
"""A Git working tree.""" |
114 |
||
|
0.415.3
by Jelmer Vernooij
Open index on demand. |
115 |
def __init__(self, controldir, repo, branch): |
|
0.360.1
by Jelmer Vernooij
Implement GitMemoryTree. |
116 |
MutableGitIndexTree.__init__(self) |
|
0.200.1741
by Jelmer Vernooij
Fix opentree tests. |
117 |
basedir = controldir.root_transport.local_abspath('.') |
118 |
self.basedir = osutils.realpath(basedir) |
|
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
119 |
self.controldir = controldir |
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
120 |
self.repository = repo |
|
0.200.1205
by Jelmer Vernooij
Implement GitWorkingTree.stored_kind. |
121 |
self.store = self.repository._git.object_store |
|
0.200.384
by Jelmer Vernooij
Fix reading of inventory from index. |
122 |
self.mapping = self.repository.get_mapping() |
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
123 |
self._branch = branch |
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
124 |
self._transport = controldir.transport |
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
125 |
self._format = GitWorkingTreeFormat() |
|
0.415.3
by Jelmer Vernooij
Open index on demand. |
126 |
self.index = None |
|
0.415.4
by Jelmer Vernooij
proper locking on index. |
127 |
self._index_file = None |
|
0.200.239
by Jelmer Vernooij
Provide views. |
128 |
self.views = self._make_views() |
|
0.200.1173
by Jelmer Vernooij
Provide GitWorkingTree._rules_searcher. |
129 |
self._rules_searcher = None |
|
0.200.381
by Jelmer Vernooij
Support working trees properly, status and ls. |
130 |
self._detect_case_handling() |
|
0.200.1202
by Jelmer Vernooij
Implement has_or_had_id. |
131 |
self._reset_data() |
|
0.200.1476
by Jelmer Vernooij
Cope with working tree refactoring. |
132 |
|
|
0.200.1650
by Jelmer Vernooij
Implement GitWorkingTree.supports_tree_reference. |
133 |
def supports_tree_reference(self): |
|
0.429.2
by Jelmer Vernooij
Some more work on submodule support. |
134 |
return True |
|
0.200.1650
by Jelmer Vernooij
Implement GitWorkingTree.supports_tree_reference. |
135 |
|
|
0.349.1
by Jelmer Vernooij
Support supports_rename_tracking method. |
136 |
def supports_rename_tracking(self): |
137 |
return False |
|
138 |
||
|
0.415.3
by Jelmer Vernooij
Open index on demand. |
139 |
def _read_index(self): |
140 |
self.index = Index(self.control_transport.local_abspath('index')) |
|
141 |
self._index_dirty = False |
|
142 |
||
|
0.200.1476
by Jelmer Vernooij
Cope with working tree refactoring. |
143 |
def lock_read(self): |
144 |
"""Lock the repository for read operations. |
|
145 |
||
|
0.200.1646
by Jelmer Vernooij
Rename bzrlib to breezy. |
146 |
:return: A breezy.lock.LogicalLockResult.
|
|
0.200.1476
by Jelmer Vernooij
Cope with working tree refactoring. |
147 |
"""
|
148 |
if not self._lock_mode: |
|
149 |
self._lock_mode = 'r' |
|
150 |
self._lock_count = 1 |
|
|
0.415.3
by Jelmer Vernooij
Open index on demand. |
151 |
self._read_index() |
|
0.200.1476
by Jelmer Vernooij
Cope with working tree refactoring. |
152 |
else: |
153 |
self._lock_count += 1 |
|
154 |
self.branch.lock_read() |
|
155 |
return lock.LogicalLockResult(self.unlock) |
|
156 |
||
|
0.383.1
by Jelmer Vernooij
Fix a bunch of locking issues. |
157 |
def _lock_write_tree(self): |
158 |
# TODO(jelmer): Actually create index.lock
|
|
159 |
if not self._lock_mode: |
|
160 |
self._lock_mode = 'w' |
|
161 |
self._lock_count = 1 |
|
|
0.415.4
by Jelmer Vernooij
proper locking on index. |
162 |
try: |
|
0.415.5
by Jelmer Vernooij
Don't flush, just wait for unlock. |
163 |
self._index_file = GitFile(self.control_transport.local_abspath('index'), 'wb') |
|
0.415.4
by Jelmer Vernooij
proper locking on index. |
164 |
except FileLocked: |
165 |
raise errors.LockContention('index') |
|
|
0.415.3
by Jelmer Vernooij
Open index on demand. |
166 |
self._read_index() |
|
0.383.1
by Jelmer Vernooij
Fix a bunch of locking issues. |
167 |
elif self._lock_mode == 'r': |
168 |
raise errors.ReadOnlyError(self) |
|
169 |
else: |
|
170 |
self._lock_count +=1 |
|
171 |
||
|
0.200.1477
by Jelmer Vernooij
Implement GitWorkingTree.lock_tree_write. |
172 |
def lock_tree_write(self): |
173 |
self.branch.lock_read() |
|
|
0.383.1
by Jelmer Vernooij
Fix a bunch of locking issues. |
174 |
try: |
175 |
self._lock_write_tree() |
|
176 |
return lock.LogicalLockResult(self.unlock) |
|
177 |
except: |
|
178 |
self.branch.unlock() |
|
179 |
raise
|
|
|
0.200.1477
by Jelmer Vernooij
Implement GitWorkingTree.lock_tree_write. |
180 |
|
|
0.200.1476
by Jelmer Vernooij
Cope with working tree refactoring. |
181 |
def lock_write(self, token=None): |
182 |
self.branch.lock_write() |
|
|
0.383.1
by Jelmer Vernooij
Fix a bunch of locking issues. |
183 |
try: |
184 |
self._lock_write_tree() |
|
185 |
return lock.LogicalLockResult(self.unlock) |
|
186 |
except: |
|
187 |
self.branch.unlock() |
|
188 |
raise
|
|
|
0.200.1476
by Jelmer Vernooij
Cope with working tree refactoring. |
189 |
|
190 |
def is_locked(self): |
|
191 |
return self._lock_count >= 1 |
|
192 |
||
193 |
def get_physical_lock_status(self): |
|
194 |
return False |
|
195 |
||
|
0.415.4
by Jelmer Vernooij
proper locking on index. |
196 |
def break_lock(self): |
197 |
try: |
|
198 |
self.control_transport.delete('index.lock') |
|
199 |
except errors.NoSuchFile: |
|
200 |
pass
|
|
201 |
self.branch.break_lock() |
|
202 |
||
|
0.383.1
by Jelmer Vernooij
Fix a bunch of locking issues. |
203 |
@only_raises(errors.LockNotHeld, errors.LockBroken) |
|
0.200.1476
by Jelmer Vernooij
Cope with working tree refactoring. |
204 |
def unlock(self): |
205 |
if not self._lock_count: |
|
206 |
return lock.cant_unlock_not_held(self) |
|
|
0.383.1
by Jelmer Vernooij
Fix a bunch of locking issues. |
207 |
try: |
208 |
self._cleanup() |
|
209 |
self._lock_count -= 1 |
|
210 |
if self._lock_count > 0: |
|
211 |
return
|
|
|
0.415.4
by Jelmer Vernooij
proper locking on index. |
212 |
if self._index_file is not None: |
213 |
if self._index_dirty: |
|
214 |
self._flush(self._index_file) |
|
215 |
self._index_file.close() |
|
216 |
else: |
|
|
0.415.5
by Jelmer Vernooij
Don't flush, just wait for unlock. |
217 |
# Somebody else already wrote the index file
|
218 |
# by calling .flush()
|
|
219 |
self._index_file.abort() |
|
|
0.415.4
by Jelmer Vernooij
proper locking on index. |
220 |
self._index_file = None |
|
0.383.1
by Jelmer Vernooij
Fix a bunch of locking issues. |
221 |
self._lock_mode = None |
|
0.415.3
by Jelmer Vernooij
Open index on demand. |
222 |
self.index = None |
|
0.383.1
by Jelmer Vernooij
Fix a bunch of locking issues. |
223 |
finally: |
224 |
self.branch.unlock() |
|
|
0.200.1658
by Jelmer Vernooij
Fix handling of ignores - return patterns that matched. |
225 |
|
|
0.360.1
by Jelmer Vernooij
Implement GitMemoryTree. |
226 |
def _cleanup(self): |
227 |
pass
|
|
228 |
||
|
0.200.1322
by Jelmer Vernooij
Add case detection. |
229 |
def _detect_case_handling(self): |
230 |
try: |
|
231 |
self._transport.stat(".git/cOnFiG") |
|
232 |
except errors.NoSuchFile: |
|
233 |
self.case_sensitive = True |
|
234 |
else: |
|
235 |
self.case_sensitive = False |
|
236 |
||
|
0.200.1315
by Jelmer Vernooij
Implement WorkingTree.merge_modified. |
237 |
def merge_modified(self): |
238 |
return {} |
|
239 |
||
|
0.200.1696
by Jelmer Vernooij
Fix set_merge_modified. |
240 |
def set_merge_modified(self, modified_hashes): |
|
0.298.1
by Jelmer Vernooij
mark GitWorkngTree.set_merge_modified as unsupported. |
241 |
raise errors.UnsupportedOperation(self.set_merge_modified, self) |
|
0.200.1690
by Jelmer Vernooij
Implement WorkingTree.set_merge_modified. |
242 |
|
|
0.200.1220
by Jelmer Vernooij
Support set_parent_trees. |
243 |
def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False): |
244 |
self.set_parent_ids([p for p, t in parents_list]) |
|
245 |
||
|
0.305.1
by Jelmer Vernooij
Reset RHS parents after commit. |
246 |
def _set_merges_from_parent_ids(self, rhs_parent_ids): |
|
0.200.1779
by Jelmer Vernooij
Actually store git revision ids rather than bzr revision ids. |
247 |
try: |
|
0.305.1
by Jelmer Vernooij
Reset RHS parents after commit. |
248 |
merges = [self.branch.lookup_bzr_revision_id(revid)[0] for revid in rhs_parent_ids] |
|
0.200.1779
by Jelmer Vernooij
Actually store git revision ids rather than bzr revision ids. |
249 |
except errors.NoSuchRevision as e: |
250 |
raise errors.GhostRevisionUnusableHere(e.revision) |
|
|
0.304.1
by Jelmer Vernooij
Delete MERGE_HEAD if there are no parent ids. |
251 |
if merges: |
252 |
self.control_transport.put_bytes('MERGE_HEAD', '\n'.join(merges), |
|
253 |
mode=self.controldir._get_file_mode()) |
|
254 |
else: |
|
255 |
try: |
|
256 |
self.control_transport.delete('MERGE_HEAD') |
|
257 |
except errors.NoSuchFile: |
|
258 |
pass
|
|
|
0.200.1720
by Jelmer Vernooij
Fix handling of pending merges. |
259 |
|
260 |
def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False): |
|
261 |
"""Set the parent ids to revision_ids. |
|
262 |
||
263 |
See also set_parent_trees. This api will try to retrieve the tree data
|
|
264 |
for each element of revision_ids from the trees repository. If you have
|
|
265 |
tree data already available, it is more efficient to use
|
|
266 |
set_parent_trees rather than set_parent_ids. set_parent_ids is however
|
|
267 |
an easier API to use.
|
|
268 |
||
269 |
:param revision_ids: The revision_ids to set as the parent ids of this
|
|
270 |
working tree. Any of these may be ghosts.
|
|
271 |
"""
|
|
272 |
with self.lock_tree_write(): |
|
273 |
self._check_parents_for_ghosts(revision_ids, |
|
274 |
allow_leftmost_as_ghost=allow_leftmost_as_ghost) |
|
275 |
for revision_id in revision_ids: |
|
276 |
_mod_revision.check_not_reserved_id(revision_id) |
|
277 |
||
278 |
revision_ids = self._filter_parent_ids_by_ancestry(revision_ids) |
|
279 |
||
280 |
if len(revision_ids) > 0: |
|
281 |
self.set_last_revision(revision_ids[0]) |
|
282 |
else: |
|
283 |
self.set_last_revision(_mod_revision.NULL_REVISION) |
|
284 |
||
|
0.305.1
by Jelmer Vernooij
Reset RHS parents after commit. |
285 |
self._set_merges_from_parent_ids(revision_ids[1:]) |
|
0.200.1720
by Jelmer Vernooij
Fix handling of pending merges. |
286 |
|
287 |
def get_parent_ids(self): |
|
288 |
"""See Tree.get_parent_ids. |
|
289 |
||
290 |
This implementation reads the pending merges list and last_revision
|
|
291 |
value and uses that to decide what the parents list should be.
|
|
292 |
"""
|
|
293 |
last_rev = _mod_revision.ensure_null(self._last_revision()) |
|
294 |
if _mod_revision.NULL_REVISION == last_rev: |
|
295 |
parents = [] |
|
296 |
else: |
|
297 |
parents = [last_rev] |
|
298 |
try: |
|
299 |
merges_bytes = self.control_transport.get_bytes('MERGE_HEAD') |
|
300 |
except errors.NoSuchFile: |
|
301 |
pass
|
|
302 |
else: |
|
303 |
for l in osutils.split_lines(merges_bytes): |
|
304 |
revision_id = l.rstrip('\n') |
|
|
0.200.1779
by Jelmer Vernooij
Actually store git revision ids rather than bzr revision ids. |
305 |
parents.append(self.branch.lookup_foreign_revision_id(revision_id)) |
|
0.200.1720
by Jelmer Vernooij
Fix handling of pending merges. |
306 |
return parents |
307 |
||
|
0.200.1243
by Jelmer Vernooij
Implement WorkingTree.check_state. |
308 |
def check_state(self): |
309 |
"""Check that the working state is/isn't valid.""" |
|
310 |
pass
|
|
311 |
||
|
0.200.1215
by Jelmer Vernooij
Implement GitWorkingTree.remove. |
312 |
def remove(self, files, verbose=False, to_file=None, keep_files=True, |
313 |
force=False): |
|
314 |
"""Remove nominated files from the working tree metadata. |
|
315 |
||
316 |
:param files: File paths relative to the basedir.
|
|
317 |
:param keep_files: If true, the files will also be kept.
|
|
318 |
:param force: Delete files and directories, even if they are changed
|
|
319 |
and even if the directories are not empty.
|
|
320 |
"""
|
|
321 |
if isinstance(files, basestring): |
|
322 |
files = [files] |
|
323 |
||
324 |
if to_file is None: |
|
325 |
to_file = sys.stdout |
|
326 |
||
327 |
def backup(file_to_backup): |
|
328 |
abs_path = self.abspath(file_to_backup) |
|
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
329 |
backup_name = self.controldir._available_backup_name(file_to_backup) |
|
0.200.1215
by Jelmer Vernooij
Implement GitWorkingTree.remove. |
330 |
osutils.rename(abs_path, self.abspath(backup_name)) |
331 |
return "removed %s (but kept a copy: %s)" % ( |
|
332 |
file_to_backup, backup_name) |
|
333 |
||
|
0.357.1
by Jelmer Vernooij
Fix some remove tests. |
334 |
# Sort needed to first handle directory content before the directory
|
335 |
files_to_backup = [] |
|
336 |
||
|
0.357.2
by Jelmer Vernooij
Fix more remove tests. |
337 |
all_files = set() |
338 |
||
339 |
def recurse_directory_to_add_files(directory): |
|
340 |
# Recurse directory and add all files
|
|
341 |
# so we can check if they have changed.
|
|
342 |
for parent_info, file_infos in self.walkdirs(directory): |
|
343 |
for relpath, basename, kind, lstat, fileid, kind in file_infos: |
|
344 |
# Is it versioned or ignored?
|
|
345 |
if self.is_versioned(relpath): |
|
346 |
# Add nested content for deletion.
|
|
347 |
all_files.add(relpath) |
|
348 |
else: |
|
349 |
# Files which are not versioned
|
|
350 |
# should be treated as unknown.
|
|
351 |
files_to_backup.append(relpath) |
|
352 |
||
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
353 |
with self.lock_tree_write(): |
|
0.357.2
by Jelmer Vernooij
Fix more remove tests. |
354 |
for filepath in files: |
355 |
# Get file name into canonical form.
|
|
356 |
abspath = self.abspath(filepath) |
|
357 |
filepath = self.relpath(abspath) |
|
358 |
||
359 |
if filepath: |
|
360 |
all_files.add(filepath) |
|
361 |
recurse_directory_to_add_files(filepath) |
|
362 |
||
363 |
files = list(all_files) |
|
364 |
||
365 |
if len(files) == 0: |
|
366 |
return # nothing to do |
|
367 |
||
368 |
# Sort needed to first handle directory content before the directory
|
|
369 |
files.sort(reverse=True) |
|
370 |
||
|
0.357.1
by Jelmer Vernooij
Fix some remove tests. |
371 |
# Bail out if we are going to delete files we shouldn't
|
372 |
if not keep_files and not force: |
|
373 |
for (file_id, path, content_change, versioned, parent_id, name, |
|
374 |
kind, executable) in self.iter_changes(self.basis_tree(), |
|
375 |
include_unchanged=True, require_versioned=False, |
|
376 |
want_unversioned=True, specific_files=files): |
|
377 |
if versioned[0] == False: |
|
378 |
# The record is unknown or newly added
|
|
379 |
files_to_backup.append(path[1]) |
|
|
0.357.2
by Jelmer Vernooij
Fix more remove tests. |
380 |
files_to_backup.extend(osutils.parent_directories(path[1])) |
|
0.357.1
by Jelmer Vernooij
Fix some remove tests. |
381 |
elif (content_change and (kind[1] is not None) and |
382 |
osutils.is_inside_any(files, path[1])): |
|
383 |
# Versioned and changed, but not deleted, and still
|
|
384 |
# in one of the dirs to be deleted.
|
|
385 |
files_to_backup.append(path[1]) |
|
|
0.357.2
by Jelmer Vernooij
Fix more remove tests. |
386 |
files_to_backup.extend(osutils.parent_directories(path[1])) |
387 |
||
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
388 |
for f in files: |
|
0.200.1735
by Jelmer Vernooij
Fix remove tests. |
389 |
if f == '': |
390 |
continue
|
|
|
0.357.1
by Jelmer Vernooij
Fix some remove tests. |
391 |
|
392 |
try: |
|
393 |
kind = self.kind(f) |
|
394 |
except errors.NoSuchFile: |
|
395 |
kind = None |
|
396 |
||
397 |
abs_path = self.abspath(f) |
|
398 |
if verbose: |
|
399 |
# having removed it, it must be either ignored or unknown
|
|
400 |
if self.is_ignored(f): |
|
401 |
new_status = 'I' |
|
402 |
else: |
|
403 |
new_status = '?' |
|
404 |
kind_ch = osutils.kind_marker(kind) |
|
405 |
to_file.write(new_status + ' ' + f + kind_ch + '\n') |
|
406 |
if kind is None: |
|
407 |
message = "%s does not exist" % (f, ) |
|
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
408 |
else: |
|
0.357.1
by Jelmer Vernooij
Fix some remove tests. |
409 |
if not keep_files: |
410 |
if f in files_to_backup and not force: |
|
|
0.357.2
by Jelmer Vernooij
Fix more remove tests. |
411 |
message = backup(f) |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
412 |
else: |
|
0.357.1
by Jelmer Vernooij
Fix some remove tests. |
413 |
if kind == 'directory': |
414 |
osutils.rmtree(abs_path) |
|
415 |
else: |
|
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
416 |
osutils.delete_any(abs_path) |
|
0.357.2
by Jelmer Vernooij
Fix more remove tests. |
417 |
message = "deleted %s" % (f,) |
418 |
else: |
|
419 |
message = "removed %s" % (f,) |
|
|
0.357.1
by Jelmer Vernooij
Fix some remove tests. |
420 |
self._unversion_path(f) |
|
0.200.1215
by Jelmer Vernooij
Implement GitWorkingTree.remove. |
421 |
|
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
422 |
# print only one message (if any) per file.
|
423 |
if message is not None: |
|
424 |
trace.note(message) |
|
|
0.357.1
by Jelmer Vernooij
Fix some remove tests. |
425 |
self._versioned_dirs = None |
|
0.200.1192
by Jelmer Vernooij
Implement path2id. |
426 |
|
|
0.200.1240
by Jelmer Vernooij
Implement GitWorkingTree.smart_add. |
427 |
def smart_add(self, file_list, recurse=True, action=None, save=True): |
|
0.200.1771
by Jelmer Vernooij
Fix implicit tree unicode add test. |
428 |
if not file_list: |
429 |
file_list = [u'.'] |
|
|
0.200.1781
by Jelmer Vernooij
Support expanding symlinks. |
430 |
|
431 |
# expand any symlinks in the directory part, while leaving the
|
|
432 |
# filename alone
|
|
433 |
# only expanding if symlinks are supported avoids windows path bugs
|
|
434 |
if osutils.has_symlinks(): |
|
435 |
file_list = list(map(osutils.normalizepath, file_list)) |
|
436 |
||
|
0.369.1
by Jelmer Vernooij
Implement conflict handling. |
437 |
conflicts_related = set() |
438 |
for c in self.conflicts(): |
|
439 |
conflicts_related.update(c.associated_filenames()) |
|
440 |
||
|
0.200.1240
by Jelmer Vernooij
Implement GitWorkingTree.smart_add. |
441 |
added = [] |
442 |
ignored = {} |
|
443 |
user_dirs = [] |
|
|
0.200.1733
by Jelmer Vernooij
Support handling of custom ids in smart_add. |
444 |
def call_action(filepath, kind): |
445 |
if action is not None: |
|
446 |
parent_path = posixpath.dirname(filepath) |
|
447 |
parent_id = self.path2id(parent_path) |
|
448 |
parent_ie = self._get_dir_ie(parent_path, parent_id) |
|
449 |
file_id = action(self, parent_ie, filepath, kind) |
|
450 |
if file_id is not None: |
|
451 |
raise workingtree.SettingFileIdUnsupported() |
|
452 |
||
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
453 |
with self.lock_tree_write(): |
454 |
for filepath in osutils.canonical_relpaths(self.basedir, file_list): |
|
|
0.352.1
by Jelmer Vernooij
Check for normalization during add. |
455 |
filepath, can_access = osutils.normalized_filename(filepath) |
456 |
if not can_access: |
|
457 |
raise errors.InvalidNormalization(filepath) |
|
458 |
||
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
459 |
abspath = self.abspath(filepath) |
|
0.200.1240
by Jelmer Vernooij
Implement GitWorkingTree.smart_add. |
460 |
kind = osutils.file_kind(abspath) |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
461 |
if kind in ("file", "symlink"): |
|
0.429.2
by Jelmer Vernooij
Some more work on submodule support. |
462 |
(index, subpath) = self._lookup_index(filepath.encode('utf-8')) |
463 |
if subpath in index: |
|
|
0.369.2
by Jelmer Vernooij
Fix tests. |
464 |
# Already present
|
465 |
continue
|
|
|
0.200.1733
by Jelmer Vernooij
Support handling of custom ids in smart_add. |
466 |
call_action(filepath, kind) |
|
0.200.1308
by Jelmer Vernooij
Write index to disk after adding files. |
467 |
if save: |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
468 |
self._index_add_entry(filepath, kind) |
469 |
added.append(filepath) |
|
470 |
elif kind == "directory": |
|
|
0.429.2
by Jelmer Vernooij
Some more work on submodule support. |
471 |
(index, subpath) = self._lookup_index(filepath.encode('utf-8')) |
472 |
if subpath not in index: |
|
|
0.369.2
by Jelmer Vernooij
Fix tests. |
473 |
call_action(filepath, kind) |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
474 |
if recurse: |
475 |
user_dirs.append(filepath) |
|
476 |
else: |
|
477 |
raise errors.BadFileKindError(filename=abspath, kind=kind) |
|
478 |
for user_dir in user_dirs: |
|
479 |
abs_user_dir = self.abspath(user_dir) |
|
|
0.200.1752
by Jelmer Vernooij
Don't traverse nested trees in WorkingTree.smart_add. |
480 |
if user_dir != '': |
481 |
try: |
|
482 |
transport = _mod_transport.get_transport_from_path(abs_user_dir) |
|
483 |
_mod_controldir.ControlDirFormat.find_format(transport) |
|
484 |
subtree = True |
|
485 |
except errors.NotBranchError: |
|
486 |
subtree = False |
|
487 |
except errors.UnsupportedFormatError: |
|
488 |
subtree = False |
|
489 |
else: |
|
490 |
subtree = False |
|
491 |
if subtree: |
|
|
0.200.1769
by Jelmer Vernooij
Raise proper error when encountering nested trees. |
492 |
trace.warning('skipping nested tree %r', abs_user_dir) |
|
0.200.1752
by Jelmer Vernooij
Don't traverse nested trees in WorkingTree.smart_add. |
493 |
continue
|
494 |
||
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
495 |
for name in os.listdir(abs_user_dir): |
496 |
subp = os.path.join(user_dir, name) |
|
497 |
if self.is_control_filename(subp) or self.mapping.is_special_file(subp): |
|
498 |
continue
|
|
499 |
ignore_glob = self.is_ignored(subp) |
|
500 |
if ignore_glob is not None: |
|
501 |
ignored.setdefault(ignore_glob, []).append(subp) |
|
502 |
continue
|
|
503 |
abspath = self.abspath(subp) |
|
504 |
kind = osutils.file_kind(abspath) |
|
505 |
if kind == "directory": |
|
506 |
user_dirs.append(subp) |
|
507 |
else: |
|
|
0.369.2
by Jelmer Vernooij
Fix tests. |
508 |
if subp in self.index: |
509 |
# Already present
|
|
510 |
continue
|
|
|
0.369.3
by Jelmer Vernooij
Fix another conflict test. |
511 |
if subp in conflicts_related: |
512 |
continue
|
|
|
0.200.1733
by Jelmer Vernooij
Support handling of custom ids in smart_add. |
513 |
call_action(filepath, kind) |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
514 |
if save: |
515 |
self._index_add_entry(subp, kind) |
|
|
0.200.1751
by Jelmer Vernooij
Fix smart_add return value. |
516 |
added.append(subp) |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
517 |
return added, ignored |
|
0.200.1240
by Jelmer Vernooij
Implement GitWorkingTree.smart_add. |
518 |
|
|
0.200.1712
by Jelmer Vernooij
Add file_id prefix. |
519 |
def has_filename(self, filename): |
520 |
return osutils.lexists(self.abspath(filename)) |
|
521 |
||
|
0.200.1766
by Jelmer Vernooij
Fix another list_files test, integrate is_versioned. |
522 |
def _iter_files_recursive(self, from_dir=None, include_dirs=False): |
|
0.200.1328
by Jelmer Vernooij
More test fixes. |
523 |
if from_dir is None: |
|
0.379.1
by Jelmer Vernooij
Improve unicode handling in GitWorkingTree. |
524 |
from_dir = u"" |
|
0.341.1
by Jelmer Vernooij
Fix BadFilenameEncoding raising during WorkingTree.extras. |
525 |
for (dirpath, dirnames, filenames) in os.walk(self.abspath(from_dir).encode(osutils._fs_enc)): |
|
0.200.1302
by Jelmer Vernooij
Significantly improve performance of WorkingTree.extras(). |
526 |
dir_relpath = dirpath[len(self.basedir):].strip("/") |
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
527 |
if self.controldir.is_control_filename(dir_relpath): |
|
0.200.605
by Jelmer Vernooij
Ignore directories in WorkingTree.extras(). |
528 |
continue
|
|
0.200.1766
by Jelmer Vernooij
Fix another list_files test, integrate is_versioned. |
529 |
for name in list(dirnames): |
530 |
if self.controldir.is_control_filename(name): |
|
531 |
dirnames.remove(name) |
|
532 |
continue
|
|
533 |
relpath = os.path.join(dir_relpath, name) |
|
534 |
if include_dirs: |
|
|
0.341.1
by Jelmer Vernooij
Fix BadFilenameEncoding raising during WorkingTree.extras. |
535 |
try: |
536 |
yield relpath.decode(osutils._fs_enc) |
|
|
0.379.1
by Jelmer Vernooij
Improve unicode handling in GitWorkingTree. |
537 |
except UnicodeDecodeError: |
|
0.341.1
by Jelmer Vernooij
Fix BadFilenameEncoding raising during WorkingTree.extras. |
538 |
raise errors.BadFilenameEncoding( |
539 |
relpath, osutils._fs_enc) |
|
|
0.200.1766
by Jelmer Vernooij
Fix another list_files test, integrate is_versioned. |
540 |
if not self._has_dir(relpath): |
541 |
dirnames.remove(name) |
|
542 |
for name in filenames: |
|
543 |
if not self.mapping.is_special_file(name): |
|
|
0.341.1
by Jelmer Vernooij
Fix BadFilenameEncoding raising during WorkingTree.extras. |
544 |
yp = os.path.join(dir_relpath, name) |
545 |
try: |
|
546 |
yield yp.decode(osutils._fs_enc) |
|
547 |
except UnicodeDecodeError: |
|
548 |
raise errors.BadFilenameEncoding( |
|
549 |
yp, osutils._fs_enc) |
|
|
0.200.1327
by Jelmer Vernooij
Factor out all file browsing in extras. |
550 |
|
551 |
def extras(self): |
|
552 |
"""Yield all unversioned files in this WorkingTree. |
|
553 |
"""
|
|
|
0.200.1676
by Jelmer Vernooij
Fix typo. |
554 |
with self.lock_read(): |
|
0.429.11
by Jelmer Vernooij
Merge trunk. |
555 |
index_paths = set([p.decode('utf-8') for p, i in self._recurse_index_entries()]) |
556 |
all_paths = set(self._iter_files_recursive(include_dirs=True)) |
|
557 |
for p in (all_paths - index_paths): |
|
|
0.379.1
by Jelmer Vernooij
Improve unicode handling in GitWorkingTree. |
558 |
if not self._has_dir(p): |
559 |
yield p |
|
|
0.200.605
by Jelmer Vernooij
Ignore directories in WorkingTree.extras(). |
560 |
|
|
0.429.17
by Jelmer Vernooij
Fix some more tests. |
561 |
def _gather_kinds(self, files, kinds): |
562 |
"""See MutableTree._gather_kinds.""" |
|
563 |
with self.lock_tree_write(): |
|
564 |
for pos, f in enumerate(files): |
|
565 |
if kinds[pos] is None: |
|
566 |
fullpath = osutils.normpath(self.abspath(f)) |
|
567 |
try: |
|
568 |
kind = osutils.file_kind(fullpath) |
|
569 |
except OSError as e: |
|
570 |
if e.errno == errno.ENOENT: |
|
571 |
raise errors.NoSuchFile(fullpath) |
|
572 |
if kind == 'directory' and f != '' and os.path.exists(os.path.join(fullpath, '.git')): |
|
573 |
kind = 'tree-reference' |
|
574 |
kinds[pos] = kind |
|
575 |
||
|
0.200.382
by Jelmer Vernooij
Support flushing index. |
576 |
def flush(self): |
|
0.287.6
by Jelmer Vernooij
Fix some more tests. |
577 |
if self._lock_mode != 'w': |
578 |
raise errors.NotWriteLocked(self) |
|
|
0.415.5
by Jelmer Vernooij
Don't flush, just wait for unlock. |
579 |
# TODO(jelmer): This shouldn't be writing in-place, but index.lock is
|
580 |
# already in use and GitFile doesn't allow overriding the lock file name :(
|
|
|
0.415.4
by Jelmer Vernooij
proper locking on index. |
581 |
f = open(self.control_transport.local_abspath('index'), 'wb') |
582 |
# Note that _flush will close the file
|
|
583 |
self._flush(f) |
|
584 |
||
585 |
def _flush(self, f): |
|
586 |
try: |
|
587 |
shaf = SHA1Writer(f) |
|
588 |
write_index_dict(shaf, self.index) |
|
589 |
shaf.close() |
|
590 |
except: |
|
591 |
f.abort() |
|
592 |
raise
|
|
593 |
self._index_dirty = False |
|
|
0.200.382
by Jelmer Vernooij
Support flushing index. |
594 |
|
|
0.200.1202
by Jelmer Vernooij
Implement has_or_had_id. |
595 |
def has_or_had_id(self, file_id): |
596 |
if self.has_id(file_id): |
|
597 |
return True |
|
598 |
if self.had_id(file_id): |
|
599 |
return True |
|
600 |
return False |
|
601 |
||
602 |
def had_id(self, file_id): |
|
603 |
path = self._basis_fileid_map.lookup_file_id(file_id) |
|
604 |
try: |
|
605 |
head = self.repository._git.head() |
|
606 |
except KeyError: |
|
607 |
# Assume no if basis is not accessible
|
|
608 |
return False |
|
|
0.336.2
by Jelmer Vernooij
Don't use ZERO_SHA outside of remote communication to indicate empty history. |
609 |
try: |
610 |
root_tree = self.store[head].tree |
|
611 |
except KeyError: |
|
|
0.200.1205
by Jelmer Vernooij
Implement GitWorkingTree.stored_kind. |
612 |
return False |
|
0.200.1202
by Jelmer Vernooij
Implement has_or_had_id. |
613 |
try: |
614 |
tree_lookup_path(self.store.__getitem__, root_tree, path) |
|
615 |
except KeyError: |
|
616 |
return False |
|
617 |
else: |
|
618 |
return True |
|
619 |
||
|
0.285.1
by Jelmer Vernooij
Swap arguments for tree methods. |
620 |
def get_file_mtime(self, path, file_id=None): |
|
0.200.1200
by Jelmer Vernooij
Support GitWorkingTree.get_file_mtime. |
621 |
"""See Tree.get_file_mtime.""" |
|
0.285.1
by Jelmer Vernooij
Swap arguments for tree methods. |
622 |
try: |
|
0.360.1
by Jelmer Vernooij
Implement GitMemoryTree. |
623 |
return self._lstat(path).st_mtime |
|
0.285.1
by Jelmer Vernooij
Swap arguments for tree methods. |
624 |
except OSError, (num, msg): |
625 |
if num == errno.ENOENT: |
|
626 |
raise errors.NoSuchFile(path) |
|
627 |
raise
|
|
|
0.200.1200
by Jelmer Vernooij
Support GitWorkingTree.get_file_mtime. |
628 |
|
|
0.200.1655
by Jelmer Vernooij
Basic support for git ignores. |
629 |
def is_ignored(self, filename): |
630 |
r"""Check whether the filename matches an ignore pattern. |
|
631 |
||
632 |
If the file is ignored, returns the pattern which caused it to
|
|
633 |
be ignored, otherwise None. So this can simply be used as a
|
|
634 |
boolean if desired."""
|
|
635 |
if getattr(self, '_global_ignoreglobster', None) is None: |
|
636 |
ignore_globs = set() |
|
637 |
ignore_globs.update(ignores.get_runtime_ignores()) |
|
638 |
ignore_globs.update(ignores.get_user_ignores()) |
|
639 |
self._global_ignoreglobster = globbing.ExceptionGlobster(ignore_globs) |
|
|
0.200.1656
by Jelmer Vernooij
Report proper patterns, ignore files. |
640 |
match = self._global_ignoreglobster.match(filename) |
641 |
if match is not None: |
|
642 |
return match |
|
|
0.200.1716
by Jelmer Vernooij
Fix some more tests. |
643 |
try: |
644 |
if self.kind(filename) == 'directory': |
|
645 |
filename += b'/' |
|
646 |
except errors.NoSuchFile: |
|
647 |
pass
|
|
648 |
filename = filename.lstrip(b'/') |
|
|
0.200.1658
by Jelmer Vernooij
Fix handling of ignores - return patterns that matched. |
649 |
ignore_manager = self._get_ignore_manager() |
650 |
ps = list(ignore_manager.find_matching(filename)) |
|
651 |
if not ps: |
|
652 |
return None |
|
653 |
if not ps[-1].is_exclude: |
|
654 |
return None |
|
655 |
return bytes(ps[-1]) |
|
656 |
||
657 |
def _get_ignore_manager(self): |
|
658 |
ignoremanager = getattr(self, '_ignoremanager', None) |
|
659 |
if ignoremanager is not None: |
|
660 |
return ignoremanager |
|
661 |
||
662 |
ignore_manager = IgnoreFilterManager.from_repo(self.repository._git) |
|
663 |
self._ignoremanager = ignore_manager |
|
664 |
return ignore_manager |
|
|
0.200.409
by Jelmer Vernooij
Support parsing .gitignore. |
665 |
|
|
0.200.1716
by Jelmer Vernooij
Fix some more tests. |
666 |
def _flush_ignore_list_cache(self): |
667 |
self._ignoremanager = None |
|
668 |
||
|
0.200.508
by Jelmer Vernooij
Skip inventory caching bits. |
669 |
def set_last_revision(self, revid): |
|
0.200.1720
by Jelmer Vernooij
Fix handling of pending merges. |
670 |
if _mod_revision.is_null(revid): |
671 |
self.branch.set_last_revision_info(0, revid) |
|
672 |
return False |
|
673 |
_mod_revision.check_not_reserved_id(revid) |
|
674 |
try: |
|
675 |
self.branch.generate_revision_history(revid) |
|
676 |
except errors.NoSuchRevision: |
|
677 |
raise errors.GhostRevisionUnusableHere(revid) |
|
|
0.200.508
by Jelmer Vernooij
Skip inventory caching bits. |
678 |
|
|
0.200.379
by Jelmer Vernooij
Re-enable working tree support. |
679 |
def _reset_data(self): |
|
0.248.3
by Jelmer Vernooij
Handle working trees without valid HEAD branch. |
680 |
try: |
681 |
head = self.repository._git.head() |
|
|
0.336.2
by Jelmer Vernooij
Don't use ZERO_SHA outside of remote communication to indicate empty history. |
682 |
except KeyError: |
|
0.200.1202
by Jelmer Vernooij
Implement has_or_had_id. |
683 |
self._basis_fileid_map = GitFileIdMap({}, self.mapping) |
|
0.200.948
by Jelmer Vernooij
Cope with empty inventories. |
684 |
else: |
|
0.336.2
by Jelmer Vernooij
Don't use ZERO_SHA outside of remote communication to indicate empty history. |
685 |
self._basis_fileid_map = self.mapping.get_fileid_map( |
686 |
self.store.__getitem__, self.store[head].tree) |
|
|
0.371.1
by Jelmer Vernooij
Implement WorkingTree.reset_state(). |
687 |
self._fileid_map = self._basis_fileid_map.copy() |
|
0.200.379
by Jelmer Vernooij
Re-enable working tree support. |
688 |
|
|
0.285.1
by Jelmer Vernooij
Swap arguments for tree methods. |
689 |
def get_file_verifier(self, path, file_id=None, stat_value=None): |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
690 |
with self.lock_read(): |
|
0.429.2
by Jelmer Vernooij
Some more work on submodule support. |
691 |
(index, subpath) = self._lookup_index(path.encode('utf-8')) |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
692 |
try: |
|
0.429.2
by Jelmer Vernooij
Some more work on submodule support. |
693 |
return ("GIT", index[subpath].sha) |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
694 |
except KeyError: |
695 |
if self._has_dir(path): |
|
696 |
return ("GIT", None) |
|
|
0.285.1
by Jelmer Vernooij
Swap arguments for tree methods. |
697 |
raise errors.NoSuchFile(path) |
|
0.200.1302
by Jelmer Vernooij
Significantly improve performance of WorkingTree.extras(). |
698 |
|
|
0.285.1
by Jelmer Vernooij
Swap arguments for tree methods. |
699 |
def get_file_sha1(self, path, file_id=None, stat_value=None): |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
700 |
with self.lock_read(): |
|
0.200.1772
by Jelmer Vernooij
Fix handling of unversioned file in get_file_sha1. |
701 |
if not self.is_versioned(path): |
702 |
raise errors.NoSuchFile(path) |
|
703 |
abspath = self.abspath(path) |
|
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
704 |
try: |
705 |
return osutils.sha_file_by_name(abspath) |
|
706 |
except OSError, (num, msg): |
|
707 |
if num in (errno.EISDIR, errno.ENOENT): |
|
|
0.200.1772
by Jelmer Vernooij
Fix handling of unversioned file in get_file_sha1. |
708 |
return None |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
709 |
raise
|
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
710 |
|
|
0.200.610
by Jelmer Vernooij
Support retrieving basis tree properly. |
711 |
def revision_tree(self, revid): |
712 |
return self.repository.revision_tree(revid) |
|
713 |
||
|
0.200.1239
by Jelmer Vernooij
Implement GitWorkingTree.filter_unversioned_files. |
714 |
def filter_unversioned_files(self, files): |
|
0.200.1766
by Jelmer Vernooij
Fix another list_files test, integrate is_versioned. |
715 |
return set([p for p in files if not self.is_versioned(p)]) |
|
0.200.1239
by Jelmer Vernooij
Implement GitWorkingTree.filter_unversioned_files. |
716 |
|
|
0.264.11
by Jelmer Vernooij
Completer implementation of iter_entries_by_dir and list_files. |
717 |
def _is_executable_from_path_and_stat_from_stat(self, path, stat_result): |
718 |
mode = stat_result.st_mode |
|
719 |
return bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode) |
|
720 |
||
|
0.318.1
by Jelmer Vernooij
Fix executable test. |
721 |
def _is_executable_from_path_and_stat_from_basis(self, path, stat_result): |
722 |
return self.basis_tree().is_executable(path) |
|
723 |
||
|
0.285.1
by Jelmer Vernooij
Swap arguments for tree methods. |
724 |
def stored_kind(self, path, file_id=None): |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
725 |
with self.lock_read(): |
|
0.429.2
by Jelmer Vernooij
Some more work on submodule support. |
726 |
(index, subpath) = self._lookup_index(path.encode('utf-8')) |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
727 |
try: |
|
0.429.2
by Jelmer Vernooij
Some more work on submodule support. |
728 |
return mode_kind(index[subpath].mode) |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
729 |
except KeyError: |
730 |
# Maybe it's a directory?
|
|
731 |
if self._has_dir(path): |
|
732 |
return "directory" |
|
|
0.285.1
by Jelmer Vernooij
Swap arguments for tree methods. |
733 |
raise errors.NoSuchFile(path) |
|
0.200.1205
by Jelmer Vernooij
Implement GitWorkingTree.stored_kind. |
734 |
|
|
0.360.1
by Jelmer Vernooij
Implement GitMemoryTree. |
735 |
def _lstat(self, path): |
736 |
return os.lstat(self.abspath(path)) |
|
737 |
||
|
0.285.1
by Jelmer Vernooij
Swap arguments for tree methods. |
738 |
def is_executable(self, path, file_id=None): |
|
0.379.1
by Jelmer Vernooij
Improve unicode handling in GitWorkingTree. |
739 |
with self.lock_read(): |
740 |
if getattr(self, "_supports_executable", osutils.supports_executable)(): |
|
741 |
mode = self._lstat(path).st_mode |
|
742 |
else: |
|
|
0.429.2
by Jelmer Vernooij
Some more work on submodule support. |
743 |
(index, subpath) = self._lookup_index(path.encode('utf-8')) |
|
0.379.1
by Jelmer Vernooij
Improve unicode handling in GitWorkingTree. |
744 |
try: |
|
0.429.2
by Jelmer Vernooij
Some more work on submodule support. |
745 |
mode = index[subpath].mode |
|
0.379.1
by Jelmer Vernooij
Improve unicode handling in GitWorkingTree. |
746 |
except KeyError: |
747 |
mode = 0 |
|
748 |
return bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode) |
|
|
0.264.11
by Jelmer Vernooij
Completer implementation of iter_entries_by_dir and list_files. |
749 |
|
|
0.200.1539
by Jelmer Vernooij
Cope with new is_executable. |
750 |
def _is_executable_from_path_and_stat(self, path, stat_result): |
751 |
if getattr(self, "_supports_executable", osutils.supports_executable)(): |
|
752 |
return self._is_executable_from_path_and_stat_from_stat(path, stat_result) |
|
753 |
else: |
|
754 |
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. |
755 |
|
|
0.264.10
by Jelmer Vernooij
Yield inventory entries. |
756 |
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. |
757 |
if from_dir is None: |
|
0.379.1
by Jelmer Vernooij
Improve unicode handling in GitWorkingTree. |
758 |
from_dir = u"" |
|
0.264.11
by Jelmer Vernooij
Completer implementation of iter_entries_by_dir and list_files. |
759 |
dir_ids = {} |
|
0.200.1767
by Jelmer Vernooij
Fix references to Tree*. |
760 |
fk_entries = {'directory': tree.TreeDirectory, |
761 |
'file': tree.TreeFile, |
|
|
0.429.5
by Jelmer Vernooij
Fix tree_content_summary test. |
762 |
'symlink': tree.TreeLink, |
|
0.429.8
by Jelmer Vernooij
Fix class name. |
763 |
'tree-reference': tree.TreeReference} |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
764 |
with self.lock_read(): |
765 |
root_ie = self._get_dir_ie(u"", None) |
|
766 |
if include_root and not from_dir: |
|
767 |
yield "", "V", root_ie.kind, root_ie.file_id, root_ie |
|
768 |
dir_ids[u""] = root_ie.file_id |
|
769 |
if recursive: |
|
|
0.200.1766
by Jelmer Vernooij
Fix another list_files test, integrate is_versioned. |
770 |
path_iterator = sorted(self._iter_files_recursive(from_dir, include_dirs=True)) |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
771 |
else: |
|
0.379.1
by Jelmer Vernooij
Improve unicode handling in GitWorkingTree. |
772 |
path_iterator = sorted([os.path.join(from_dir, name.decode(osutils._fs_enc)) for name in |
773 |
os.listdir(self.abspath(from_dir).encode(osutils._fs_enc)) if not self.controldir.is_control_filename(name) |
|
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
774 |
and not self.mapping.is_special_file(name)]) |
775 |
for path in path_iterator: |
|
776 |
try: |
|
|
0.429.2
by Jelmer Vernooij
Some more work on submodule support. |
777 |
encoded_path = path.encode("utf-8") |
|
0.379.1
by Jelmer Vernooij
Improve unicode handling in GitWorkingTree. |
778 |
except UnicodeEncodeError: |
779 |
raise errors.BadFilenameEncoding( |
|
780 |
path, osutils._fs_enc) |
|
|
0.429.2
by Jelmer Vernooij
Some more work on submodule support. |
781 |
(index, index_path) = self._lookup_index(encoded_path) |
|
0.379.1
by Jelmer Vernooij
Improve unicode handling in GitWorkingTree. |
782 |
try: |
|
0.429.2
by Jelmer Vernooij
Some more work on submodule support. |
783 |
value = index[index_path] |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
784 |
except KeyError: |
785 |
value = None |
|
|
0.429.5
by Jelmer Vernooij
Fix tree_content_summary test. |
786 |
kind = self.kind(path) |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
787 |
parent, name = posixpath.split(path) |
788 |
for dir_path, dir_ie in self._add_missing_parent_ids(parent, dir_ids): |
|
|
0.200.1766
by Jelmer Vernooij
Fix another list_files test, integrate is_versioned. |
789 |
pass
|
|
0.429.5
by Jelmer Vernooij
Fix tree_content_summary test. |
790 |
if kind in ('directory', 'tree-reference'): |
|
0.200.1766
by Jelmer Vernooij
Fix another list_files test, integrate is_versioned. |
791 |
if path != from_dir: |
792 |
if self._has_dir(path): |
|
793 |
ie = self._get_dir_ie(path, self.path2id(path)) |
|
794 |
status = "V" |
|
795 |
file_id = ie.file_id |
|
796 |
elif self.is_ignored(path): |
|
797 |
status = "I" |
|
798 |
ie = fk_entries[kind]() |
|
799 |
file_id = None |
|
800 |
else: |
|
801 |
status = "?" |
|
802 |
ie = fk_entries[kind]() |
|
803 |
file_id = None |
|
804 |
yield posixpath.relpath(path, from_dir), status, kind, file_id, ie |
|
805 |
continue
|
|
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
806 |
if value is not None: |
807 |
ie = self._get_file_ie(name, path, value, dir_ids[parent]) |
|
|
0.200.1766
by Jelmer Vernooij
Fix another list_files test, integrate is_versioned. |
808 |
yield posixpath.relpath(path, from_dir), "V", ie.kind, ie.file_id, ie |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
809 |
else: |
810 |
ie = fk_entries[kind]() |
|
|
0.200.1766
by Jelmer Vernooij
Fix another list_files test, integrate is_versioned. |
811 |
yield posixpath.relpath(path, from_dir), ("I" if self.is_ignored(path) else "?"), kind, None, ie |
|
0.264.10
by Jelmer Vernooij
Yield inventory entries. |
812 |
|
|
0.200.1206
by Jelmer Vernooij
Implement GitWorkingTree.all_file_ids. |
813 |
def all_file_ids(self): |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
814 |
with self.lock_read(): |
815 |
ids = {u"": self.path2id("")} |
|
816 |
for path in self.index: |
|
817 |
if self.mapping.is_special_file(path): |
|
818 |
continue
|
|
819 |
path = path.decode("utf-8") |
|
820 |
parent = posixpath.dirname(path).strip("/") |
|
821 |
for e in self._add_missing_parent_ids(parent, ids): |
|
822 |
pass
|
|
823 |
ids[path] = self.path2id(path) |
|
824 |
return set(ids.values()) |
|
|
0.200.1206
by Jelmer Vernooij
Implement GitWorkingTree.all_file_ids. |
825 |
|
|
0.200.1710
by Jelmer Vernooij
Regenerate xfail. |
826 |
def all_versioned_paths(self): |
827 |
with self.lock_read(): |
|
828 |
paths = {u""} |
|
829 |
for path in self.index: |
|
830 |
if self.mapping.is_special_file(path): |
|
831 |
continue
|
|
832 |
path = path.decode("utf-8") |
|
833 |
paths.add(path) |
|
834 |
while path != "": |
|
835 |
path = posixpath.dirname(path).strip("/") |
|
836 |
if path in paths: |
|
837 |
break
|
|
838 |
paths.add(path) |
|
839 |
return paths |
|
840 |
||
|
0.200.1716
by Jelmer Vernooij
Fix some more tests. |
841 |
def iter_child_entries(self, path, file_id=None): |
842 |
encoded_path = path.encode('utf-8') |
|
|
0.379.1
by Jelmer Vernooij
Improve unicode handling in GitWorkingTree. |
843 |
with self.lock_read(): |
844 |
parent_id = self.path2id(path) |
|
845 |
found_any = False |
|
846 |
seen_children = set() |
|
847 |
for item_path, value in self.index.iteritems(): |
|
848 |
if self.mapping.is_special_file(item_path): |
|
849 |
continue
|
|
850 |
if not osutils.is_inside(encoded_path, item_path): |
|
851 |
continue
|
|
852 |
found_any = True |
|
853 |
subpath = posixpath.relpath(item_path, encoded_path) |
|
854 |
if b'/' in subpath: |
|
855 |
dirname = subpath.split(b'/', 1)[0] |
|
856 |
file_ie = self._get_dir_ie(posixpath.join(path, dirname), parent_id) |
|
857 |
else: |
|
858 |
(parent, name) = posixpath.split(item_path) |
|
859 |
file_ie = self._get_file_ie( |
|
860 |
name.decode('utf-8'), |
|
861 |
item_path.decode('utf-8'), value, parent_id) |
|
862 |
yield file_ie |
|
863 |
if not found_any and path != u'': |
|
864 |
raise errors.NoSuchFile(path) |
|
|
0.200.1716
by Jelmer Vernooij
Fix some more tests. |
865 |
|
|
0.200.619
by Jelmer Vernooij
Provide dummy WorkingTree.conflicts() implementation rather than spending a lot of time not finding any conflicts. |
866 |
def conflicts(self): |
|
0.200.1675
by Jelmer Vernooij
Remove uses of decorators. |
867 |
with self.lock_read(): |
|
0.369.2
by Jelmer Vernooij
Fix tests. |
868 |
conflicts = _mod_conflicts.ConflictList() |
|
0.369.1
by Jelmer Vernooij
Implement conflict handling. |
869 |
for item_path, value in self.index.iteritems(): |
870 |
if value.flags & FLAG_STAGEMASK: |
|
871 |
conflicts.append(_mod_conflicts.TextConflict(item_path.decode('utf-8'))) |
|
872 |
return conflicts |
|
873 |
||
874 |
def set_conflicts(self, conflicts): |
|
875 |
by_path = set() |
|
876 |
for conflict in conflicts: |
|
877 |
if conflict.typestring in ('text conflict', 'contents conflict'): |
|
878 |
by_path.add(conflict.path.encode('utf-8')) |
|
879 |
else: |
|
880 |
raise errors.UnsupportedOperation(self.set_conflicts, self) |
|
881 |
with self.lock_tree_write(): |
|
882 |
for path in self.index: |
|
883 |
self._set_conflicted(path, path in by_path) |
|
884 |
||
885 |
def _set_conflicted(self, path, conflicted): |
|
886 |
trace.mutter('change conflict: %r -> %r', path, conflicted) |
|
887 |
value = self.index[path] |
|
|
0.415.1
by Jelmer Vernooij
Only write index when it's dirty. |
888 |
self._index_dirty = True |
|
0.369.1
by Jelmer Vernooij
Implement conflict handling. |
889 |
if conflicted: |
890 |
self.index[path] = (value[:9] + (value[9] | FLAG_STAGEMASK, )) |
|
891 |
else: |
|
892 |
self.index[path] = (value[:9] + (value[9] &~ FLAG_STAGEMASK, )) |
|
893 |
||
894 |
def add_conflicts(self, new_conflicts): |
|
895 |
with self.lock_tree_write(): |
|
896 |
for conflict in new_conflicts: |
|
897 |
if conflict.typestring in ('text conflict', 'contents conflict'): |
|
898 |
try: |
|
899 |
self._set_conflicted(conflict.path.encode('utf-8'), True) |
|
900 |
except KeyError: |
|
901 |
raise errors.UnsupportedOperation(self.add_conflicts, self) |
|
902 |
else: |
|
903 |
raise errors.UnsupportedOperation(self.add_conflicts, self) |
|
|
0.200.619
by Jelmer Vernooij
Provide dummy WorkingTree.conflicts() implementation rather than spending a lot of time not finding any conflicts. |
904 |
|
|
0.200.1705
by Jelmer Vernooij
Fix walkdirs. |
905 |
def walkdirs(self, prefix=""): |
|
0.324.1
by Jelmer Vernooij
initial work fixing walkdirs. |
906 |
"""Walk the directories of this tree. |
907 |
||
908 |
returns a generator which yields items in the form:
|
|
909 |
((curren_directory_path, fileid),
|
|
910 |
[(file1_path, file1_name, file1_kind, (lstat), file1_id,
|
|
911 |
file1_kind), ... ])
|
|
912 |
||
913 |
This API returns a generator, which is only valid during the current
|
|
914 |
tree transaction - within a single lock_read or lock_write duration.
|
|
915 |
||
916 |
If the tree is not locked, it may cause an error to be raised,
|
|
917 |
depending on the tree implementation.
|
|
918 |
"""
|
|
919 |
from bisect import bisect_left |
|
920 |
import operator |
|
921 |
disk_top = self.abspath(prefix) |
|
922 |
if disk_top.endswith('/'): |
|
923 |
disk_top = disk_top[:-1] |
|
924 |
top_strip_len = len(disk_top) + 1 |
|
925 |
inventory_iterator = self._walkdirs(prefix) |
|
926 |
disk_iterator = osutils.walkdirs(disk_top, prefix) |
|
927 |
try: |
|
928 |
current_disk = next(disk_iterator) |
|
929 |
disk_finished = False |
|
930 |
except OSError as e: |
|
931 |
if not (e.errno == errno.ENOENT or |
|
932 |
(sys.platform == 'win32' and e.errno == ERROR_PATH_NOT_FOUND)): |
|
933 |
raise
|
|
934 |
current_disk = None |
|
935 |
disk_finished = True |
|
936 |
try: |
|
937 |
current_inv = next(inventory_iterator) |
|
938 |
inv_finished = False |
|
939 |
except StopIteration: |
|
940 |
current_inv = None |
|
941 |
inv_finished = True |
|
942 |
while not inv_finished or not disk_finished: |
|
943 |
if current_disk: |
|
944 |
((cur_disk_dir_relpath, cur_disk_dir_path_from_top), |
|
945 |
cur_disk_dir_content) = current_disk |
|
946 |
else: |
|
947 |
((cur_disk_dir_relpath, cur_disk_dir_path_from_top), |
|
948 |
cur_disk_dir_content) = ((None, None), None) |
|
949 |
if not disk_finished: |
|
950 |
# strip out .bzr dirs
|
|
951 |
if (cur_disk_dir_path_from_top[top_strip_len:] == '' and |
|
952 |
len(cur_disk_dir_content) > 0): |
|
953 |
# osutils.walkdirs can be made nicer -
|
|
954 |
# yield the path-from-prefix rather than the pathjoined
|
|
955 |
# value.
|
|
956 |
bzrdir_loc = bisect_left(cur_disk_dir_content, |
|
957 |
('.git', '.git')) |
|
958 |
if (bzrdir_loc < len(cur_disk_dir_content) |
|
959 |
and self.controldir.is_control_filename( |
|
960 |
cur_disk_dir_content[bzrdir_loc][0])): |
|
961 |
# we dont yield the contents of, or, .bzr itself.
|
|
962 |
del cur_disk_dir_content[bzrdir_loc] |
|
963 |
if inv_finished: |
|
964 |
# everything is unknown
|
|
965 |
direction = 1 |
|
966 |
elif disk_finished: |
|
967 |
# everything is missing
|
|
968 |
direction = -1 |
|
969 |
else: |
|
970 |
direction = cmp(current_inv[0][0], cur_disk_dir_relpath) |
|
971 |
if direction > 0: |
|
972 |
# disk is before inventory - unknown
|
|
973 |
dirblock = [(relpath, basename, kind, stat, None, None) for |
|
974 |
relpath, basename, kind, stat, top_path in |
|
975 |
cur_disk_dir_content] |
|
976 |
yield (cur_disk_dir_relpath, None), dirblock |
|
977 |
try: |
|
978 |
current_disk = next(disk_iterator) |
|
979 |
except StopIteration: |
|
980 |
disk_finished = True |
|
981 |
elif direction < 0: |
|
982 |
# inventory is before disk - missing.
|
|
983 |
dirblock = [(relpath, basename, 'unknown', None, fileid, kind) |
|
984 |
for relpath, basename, dkind, stat, fileid, kind in |
|
985 |
current_inv[1]] |
|
986 |
yield (current_inv[0][0], current_inv[0][1]), dirblock |
|
987 |
try: |
|
988 |
current_inv = next(inventory_iterator) |
|
989 |
except StopIteration: |
|
990 |
inv_finished = True |
|
991 |
else: |
|
992 |
# versioned present directory
|
|
993 |
# merge the inventory and disk data together
|
|
994 |
dirblock = [] |
|
995 |
for relpath, subiterator in itertools.groupby(sorted( |
|
996 |
current_inv[1] + cur_disk_dir_content, |
|
997 |
key=operator.itemgetter(0)), operator.itemgetter(1)): |
|
998 |
path_elements = list(subiterator) |
|
999 |
if len(path_elements) == 2: |
|
1000 |
inv_row, disk_row = path_elements |
|
1001 |
# versioned, present file
|
|
1002 |
dirblock.append((inv_row[0], |
|
1003 |
inv_row[1], disk_row[2], |
|
1004 |
disk_row[3], inv_row[4], |
|
1005 |
inv_row[5])) |
|
1006 |
elif len(path_elements[0]) == 5: |
|
1007 |
# unknown disk file
|
|
1008 |
dirblock.append((path_elements[0][0], |
|
1009 |
path_elements[0][1], path_elements[0][2], |
|
1010 |
path_elements[0][3], None, None)) |
|
1011 |
elif len(path_elements[0]) == 6: |
|
1012 |
# versioned, absent file.
|
|
1013 |
dirblock.append((path_elements[0][0], |
|
1014 |
path_elements[0][1], 'unknown', None, |
|
1015 |
path_elements[0][4], path_elements[0][5])) |
|
1016 |
else: |
|
1017 |
raise NotImplementedError('unreachable code') |
|
1018 |
yield current_inv[0], dirblock |
|
1019 |
try: |
|
1020 |
current_inv = next(inventory_iterator) |
|
1021 |
except StopIteration: |
|
1022 |
inv_finished = True |
|
1023 |
try: |
|
1024 |
current_disk = next(disk_iterator) |
|
1025 |
except StopIteration: |
|
1026 |
disk_finished = True |
|
1027 |
||
1028 |
def _walkdirs(self, prefix=""): |
|
|
0.200.1210
by Jelmer Vernooij
Implement GitWorkingTree._walkdirs. |
1029 |
if prefix != "": |
1030 |
prefix += "/" |
|
|
0.379.1
by Jelmer Vernooij
Improve unicode handling in GitWorkingTree. |
1031 |
prefix = prefix.encode('utf-8') |
|
0.353.1
by Jelmer Vernooij
Iterate over dirs in _walkdirs. |
1032 |
per_dir = defaultdict(set) |
|
0.325.2
by Jelmer Vernooij
Handle root in walkdirs. |
1033 |
if prefix == "": |
|
0.353.1
by Jelmer Vernooij
Iterate over dirs in _walkdirs. |
1034 |
per_dir[('', self.get_root_id())] = set() |
1035 |
def add_entry(path, kind): |
|
1036 |
if path == '' or not path.startswith(prefix): |
|
1037 |
return
|
|
|
0.200.1210
by Jelmer Vernooij
Implement GitWorkingTree._walkdirs. |
1038 |
(dirname, child_name) = posixpath.split(path) |
|
0.353.1
by Jelmer Vernooij
Iterate over dirs in _walkdirs. |
1039 |
add_entry(dirname, 'directory') |
|
0.200.1210
by Jelmer Vernooij
Implement GitWorkingTree._walkdirs. |
1040 |
dirname = dirname.decode("utf-8") |
1041 |
dir_file_id = self.path2id(dirname) |
|
|
0.361.2
by Jelmer Vernooij
Fix up assert. |
1042 |
if not isinstance(value, tuple) or len(value) != 10: |
|
0.361.1
by Jelmer Vernooij
Don't use assert. |
1043 |
raise ValueError(value) |
|
0.353.1
by Jelmer Vernooij
Iterate over dirs in _walkdirs. |
1044 |
per_dir[(dirname, dir_file_id)].add( |
|
0.200.1210
by Jelmer Vernooij
Implement GitWorkingTree._walkdirs. |
1045 |
(path.decode("utf-8"), child_name.decode("utf-8"), |
|
0.353.1
by Jelmer Vernooij
Iterate over dirs in _walkdirs. |
1046 |
kind, None, |
|
0.200.1210
by Jelmer Vernooij
Implement GitWorkingTree._walkdirs. |
1047 |
self.path2id(path.decode("utf-8")), |
|
0.353.1
by Jelmer Vernooij
Iterate over dirs in _walkdirs. |
1048 |
kind)) |
|
0.379.1
by Jelmer Vernooij
Improve unicode handling in GitWorkingTree. |
1049 |
with self.lock_read(): |
1050 |
for path, value in self.index.iteritems(): |
|
1051 |
if self.mapping.is_special_file(path): |
|
1052 |
continue
|
|
1053 |
if not path.startswith(prefix): |
|
1054 |
continue
|
|
1055 |
add_entry(path, mode_kind(value.mode)) |
|
|
0.353.1
by Jelmer Vernooij
Iterate over dirs in _walkdirs. |
1056 |
return ((k, sorted(v)) for (k, v) in sorted(per_dir.iteritems())) |
|
0.200.1542
by Jelmer Vernooij
Refactor iter_changes. |
1057 |
|
|
0.200.1677
by Jelmer Vernooij
Mark shelving as unsupported. |
1058 |
def get_shelf_manager(self): |
|
0.200.1729
by Jelmer Vernooij
ShelvingUnsupported doesn't take an argument. |
1059 |
raise workingtree.ShelvingUnsupported() |
|
0.200.1677
by Jelmer Vernooij
Mark shelving as unsupported. |
1060 |
|
|
0.200.1678
by Jelmer Vernooij
Fix tests. |
1061 |
def store_uncommitted(self): |
1062 |
raise errors.StoringUncommittedNotSupported(self) |
|
1063 |
||
|
0.200.1703
by Jelmer Vernooij
Implement apply_inventory_delta. |
1064 |
def apply_inventory_delta(self, changes): |
1065 |
for (old_path, new_path, file_id, ie) in changes: |
|
1066 |
if old_path is not None: |
|
|
0.429.25
by Jelmer Vernooij
Merge trunk. |
1067 |
(index, old_subpath) = self._lookup_index(old_path.encode('utf-8')) |
|
0.385.1
by Jelmer Vernooij
Use specific_files argument to Tree.iter_entries_by_dir. |
1068 |
try: |
|
0.429.25
by Jelmer Vernooij
Merge trunk. |
1069 |
self._index_del_entry(index, old_subpath) |
|
0.385.1
by Jelmer Vernooij
Use specific_files argument to Tree.iter_entries_by_dir. |
1070 |
except KeyError: |
1071 |
pass
|
|
1072 |
else: |
|
1073 |
self._versioned_dirs = None |
|
|
0.200.1703
by Jelmer Vernooij
Implement apply_inventory_delta. |
1074 |
if new_path is not None and ie.kind != 'directory': |
|
0.429.16
by Jelmer Vernooij
Look at reference_revision on ie. |
1075 |
if ie.kind == 'tree-reference': |
1076 |
self._index_add_entry( |
|
1077 |
new_path, ie.kind, |
|
1078 |
reference_revision=ie.reference_revision) |
|
1079 |
else: |
|
1080 |
self._index_add_entry(new_path, ie.kind) |
|
|
0.316.2
by Jelmer Vernooij
Flush after modifying index. |
1081 |
self.flush() |
|
0.200.1703
by Jelmer Vernooij
Implement apply_inventory_delta. |
1082 |
|
|
0.200.1756
by Jelmer Vernooij
Initial work on annotate support. |
1083 |
def annotate_iter(self, path, file_id=None, |
1084 |
default_revision=_mod_revision.CURRENT_REVISION): |
|
1085 |
"""See Tree.annotate_iter |
|
1086 |
||
1087 |
This implementation will use the basis tree implementation if possible.
|
|
1088 |
Lines not in the basis are attributed to CURRENT_REVISION
|
|
1089 |
||
1090 |
If there are pending merges, lines added by those merges will be
|
|
1091 |
incorrectly attributed to CURRENT_REVISION (but after committing, the
|
|
1092 |
attribution will be correct).
|
|
1093 |
"""
|
|
1094 |
with self.lock_read(): |
|
1095 |
maybe_file_parent_keys = [] |
|
1096 |
for parent_id in self.get_parent_ids(): |
|
1097 |
try: |
|
1098 |
parent_tree = self.revision_tree(parent_id) |
|
1099 |
except errors.NoSuchRevisionInTree: |
|
1100 |
parent_tree = self.branch.repository.revision_tree( |
|
1101 |
parent_id) |
|
1102 |
with parent_tree.lock_read(): |
|
1103 |
# TODO(jelmer): Use rename/copy tracker to find path name in parent
|
|
1104 |
parent_path = path |
|
1105 |
try: |
|
1106 |
kind = parent_tree.kind(parent_path) |
|
1107 |
except errors.NoSuchFile: |
|
1108 |
continue
|
|
1109 |
if kind != 'file': |
|
1110 |
# Note: this is slightly unnecessary, because symlinks and
|
|
1111 |
# directories have a "text" which is the empty text, and we
|
|
1112 |
# know that won't mess up annotations. But it seems cleaner
|
|
1113 |
continue
|
|
1114 |
parent_text_key = ( |
|
1115 |
parent_path, |
|
1116 |
parent_tree.get_file_revision(parent_path)) |
|
1117 |
if parent_text_key not in maybe_file_parent_keys: |
|
1118 |
maybe_file_parent_keys.append(parent_text_key) |
|
1119 |
graph = self.branch.repository.get_file_graph() |
|
1120 |
heads = graph.heads(maybe_file_parent_keys) |
|
1121 |
file_parent_keys = [] |
|
1122 |
for key in maybe_file_parent_keys: |
|
1123 |
if key in heads: |
|
1124 |
file_parent_keys.append(key) |
|
1125 |
||
1126 |
# Now we have the parents of this content
|
|
1127 |
from breezy.annotate import Annotator |
|
1128 |
from .annotate import AnnotateProvider |
|
1129 |
annotator = Annotator(AnnotateProvider( |
|
1130 |
self.branch.repository._file_change_scanner)) |
|
1131 |
text = self.get_file_text(path) |
|
1132 |
this_key = (path, default_revision) |
|
1133 |
annotator.add_special_text(this_key, file_parent_keys, text) |
|
1134 |
annotations = [(key[-1], line) |
|
1135 |
for key, line in annotator.annotate_flat(this_key)] |
|
1136 |
return annotations |
|
1137 |
||
|
0.360.4
by Jelmer Vernooij
Implement MemoryTree.rename_one, MemoryTree.mkdir. |
1138 |
def _rename_one(self, from_rel, to_rel): |
1139 |
os.rename(self.abspath(from_rel), self.abspath(to_rel)) |
|
1140 |
||
|
0.373.1
by Jelmer Vernooij
Fix WorkingTree.reset_state(). |
1141 |
def _build_checkout_with_index(self): |
1142 |
build_index_from_tree( |
|
1143 |
self.user_transport.local_abspath('.'), |
|
1144 |
self.control_transport.local_abspath("index"), |
|
1145 |
self.store, |
|
1146 |
None if self.branch.head is None else self.store[self.branch.head].tree) |
|
1147 |
||
|
0.371.1
by Jelmer Vernooij
Implement WorkingTree.reset_state(). |
1148 |
def reset_state(self, revision_ids=None): |
1149 |
"""Reset the state of the working tree. |
|
1150 |
||
1151 |
This does a hard-reset to a last-known-good state. This is a way to
|
|
1152 |
fix if something got corrupted (like the .git/index file)
|
|
1153 |
"""
|
|
1154 |
with self.lock_tree_write(): |
|
1155 |
if revision_ids is not None: |
|
1156 |
self.set_parent_ids(revision_ids) |
|
|
0.373.1
by Jelmer Vernooij
Fix WorkingTree.reset_state(). |
1157 |
self.index.clear() |
|
0.415.1
by Jelmer Vernooij
Only write index when it's dirty. |
1158 |
self._index_dirty = True |
|
0.373.1
by Jelmer Vernooij
Fix WorkingTree.reset_state(). |
1159 |
if self.branch.head is not None: |
1160 |
for entry in self.store.iter_tree_contents(self.store[self.branch.head].tree): |
|
1161 |
if not validate_path(entry.path): |
|
1162 |
continue
|
|
1163 |
||
1164 |
if S_ISGITLINK(entry.mode): |
|
1165 |
pass # TODO(jelmer): record and return submodule paths |
|
1166 |
else: |
|
1167 |
# Let's at least try to use the working tree file:
|
|
1168 |
try: |
|
1169 |
st = self._lstat(self.abspath(entry.path)) |
|
1170 |
except OSError, (num, msg): |
|
1171 |
# But if it doesn't exist, we'll make something up.
|
|
1172 |
obj = self.store[entry.sha] |
|
1173 |
st = os.stat_result((entry.mode, 0, 0, 0, |
|
1174 |
0, 0, len(obj.as_raw_string()), 0, |
|
1175 |
0, 0)) |
|
|
0.429.2
by Jelmer Vernooij
Some more work on submodule support. |
1176 |
(index, subpath) = self._lookup_index(entry.path) |
1177 |
index[subpath] = index_entry_from_stat(st, entry.sha, 0) |
|
|
0.371.1
by Jelmer Vernooij
Implement WorkingTree.reset_state(). |
1178 |
|
|
0.380.1
by Jelmer Vernooij
Implement WorkingTree.pull. |
1179 |
def pull(self, source, overwrite=False, stop_revision=None, |
1180 |
change_reporter=None, possible_transports=None, local=False, |
|
1181 |
show_base=False): |
|
1182 |
with self.lock_write(), source.lock_read(): |
|
1183 |
old_revision = self.branch.last_revision() |
|
1184 |
basis_tree = self.basis_tree() |
|
1185 |
count = self.branch.pull(source, overwrite, stop_revision, |
|
1186 |
possible_transports=possible_transports, |
|
1187 |
local=local) |
|
1188 |
new_revision = self.branch.last_revision() |
|
1189 |
if new_revision != old_revision: |
|
1190 |
with basis_tree.lock_read(): |
|
1191 |
new_basis_tree = self.branch.basis_tree() |
|
1192 |
merge.merge_inner( |
|
1193 |
self.branch, |
|
1194 |
new_basis_tree, |
|
1195 |
basis_tree, |
|
1196 |
this_tree=self, |
|
1197 |
change_reporter=change_reporter, |
|
1198 |
show_base=show_base) |
|
1199 |
return count |
|
1200 |
||
|
0.429.2
by Jelmer Vernooij
Some more work on submodule support. |
1201 |
def add_reference(self, sub_tree): |
1202 |
"""Add a TreeReference to the tree, pointing at sub_tree. |
|
1203 |
||
1204 |
:param sub_tree: subtree to add.
|
|
1205 |
"""
|
|
1206 |
with self.lock_tree_write(): |
|
1207 |
try: |
|
1208 |
sub_tree_path = self.relpath(sub_tree.basedir) |
|
1209 |
except errors.PathNotChild: |
|
1210 |
raise BadReferenceTarget( |
|
1211 |
self, sub_tree, 'Target not inside tree.') |
|
1212 |
||
1213 |
self._add([sub_tree_path], [None], ['tree-reference']) |
|
1214 |
||
|
0.429.10
by Jelmer Vernooij
use new read_submodule_head from dulwich. |
1215 |
def _read_submodule_head(self, path): |
1216 |
return read_submodule_head(self.abspath(path)) |
|
1217 |
||
|
0.429.5
by Jelmer Vernooij
Fix tree_content_summary test. |
1218 |
def get_reference_revision(self, path, file_id=None): |
1219 |
hexsha = self._read_submodule_head(path) |
|
|
0.429.16
by Jelmer Vernooij
Look at reference_revision on ie. |
1220 |
if hexsha is None: |
1221 |
return _mod_revision.NULL_REVISION |
|
|
0.429.5
by Jelmer Vernooij
Fix tree_content_summary test. |
1222 |
return self.branch.lookup_foreign_revision_id(hexsha) |
1223 |
||
|
0.429.2
by Jelmer Vernooij
Some more work on submodule support. |
1224 |
def get_nested_tree(self, path, file_id=None): |
1225 |
return workingtree.WorkingTree.open(self.abspath(path)) |
|
1226 |
||
|
0.429.5
by Jelmer Vernooij
Fix tree_content_summary test. |
1227 |
def _directory_is_tree_reference(self, relpath): |
1228 |
# as a special case, if a directory contains control files then
|
|
1229 |
# it's a tree reference, except that the root of the tree is not
|
|
1230 |
return relpath and osutils.lexists(self.abspath(relpath) + u"/.git") |
|
1231 |
||
|
0.429.15
by Jelmer Vernooij
Autodetect tree-reference based on index. |
1232 |
def extract(self, sub_path, file_id=None, format=None): |
1233 |
"""Extract a subtree from this tree. |
|
1234 |
||
1235 |
A new branch will be created, relative to the path for this tree.
|
|
1236 |
"""
|
|
1237 |
def mkdirs(path): |
|
1238 |
segments = osutils.splitpath(path) |
|
1239 |
transport = self.branch.controldir.root_transport |
|
1240 |
for name in segments: |
|
1241 |
transport = transport.clone(name) |
|
1242 |
transport.ensure_base() |
|
1243 |
return transport |
|
1244 |
||
1245 |
with self.lock_tree_write(): |
|
1246 |
self.flush() |
|
1247 |
branch_transport = mkdirs(sub_path) |
|
1248 |
if format is None: |
|
1249 |
format = self.controldir.cloning_metadir() |
|
1250 |
branch_transport.ensure_base() |
|
1251 |
branch_bzrdir = format.initialize_on_transport(branch_transport) |
|
1252 |
try: |
|
1253 |
repo = branch_bzrdir.find_repository() |
|
1254 |
except errors.NoRepositoryPresent: |
|
1255 |
repo = branch_bzrdir.create_repository() |
|
1256 |
if not repo.supports_rich_root(): |
|
1257 |
raise errors.RootNotRich() |
|
1258 |
new_branch = branch_bzrdir.create_branch() |
|
1259 |
new_branch.pull(self.branch) |
|
1260 |
for parent_id in self.get_parent_ids(): |
|
1261 |
new_branch.fetch(self.branch, parent_id) |
|
1262 |
tree_transport = self.controldir.root_transport.clone(sub_path) |
|
1263 |
if tree_transport.base != branch_transport.base: |
|
1264 |
tree_bzrdir = format.initialize_on_transport(tree_transport) |
|
1265 |
tree_bzrdir.set_branch_reference(new_branch) |
|
1266 |
else: |
|
1267 |
tree_bzrdir = branch_bzrdir |
|
1268 |
wt = tree_bzrdir.create_workingtree(_mod_revision.NULL_REVISION) |
|
1269 |
wt.set_parent_ids(self.get_parent_ids()) |
|
1270 |
return wt |
|
1271 |
||
|
0.425.1
by Jelmer Vernooij
Add really basic check implementation. |
1272 |
def _get_check_refs(self): |
1273 |
"""Return the references needed to perform a check of this tree. |
|
1274 |
||
1275 |
The default implementation returns no refs, and is only suitable for
|
|
1276 |
trees that have no local caching and can commit on ghosts at any time.
|
|
1277 |
||
1278 |
:seealso: breezy.check for details about check_refs.
|
|
1279 |
"""
|
|
1280 |
return [] |
|
1281 |
||
|
0.428.1
by Jelmer Vernooij
Fix clone_preserves_content test. |
1282 |
def copy_content_into(self, tree, revision_id=None): |
1283 |
"""Copy the current content and user files of this tree into tree.""" |
|
1284 |
with self.lock_read(): |
|
1285 |
if revision_id is None: |
|
1286 |
merge.transform_tree(tree, self) |
|
1287 |
else: |
|
1288 |
# TODO now merge from tree.last_revision to revision (to
|
|
1289 |
# preserve user local changes)
|
|
1290 |
try: |
|
1291 |
other_tree = self.revision_tree(revision_id) |
|
1292 |
except errors.NoSuchRevision: |
|
1293 |
other_tree = self.branch.repository.revision_tree( |
|
1294 |
revision_id) |
|
1295 |
||
1296 |
merge.transform_tree(tree, other_tree) |
|
1297 |
if revision_id == _mod_revision.NULL_REVISION: |
|
1298 |
new_parents = [] |
|
1299 |
else: |
|
1300 |
new_parents = [revision_id] |
|
1301 |
tree.set_parent_ids(new_parents) |
|
1302 |
||
|
0.200.1308
by Jelmer Vernooij
Write index to disk after adding files. |
1303 |
|
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
1304 |
class GitWorkingTreeFormat(workingtree.WorkingTreeFormat): |
1305 |
||
|
0.200.1206
by Jelmer Vernooij
Implement GitWorkingTree.all_file_ids. |
1306 |
_tree_class = GitWorkingTree |
1307 |
||
|
0.200.1295
by Jelmer Vernooij
Mark working trees as not supporting directories. |
1308 |
supports_versioned_directories = False |
1309 |
||
|
0.200.1661
by Jelmer Vernooij
Set supports_setting_file_ids to False. |
1310 |
supports_setting_file_ids = False |
1311 |
||
|
0.200.1677
by Jelmer Vernooij
Mark shelving as unsupported. |
1312 |
supports_store_uncommitted = False |
1313 |
||
|
0.200.1723
by Jelmer Vernooij
Set supports_leftmost_parent_id_as_ghost property. |
1314 |
supports_leftmost_parent_id_as_ghost = False |
1315 |
||
|
0.200.1779
by Jelmer Vernooij
Actually store git revision ids rather than bzr revision ids. |
1316 |
supports_righthand_parent_id_as_ghost = False |
1317 |
||
|
0.200.1768
by Jelmer Vernooij
Fix handling of normalized filenames. |
1318 |
requires_normalized_unicode_filenames = True |
1319 |
||
|
0.367.1
by Jelmer Vernooij
Set supports_merge_modified flag. |
1320 |
supports_merge_modified = False |
1321 |
||
|
0.200.656
by Jelmer Vernooij
Implement GitWorkingTreeFormat._matchingbzrdir. |
1322 |
@property
|
|
0.200.1665
by Jelmer Vernooij
Rename _matchingbzrdir to _matchingcnotroldir. |
1323 |
def _matchingcontroldir(self): |
|
0.200.1641
by Jelmer Vernooij
Use relative imports where possible. |
1324 |
from .dir import LocalGitControlDirFormat |
|
0.200.1013
by Jelmer Vernooij
More renames. |
1325 |
return LocalGitControlDirFormat() |
|
0.200.656
by Jelmer Vernooij
Implement GitWorkingTreeFormat._matchingbzrdir. |
1326 |
|
|
0.200.90
by Jelmer Vernooij
Basic support for opening working trees. |
1327 |
def get_format_description(self): |
1328 |
return "Git Working Tree" |
|
|
0.200.616
by Jelmer Vernooij
Provide custom intertree implementation for GitRevisionTree->GitWorkingTree. |
1329 |
|
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
1330 |
def initialize(self, a_controldir, revision_id=None, from_branch=None, |
|
0.200.1096
by Jelmer Vernooij
Implement GitWorkingTreeFormat.initialize. |
1331 |
accelerator_tree=None, hardlink=False): |
1332 |
"""See WorkingTreeFormat.initialize().""" |
|
|
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
1333 |
if not isinstance(a_controldir, LocalGitDir): |
1334 |
raise errors.IncompatibleFormat(self, a_controldir) |
|
|
0.388.2
by Jelmer Vernooij
Allow opening nascent branches when opening trees. |
1335 |
branch = a_controldir.open_branch(nascent_ok=True) |
|
0.308.1
by Jelmer Vernooij
Set revision id if specified to WorkingTreeFormat.initialize. |
1336 |
if revision_id is not None: |
1337 |
branch.set_last_revision(revision_id) |
|
|
0.200.1680
by Jelmer Vernooij
Fix repo locks. |
1338 |
wt = GitWorkingTree( |
|
0.415.3
by Jelmer Vernooij
Open index on demand. |
1339 |
a_controldir, a_controldir.open_repository(), branch) |
|
0.200.1680
by Jelmer Vernooij
Fix repo locks. |
1340 |
for hook in MutableTree.hooks['post_build_tree']: |
1341 |
hook(wt) |
|
1342 |
return wt |
|
|
0.200.1096
by Jelmer Vernooij
Implement GitWorkingTreeFormat.initialize. |
1343 |
|
|
0.200.616
by Jelmer Vernooij
Provide custom intertree implementation for GitRevisionTree->GitWorkingTree. |
1344 |
|
|
0.287.3
by Jelmer Vernooij
Some improvements to changes iterator. |
1345 |
class InterIndexGitTree(InterGitTrees): |
|
0.200.616
by Jelmer Vernooij
Provide custom intertree implementation for GitRevisionTree->GitWorkingTree. |
1346 |
"""InterTree that works between a Git revision tree and an index.""" |
1347 |
||
1348 |
def __init__(self, source, target): |
|
1349 |
super(InterIndexGitTree, self).__init__(source, target) |
|
1350 |
self._index = target.index |
|
1351 |
||
1352 |
@classmethod
|
|
1353 |
def is_compatible(cls, source, target): |
|
|
0.200.1641
by Jelmer Vernooij
Use relative imports where possible. |
1354 |
from .repository import GitRevisionTree |
|
0.200.1636
by Jelmer Vernooij
Some formatting fixes. |
1355 |
return (isinstance(source, GitRevisionTree) and |
|
0.200.616
by Jelmer Vernooij
Provide custom intertree implementation for GitRevisionTree->GitWorkingTree. |
1356 |
isinstance(target, GitWorkingTree)) |
1357 |
||
|
0.287.3
by Jelmer Vernooij
Some improvements to changes iterator. |
1358 |
def _iter_git_changes(self, want_unchanged=False, specific_files=None, |
|
0.391.4
by Jelmer Vernooij
Simplify InterGitTrees implementation. |
1359 |
require_versioned=False, extra_trees=None, |
|
0.391.3
by Jelmer Vernooij
Simplify handling of unversioned paths. |
1360 |
want_unversioned=False): |
|
0.385.1
by Jelmer Vernooij
Use specific_files argument to Tree.iter_entries_by_dir. |
1361 |
trees = [self.source] |
1362 |
if extra_trees is not None: |
|
1363 |
trees.extend(extra_trees) |
|
1364 |
if specific_files is not None: |
|
1365 |
specific_files = self.target.find_related_paths_across_trees( |
|
1366 |
specific_files, trees, |
|
1367 |
require_versioned=require_versioned) |
|
|
0.287.3
by Jelmer Vernooij
Some improvements to changes iterator. |
1368 |
# TODO(jelmer): Restrict to specific_files, for performance reasons.
|
1369 |
with self.lock_read(): |
|
|
0.200.1754
by Jelmer Vernooij
Avoid updating index when just comparing trees. |
1370 |
return changes_between_git_tree_and_working_copy( |
|
0.287.3
by Jelmer Vernooij
Some improvements to changes iterator. |
1371 |
self.source.store, self.source.tree, |
|
0.357.1
by Jelmer Vernooij
Fix some remove tests. |
1372 |
self.target, want_unchanged=want_unchanged, |
|
0.391.3
by Jelmer Vernooij
Simplify handling of unversioned paths. |
1373 |
want_unversioned=want_unversioned) |
|
0.287.3
by Jelmer Vernooij
Some improvements to changes iterator. |
1374 |
|
|
0.200.1179
by Jelmer Vernooij
Avoid using verifiers for natively imported revisions, save a lot of time. |
1375 |
|
|
0.200.616
by Jelmer Vernooij
Provide custom intertree implementation for GitRevisionTree->GitWorkingTree. |
1376 |
tree.InterTree.register_optimiser(InterIndexGitTree) |
|
0.200.1529
by Jelmer Vernooij
Add changes_between_tree_and_index. |
1377 |
|
1378 |
||
|
0.200.1754
by Jelmer Vernooij
Avoid updating index when just comparing trees. |
1379 |
def changes_between_git_tree_and_working_copy(store, from_tree_sha, target, |
|
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
1380 |
want_unchanged=False, want_unversioned=False): |
|
0.200.1754
by Jelmer Vernooij
Avoid updating index when just comparing trees. |
1381 |
"""Determine the changes between a git tree and a working tree with index. |
1382 |
||
1383 |
"""
|
|
|
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
1384 |
extras = set() |
1385 |
blobs = {} |
|
1386 |
# Report dirified directories to commit_tree first, so that they can be
|
|
1387 |
# replaced with non-empty directories if they have contents.
|
|
1388 |
dirified = [] |
|
|
0.391.6
by Jelmer Vernooij
Directly call index_entry_from_path. |
1389 |
target_root_path = target.abspath('.').encode(sys.getfilesystemencoding()) |
|
0.429.11
by Jelmer Vernooij
Merge trunk. |
1390 |
for path, index_entry in target._recurse_index_entries(): |
|
0.391.6
by Jelmer Vernooij
Directly call index_entry_from_path. |
1391 |
try: |
1392 |
live_entry = index_entry_from_path( |
|
1393 |
target.abspath(path.decode('utf-8')).encode(osutils._fs_enc)) |
|
1394 |
except EnvironmentError as e: |
|
|
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
1395 |
if e.errno == errno.ENOENT: |
1396 |
# Entry was removed; keep it listed, but mark it as gone.
|
|
1397 |
blobs[path] = (ZERO_SHA, 0) |
|
1398 |
elif e.errno == errno.EISDIR: |
|
1399 |
# Entry was turned into a directory
|
|
1400 |
dirified.append((path, Tree().id, stat.S_IFDIR)) |
|
1401 |
store.add_object(Tree()) |
|
|
0.391.6
by Jelmer Vernooij
Directly call index_entry_from_path. |
1402 |
else: |
1403 |
raise
|
|
|
0.391.1
by Jelmer Vernooij
Use new iter_fresh_objects. |
1404 |
else: |
|
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
1405 |
blobs[path] = (live_entry.sha, cleanup_mode(live_entry.mode)) |
|
0.391.3
by Jelmer Vernooij
Simplify handling of unversioned paths. |
1406 |
if want_unversioned: |
1407 |
for e in target.extras(): |
|
1408 |
ap = target.abspath(e) |
|
1409 |
st = os.lstat(ap) |
|
1410 |
try: |
|
1411 |
np, accessible = osutils.normalized_filename(e) |
|
1412 |
except UnicodeDecodeError: |
|
1413 |
raise errors.BadFilenameEncoding( |
|
1414 |
e, osutils._fs_enc) |
|
1415 |
if stat.S_ISDIR(st.st_mode): |
|
1416 |
blob = Tree() |
|
1417 |
else: |
|
1418 |
blob = blob_from_path_and_stat(ap.encode('utf-8'), st) |
|
1419 |
store.add_object(blob) |
|
1420 |
np = np.encode('utf-8') |
|
|
0.392.1
by Jelmer Vernooij
Call cleanup mode for extra entries. |
1421 |
blobs[np] = (blob.id, cleanup_mode(st.st_mode)) |
|
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
1422 |
extras.add(np) |
1423 |
to_tree_sha = commit_tree(store, dirified + [(p, s, m) for (p, (s, m)) in blobs.iteritems()]) |
|
1424 |
return store.tree_changes( |
|
|
0.391.2
by Jelmer Vernooij
Pass along target_missing. |
1425 |
from_tree_sha, to_tree_sha, include_trees=True, |
|
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
1426 |
want_unchanged=want_unchanged, change_type_same=True), extras |