/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-19 21:26:53 UTC
  • mfrom: (7490.40.19 work)
  • mto: This revision was merged to the branch mainline in revision 7516.
  • Revision ID: jelmer@jelmer.uk-20200619212653-7j6rgywzczhc8cmj
Merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    parse_submodules,
27
27
    ConfigFile as GitConfigFile,
28
28
    )
29
 
from dulwich.diff_tree import tree_changes
 
29
from dulwich.diff_tree import tree_changes, RenameDetector
30
30
from dulwich.errors import NotTreeError
31
31
from dulwich.index import (
32
32
    blob_from_path_and_stat,
731
731
        target_extras = set()
732
732
    ret = delta.TreeDelta()
733
733
    added = []
734
 
    for (oldpath, newpath), (oldmode, newmode), (oldsha, newsha) in changes:
 
734
    for (change_type, old, new) in changes:
 
735
        (oldpath, oldmode, oldsha) = old
 
736
        (newpath, newmode, newsha) = new
735
737
        if newpath == b'' and not include_root:
736
738
            continue
737
739
        if oldpath is not None:
803
805
            fileid, (oldpath_decoded, newpath_decoded), (oldsha != newsha),
804
806
            (oldversioned, newversioned),
805
807
            (oldparent, newparent), (oldname, newname),
806
 
            (oldkind, newkind), (oldexe, newexe))
 
808
            (oldkind, newkind), (oldexe, newexe),
 
809
            copied=(change_type == 'copy'))
807
810
        if oldpath is None:
808
811
            added.append((newpath, newkind))
809
812
        elif newpath is None or newmode == 0:
810
813
            ret.removed.append(change)
811
814
        elif oldpath != newpath:
812
 
            ret.renamed.append(change)
 
815
            if change_type == 'copy':
 
816
                ret.copied.append(change)
 
817
            else:
 
818
                ret.renamed.append(change)
813
819
        elif mode_kind(oldmode) != mode_kind(newmode):
814
820
            ret.kind_changed.append(change)
815
821
        elif oldsha != newsha or oldmode != newmode:
857
863
    """
858
864
    if target_extras is None:
859
865
        target_extras = set()
860
 
    for (oldpath, newpath), (oldmode, newmode), (oldsha, newsha) in changes:
 
866
    for (change_type, old, new) in changes:
 
867
        (oldpath, oldmode, oldsha) = old
 
868
        (newpath, newmode, newsha) = new
861
869
        if oldpath is not None:
862
870
            oldpath_decoded = oldpath.decode('utf-8')
863
871
        else:
928
936
            fileid, (oldpath_decoded, newpath_decoded), (oldsha != newsha),
929
937
            (oldversioned, newversioned),
930
938
            (oldparent, newparent), (oldname, newname),
931
 
            (oldkind, newkind), (oldexe, newexe))
 
939
            (oldkind, newkind), (oldexe, newexe),
 
940
            copied=(change_type == 'copy'))
932
941
 
933
942
 
934
943
class InterGitTrees(_mod_tree.InterTree):
991
1000
        paths = set(paths)
992
1001
        ret = {}
993
1002
        changes = self._iter_git_changes(specific_files=paths)[0]
994
 
        for (oldpath, newpath), (oldmode, newmode), (oldsha, newsha) in changes:
 
1003
        for (change_type, old, new) in changes:
 
1004
            oldpath = old[0]
 
1005
            newpath = new[0]
995
1006
            if oldpath in paths:
996
1007
                ret[oldpath] = newpath
997
1008
        for path in paths:
1009
1020
        paths = set(paths)
1010
1021
        ret = {}
1011
1022
        changes = self._iter_git_changes(specific_files=paths)[0]
1012
 
        for (oldpath, newpath), (oldmode, newmode), (oldsha, newsha) in changes:
 
1023
        for (change_type, old, new) in changes:
 
1024
            oldpath = old[0]
 
1025
            newpath = new[0]
1013
1026
            if newpath in paths:
1014
1027
                ret[newpath] = oldpath
1015
1028
        for path in paths:
1054
1067
                    self.target._repository._git.object_store])
1055
1068
        else:
1056
1069
            store = self.source._repository._git.object_store
1057
 
        return store.tree_changes(
1058
 
            self.source.tree, self.target.tree, want_unchanged=want_unchanged,
1059
 
            include_trees=True, change_type_same=True), set()
 
1070
        rename_detector = RenameDetector(store)
 
1071
        return tree_changes(
 
1072
            store, self.source.tree, self.target.tree, want_unchanged=want_unchanged,
 
1073
            include_trees=True, change_type_same=True, rename_detector=rename_detector), set()
1060
1074
 
1061
1075
 
1062
1076
_mod_tree.InterTree.register_optimiser(InterGitRevisionTrees)
1595
1609
    def __init__(self, source, target):
1596
1610
        super(InterIndexGitTree, self).__init__(source, target)
1597
1611
        self._index = target.index
 
1612
        if self.source.store == self.target.store:
 
1613
            self.store = self.source.store
 
1614
        else:
 
1615
            self.store = OverlayObjectStore(
 
1616
                [self.source.store, self.target.store])
 
1617
        self.rename_detector = RenameDetector(self.store)
1598
1618
 
1599
1619
    @classmethod
1600
1620
    def is_compatible(cls, source, target):
1616
1636
            return changes_between_git_tree_and_working_copy(
1617
1637
                self.source.store, self.source.tree,
1618
1638
                self.target, want_unchanged=want_unchanged,
1619
 
                want_unversioned=want_unversioned)
 
1639
                want_unversioned=want_unversioned,
 
1640
                rename_detector=self.rename_detector)
1620
1641
 
1621
1642
 
1622
1643
_mod_tree.InterTree.register_optimiser(InterIndexGitTree)
1623
1644
 
1624
1645
 
1625
 
def changes_between_git_tree_and_working_copy(store, from_tree_sha, target,
 
1646
def changes_between_git_tree_and_working_copy(source_store, from_tree_sha, target,
1626
1647
                                              want_unchanged=False,
1627
 
                                              want_unversioned=False):
 
1648
                                              want_unversioned=False,
 
1649
                                              rename_detector=None):
1628
1650
    """Determine the changes between a git tree and a working tree with index.
