/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 bzrlib/workingtree.py

merge trailing whitespace removal

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""WorkingTree object and friends.
18
18
 
19
19
A WorkingTree represents the editable working copy of a branch.
20
 
Operations which represent the WorkingTree are also done here, 
21
 
such as renaming or adding files.  The WorkingTree has an inventory 
22
 
which is updated by these operations.  A commit produces a 
 
20
Operations which represent the WorkingTree are also done here,
 
21
such as renaming or adding files.  The WorkingTree has an inventory
 
22
which is updated by these operations.  A commit produces a
23
23
new revision based on the workingtree and its inventory.
24
24
 
25
25
At the moment every WorkingTree has its own branch.  Remote
123
123
class TreeEntry(object):
124
124
    """An entry that implements the minimum interface used by commands.
125
125
 
126
 
    This needs further inspection, it may be better to have 
 
126
    This needs further inspection, it may be better to have
127
127
    InventoryEntries without ids - though that seems wrong. For now,
128
128
    this is a parallel hierarchy to InventoryEntry, and needs to become
129
129
    one of several things: decorates to that hierarchy, children of, or
132
132
    no InventoryEntry available - i.e. for unversioned objects.
133
133
    Perhaps they should be UnversionedEntry et al. ? - RBC 20051003
134
134
    """
135
 
 
 
135
 
136
136
    def __eq__(self, other):
137
137
        # yes, this us ugly, TODO: best practice __eq__ style.
138
138
        return (isinstance(other, TreeEntry)
139
139
                and other.__class__ == self.__class__)
140
 
 
 
140
 
141
141
    def kind_character(self):
142
142
        return "???"
143
143
 
383
383
 
384
384
    def basis_tree(self):
385
385
        """Return RevisionTree for the current last revision.
386
 
        
 
386
 
387
387
        If the left most parent is a ghost then the returned tree will be an
388
 
        empty tree - one obtained by calling 
 
388
        empty tree - one obtained by calling
389
389
        repository.revision_tree(NULL_REVISION).
390
390
        """
391
391
        try:
420
420
 
421
421
    def relpath(self, path):
422
422
        """Return the local path portion from a given path.
423
 
        
424
 
        The path may be absolute or relative. If its a relative path it is 
 
423
 
 
424
        The path may be absolute or relative. If its a relative path it is
425
425
        interpreted relative to the python current working directory.
426
426
        """
427
427
        return osutils.relpath(self.basedir, path)
496
496
 
497
497
    def get_parent_ids(self):
498
498
        """See Tree.get_parent_ids.
499
 
        
 
499
 
500
500
        This implementation reads the pending merges list and last_revision
501
501
        value and uses that to decide what the parents list should be.
502
502
        """
519
519
    def get_root_id(self):
520
520
        """Return the id of this trees root"""
521
521
        return self._inventory.root.file_id
522
 
        
 
522
 
523
523
    def _get_store_filename(self, file_id):
524
524
        ## XXX: badly named; this is not in the store at all
525
525
        return self.abspath(self.id2path(file_id))
527
527
    @needs_read_lock
528
528
    def clone(self, to_bzrdir, revision_id=None):
529
529
        """Duplicate this working tree into to_bzr, including all state.
530
 
        
 
530
 
531
531
        Specifically modified files are kept as modified, but
532
532
        ignored and unknown files are discarded.
533
533
 
534
534
        If you want to make a new line of development, see bzrdir.sprout()
535
535
 
536
536
        revision
537
 
            If not None, the cloned tree will have its last revision set to 
 
537
            If not None, the cloned tree will have its last revision set to
538
538
            revision, and and difference between the source trees last revision
539
539
            and this one merged in.
540
540
        """
623
623
        """See MutableTree._add."""
624
624
        # TODO: Re-adding a file that is removed in the working copy
625
625
        # should probably put it back with the previous ID.
626
 
        # the read and write working inventory should not occur in this 
 
626
        # the read and write working inventory should not occur in this
627
627
        # function - they should be part of lock_write and unlock.
628
628
        inv = self.inventory
629
629
        for f, file_id, kind in zip(files, ids, kinds):
748
748
        """Check that all merged revisions are proper 'heads'.
749
749
 
750
750
        This will always return the first revision_id, and any merged revisions
751
 
        which are 
 
751
        which are
752
752
        """
753
753
        if len(revision_ids) == 0:
754
754
            return revision_ids
766
766
    @needs_tree_write_lock
