/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/git/tree.py

  • Committer: Jelmer Vernooij
  • Date: 2020-06-15 01:29:36 UTC
  • mfrom: (7490.40.4 work)
  • mto: (7490.40.19 work)
  • mto: This revision was merged to the branch mainline in revision 7516.
  • Revision ID: jelmer@jelmer.uk-20200615012936-1adqbu592y7lzmy8
Merge upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
from io import BytesIO
25
25
import os
26
26
 
 
27
from dulwich import __version__ as dulwich_version
27
28
from dulwich.config import (
28
29
    parse_submodules,
29
30
    ConfigFile as GitConfigFile,
30
31
    )
31
 
from dulwich.diff_tree import tree_changes
 
32
from dulwich.diff_tree import tree_changes, RenameDetector
32
33
from dulwich.errors import NotTreeError
33
34
from dulwich.index import (
34
35
    blob_from_path_and_stat,
737
738
        target_extras = set()
738
739
    ret = delta.TreeDelta()
739
740
    added = []
740
 
    for (oldpath, newpath), (oldmode, newmode), (oldsha, newsha) in changes:
 
741
    for (change_type, old, new) in changes:
 
742
        (oldpath, oldmode, oldsha) = old
 
743
        (newpath, newmode, newsha) = new
741
744
        if newpath == b'' and not include_root:
742
745
            continue
743
746
        if oldpath is not None:
809
812
            fileid, (oldpath_decoded, newpath_decoded), (oldsha != newsha),
810
813
            (oldversioned, newversioned),
811
814
            (oldparent, newparent), (oldname, newname),
812
 
            (oldkind, newkind), (oldexe, newexe))
 
815
            (oldkind, newkind), (oldexe, newexe),
 
816
            copied=(change_type == 'copy'))
813
817
        if oldpath is None:
814
818
            added.append((newpath, newkind))
815
819
        elif newpath is None or newmode == 0:
816
820
            ret.removed.append(change)
817
821
        elif oldpath != newpath:
818
 
            ret.renamed.append(change)
 
822
            if change_type == 'copy':
 
823
                ret.copied.append(change)
 
824
            else:
 
825
                ret.renamed.append(change)
819
826
        elif mode_kind(oldmode) != mode_kind(newmode):
820
827
            ret.kind_changed.append(change)
821
828
        elif oldsha != newsha or oldmode != newmode:
863
870
    """
864
871
    if target_extras is None:
865
872
        target_extras = set()
866
 
    for (oldpath, newpath), (oldmode, newmode), (oldsha, newsha) in changes:
 
873
    for (change_type, old, new) in changes:
 
874
        (oldpath, oldmode, oldsha) = old
 
875
        (newpath, newmode, newsha) = new
867
876
        if oldpath is not None:
868
877
            oldpath_decoded = oldpath.decode('utf-8')
869
878
        else:
934
943
            fileid, (oldpath_decoded, newpath_decoded), (oldsha != newsha),
935
944
            (oldversioned, newversioned),
936
945
            (oldparent, newparent), (oldname, newname),
937
 
            (oldkind, newkind), (oldexe, newexe))
 
946
            (oldkind, newkind), (oldexe, newexe),
 
947
            copied=(change_type == 'copy'))
938
948
 
939
949
 
940
950
class InterGitTrees(_mod_tree.InterTree):
997
1007
        paths = set(paths)
998
1008
        ret = {}
999
1009
        changes = self._iter_git_changes(specific_files=paths)[0]
1000
 
        for (oldpath, newpath), (oldmode, newmode), (oldsha, newsha) in changes:
 
1010
        for (change_type, old, new) in changes:
 
1011
            oldpath = old[0]
 
1012
            newpath = new[0]
1001
1013
            if oldpath in paths:
1002
1014
                ret[oldpath] = newpath
1003
1015
        for path in paths:
1015
1027
        paths = set(paths)
1016
1028
        ret = {}
1017
1029
        changes = self._iter_git_changes(specific_files=paths)[0]
1018
 
        for (oldpath, newpath), (oldmode, newmode), (oldsha, newsha) in changes:
 
1030
        for (change_type, old, new) in changes:
 
1031
            oldpath = old[0]
 
1032
            newpath = new[0]
1019
1033
            if newpath in paths:
1020
1034
                ret[newpath] = oldpath
1021
1035
        for path in paths:
1060
1074
                    self.target._repository._git.object_store])
1061
1075
        else:
1062
1076
            store = self.source._repository._git.object_store
1063
 
        return store.tree_changes(
1064
 
            self.source.tree, self.target.tree, want_unchanged=want_unchanged,
1065
 
            include_trees=True, change_type_same=True), set()
 
1077
        if dulwich_version >= (0, 19, 15):
 
1078
            rename_detector = RenameDetector(store)
 
1079
        else:
 
1080
            rename_detector = None
 
1081
        return tree_changes(
 
1082
            store, self.source.tree, self.target.tree, want_unchanged=want_unchanged,
 
1083
            include_trees=True, change_type_same=True, rename_detector=rename_detector), set()
1066
1084
 
1067
1085
 
1068
1086
_mod_tree.InterTree.register_optimiser(InterGitRevisionTrees)
1601
1619
    def __init__(self, source, target):
1602
1620
        super(InterIndexGitTree, self).__init__(source, target)
1603
1621
        self._index = target.index
 
1622
        if dulwich_version >= (0, 19, 15):
 
1623
            self.rename_detector = RenameDetector(self.source.store)
 
1624
        else:
 
1625
            self.rename_detector = None
1604
1626
 
1605
1627
    @classmethod
1606
1628
    def is_compatible(cls, source, target):
1622
1644
            return changes_between_git_tree_and_working_copy(
1623
1645
                self.source.store, self.source.tree,
1624
1646
                self.target, want_unchanged=want_unchanged,
1625
 
                want_unversioned=want_unversioned)
 
1647
                want_unversioned=want_unversioned,
 
1648
                rename_detector=self.rename_detector)
1626
1649
 
1627
1650
 
1628
1651
_mod_tree.InterTree.register_optimiser(InterIndexGitTree)
1630
1653
 
1631
1654
def changes_between_git_tree_and_working_copy(store, from_tree_sha, target,
1632
1655
                                              want_unchanged=False,
1633
 
                                              want_unversioned=False):
 
1656
                                              want_unversioned=False,
 
1657
                                              rename_detector=None):
1634
1658
    """Determine the changes between a git tree and a working tree with index.
1635
1659
 
1636
1660
    """
1676
1700
                    e, osutils._fs_enc)
1677
1701
            if stat.S_ISDIR(st.st_mode):
1678
1702
                blob = Tree()
1679
 
            else:
 
1703
            elif stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode):
1680
1704
                blob = blob_from_path_and_stat(
1681
1705
                    target.abspath(e).encode(osutils._fs_enc), st)
 
1706
            else:
 
1707
                continue
1682
1708
            store.add_object(blob)
1683
1709
            np = np.encode('utf-8')
1684
1710
            blobs[np] = (blob.id, cleanup_mode(st.st_mode))
1685
1711
            extras.add(np)
1686
1712
    to_tree_sha = commit_tree(
1687
1713
        store, dirified + [(p, s, m) for (p, (s, m)) in blobs.items()])
1688
 
    return store.tree_changes(
1689
 
        from_tree_sha, to_tree_sha, include_trees=True,
 
1714
    return tree_changes(
 
1715
        store, from_tree_sha, to_tree_sha, include_trees=True,
 
1716
        rename_detector=rename_detector,
1690
1717
        want_unchanged=want_unchanged, change_type_same=True), extras