~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Martin Pool
  • Date: 2009-06-19 09:06:56 UTC
  • mfrom: (4463 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4464.
  • Revision ID: mbp@sourcefrog.net-20090619090656-d5weqeecyscv8kqp
merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
48
48
import itertools
49
49
import operator
50
50
import stat
 
51
from time import time
 
52
import warnings
51
53
import re
52
54
 
53
55
import bzrlib
55
57
    branch,
56
58
    bzrdir,
57
59
    conflicts as _mod_conflicts,
 
60
    dirstate,
58
61
    errors,
59
62
    generate_ids,
60
63
    globbing,
61
 
    graph as _mod_graph,
62
64
    hashcache,
63
65
    ignores,
64
 
    inventory,
65
66
    merge,
66
67
    revision as _mod_revision,
67
68
    revisiontree,
 
69
    repository,
68
70
    textui,
69
71
    trace,
70
72
    transform,
71
73
    ui,
 
74
    urlutils,
72
75
    views,
73
76
    xml5,
 
77
    xml6,
74
78
    xml7,
75
79
    )
76
80
import bzrlib.branch
77
81
from bzrlib.transport import get_transport
 
82
import bzrlib.ui
78
83
from bzrlib.workingtree_4 import (
79
84
    WorkingTreeFormat4,
80
85
    WorkingTreeFormat5,
84
89
 
85
90
from bzrlib import symbol_versioning
86
91
from bzrlib.decorators import needs_read_lock, needs_write_lock
 
92
from bzrlib.inventory import InventoryEntry, Inventory, ROOT_ID, TreeReference
87
93
from bzrlib.lockable_files import LockableFiles
88
94
from bzrlib.lockdir import LockDir
89
95
import bzrlib.mutabletree
90
96
from bzrlib.mutabletree import needs_tree_write_lock
91
97
from bzrlib import osutils
92
98
from bzrlib.osutils import (
 
99
    compact_date,
93
100
    file_kind,
94
101
    isdir,
95
102
    normpath,
96
103
    pathjoin,
 
104
    rand_chars,
97
105
    realpath,
98
106
    safe_unicode,
99
107
    splitpath,
103
111
from bzrlib.trace import mutter, note
104
112
from bzrlib.transport.local import LocalTransport
105
113
from bzrlib.progress import DummyProgress, ProgressPhase
106
 
from bzrlib.revision import CURRENT_REVISION
 
114
from bzrlib.revision import NULL_REVISION, CURRENT_REVISION
107
115
from bzrlib.rio import RioReader, rio_file, Stanza
108
 
from bzrlib.symbol_versioning import (
109
 
    deprecated_passed,
110
 
    DEPRECATED_PARAMETER,
111
 
    )
 
116
from bzrlib.symbol_versioning import (deprecated_passed,
 
117
        deprecated_method,
 
118
        deprecated_function,
 
119
        DEPRECATED_PARAMETER,
 
120
        )
112
121
 
113
122
 
114
123
MERGE_MODIFIED_HEADER_1 = "BZR merge-modified list format 1"
478
487
        incorrectly attributed to CURRENT_REVISION (but after committing, the
479
488
        attribution will be correct).
480
489
        """
481
 
        maybe_file_parent_keys = []
482
 
        for parent_id in self.get_parent_ids():
483
 
            try:
484
 
                parent_tree = self.revision_tree(parent_id)
485
 
            except errors.NoSuchRevisionInTree:
486
 
                parent_tree = self.branch.repository.revision_tree(parent_id)
487
 
            parent_tree.lock_read()
488
 
            try:
489
 
                if file_id not in parent_tree:
490
 
                    continue
491
 
                ie = parent_tree.inventory[file_id]
492
 
                if ie.kind != 'file':
493
 
                    # Note: this is slightly unnecessary, because symlinks and
494
 
                    # directories have a "text" which is the empty text, and we
495
 
                    # know that won't mess up annotations. But it seems cleaner
496
 
                    continue
497
 
                parent_text_key = (file_id, ie.revision)
498
 
                if parent_text_key not in maybe_file_parent_keys:
499
 
                    maybe_file_parent_keys.append(parent_text_key)
500
 
            finally:
501
 
                parent_tree.unlock()
502
 
        graph = _mod_graph.Graph(self.branch.repository.texts)
503
 
        heads = graph.heads(maybe_file_parent_keys)
504
 
        file_parent_keys = []
505
 
        for key in maybe_file_parent_keys:
506
 
            if key in heads:
507
 
                file_parent_keys.append(key)
508
 
 
509
 
        # Now we have the parents of this content
510
 
        annotator = self.branch.repository.texts.get_annotator()
511
 
        text = self.get_file(file_id).read()
512
 
        this_key =(file_id, default_revision)
513
 
        annotator.add_special_text(this_key, file_parent_keys, text)
514
 
        annotations = [(key[-1], line)
515
 
                       for key, line in annotator.annotate_flat(this_key)]
516
 
        return annotations
 
490
        basis = self.basis_tree()
 
491
        basis.lock_read()
 
492
        try:
 
493
            changes = self.iter_changes(basis, True, [self.id2path(file_id)],
 
494
                require_versioned=True).next()
 
495
            changed_content, kind = changes[2], changes[6]
 
496
            if not changed_content:
 
497
                return basis.annotate_iter(file_id)
 
498
            if kind[1] is None:
 
499
                return None
 
500
            import annotate
 
501
            if kind[0] != 'file':
 
502
                old_lines = []
 
503
            else:
 
504
                old_lines = list(basis.annotate_iter(file_id))
 
505
            old = [old_lines]
 
506
            for tree in self.branch.repository.revision_trees(
 
507
                self.get_parent_ids()[1:]):
 
508
                if file_id not in tree:
 
509
                    continue
 
510
                old.append(list(tree.annotate_iter(file_id)))
 
511
            return annotate.reannotate(old, self.get_file(file_id).readlines(),
 
512
                                       default_revision)
 
513
        finally:
 
514
            basis.unlock()
517
515
 
518
516
    def _get_ancestors(self, default_revision):
519
517
        ancestors = set([default_revision])
891
889
            branch.last_revision().
892
890
        """
893
891
        from bzrlib.merge import Merger, Merge3Merger
894
 
        pb = ui.ui_factory.nested_progress_bar()
 
892
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
895
893
        try:
896
894
            merger = Merger(self.branch, this_tree=self, pb=pb)
897
895
            merger.pp = ProgressPhase("Merge phase", 5, pb)
1083
1081
            branch.BranchReferenceFormat().initialize(tree_bzrdir, new_branch)
1084
1082
        else:
1085
1083
            tree_bzrdir = branch_bzrdir
1086
 
        wt = tree_bzrdir.create_workingtree(_mod_revision.NULL_REVISION)
 
1084
        wt = tree_bzrdir.create_workingtree(NULL_REVISION)
1087
1085
        wt.set_parent_ids(self.get_parent_ids())
1088
1086
        my_inv = self.inventory
1089
 
        child_inv = inventory.Inventory(root_id=None)
 
1087
        child_inv = Inventory(root_id=None)
1090
1088
        new_root = my_inv[file_id]
1091
1089
        my_inv.remove_recursive_id(file_id)
1092
1090
        new_root.parent_id = None
1418
1416
        inv = self.inventory
1419
1417
        for entry in moved:
1420
1418
            try:
1421
 
                self._move_entry(WorkingTree._RenameEntry(
1422
 
                    entry.to_rel, entry.from_id,
 
1419
                self._move_entry(_RenameEntry(entry.to_rel, entry.from_id,
1423
1420
                    entry.to_tail, entry.to_parent_id, entry.from_rel,
1424
1421
                    entry.from_tail, entry.from_parent_id,
1425
1422
                    entry.only_change_inv))
1576
1573
    @needs_write_lock
1577
1574
    def pull(self, source, overwrite=False, stop_revision=None,
1578
1575
             change_reporter=None, possible_transports=None, local=False):
1579
 
        top_pb = ui.ui_factory.nested_progress_bar()
 
1576
        top_pb = bzrlib.ui.ui_factory.nested_progress_bar()
1580
1577
        source.lock_read()
1581
1578
        try:
1582
1579
            pp = ProgressPhase("Pull phase", 2, top_pb)
1590
1587
            if new_revision_info != old_revision_info:
1591
1588
                pp.next_phase()
1592
1589
                repository = self.branch.repository
1593
 
                pb = ui.ui_factory.nested_progress_bar()
 
1590
                pb = bzrlib.ui.ui_factory.nested_progress_bar()
1594
1591
                basis_tree.lock_read()
1595
1592
                try:
1596
1593
                    new_basis_tree = self.branch.basis_tree()
2045
2042
            if filenames is None and len(self.get_parent_ids()) > 1:
2046
2043
                parent_trees = []
2047
2044
                last_revision = self.last_revision()
2048
 
                if last_revision != _mod_revision.NULL_REVISION:
 
2045
                if last_revision != NULL_REVISION:
2049
2046
                    if basis_tree is None:
2050
2047
                        basis_tree = self.basis_tree()
2051
2048
                        basis_tree.lock_read()
2089
2086
    def set_inventory(self, new_inventory_list):
2090
2087
        from bzrlib.inventory import (Inventory,
2091
2088
                                      InventoryDirectory,
 
2089
                                      InventoryEntry,
2092
2090
                                      InventoryFile,
2093
2091
                                      InventoryLink)
2094
2092
        inv = Inventory(self.get_root_id())
2636
2634
 
2637
2635
    def _change_last_revision(self, revision_id):
2638
2636
        """See WorkingTree._change_last_revision."""
2639
 
        if revision_id is None or revision_id == _mod_revision.NULL_REVISION:
 
2637
        if revision_id is None or revision_id == NULL_REVISION:
2640
2638
            try:
2641
2639
                self._transport.delete('last-revision')
2642
2640
            except errors.NoSuchFile:
2806
2804
        no working tree.  (See bug #43064).
2807
2805
        """
2808
2806
        sio = StringIO()
2809
 
        inv = inventory.Inventory()
 
2807
        inv = Inventory()
2810
2808
        xml5.serializer_v5.write_inventory(inv, sio, working=True)
2811
2809
        sio.seek(0)
2812
2810
        transport.put_file('inventory', sio, file_mode)
2828
2826
            branch.generate_revision_history(revision_id)
2829
2827
        finally:
2830
2828
            branch.unlock()
2831
 
        inv = inventory.Inventory()
 
2829
        inv = Inventory()
2832
2830
        wt = WorkingTree2(a_bzrdir.root_transport.local_abspath('.'),
2833
2831
                         branch,
2834
2832
                         inv,
2951
2949
            # only set an explicit root id if there is one to set.
2952
2950
            if basis_tree.inventory.root is not None:
2953
2951
                wt.set_root_id(basis_tree.get_root_id())
2954
 
            if revision_id == _mod_revision.NULL_REVISION:
 
2952
            if revision_id == NULL_REVISION:
2955
2953
                wt.set_parent_trees([])
2956
2954
            else:
2957
2955
                wt.set_parent_trees([(revision_id, basis_tree)])
2964
2962
        return wt
2965
2963
 
2966
2964
    def _initial_inventory(self):
2967
 
        return inventory.Inventory()
 
2965
        return Inventory()
2968
2966
 
2969
2967
    def __init__(self):
2970
2968
        super(WorkingTreeFormat3, self).__init__()