767
767
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
768
768
        """Set the parent ids to revision_ids.
769
 
        
 
769
 
770
770
        See also set_parent_trees. This api will try to retrieve the tree data
771
771
        for each element of revision_ids from the trees repository. If you have
772
772
        tree data already available, it is more efficient to use
905
905
    def merge_modified(self):
906
906
        """Return a dictionary of files modified by a merge.
907
907
 
908
 
        The list is initialized by WorkingTree.set_merge_modified, which is 
 
908
        The list is initialized by WorkingTree.set_merge_modified, which is
909
909
        typically called after we make some automatic updates to the tree
910
910
        because of a merge.
911
911
 
1001
1001
        return False
1002
1002
 
1003
1003
    def _directory_may_be_tree_reference(self, relpath):
1004
 
        # as a special case, if a directory contains control files then 
 
1004
        # as a special case, if a directory contains control files then
1005
1005
        # it's a tree reference, except that the root of the tree is not
1006
1006
        return relpath and osutils.isdir(self.abspath(relpath) + u"/.bzr")
1007
1007
        # TODO: We could ask all the control formats whether they
1018
1018
    @needs_tree_write_lock
1019
1019
    def extract(self, file_id, format=None):
1020
1020
        """Extract a subtree from this tree.
1021
 
        
 
1021
 
1022
1022
        A new branch will be created, relative to the path for this tree.
1023
1023
        """
1024
1024
        self.flush()
1029
1029
                transport = transport.clone(name)
1030
1030
                transport.ensure_base()
1031
1031
            return transport
1032
 
            
 
1032
 
1033
1033
        sub_path = self.id2path(file_id)
1034
1034
        branch_transport = mkdirs(sub_path)
1035
1035
        if format is None:
1117
1117
        # directory file_id, relative path, absolute path, reverse sorted children
1118
1118
        children = os.listdir(self.basedir)
1119
1119
        children.sort()
1120
 
        # jam 20060527 The kernel sized tree seems equivalent whether we 
 
1120
        # jam 20060527 The kernel sized tree seems equivalent whether we
1121
1121
        # use a deque and popleft to keep them sorted, or if we use a plain
1122
1122
        # list and just reverse() them.
1123
1123
        children = collections.deque(children)
1143
1143
 
1144
1144
                # absolute path
1145
1145
                fap = from_dir_abspath + '/' + f
1146
 
                
 
1146
 
1147
1147
                f_ie = inv.get_child(from_dir_id, f)
1148
1148
                if f_ie:
1149
1149
                    c = 'V'
1181
1181
                    except KeyError:
1182
1182
                        yield fp[1:], c, fk, None, TreeEntry()
1183
1183
                    continue
1184
 
                
 
1184
 
1185
1185
                if fk != 'directory':
1186
1186
                    continue
1187
1187
 
1204
1204
        to_dir must exist in the inventory.
1205
1205
 
1206
1206
        If to_dir exists and is a directory, the files are moved into
1207
 
        it, keeping their old names.  
 
1207
        it, keeping their old names.
1208
1208
 
1209
1209
        Note that to_dir is only the last component of the new name;
1210
1210
        this doesn't change the directory.
1487
1487
        These are files in the working directory that are not versioned or
1488
1488
        control files or ignored.
1489
1489
        """
1490
 
        # force the extras method to be fully executed before returning, to 
 
1490
        # force the extras method to be fully executed before returning, to
1491
1491
        # prevent race conditions with the lock
1492
1492
        return iter(
1493
1493
            [subp for subp in self.extras() if not self.is_ignored(subp)])
1508
1508
            else:
1509
1509
                raise errors.NoSuchId(self, file_id)
1510
1510
        if len(file_ids):
1511
 
            # in the future this should just set a dirty bit to wait for the 
 
1511
            # in the future this should just set a dirty bit to wait for the
1512
1512
            # final unlock. However, until all methods of workingtree start
1513
 
            # with the current in -memory inventory rather than triggering 
 
1513
            # with the current in -memory inventory rather than triggering
1514
1514
            # a read, it is more complex - we need to teach read_inventory
1515
1515
            # to know when to read, and when to not read first... and possibly
1516
1516
            # to save first when the in memory one may be corrupted.
1517
1517
            # so for now, we just only write it if it is indeed dirty.
1518
1518
            # - RBC 20060907
1519
1519
            self._write_inventory(self._inventory)
1520
 
    
 
1520
 
1521
1521
    def _iter_conflicts(self):
1522
1522
        conflicted = set()
1523
1523
        for info in self.list_files():
1566
1566
                # reuse the revisiontree we merged against to set the new
1567
1567
                # tree data.
1568
1568
                parent_trees = [(self.branch.last_revision(), new_basis_tree)]
1569
 
                # we have to pull the merge trees out again, because 
1570
 
                # merge_inner has set the ids. - this corner is not yet 
 
1569
                # we have to pull the merge trees out again, because
 
1570
                # merge_inner has set the ids. - this corner is not yet
1571
1571
                # layered well enough to prevent double handling.
1572
1572
                # XXX TODO: Fix the double handling: telling the tree about
1573
1573
                # the already known parent data is wasteful.
1627
1627
                            fl.append(subf_norm)
1628
1628
                    else:
1629
1629
                        fl.append(subf)
1630
 
            
 
1630
 
1631
1631
            fl.sort()
1632
1632
            for subf in fl:
1633
1633
                subp = pathjoin(path, subf)
1784
1784
 
1785
1785
    def _change_last_revision(self, new_revision):
1786
1786
        """Template method part of set_last_revision to perform the change.
