1
# Copyright (C) 2009-2018 Jelmer Vernooij <jelmer@jelmer.uk>
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
from __future__ import absolute_import
22
from collections import deque
24
from io import BytesIO
27
from dulwich.config import (
29
ConfigFile as GitConfigFile,
31
from dulwich.diff_tree import tree_changes, RenameDetector
32
from dulwich.errors import NotTreeError
33
from dulwich.index import (
34
blob_from_path_and_stat,
37
index_entry_from_stat,
40
from dulwich.object_store import (
44
from dulwich.objects import (
55
controldir as _mod_controldir,
65
from ..revision import (
69
from ..sixish import (
74
from .mapping import (
81
from .transportgit import (
85
from ..bzr.inventorytree import InventoryTreeChange
88
class GitTreeDirectory(_mod_tree.TreeDirectory):
90
__slots__ = ['file_id', 'name', 'parent_id']
92
def __init__(self, file_id, name, parent_id):
93
self.file_id = file_id
95
self.parent_id = parent_id
102
def executable(self):
106
return self.__class__(
107
self.file_id, self.name, self.parent_id)
110
return "%s(file_id=%r, name=%r, parent_id=%r)" % (
111
self.__class__.__name__, self.file_id, self.name,
114
def __eq__(self, other):
115
return (self.kind == other.kind and
116
self.file_id == other.file_id and
117
self.name == other.name and
118
self.parent_id == other.parent_id)
121
class GitTreeFile(_mod_tree.TreeFile):
123
__slots__ = ['file_id', 'name', 'parent_id', 'text_size',
124
'executable', 'git_sha1']
126
def __init__(self, file_id, name, parent_id, text_size=None,
127
git_sha1=None, executable=None):
128
self.file_id = file_id
130
self.parent_id = parent_id
131
self.text_size = text_size
132
self.git_sha1 = git_sha1
133
self.executable = executable
139
def __eq__(self, other):
140
return (self.kind == other.kind and
141
self.file_id == other.file_id and
142
self.name == other.name and
143
self.parent_id == other.parent_id and
144
self.git_sha1 == other.git_sha1 and
145
self.text_size == other.text_size and
146
self.executable == other.executable)
149
return ("%s(file_id=%r, name=%r, parent_id=%r, text_size=%r, "
150
"git_sha1=%r, executable=%r)") % (
151
type(self).__name__, self.file_id, self.name, self.parent_id,
152
self.text_size, self.git_sha1, self.executable)
155
ret = self.__class__(
156
self.file_id, self.name, self.parent_id)
157
ret.git_sha1 = self.git_sha1
158
ret.text_size = self.text_size
159
ret.executable = self.executable
163
class GitTreeSymlink(_mod_tree.TreeLink):
165
__slots__ = ['file_id', 'name', 'parent_id', 'symlink_target']
167
def __init__(self, file_id, name, parent_id,
168
symlink_target=None):
169
self.file_id = file_id
171
self.parent_id = parent_id
172
self.symlink_target = symlink_target
179
def executable(self):
187
return "%s(file_id=%r, name=%r, parent_id=%r, symlink_target=%r)" % (
188
type(self).__name__, self.file_id, self.name, self.parent_id,
191
def __eq__(self, other):
192
return (self.kind == other.kind and
193
self.file_id == other.file_id and
194
self.name == other.name and
195
self.parent_id == other.parent_id and
196
self.symlink_target == other.symlink_target)
199
return self.__class__(
200
self.file_id, self.name, self.parent_id,
204
class GitTreeSubmodule(_mod_tree.TreeReference):
206
__slots__ = ['file_id', 'name', 'parent_id', 'reference_revision']
208
def __init__(self, file_id, name, parent_id, reference_revision=None):
209
self.file_id = file_id
211
self.parent_id = parent_id
212
self.reference_revision = reference_revision
215
def executable(self):
220
return 'tree-reference'
223
return ("%s(file_id=%r, name=%r, parent_id=%r, "
224
"reference_revision=%r)") % (
225
type(self).__name__, self.file_id, self.name, self.parent_id,
226
self.reference_revision)
228
def __eq__(self, other):
229
return (self.kind == other.kind and
230
self.file_id == other.file_id and
231
self.name == other.name and
232
self.parent_id == other.parent_id and
233
self.reference_revision == other.reference_revision)
236
return self.__class__(
237
self.file_id, self.name, self.parent_id,
238
self.reference_revision)
242
'directory': GitTreeDirectory,
244
'symlink': GitTreeSymlink,
245
'tree-reference': GitTreeSubmodule,
249
def ensure_normalized_path(path):
250
"""Check whether path is normalized.
252
:raises InvalidNormalization: When path is not normalized, and cannot be
253
accessed on this platform by the normalized path.
254
:return: The NFC normalised version of path.
256
norm_path, can_access = osutils.normalized_filename(path)
257
if norm_path != path:
261
raise errors.InvalidNormalization(path)
265
class GitTree(_mod_tree.Tree):
267
def iter_git_objects(self):
268
"""Iterate over all the objects in the tree.
270
:return :Yields tuples with (path, sha, mode)
272
raise NotImplementedError(self.iter_git_objects)
274
def git_snapshot(self, want_unversioned=False):
275
"""Snapshot a tree, and return tree object.
277
:return: Tree sha and set of extras
279
raise NotImplementedError(self.snapshot)
282
class GitRevisionTree(revisiontree.RevisionTree, GitTree):
283
"""Revision tree implementation based on Git objects."""
285
def __init__(self, repository, revision_id):
286
self._revision_id = revision_id
287
self._repository = repository
288
self._submodules = None
289
self.store = repository._git.object_store
290
if not isinstance(revision_id, bytes):
291
raise TypeError(revision_id)
292
self.commit_id, self.mapping = repository.lookup_bzr_revision_id(
294
if revision_id == NULL_REVISION:
296
self.mapping = default_mapping
299
commit = self.store[self.commit_id]
301
raise errors.NoSuchRevision(repository, revision_id)
302
self.tree = commit.tree
304
def git_snapshot(self, want_unversioned=False):
305
return self.tree, set()
307
def _submodule_info(self):
308
if self._submodules is None:
310
with self.get_file('.gitmodules') as f:
311
config = GitConfigFile.from_file(f)
314
for path, url, section in parse_submodules(config)}
315
except errors.NoSuchFile:
316
self._submodules = {}
317
return self._submodules
319
def _get_submodule_repository(self, relpath):
320
if not isinstance(relpath, bytes):
321
raise TypeError(relpath)
323
info = self._submodule_info()[relpath]
325
nested_repo_transport = self._repository.controldir.user_transport.clone(
326
decode_git_path(relpath))
328
nested_repo_transport = self._repository.controldir.control_transport.clone(
329
posixpath.join('modules', decode_git_path(info[1])))
330
nested_controldir = _mod_controldir.ControlDir.open_from_transport(
331
nested_repo_transport)
332
return nested_controldir.find_repository()
334
def _get_submodule_store(self, relpath):
335
return self._get_submodule_repository(relpath)._git.object_store
337
def get_nested_tree(self, path):
338
encoded_path = encode_git_path(path)
339
nested_repo = self._get_submodule_repository(encoded_path)
340
ref_rev = self.get_reference_revision(path)
341
return nested_repo.revision_tree(ref_rev)
343
def supports_rename_tracking(self):
346
def get_file_revision(self, path):
347
change_scanner = self._repository._file_change_scanner
348
if self.commit_id == ZERO_SHA:
350
(unused_path, commit_id) = change_scanner.find_last_change_revision(
351
encode_git_path(path), self.commit_id)
352
return self._repository.lookup_foreign_revision_id(
353
commit_id, self.mapping)
355
def get_file_mtime(self, path):
357
revid = self.get_file_revision(path)
359
raise errors.NoSuchFile(path)
361
rev = self._repository.get_revision(revid)
362
except errors.NoSuchRevision:
363
raise _mod_tree.FileTimestampUnavailable(path)
366
def id2path(self, file_id, recurse='down'):
368
path = self.mapping.parse_file_id(file_id)
370
raise errors.NoSuchId(self, file_id)
371
if self.is_versioned(path):
373
raise errors.NoSuchId(self, file_id)
375
def is_versioned(self, path):
376
return self.has_filename(path)
378
def path2id(self, path):
379
if self.mapping.is_special_file(path):
381
if not self.is_versioned(path):
383
return self.mapping.generate_file_id(osutils.safe_unicode(path))
385
def all_file_ids(self):
386
raise errors.UnsupportedOperation(self.all_file_ids, self)
388
def all_versioned_paths(self):
390
todo = [(self.store, b'', self.tree)]
392
(store, path, tree_id) = todo.pop()
395
tree = store[tree_id]
396
for name, mode, hexsha in tree.items():
397
subpath = posixpath.join(path, name)
398
ret.add(decode_git_path(subpath))
399
if stat.S_ISDIR(mode):
400
todo.append((store, subpath, hexsha))
403
def _lookup_path(self, path):
404
if self.tree is None:
405
raise errors.NoSuchFile(path)
407
encoded_path = encode_git_path(path)
408
parts = encoded_path.split(b'/')
412
for i, p in enumerate(parts):
416
if not isinstance(obj, Tree):
417
raise NotTreeError(hexsha)
419
mode, hexsha = obj[p]
421
raise errors.NoSuchFile(path)
422
if S_ISGITLINK(mode) and i != len(parts) - 1:
423
store = self._get_submodule_store(b'/'.join(parts[:i + 1]))
424
hexsha = store[hexsha].tree
425
return (store, mode, hexsha)
427
def is_executable(self, path):
428
(store, mode, hexsha) = self._lookup_path(path)
430
# the tree root is a directory
432
return mode_is_executable(mode)
434
def kind(self, path):
435
(store, mode, hexsha) = self._lookup_path(path)
437
# the tree root is a directory
439
return mode_kind(mode)
441
def has_filename(self, path):
443
self._lookup_path(path)
444
except errors.NoSuchFile:
449
def _submodule_info(self):
450
if self._submodules is None:
452
with self.get_file('.gitmodules') as f:
453
config = GitConfigFile.from_file(f)
456
for path, url, section in parse_submodules(config)}
457
except errors.NoSuchFile:
458
self._submodules = {}
459
return self._submodules
461
def list_files(self, include_root=False, from_dir=None, recursive=True,
462
recurse_nested=False):
463
if self.tree is None:
465
if from_dir is None or from_dir == '.':
467
(store, mode, hexsha) = self._lookup_path(from_dir)
468
if mode is None: # Root
469
root_ie = self._get_dir_ie(b"", None)
471
parent_path = posixpath.dirname(from_dir)
472
parent_id = self.mapping.generate_file_id(parent_path)
473
if mode_kind(mode) == 'directory':
474
root_ie = self._get_dir_ie(encode_git_path(from_dir), parent_id)
476
root_ie = self._get_file_ie(
477
store, encode_git_path(from_dir),
478
posixpath.basename(from_dir), mode, hexsha)
480
yield (from_dir, "V", root_ie.kind, root_ie)
482
if root_ie.kind == 'directory':
483
todo.append((store, encode_git_path(from_dir),
484
b"", hexsha, root_ie.file_id))
486
(store, path, relpath, hexsha, parent_id) = todo.pop()
488
for name, mode, hexsha in tree.iteritems():
489
if self.mapping.is_special_file(name):
491
child_path = posixpath.join(path, name)
492
child_relpath = posixpath.join(relpath, name)
493
if S_ISGITLINK(mode) and recurse_nested:
495
store = self._get_submodule_store(child_relpath)
496
hexsha = store[hexsha].tree
497
if stat.S_ISDIR(mode):
498
ie = self._get_dir_ie(child_path, parent_id)
501
(store, child_path, child_relpath, hexsha,
504
ie = self._get_file_ie(
505
store, child_path, name, mode, hexsha, parent_id)
506
yield (decode_git_path(child_relpath), "V", ie.kind, ie)
508
def _get_file_ie(self, store, path, name, mode, hexsha, parent_id):
509
if not isinstance(path, bytes):
510
raise TypeError(path)
511
if not isinstance(name, bytes):
512
raise TypeError(name)
513
kind = mode_kind(mode)
514
path = decode_git_path(path)
515
name = decode_git_path(name)
516
file_id = self.mapping.generate_file_id(path)
517
ie = entry_factory[kind](file_id, name, parent_id)
518
if kind == 'symlink':
519
ie.symlink_target = decode_git_path(store[hexsha].data)
520
elif kind == 'tree-reference':
521
ie.reference_revision = self.mapping.revision_id_foreign_to_bzr(
526
ie.executable = mode_is_executable(mode)
529
def _get_dir_ie(self, path, parent_id):
530
path = decode_git_path(path)
531
file_id = self.mapping.generate_file_id(path)
532
return GitTreeDirectory(file_id, posixpath.basename(path), parent_id)
534
def iter_child_entries(self, path):
535
(store, mode, tree_sha) = self._lookup_path(path)
537
if mode is not None and not stat.S_ISDIR(mode):
540
encoded_path = encode_git_path(path)
541
file_id = self.path2id(path)
542
tree = store[tree_sha]
543
for name, mode, hexsha in tree.iteritems():
544
if self.mapping.is_special_file(name):
546
child_path = posixpath.join(encoded_path, name)
547
if stat.S_ISDIR(mode):
548
yield self._get_dir_ie(child_path, file_id)
550
yield self._get_file_ie(store, child_path, name, mode, hexsha,
553
def iter_entries_by_dir(self, specific_files=None,
554
recurse_nested=False):
555
if self.tree is None:
557
if specific_files is not None:
558
if specific_files in ([""], []):
559
specific_files = None
561
specific_files = set([encode_git_path(p)
562
for p in specific_files])
563
todo = deque([(self.store, b"", self.tree, self.path2id(''))])
564
if specific_files is None or u"" in specific_files:
565
yield u"", self._get_dir_ie(b"", None)
567
store, path, tree_sha, parent_id = todo.popleft()
568
tree = store[tree_sha]
570
for name, mode, hexsha in tree.iteritems():
571
if self.mapping.is_special_file(name):
573
child_path = posixpath.join(path, name)
574
child_path_decoded = decode_git_path(child_path)
575
if recurse_nested and S_ISGITLINK(mode):
577
store = self._get_submodule_store(child_path)
578
hexsha = store[hexsha].tree
579
if stat.S_ISDIR(mode):
580
if (specific_files is None or
581
any([p for p in specific_files if p.startswith(
584
(store, child_path, hexsha,
585
self.path2id(child_path_decoded)))
586
if specific_files is None or child_path in specific_files:
587
if stat.S_ISDIR(mode):
588
yield (child_path_decoded,
589
self._get_dir_ie(child_path, parent_id))
591
yield (child_path_decoded,
592
self._get_file_ie(store, child_path, name, mode,
594
todo.extendleft(reversed(extradirs))
596
def iter_references(self):
597
if self.supports_tree_reference():
598
for path, entry in self.iter_entries_by_dir():
599
if entry.kind == 'tree-reference':
602
def get_revision_id(self):
603
"""See RevisionTree.get_revision_id."""
604
return self._revision_id
606
def get_file_sha1(self, path, stat_value=None):
607
if self.tree is None:
608
raise errors.NoSuchFile(path)
609
return osutils.sha_string(self.get_file_text(path))
611
def get_file_verifier(self, path, stat_value=None):
612
(store, mode, hexsha) = self._lookup_path(path)
613
return ("GIT", hexsha)
615
def get_file_size(self, path):
616
(store, mode, hexsha) = self._lookup_path(path)
617
if stat.S_ISREG(mode):
618
return len(store[hexsha].data)
621
def get_file_text(self, path):
622
"""See RevisionTree.get_file_text."""
623
(store, mode, hexsha) = self._lookup_path(path)
624
if stat.S_ISREG(mode):
625
return store[hexsha].data
629
def get_symlink_target(self, path):
630
"""See RevisionTree.get_symlink_target."""
631
(store, mode, hexsha) = self._lookup_path(path)
632
if stat.S_ISLNK(mode):
633
return decode_git_path(store[hexsha].data)
637
def get_reference_revision(self, path):
638
"""See RevisionTree.get_symlink_target."""
639
(store, mode, hexsha) = self._lookup_path(path)
640
if S_ISGITLINK(mode):
642
nested_repo = self._get_submodule_repository(encode_git_path(path))
643
except errors.NotBranchError:
644
return self.mapping.revision_id_foreign_to_bzr(hexsha)
646
return nested_repo.lookup_foreign_revision_id(hexsha)
650
def _comparison_data(self, entry, path):
652
return None, False, None
653
return entry.kind, entry.executable, None
655
def path_content_summary(self, path):
656
"""See Tree.path_content_summary."""
658
(store, mode, hexsha) = self._lookup_path(path)
659
except errors.NoSuchFile:
660
return ('missing', None, None, None)
661
kind = mode_kind(mode)
663
executable = mode_is_executable(mode)
664
contents = store[hexsha].data
665
return (kind, len(contents), executable,
666
osutils.sha_string(contents))
667
elif kind == 'symlink':
668
return (kind, None, None, decode_git_path(store[hexsha].data))
669
elif kind == 'tree-reference':
670
nested_repo = self._get_submodule_repository(encode_git_path(path))
671
return (kind, None, None,
672
nested_repo.lookup_foreign_revision_id(hexsha))
674
return (kind, None, None, None)
676
def find_related_paths_across_trees(self, paths, trees=[],
677
require_versioned=True):
680
if require_versioned:
681
trees = [self] + (trees if trees is not None else [])
685
if t.is_versioned(p):
690
raise errors.PathsNotVersionedError(unversioned)
691
return filter(self.is_versioned, paths)
693
def _iter_tree_contents(self, include_trees=False):
694
if self.tree is None:
696
return self.store.iter_tree_contents(
697
self.tree, include_trees=include_trees)
699
def annotate_iter(self, path, default_revision=CURRENT_REVISION):
700
"""Return an iterator of revision_id, line tuples.
702
For working trees (and mutable trees in general), the special
703
revision_id 'current:' will be used for lines that are new in this
704
tree, e.g. uncommitted changes.
705
:param default_revision: For lines that don't match a basis, mark them
706
with this revision id. Not all implementations will make use of
709
with self.lock_read():
710
# Now we have the parents of this content
711
from breezy.annotate import Annotator
712
from .annotate import AnnotateProvider
713
annotator = Annotator(AnnotateProvider(
714
self._repository._file_change_scanner))
715
this_key = (path, self.get_file_revision(path))
716
annotations = [(key[-1], line)
717
for key, line in annotator.annotate_flat(this_key)]
720
def _get_rules_searcher(self, default_searcher):
721
return default_searcher
723
def walkdirs(self, prefix=u""):
724
(store, mode, hexsha) = self._lookup_path(prefix)
726
[(store, encode_git_path(prefix), hexsha)])
728
store, path, tree_sha = todo.popleft()
729
path_decoded = decode_git_path(path)
730
tree = store[tree_sha]
732
for name, mode, hexsha in tree.iteritems():
733
if self.mapping.is_special_file(name):
735
child_path = posixpath.join(path, name)
736
if stat.S_ISDIR(mode):
737
todo.append((store, child_path, hexsha))
739
(decode_git_path(child_path), decode_git_path(name),
740
mode_kind(mode), None,
742
yield path_decoded, children
744
def preview_transform(self, pb=None):
745
from .transform import GitTransformPreview
746
return GitTransformPreview(self, pb=pb)
749
def tree_delta_from_git_changes(changes, mappings,
751
require_versioned=False, include_root=False,
752
source_extras=None, target_extras=None):
753
"""Create a TreeDelta from two git trees.
755
source and target are iterators over tuples with:
756
(filename, sha, mode)
758
(old_mapping, new_mapping) = mappings
759
if target_extras is None:
760
target_extras = set()
761
if source_extras is None:
762
source_extras = set()
763
ret = delta.TreeDelta()
765
for (change_type, old, new) in changes:
766
(oldpath, oldmode, oldsha) = old
767
(newpath, newmode, newsha) = new
768
if newpath == b'' and not include_root:
770
copied = (change_type == 'copy')
771
if oldpath is not None:
772
oldpath_decoded = decode_git_path(oldpath)
774
oldpath_decoded = None
775
if newpath is not None:
776
newpath_decoded = decode_git_path(newpath)
778
newpath_decoded = None
779
if not (specific_files is None or
780
(oldpath is not None and
781
osutils.is_inside_or_parent_of_any(
782
specific_files, oldpath_decoded)) or
783
(newpath is not None and
784
osutils.is_inside_or_parent_of_any(
785
specific_files, newpath_decoded))):
795
oldversioned = (oldpath not in source_extras)
797
oldexe = mode_is_executable(oldmode)
798
oldkind = mode_kind(oldmode)
806
(oldparentpath, oldname) = osutils.split(oldpath_decoded)
807
oldparent = old_mapping.generate_file_id(oldparentpath)
815
newversioned = (newpath not in target_extras)
817
newexe = mode_is_executable(newmode)
818
newkind = mode_kind(newmode)
822
if newpath_decoded == u'':
826
newparentpath, newname = osutils.split(newpath_decoded)
827
newparent = new_mapping.generate_file_id(newparentpath)
828
if oldversioned and not copied:
829
fileid = old_mapping.generate_file_id(oldpath_decoded)
831
fileid = new_mapping.generate_file_id(newpath_decoded)
834
if old_mapping.is_special_file(oldpath):
836
if new_mapping.is_special_file(newpath):
838
if oldpath is None and newpath is None:
840
change = InventoryTreeChange(
841
fileid, (oldpath_decoded, newpath_decoded), (oldsha != newsha),
842
(oldversioned, newversioned),
843
(oldparent, newparent), (oldname, newname),
844
(oldkind, newkind), (oldexe, newexe),
846
if newpath is not None and not newversioned and newkind != 'directory':
847
change.file_id = None
848
ret.unversioned.append(change)
849
elif change_type == 'add':
850
added.append((newpath, newkind))
851
elif newpath is None or newmode == 0:
852
ret.removed.append(change)
853
elif change_type == 'delete':
854
ret.removed.append(change)
855
elif change_type == 'copy':
856
if stat.S_ISDIR(oldmode) and stat.S_ISDIR(newmode):
858
ret.copied.append(change)
859
elif change_type == 'rename':
860
if stat.S_ISDIR(oldmode) and stat.S_ISDIR(newmode):
862
ret.renamed.append(change)
863
elif mode_kind(oldmode) != mode_kind(newmode):
864
ret.kind_changed.append(change)
865
elif oldsha != newsha or oldmode != newmode:
866
if stat.S_ISDIR(oldmode) and stat.S_ISDIR(newmode):
868
ret.modified.append(change)
870
ret.unchanged.append(change)
872
implicit_dirs = {b''}
873
for path, kind in added:
874
if kind == 'directory' or path in target_extras:
876
implicit_dirs.update(osutils.parent_directories(path))
878
for path, kind in added:
879
if kind == 'directory' and path not in implicit_dirs:
881
path_decoded = decode_git_path(path)
882
parent_path, basename = osutils.split(path_decoded)
883
parent_id = new_mapping.generate_file_id(parent_path)
884
file_id = new_mapping.generate_file_id(path_decoded)
887
file_id, (None, path_decoded), True,
890
(None, basename), (None, kind), (None, False)))
895
def changes_from_git_changes(changes, mapping, specific_files=None,
896
include_unchanged=False, source_extras=None,
898
"""Create a iter_changes-like generator from a git stream.
900
source and target are iterators over tuples with:
901
(filename, sha, mode)
903
if target_extras is None:
904
target_extras = set()
905
if source_extras is None:
906
source_extras = set()
907
for (change_type, old, new) in changes:
908
if change_type == 'unchanged' and not include_unchanged:
910
(oldpath, oldmode, oldsha) = old
911
(newpath, newmode, newsha) = new
912
if oldpath is not None:
913
oldpath_decoded = decode_git_path(oldpath)
915
oldpath_decoded = None
916
if newpath is not None:
917
newpath_decoded = decode_git_path(newpath)
919
newpath_decoded = None
920
if not (specific_files is None or
921
(oldpath_decoded is not None and
922
osutils.is_inside_or_parent_of_any(
923
specific_files, oldpath_decoded)) or
924
(newpath_decoded is not None and
925
osutils.is_inside_or_parent_of_any(
926
specific_files, newpath_decoded))):
928
if oldpath is not None and mapping.is_special_file(oldpath):
930
if newpath is not None and mapping.is_special_file(newpath):
939
oldversioned = (oldpath not in source_extras)
941
oldexe = mode_is_executable(oldmode)
942
oldkind = mode_kind(oldmode)
946
if oldpath_decoded == u'':
950
(oldparentpath, oldname) = osutils.split(oldpath_decoded)
951
oldparent = mapping.generate_file_id(oldparentpath)
959
newversioned = (newpath not in target_extras)
961
newexe = mode_is_executable(newmode)
962
newkind = mode_kind(newmode)
966
if newpath_decoded == u'':
970
newparentpath, newname = osutils.split(newpath_decoded)
971
newparent = mapping.generate_file_id(newparentpath)
972
if (not include_unchanged and
973
oldkind == 'directory' and newkind == 'directory' and
974
oldpath_decoded == newpath_decoded):
976
if oldversioned and change_type != 'copy':
977
fileid = mapping.generate_file_id(oldpath_decoded)
979
fileid = mapping.generate_file_id(newpath_decoded)
982
yield InventoryTreeChange(
983
fileid, (oldpath_decoded, newpath_decoded), (oldsha != newsha),
984
(oldversioned, newversioned),
985
(oldparent, newparent), (oldname, newname),
986
(oldkind, newkind), (oldexe, newexe),
987
copied=(change_type == 'copy'))
990
class InterGitTrees(_mod_tree.InterTree):
991
"""InterTree that works between two git trees."""
993
_matching_from_tree_format = None
994
_matching_to_tree_format = None
995
_test_mutable_trees_to_test_trees = None
997
def __init__(self, source, target):
998
super(InterGitTrees, self).__init__(source, target)
999
if self.source.store == self.target.store:
1000
self.store = self.source.store
1002
self.store = OverlayObjectStore(
1003
[self.source.store, self.target.store])
1004
self.rename_detector = RenameDetector(self.store)
1007
def is_compatible(cls, source, target):
1008
return isinstance(source, GitTree) and isinstance(target, GitTree)
1010
def compare(self, want_unchanged=False, specific_files=None,
1011
extra_trees=None, require_versioned=False, include_root=False,
1012
want_unversioned=False):
1013
with self.lock_read():
1014
changes, source_extras, target_extras = self._iter_git_changes(
1015
want_unchanged=want_unchanged,
1016
require_versioned=require_versioned,
1017
specific_files=specific_files,
1018
extra_trees=extra_trees,
1019
want_unversioned=want_unversioned)
1020
return tree_delta_from_git_changes(
1021
changes, (self.source.mapping, self.target.mapping),
1022
specific_files=specific_files,
1023
include_root=include_root,
1024
source_extras=source_extras, target_extras=target_extras)
1026
def iter_changes(self, include_unchanged=False, specific_files=None,
1027
pb=None, extra_trees=[], require_versioned=True,
1028
want_unversioned=False):
1029
with self.lock_read():
1030
changes, source_extras, target_extras = self._iter_git_changes(
1031
want_unchanged=include_unchanged,
1032
require_versioned=require_versioned,
1033
specific_files=specific_files,
1034
extra_trees=extra_trees,
1035
want_unversioned=want_unversioned)
1036
return changes_from_git_changes(
1037
changes, self.target.mapping,
1038
specific_files=specific_files,
1039
include_unchanged=include_unchanged,
1040
source_extras=source_extras,
1041
target_extras=target_extras)
1043
def _iter_git_changes(self, want_unchanged=False, specific_files=None,
1044
require_versioned=False, extra_trees=None,
1045
want_unversioned=False, include_trees=True):
1046
trees = [self.source]
1047
if extra_trees is not None:
1048
trees.extend(extra_trees)
1049
if specific_files is not None:
1050
specific_files = self.target.find_related_paths_across_trees(
1051
specific_files, trees,
1052
require_versioned=require_versioned)
1053
# TODO(jelmer): Restrict to specific_files, for performance reasons.
1054
with self.lock_read():
1055
from_tree_sha, from_extras = self.source.git_snapshot(
1056
want_unversioned=want_unversioned)
1057
to_tree_sha, to_extras = self.target.git_snapshot(
1058
want_unversioned=want_unversioned)
1059
changes = tree_changes(
1060
self.store, from_tree_sha, to_tree_sha,
1061
include_trees=include_trees,
1062
rename_detector=self.rename_detector,
1063
want_unchanged=want_unchanged, change_type_same=True)
1064
return changes, from_extras, to_extras
1066
def find_target_path(self, path, recurse='none'):
1067
ret = self.find_target_paths([path], recurse=recurse)
1070
def find_source_path(self, path, recurse='none'):
1071
ret = self.find_source_paths([path], recurse=recurse)
1074
def find_target_paths(self, paths, recurse='none'):
1077
changes = self._iter_git_changes(
1078
specific_files=paths, include_trees=False)[0]
1079
for (change_type, old, new) in changes:
1082
oldpath = decode_git_path(old[0])
1083
if oldpath in paths:
1084
ret[oldpath] = decode_git_path(new[0]) if new[0] else None
1087
if self.source.has_filename(path):
1088
if self.target.has_filename(path):
1093
raise errors.NoSuchFile(path)
1096
def find_source_paths(self, paths, recurse='none'):
1099
changes = self._iter_git_changes(
1100
specific_files=paths, include_trees=False)[0]
1101
for (change_type, old, new) in changes:
1104
newpath = decode_git_path(new[0])
1105
if newpath in paths:
1106
ret[newpath] = decode_git_path(old[0]) if old[0] else None
1109
if self.target.has_filename(path):
1110
if self.source.has_filename(path):
1115
raise errors.NoSuchFile(path)
1119
_mod_tree.InterTree.register_optimiser(InterGitTrees)
1122
class MutableGitIndexTree(mutabletree.MutableTree, GitTree):
1125
self._lock_mode = None
1126
self._lock_count = 0
1127
self._versioned_dirs = None
1128
self._index_dirty = False
1129
self._submodules = None
1131
def git_snapshot(self, want_unversioned=False):
1132
return snapshot_workingtree(self, want_unversioned=want_unversioned)
1134
def is_versioned(self, path):
1135
with self.lock_read():
1136
path = encode_git_path(path.rstrip('/'))
1137
(index, subpath) = self._lookup_index(path)
1138
return (subpath in index or self._has_dir(path))
1140
def _has_dir(self, path):
1141
if not isinstance(path, bytes):
1142
raise TypeError(path)
1145
if self._versioned_dirs is None:
1147
return path in self._versioned_dirs
1149
def _load_dirs(self):
1150
if self._lock_mode is None:
1151
raise errors.ObjectNotLocked(self)
1152
self._versioned_dirs = set()
1153
for p, sha, mode in self.iter_git_objects():
1154
self._ensure_versioned_dir(posixpath.dirname(p))
1156
def _ensure_versioned_dir(self, dirname):
1157
if not isinstance(dirname, bytes):
1158
raise TypeError(dirname)
1159
if dirname in self._versioned_dirs:
1162
self._ensure_versioned_dir(posixpath.dirname(dirname))
1163
self._versioned_dirs.add(dirname)
1165
def path2id(self, path):
1166
with self.lock_read():
1167
path = path.rstrip('/')
1168
if self.is_versioned(path.rstrip('/')):
1169
return self.mapping.generate_file_id(
1170
osutils.safe_unicode(path))
1173
def id2path(self, file_id, recurse='down'):
1176
if type(file_id) is not bytes:
1177
raise TypeError(file_id)
1178
with self.lock_read():
1180
path = self.mapping.parse_file_id(file_id)
1182
raise errors.NoSuchId(self, file_id)
1183
if self.is_versioned(path):
1185
raise errors.NoSuchId(self, file_id)
1187
def _set_root_id(self, file_id):
1188
raise errors.UnsupportedOperation(self._set_root_id, self)
1190
def _add(self, files, ids, kinds):
1191
for (path, file_id, kind) in zip(files, ids, kinds):
1192
if file_id is not None:
1193
raise workingtree.SettingFileIdUnsupported()
1194
path, can_access = osutils.normalized_filename(path)
1196
raise errors.InvalidNormalization(path)
1197
self._index_add_entry(path, kind)
1199
def _read_submodule_head(self, path):
1200
raise NotImplementedError(self._read_submodule_head)
1202
def _submodule_info(self):
1203
if self._submodules is None:
1205
with self.get_file('.gitmodules') as f:
1206
config = GitConfigFile.from_file(f)
1207
self._submodules = {
1208
path: (url, section)
1209
for path, url, section in parse_submodules(config)}
1210
except errors.NoSuchFile:
1211
self._submodules = {}
1212
return self._submodules
1214
def _lookup_index(self, encoded_path):
1215
if not isinstance(encoded_path, bytes):
1216
raise TypeError(encoded_path)
1218
if encoded_path in self.index:
1219
return self.index, encoded_path
1220
# TODO(jelmer): Perhaps have a cache with paths under which some
1223
remaining_path = encoded_path
1225
parts = remaining_path.split(b'/')
1226
for i in range(1, len(parts)):
1227
basepath = b'/'.join(parts[:i])
1229
(ctime, mtime, dev, ino, mode, uid, gid, size, sha,
1230
flags) = index[basepath]
1234
if S_ISGITLINK(mode):
1235
index = self._get_submodule_index(basepath)
1236
remaining_path = b'/'.join(parts[i:])
1239
return index, remaining_path
1241
return index, remaining_path
1242
return index, remaining_path
1244
def _index_del_entry(self, index, path):
1246
# TODO(jelmer): Keep track of dirty per index
1247
self._index_dirty = True
1249
def _index_add_entry(self, path, kind, flags=0, reference_revision=None):
1250
if kind == "directory":
1251
# Git indexes don't contain directories
1256
file, stat_val = self.get_file_with_stat(path)
1257
except (errors.NoSuchFile, IOError):
1258
# TODO: Rather than come up with something here, use the old
1261
stat_val = os.stat_result(
1262
(stat.S_IFREG | 0o644, 0, 0, 0, 0, 0, 0, 0, 0, 0))
1264
blob.set_raw_string(file.read())
1265
# Add object to the repository if it didn't exist yet
1266
if blob.id not in self.store:
1267
self.store.add_object(blob)
1269
elif kind == "symlink":
1272
stat_val = self._lstat(path)
1273
except EnvironmentError:
1274
# TODO: Rather than come up with something here, use the
1276
stat_val = os.stat_result(
1277
(stat.S_IFLNK, 0, 0, 0, 0, 0, 0, 0, 0, 0))
1278
blob.set_raw_string(encode_git_path(self.get_symlink_target(path)))
1279
# Add object to the repository if it didn't exist yet
1280
if blob.id not in self.store:
1281
self.store.add_object(blob)
1283
elif kind == "tree-reference":
1284
if reference_revision is not None:
1285
hexsha = self.branch.lookup_bzr_revision_id(
1286
reference_revision)[0]
1288
hexsha = self._read_submodule_head(path)
1290
raise errors.NoCommits(path)
1292
stat_val = self._lstat(path)
1293
except EnvironmentError:
1294
stat_val = os.stat_result(
1295
(S_IFGITLINK, 0, 0, 0, 0, 0, 0, 0, 0, 0))
1296
stat_val = os.stat_result((S_IFGITLINK, ) + stat_val[1:])
1298
raise AssertionError("unknown kind '%s'" % kind)
1299
# Add an entry to the index or update the existing entry
1300
ensure_normalized_path(path)
1301
encoded_path = encode_git_path(path)
1302
if b'\r' in encoded_path or b'\n' in encoded_path:
1303
# TODO(jelmer): Why do we need to do this?
1304
trace.mutter('ignoring path with invalid newline in it: %r', path)
1306
(index, index_path) = self._lookup_index(encoded_path)
1307
index[index_path] = index_entry_from_stat(stat_val, hexsha, flags)
1308
self._index_dirty = True
1309
if self._versioned_dirs is not None:
1310
self._ensure_versioned_dir(index_path)
1312
def iter_git_objects(self):
1313
for p, entry in self._recurse_index_entries():
1314
yield p, entry.sha, entry.mode
1316
def _recurse_index_entries(self, index=None, basepath=b"",
1317
recurse_nested=False):
1318
# Iterate over all index entries
1319
with self.lock_read():
1322
for path, value in index.items():
1323
(ctime, mtime, dev, ino, mode, uid, gid, size, sha,
1325
if S_ISGITLINK(mode) and recurse_nested:
1326
subindex = self._get_submodule_index(path)
1327
for entry in self._recurse_index_entries(
1328
index=subindex, basepath=path,
1329
recurse_nested=recurse_nested):
1332
yield (posixpath.join(basepath, path), value)
1334
def iter_entries_by_dir(self, specific_files=None,
1335
recurse_nested=False):
1336
with self.lock_read():
1337
if specific_files is not None:
1338
specific_files = set(specific_files)
1340
specific_files = None
1341
root_ie = self._get_dir_ie(u"", None)
1343
if specific_files is None or u"" in specific_files:
1344
ret[(u"", u"")] = root_ie
1345
dir_ids = {u"": root_ie.file_id}
1346
for path, value in self._recurse_index_entries(
1347
recurse_nested=recurse_nested):
1348
if self.mapping.is_special_file(path):
1350
path = decode_git_path(path)
1351
if specific_files is not None and path not in specific_files:
1353
(parent, name) = posixpath.split(path)
1355
file_ie = self._get_file_ie(name, path, value, None)
1356
except errors.NoSuchFile:
1358
if specific_files is None:
1359
for (dir_path, dir_ie) in self._add_missing_parent_ids(
1361
ret[(posixpath.dirname(dir_path), dir_path)] = dir_ie
1362
file_ie.parent_id = self.path2id(parent)
1363
ret[(posixpath.dirname(path), path)] = file_ie
1364
# Special casing for directories
1366
for path in specific_files:
1367
key = (posixpath.dirname(path), path)
1368
if key not in ret and self.is_versioned(path):
1369
ret[key] = self._get_dir_ie(path, self.path2id(key[0]))
1370
return ((path, ie) for ((_, path), ie) in sorted(viewitems(ret)))
1372
def iter_references(self):
1373
if self.supports_tree_reference():
1374
# TODO(jelmer): Implement a more efficient version of this
1375
for path, entry in self.iter_entries_by_dir():
1376
if entry.kind == 'tree-reference':
1379
def _get_dir_ie(self, path, parent_id):
1380
file_id = self.path2id(path)
1381
return GitTreeDirectory(file_id,
1382
posixpath.basename(path).strip("/"), parent_id)
1384
def _get_file_ie(self, name, path, value, parent_id):
1385
if not isinstance(name, text_type):
1386
raise TypeError(name)
1387
if not isinstance(path, text_type):
1388
raise TypeError(path)
1389
if not isinstance(value, tuple) or len(value) != 10:
1390
raise TypeError(value)
1391
(ctime, mtime, dev, ino, mode, uid, gid, size, sha, flags) = value
1392
file_id = self.path2id(path)
1393
if not isinstance(file_id, bytes):
1394
raise TypeError(file_id)
1395
kind = mode_kind(mode)
1396
ie = entry_factory[kind](file_id, name, parent_id)
1397
if kind == 'symlink':
1398
ie.symlink_target = self.get_symlink_target(path)
1399
elif kind == 'tree-reference':
1400
ie.reference_revision = self.get_reference_revision(path)
1404
ie.executable = bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)
1407
def _add_missing_parent_ids(self, path, dir_ids):
1410
parent = posixpath.dirname(path).strip("/")
1411
ret = self._add_missing_parent_ids(parent, dir_ids)
1412
parent_id = dir_ids[parent]
1413
ie = self._get_dir_ie(path, parent_id)
1414
dir_ids[path] = ie.file_id
1415
ret.append((path, ie))
1418
def _comparison_data(self, entry, path):
1420
return None, False, None
1421
return entry.kind, entry.executable, None
1423
def _unversion_path(self, path):
1424
if self._lock_mode is None:
1425
raise errors.ObjectNotLocked(self)
1426
encoded_path = encode_git_path(path)
1428
(index, subpath) = self._lookup_index(encoded_path)
1430
self._index_del_entry(index, encoded_path)
1432
# A directory, perhaps?
1433
# TODO(jelmer): Deletes that involve submodules?
1434
for p in list(index):
1435
if p.startswith(subpath + b"/"):
1437
self._index_del_entry(index, p)
1440
self._versioned_dirs = None
1443
def unversion(self, paths):
1444
with self.lock_tree_write():
1446
if self._unversion_path(path) == 0:
1447
raise errors.NoSuchFile(path)
1448
self._versioned_dirs = None
1454
def update_basis_by_delta(self, revid, delta):
1455
# TODO(jelmer): This shouldn't be called, it's inventory specific.
1456
for (old_path, new_path, file_id, ie) in delta:
1457
if old_path is not None:
1458
(index, old_subpath) = self._lookup_index(
1459
encode_git_path(old_path))
1460
if old_subpath in index:
1461
self._index_del_entry(index, old_subpath)
1462
self._versioned_dirs = None
1463
if new_path is not None and ie.kind != 'directory':
1464
self._index_add_entry(new_path, ie.kind)
1466
self._set_merges_from_parent_ids([])
1468
def move(self, from_paths, to_dir=None, after=None):
1470
with self.lock_tree_write():
1471
to_abs = self.abspath(to_dir)
1472
if not os.path.isdir(to_abs):
1473
raise errors.BzrMoveFailedError('', to_dir,
1474
errors.NotADirectory(to_abs))
1476
for from_rel in from_paths:
1477
from_tail = os.path.split(from_rel)[-1]
1478
to_rel = os.path.join(to_dir, from_tail)
1479
self.rename_one(from_rel, to_rel, after=after)
1480
rename_tuples.append((from_rel, to_rel))
1482
return rename_tuples
1484
def rename_one(self, from_rel, to_rel, after=None):
1485
from_path = encode_git_path(from_rel)
1486
to_rel, can_access = osutils.normalized_filename(to_rel)
1488
raise errors.InvalidNormalization(to_rel)
1489
to_path = encode_git_path(to_rel)
1490
with self.lock_tree_write():
1492
# Perhaps it's already moved?
1494
not self.has_filename(from_rel) and
1495
self.has_filename(to_rel) and
1496
not self.is_versioned(to_rel))
1498
if not self.has_filename(to_rel):
1499
raise errors.BzrMoveFailedError(
1500
from_rel, to_rel, errors.NoSuchFile(to_rel))
1501
if self.basis_tree().is_versioned(to_rel):
1502
raise errors.BzrMoveFailedError(
1503
from_rel, to_rel, errors.AlreadyVersionedError(to_rel))
1505
kind = self.kind(to_rel)
1508
to_kind = self.kind(to_rel)
1509
except errors.NoSuchFile:
1510
exc_type = errors.BzrRenameFailedError
1513
exc_type = errors.BzrMoveFailedError
1514
if self.is_versioned(to_rel):
1515
raise exc_type(from_rel, to_rel,
1516
errors.AlreadyVersionedError(to_rel))
1517
if not self.has_filename(from_rel):
1518
raise errors.BzrMoveFailedError(
1519
from_rel, to_rel, errors.NoSuchFile(from_rel))
1520
kind = self.kind(from_rel)
1521
if not self.is_versioned(from_rel) and kind != 'directory':
1522
raise exc_type(from_rel, to_rel,
1523
errors.NotVersionedError(from_rel))
1524
if self.has_filename(to_rel):
1525
raise errors.RenameFailedFilesExist(
1526
from_rel, to_rel, errors.FileExists(to_rel))
1528
kind = self.kind(from_rel)
1530
if not after and kind != 'directory':
1531
(index, from_subpath) = self._lookup_index(from_path)
1532
if from_subpath not in index:
1534
raise errors.BzrMoveFailedError(
1536
errors.NotVersionedError(path=from_rel))
1540
self._rename_one(from_rel, to_rel)
1541
except OSError as e:
1542
if e.errno == errno.ENOENT:
1543
raise errors.BzrMoveFailedError(
1544
from_rel, to_rel, errors.NoSuchFile(to_rel))
1546
if kind != 'directory':
1547
(index, from_index_path) = self._lookup_index(from_path)
1549
self._index_del_entry(index, from_path)
1552
self._index_add_entry(to_rel, kind)
1554
todo = [(p, i) for (p, i) in self._recurse_index_entries()
1555
if p.startswith(from_path + b'/')]
1556
for child_path, child_value in todo:
1557
(child_to_index, child_to_index_path) = self._lookup_index(
1558
posixpath.join(to_path, posixpath.relpath(child_path, from_path)))
1559
child_to_index[child_to_index_path] = child_value
1560
# TODO(jelmer): Mark individual index as dirty
1561
self._index_dirty = True
1562
(child_from_index, child_from_index_path) = self._lookup_index(
1564
self._index_del_entry(
1565
child_from_index, child_from_index_path)
1567
self._versioned_dirs = None
1570
def find_related_paths_across_trees(self, paths, trees=[],
1571
require_versioned=True):
1575
if require_versioned:
1576
trees = [self] + (trees if trees is not None else [])
1580
if t.is_versioned(p):
1585
raise errors.PathsNotVersionedError(unversioned)
1587
return filter(self.is_versioned, paths)
1589
def path_content_summary(self, path):
1590
"""See Tree.path_content_summary."""
1592
stat_result = self._lstat(path)
1593
except OSError as e:
1594
if getattr(e, 'errno', None) == errno.ENOENT:
1596
return ('missing', None, None, None)
1597
# propagate other errors
1599
kind = mode_kind(stat_result.st_mode)
1601
return self._file_content_summary(path, stat_result)
1602
elif kind == 'directory':
1603
# perhaps it looks like a plain directory, but it's really a
1605
if self._directory_is_tree_reference(path):
1606
kind = 'tree-reference'
1607
return kind, None, None, None
1608
elif kind == 'symlink':
1609
target = osutils.readlink(self.abspath(path))
1610
return ('symlink', None, None, target)
1612
return (kind, None, None, None)
1614
def stored_kind(self, relpath):
1615
(index, index_path) = self._lookup_index(encode_git_path(relpath))
1619
mode = index[index_path].mode
1623
if S_ISGITLINK(mode):
1624
return 'tree-reference'
1627
def kind(self, relpath):
1628
kind = osutils.file_kind(self.abspath(relpath))
1629
if kind == 'directory':
1630
if self._directory_is_tree_reference(relpath):
1631
return 'tree-reference'
1636
def _live_entry(self, relpath):
1637
raise NotImplementedError(self._live_entry)
1639
def transform(self, pb=None):
1640
from .transform import GitTreeTransform
1641
return GitTreeTransform(self, pb=pb)
1643
def preview_transform(self, pb=None):
1644
from .transform import GitTransformPreview
1645
return GitTransformPreview(self, pb=pb)
1647
def has_changes(self, _from_tree=None):
1648
"""Quickly check that the tree contains at least one commitable change.
1650
:param _from_tree: tree to compare against to find changes (default to
1651
the basis tree and is intended to be used by tests).
1653
:return: True if a change is found. False otherwise
1655
with self.lock_read():
1656
# Check pending merges
1657
if len(self.get_parent_ids()) > 1:
1659
if _from_tree is None:
1660
_from_tree = self.basis_tree()
1661
changes = self.iter_changes(_from_tree)
1662
if self.supports_symlinks():
1663
# Fast path for has_changes.
1665
change = next(changes)
1666
if change.path[1] == '':
1669
except StopIteration:
1673
# Slow path for has_changes.
1674
# Handle platforms that do not support symlinks in the
1675
# conditional below. This is slower than the try/except
1676
# approach below that but we don't have a choice as we
1677
# need to be sure that all symlinks are removed from the
1678
# entire changeset. This is because in platforms that
1679
# do not support symlinks, they show up as None in the
1680
# working copy as compared to the repository.
1681
# Also, exclude root as mention in the above fast path.
1683
lambda c: c[6][0] != 'symlink' and c[4] != (None, None),
1687
except StopIteration:
1692
def snapshot_workingtree(target, want_unversioned=False):
1695
# Report dirified directories to commit_tree first, so that they can be
1696
# replaced with non-empty directories if they have contents.
1698
trust_executable = target._supports_executable()
1699
for path, index_entry in target._recurse_index_entries():
1701
live_entry = target._live_entry(path)
1702
except EnvironmentError as e:
1703
if e.errno == errno.ENOENT:
1704
# Entry was removed; keep it listed, but mark it as gone.
1705
blobs[path] = (ZERO_SHA, 0)
1709
if live_entry is None:
1710
# Entry was turned into a directory.
1711
# Maybe it's just a submodule that's not checked out?
1712
if S_ISGITLINK(index_entry.mode):
1713
blobs[path] = (index_entry.sha, index_entry.mode)
1715
dirified.append((path, Tree().id, stat.S_IFDIR))
1716
target.store.add_object(Tree())
1718
mode = live_entry.mode
1719
if not trust_executable:
1720
if mode_is_executable(index_entry.mode):
1724
if live_entry.sha != index_entry.sha:
1725
rp = decode_git_path(path)
1726
if stat.S_ISREG(live_entry.mode):
1728
with target.get_file(rp) as f:
1729
blob.data = f.read()
1730
elif stat.S_ISLNK(live_entry.mode):
1732
blob.data = target.get_symlink_target(rp).encode(osutils._fs_enc)
1735
if blob is not None:
1736
target.store.add_object(blob)
1737
blobs[path] = (live_entry.sha, cleanup_mode(live_entry.mode))
1738
if want_unversioned:
1739
for extra in target._iter_files_recursive(include_dirs=False):
1741
extra, accessible = osutils.normalized_filename(extra)
1742
except UnicodeDecodeError:
1743
raise errors.BadFilenameEncoding(
1744
extra, osutils._fs_enc)
1745
np = encode_git_path(extra)
1748
st = target._lstat(extra)
1749
if stat.S_ISDIR(st.st_mode):
1751
elif stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode):
1752
blob = blob_from_path_and_stat(
1753
target.abspath(extra).encode(osutils._fs_enc), st)
1756
target.store.add_object(blob)
1757
blobs[np] = (blob.id, cleanup_mode(st.st_mode))
1760
target.store, dirified + [(p, s, m) for (p, (s, m)) in blobs.items()]), extras