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