1787
 
        
 
1787
 
1788
1788
        This is used to allow WorkingTree3 instances to not affect branch
1789
1789
        when their last revision is set.
1790
1790
        """
1816
1816
        # as commit already has that ready-to-use [while the format is the
1817
1817
        # same, that is].
1818
1818
        try:
1819
 
            # this double handles the inventory - unpack and repack - 
 
1819
            # this double handles the inventory - unpack and repack -
1820
1820
            # but is easier to understand. We can/should put a conditional
1821
1821
            # in here based on whether the inventory is in the latest format
1822
1822
            # - perhaps we should repack all inventories on a repository
1823
1823
            # upgrade ?
1824
1824
            # the fast path is to copy the raw xml from the repository. If the
1825
 
            # xml contains 'revision_id="', then we assume the right 
 
1825
            # xml contains 'revision_id="', then we assume the right
1826
1826
            # revision_id is set. We must check for this full string, because a
1827
1827
            # root node id can legitimately look like 'revision_id' but cannot
1828
1828
            # contain a '"'.
1829
1829
            xml = self.branch.repository.get_inventory_xml(new_revision)
1830
1830
            firstline = xml.split('\n', 1)[0]
1831
 
            if (not 'revision_id="' in firstline or 
 
1831
            if (not 'revision_id="' in firstline or
1832
1832
                'format="7"' not in firstline):
1833
1833
                inv = self.branch.repository.deserialise_inventory(
1834
1834
                    new_revision, xml)
1841
1841
        """Read the cached basis inventory."""
1842
1842
        path = self._basis_inventory_name()
1843
1843
        return self._transport.get_bytes(path)
1844
 
        
 
1844
 
1845
1845
    @needs_read_lock
1846
1846
    def read_working_inventory(self):
1847
1847
        """Read the working inventory.
1848
 
        
 
1848
 
1849
1849
        :raises errors.InventoryModified: read_working_inventory will fail
1850
1850
            when the current in memory inventory has been modified.
1851
1851
        """
1852
 
        # conceptually this should be an implementation detail of the tree. 
 
1852
        # conceptually this should be an implementation detail of the tree.
1853
1853
        # XXX: Deprecate this.
1854
1854
        # ElementTree does its own conversion from UTF-8, so open in
1855
1855
        # binary.
2052
2052
            name = os.path.basename(path)
2053
2053
            if name == "":
2054
2054
                continue
2055
 
            # fixme, there should be a factory function inv,add_?? 
 
2055
            # fixme, there should be a factory function inv,add_??
2056
2056
            if kind == 'directory':
2057
2057
                inv.add(InventoryDirectory(file_id, name, parent))
2058
2058
            elif kind == 'file':
2066
2066
    @needs_tree_write_lock
2067
2067
    def set_root_id(self, file_id):
2068
2068
        """Set the root id for this tree."""
2069
 
        # for compatability 
 
2069
        # for compatability
2070
2070
        if file_id is None:
2071
2071
            raise ValueError(
2072
2072
                'WorkingTree.set_root_id with fileid=None')
2076
2076
    def _set_root_id(self, file_id):
2077
2077
        """Set the root id for this tree, in a format specific manner.
2078
2078
 
2079
 
        :param file_id: The file id to assign to the root. It must not be 
 
2079
        :param file_id: The file id to assign to the root. It must not be
2080
2080
            present in the current inventory or an error will occur. It must
2081
2081
            not be None, but rather a valid file id.
2082
2082
        """
2101
2101
 
2102
2102
    def unlock(self):
2103
2103
        """See Branch.unlock.
2104
 
        
 
2104
 
2105
2105
        WorkingTree locking just uses the Branch locking facilities.
2106
2106
        This is current because all working trees have an embedded branch
2107
2107
        within them. IF in the future, we were to make branch data shareable