1629
1651
 
1630
1652
    """
1651
1673
                    blobs[path] = (index_entry.sha, index_entry.mode)
1652
1674
                else:
1653
1675
                    dirified.append((path, Tree().id, stat.S_IFDIR))
1654
 
                    store.add_object(Tree())
 
1676
                    target.store.add_object(Tree())
1655
1677
            else:
1656
1678
                mode = live_entry.mode
1657
1679
                if not trust_executable:
1659
1681
                        mode |= 0o111
1660
1682
                    else:
1661
1683
                        mode &= ~0o111
 
1684
                if live_entry.sha != index_entry.sha:
 
1685
                    rp = path.decode('utf-8')
 
1686
                    if stat.S_ISREG(live_entry.mode):
 
1687
                        blob = Blob()
 
1688
                        with target.get_file(rp) as f:
 
1689
                            blob.data = f.read()
 
1690
                    elif stat.S_ISLNK(live_entry.mode):
 
1691
                        blob = Blob()
 
1692
                        blob.data = target.get_symlink_target(rp).encode(osutils._fs_enc)
 
1693
                    else:
 
1694
                        blob = None
 
1695
                    if blob is not None:
 
1696
                        target.store.add_object(blob)
1662
1697
                blobs[path] = (live_entry.sha, cleanup_mode(live_entry.mode))
1663
1698
    if want_unversioned:
1664
1699
        for e in target.extras():
1675
1710
                    target.abspath(e).encode(osutils._fs_enc), st)
1676
1711
            else:
1677
1712
                continue
1678
 
            store.add_object(blob)
 
1713
            target.store.add_object(blob)
1679
1714
            np = np.encode('utf-8')
1680
1715
            blobs[np] = (blob.id, cleanup_mode(st.st_mode))
1681
1716
            extras.add(np)
1682
1717
    to_tree_sha = commit_tree(
1683
 
        store, dirified + [(p, s, m) for (p, (s, m)) in blobs.items()])
1684
 
    return store.tree_changes(
1685
 
        from_tree_sha, to_tree_sha, include_trees=True,
 
1718
        target.store, dirified + [(p, s, m) for (p, (s, m)) in blobs.items()])
 
1719
    store = OverlayObjectStore([source_store, target.store])
 
1720
    return tree_changes(
 
1721
        store, from_tree_sha, to_tree_sha, include_trees=True,
 
1722
        rename_detector=rename_detector,
1686
1723
        want_unchanged=want_unchanged, change_type_same=True), extras