1
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
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
90
85
from bzrlib import symbol_versioning
91
86
from bzrlib.decorators import needs_read_lock, needs_write_lock
92
from bzrlib.inventory import InventoryEntry, Inventory, ROOT_ID, TreeReference
93
87
from bzrlib.lockable_files import LockableFiles
94
88
from bzrlib.lockdir import LockDir
95
89
import bzrlib.mutabletree
96
90
from bzrlib.mutabletree import needs_tree_write_lock
97
91
from bzrlib import osutils
98
92
from bzrlib.osutils import (
111
103
from bzrlib.trace import mutter, note
112
104
from bzrlib.transport.local import LocalTransport
113
105
from bzrlib.progress import DummyProgress, ProgressPhase
114
from bzrlib.revision import NULL_REVISION, CURRENT_REVISION
106
from bzrlib.revision import CURRENT_REVISION
115
107
from bzrlib.rio import RioReader, rio_file, Stanza
116
from bzrlib.symbol_versioning import (deprecated_passed,
119
DEPRECATED_PARAMETER,
108
from bzrlib.symbol_versioning import (
110
DEPRECATED_PARAMETER,
123
114
MERGE_MODIFIED_HEADER_1 = "BZR merge-modified list format 1"
487
478
incorrectly attributed to CURRENT_REVISION (but after committing, the
488
479
attribution will be correct).
490
basis = self.basis_tree()
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)
501
if kind[0] != 'file':
504
old_lines = list(basis.annotate_iter(file_id))
506
for tree in self.branch.repository.revision_trees(
507
self.get_parent_ids()[1:]):
508
if file_id not in tree:
510
old.append(list(tree.annotate_iter(file_id)))
511
return annotate.reannotate(old, self.get_file(file_id).readlines(),
481
maybe_file_parent_keys = []
482
for parent_id in self.get_parent_ids():
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()
489
if file_id not in parent_tree:
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
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)
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:
507
file_parent_keys.append(key)
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
518
def _get_ancestors(self, default_revision):
517
519
ancestors = set([default_revision])
889
891
branch.last_revision().
891
893
from bzrlib.merge import Merger, Merge3Merger
892
pb = bzrlib.ui.ui_factory.nested_progress_bar()
894
pb = ui.ui_factory.nested_progress_bar()
894
896
merger = Merger(self.branch, this_tree=self, pb=pb)
895
897
merger.pp = ProgressPhase("Merge phase", 5, pb)
1081
1083
branch.BranchReferenceFormat().initialize(tree_bzrdir, new_branch)
1083
1085
tree_bzrdir = branch_bzrdir
1084
wt = tree_bzrdir.create_workingtree(NULL_REVISION)
1086
wt = tree_bzrdir.create_workingtree(_mod_revision.NULL_REVISION)
1085
1087
wt.set_parent_ids(self.get_parent_ids())
1086
1088
my_inv = self.inventory
1087
child_inv = Inventory(root_id=None)
1089
child_inv = inventory.Inventory(root_id=None)
1088
1090
new_root = my_inv[file_id]
1089
1091
my_inv.remove_recursive_id(file_id)
1090
1092
new_root.parent_id = None
1416
1418
inv = self.inventory
1417
1419
for entry in moved:
1419
self._move_entry(_RenameEntry(entry.to_rel, entry.from_id,
1421
self._move_entry(WorkingTree._RenameEntry(
1422
entry.to_rel, entry.from_id,
1420
1423
entry.to_tail, entry.to_parent_id, entry.from_rel,
1421
1424
entry.from_tail, entry.from_parent_id,
1422
1425
entry.only_change_inv))
1473
1476
from_tail = splitpath(from_rel)[-1]
1474
1477
from_id = inv.path2id(from_rel)
1475
1478
if from_id is None:
1476
raise errors.BzrRenameFailedError(from_rel,to_rel,
1477
errors.NotVersionedError(path=str(from_rel)))
1478
from_entry = inv[from_id]
1479
# if file is missing in the inventory maybe it's in the basis_tree
1480
basis_tree = self.branch.basis_tree()
1481
from_id = basis_tree.path2id(from_rel)
1483
raise errors.BzrRenameFailedError(from_rel,to_rel,
1484
errors.NotVersionedError(path=str(from_rel)))
1485
# put entry back in the inventory so we can rename it
1486
from_entry = basis_tree.inventory[from_id].copy()
1489
from_entry = inv[from_id]
1479
1490
from_parent_id = from_entry.parent_id
1480
1491
to_dir, to_tail = os.path.split(to_rel)
1481
1492
to_dir_id = inv.path2id(to_dir)
1573
1584
@needs_write_lock
1574
1585
def pull(self, source, overwrite=False, stop_revision=None,
1575
1586
change_reporter=None, possible_transports=None, local=False):
1576
top_pb = bzrlib.ui.ui_factory.nested_progress_bar()
1587
top_pb = ui.ui_factory.nested_progress_bar()
1577
1588
source.lock_read()
1579
1590
pp = ProgressPhase("Pull phase", 2, top_pb)
2635
2645
def _change_last_revision(self, revision_id):
2636
2646
"""See WorkingTree._change_last_revision."""
2637
if revision_id is None or revision_id == NULL_REVISION:
2647
if revision_id is None or revision_id == _mod_revision.NULL_REVISION:
2639
2649
self._transport.delete('last-revision')
2640
2650
except errors.NoSuchFile:
2949
2959
# only set an explicit root id if there is one to set.
2950
2960
if basis_tree.inventory.root is not None:
2951
2961
wt.set_root_id(basis_tree.get_root_id())
2952
if revision_id == NULL_REVISION:
2962
if revision_id == _mod_revision.NULL_REVISION:
2953
2963
wt.set_parent_trees([])
2955
2965
wt.set_parent_trees([(revision_id, basis_tree)])