2108
 
        between multiple working trees, i.e. via shared storage, then we 
 
2108
        between multiple working trees, i.e. via shared storage, then we
2109
2109
        would probably want to lock both the local tree, and the branch.
2110
2110
        """
2111
2111
        raise NotImplementedError(self.unlock)
2163
2163
        # cant set that until we update the working trees last revision to be
2164
2164
        # one from the new branch, because it will just get absorbed by the
2165
2165
        # parent de-duplication logic.
2166
 
        # 
 
2166
        #
2167
2167
        # We MUST save it even if an error occurs, because otherwise the users
2168
2168
        # local work is unreferenced and will appear to have been lost.
2169
 
        # 
 
2169
        #
2170
2170
        result = 0
2171
2171
        try:
2172
2172
            last_rev = self.get_parent_ids()[0]
2524
2524
class WorkingTree2(WorkingTree):
2525
2525
    """This is the Format 2 working tree.
2526
2526
 
2527
 
    This was the first weave based working tree. 
 
2527
    This was the first weave based working tree.
2528
2528
     - uses os locks for locking.
2529
2529
     - uses the branch last-revision.
2530
2530
    """
2563
2563
            if self._inventory_is_modified:
2564
2564
                self.flush()
2565
2565
            self._write_hashcache_if_dirty()
2566
 
                    
 
2566
 
2567
2567
        # reverse order of locking.
2568
2568
        try:
2569
2569
            return self._control_files.unlock()
2604
2604
 
2605
2605
    @needs_tree_write_lock
2606
2606
    def set_conflicts(self, conflicts):
2607
 
        self._put_rio('conflicts', conflicts.to_stanzas(), 
 
2607
        self._put_rio('conflicts', conflicts.to_stanzas(),
2608
2608
                      CONFLICT_HEADER_1)
2609
2609
 
2610
2610
    @needs_tree_write_lock
2659
2659
     * a format string,
2660
2660
     * an open routine.
2661
2661
 
2662
 
    Formats are placed in an dict by their format string for reference 
 
2662
    Formats are placed in an dict by their format string for reference
2663
2663
    during workingtree opening. Its not required that these be instances, they
2664
 
    can be classes themselves with class methods - it simply depends on 
 
2664
    can be classes themselves with class methods - it simply depends on
2665
2665
    whether state is needed for a given format or not.
2666
2666
 
2667
2667
    Once a format is deprecated, just deprecate the initialize and open
2668
 
    methods on the format class. Do not deprecate the object, as the 
 
2668
    methods on the format class. Do not deprecate the object, as the
2669
2669
    object will be created every time regardless.
2670
2670
    """
2671
2671
 
2715
2715
        """Is this format supported?
2716
2716
 
2717
2717
        Supported formats can be initialized and opened.
2718
 
        Unsupported formats may not support initialization or committing or 
 
2718
        Unsupported formats may not support initialization or committing or
2719
2719
        some other features depending on the reason for not being supported.
2720
2720
        """
2721
2721
        return True
2742
2742
 
2743
2743
 
2744
2744
class WorkingTreeFormat2(WorkingTreeFormat):
2745
 
    """The second working tree format. 
 
2745
    """The second working tree format.
2746
2746
 
2747
2747
    This format modified the hash cache from the format 1 hash cache.
2748
2748
    """
2834
2834
        - is new in bzr 0.8
2835
2835
        - uses a LockDir to guard access for writes.
2836
2836
    """
2837
 
    
 
2837
 
2838
2838
    upgrade_recommended = True
2839
2839
 
2840
2840
    def get_format_string(self):
2857
2857
 
2858
2858
    def _open_control_files(self, a_bzrdir):
2859
2859
        transport = a_bzrdir.get_workingtree_transport(None)
2860
 
        return LockableFiles(transport, self._lock_file_name, 
 
2860
        return LockableFiles(transport, self._lock_file_name,
2861
2861
                             self._lock_class)
2862
2862
 
2863
2863
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
2864
2864
                   accelerator_tree=None, hardlink=False):
2865
2865
        """See WorkingTreeFormat.initialize().
2866
 
        
 
2866
 
2867
2867
        :param revision_id: if supplied, create a working tree at a different
2868
2868
            revision than the branch is at.
2869
2869
        :param accelerator_tree: A tree which can be used for retrieving file
2940
2940
 
2941
2941
    def _open(self, a_bzrdir, control_files):
2942
2942
        """Open the tree itself.
2943
 
        
 
2943
 
2944
2944
        :param a_bzrdir: the dir for the tree.
2945
2945
        :param control_files: the control files for the tree.
2946
2946
        """