~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

  • Committer: Jelmer Vernooij
  • Date: 2011-06-16 11:57:36 UTC
  • mto: This revision was merged to the branch mainline in revision 5987.
  • Revision ID: jelmer@samba.org-20110616115736-5xuzwdf87qb81su4
Use iter_ancestry rather than get_ancestry.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
from bzrlib import (
31
31
    annotate,
32
32
    bencode,
33
 
    controldir,
 
33
    bzrdir,
34
34
    commit,
35
 
    conflicts,
36
35
    delta,
37
36
    errors,
38
37
    inventory,
42
41
    ui,
43
42
    urlutils,
44
43
    )
45
 
from bzrlib.i18n import gettext
46
44
""")
47
45
from bzrlib.errors import (DuplicateKey, MalformedTransform, NoSuchFile,
48
46
                           ReusingTransform, CantMoveRoot,
227
225
        This means that the old root trans-id becomes obsolete, so it is
228
226
        recommended only to invoke this after the root trans-id has become
229
227
        irrelevant.
230
 
 
231
228
        """
232
229
        new_roots = [k for k, v in self._new_parent.iteritems() if v is
233
230
                     ROOT_PARENT]
239
236
            self._new_root = new_roots[0]
240
237
            return
241
238
        old_new_root = new_roots[0]
 
239
        # TODO: What to do if a old_new_root is present, but self._new_root is
 
240
        #       not listed as being removed? This code explicitly unversions
 
241
        #       the old root and versions it with the new file_id. Though that
 
242
        #       seems like an incomplete delta
 
243
 
242
244
        # unversion the new root's directory.
243
 
        if self.final_kind(self._new_root) is None:
244
 
            file_id = self.final_file_id(old_new_root)
245
 
        else:
246
 
            file_id = self.final_file_id(self._new_root)
 
245
        file_id = self.final_file_id(old_new_root)
247
246
        if old_new_root in self._new_id:
248
247
            self.cancel_versioning(old_new_root)
249
248
        else:
1727
1726
        child_pb = ui.ui_factory.nested_progress_bar()
1728
1727
        try:
1729
1728
            if precomputed_delta is None:
1730
 
                child_pb.update(gettext('Apply phase'), 0, 2)
 
1729
                child_pb.update('Apply phase', 0, 2)
1731
1730
                inventory_delta = self._generate_inventory_delta()
1732
1731
                offset = 1
1733
1732
            else:
1738
1737
            else:
1739
1738
                mover = _mover
1740
1739
            try:
1741
 
                child_pb.update(gettext('Apply phase'), 0 + offset, 2 + offset)
 
1740
                child_pb.update('Apply phase', 0 + offset, 2 + offset)
1742
1741
                self._apply_removals(mover)
1743
 
                child_pb.update(gettext('Apply phase'), 1 + offset, 2 + offset)
 
1742
                child_pb.update('Apply phase', 1 + offset, 2 + offset)
1744
1743
                modified_paths = self._apply_insertions(mover)
1745
1744
            except:
1746
1745
                mover.rollback()
1749
1748
                mover.apply_deletions()
1750
1749
        finally:
1751
1750
            child_pb.finished()
1752
 
        if self.final_file_id(self.root) is None:
1753
 
            inventory_delta = [e for e in inventory_delta if e[0] != '']
1754
1751
        self._tree.apply_inventory_delta(inventory_delta)
1755
1752
        self._apply_observed_sha1s()
1756
1753
        self._done = True
1766
1763
        try:
1767
1764
            for num, trans_id in enumerate(self._removed_id):
1768
1765
                if (num % 10) == 0:
1769
 
                    child_pb.update(gettext('removing file'), num, total_entries)
 
1766
                    child_pb.update('removing file', num, total_entries)
1770
1767
                if trans_id == self._new_root:
1771
1768
                    file_id = self._tree.get_root_id()
1772
1769
                else:
1784
1781
            final_kinds = {}
1785
1782
            for num, (path, trans_id) in enumerate(new_paths):
1786
1783
                if (num % 10) == 0:
1787
 
                    child_pb.update(gettext('adding file'),
 
1784
                    child_pb.update('adding file',
1788
1785
                                    num + len(self._removed_id), total_entries)
1789
1786
                file_id = new_path_file_ids[trans_id]
1790
1787
                if file_id is None:
1834
1831
                # do not attempt to move root into a subdirectory of itself.
1835
1832
                if path == '':
1836
1833
                    continue
1837
 
                child_pb.update(gettext('removing file'), num, len(tree_paths))
 
1834
                child_pb.update('removing file', num, len(tree_paths))
1838
1835
                full_path = self._tree.abspath(path)
1839
1836
                if trans_id in self._removed_contents:
1840
1837
                    delete_path = os.path.join(self._deletiondir, trans_id)
1869
1866
        try:
1870
1867
            for num, (path, trans_id) in enumerate(new_paths):
1871
1868
                if (num % 10) == 0:
1872
 
                    child_pb.update(gettext('adding file'), num, len(new_paths))
 
1869
                    child_pb.update('adding file', num, len(new_paths))
1873
1870
                full_path = self._tree.abspath(path)
1874
1871
                if trans_id in self._needs_rename:
1875
1872
                    try:
2259
2256
        else:
2260
2257
            return None
2261
2258
 
2262
 
    def get_file_verifier(self, file_id, path=None, stat_value=None):
2263
 
        trans_id = self._transform.trans_id_file_id(file_id)
2264
 
        kind = self._transform._new_contents.get(trans_id)
2265
 
        if kind is None:
2266
 
            return self._transform._tree.get_file_verifier(file_id)
2267
 
        if kind == 'file':
2268
 
            fileobj = self.get_file(file_id)
2269
 
            try:
2270
 
                return ("SHA1", sha_file(fileobj))
2271
 
            finally:
2272
 
                fileobj.close()
2273
 
 
2274
2259
    def get_file_sha1(self, file_id, path=None, stat_value=None):
2275
2260
        trans_id = self._transform.trans_id_file_id(file_id)
2276
2261
        kind = self._transform._new_contents.get(trans_id)
2584
2569
                    existing_files.update(f[0] for f in files)
2585
2570
            for num, (tree_path, entry) in \
2586
2571
                enumerate(tree.inventory.iter_entries_by_dir()):
2587
 
                pb.update(gettext("Building tree"), num - len(deferred_contents), total)
 
2572
                pb.update("Building tree", num - len(deferred_contents), total)
2588
2573
                if entry.parent_id is None:
2589
2574
                    continue
2590
2575
                reparent = False
2596
2581
                    kind = file_kind(target_path)
2597
2582
                    if kind == "directory":
2598
2583
                        try:
2599
 
                            controldir.ControlDir.open(target_path)
 
2584
                            bzrdir.BzrDir.open(target_path)
2600
2585
                        except errors.NotBranchError:
2601
2586
                            pass
2602
2587
                        else:
2674
2659
                new_desired_files.append((file_id,
2675
2660
                    (trans_id, tree_path, text_sha1)))
2676
2661
                continue
2677
 
            pb.update(gettext('Adding file contents'), count + offset, total)
 
2662
            pb.update('Adding file contents', count + offset, total)
2678
2663
            if hardlink:
2679
2664
                tt.create_hardlink(accelerator_tree.abspath(accelerator_path),
2680
2665
                                   trans_id)
2701
2686
            contents = filtered_output_bytes(contents, filters,
2702
2687
                ContentFilterContext(tree_path, tree))
2703
2688
        tt.create_file(contents, trans_id, sha1=text_sha1)
2704
 
        pb.update(gettext('Adding file contents'), count + offset, total)
 
2689
        pb.update('Adding file contents', count + offset, total)
2705
2690
 
2706
2691
 
2707
2692
def _reparent_children(tt, old_parent, new_parent):
2953
2938
                        if basis_tree is None:
2954
2939
                            basis_tree = working_tree.basis_tree()
2955
2940
                            basis_tree.lock_read()
2956
 
                        if basis_tree.has_id(file_id):
 
2941
                        if file_id in basis_tree:
2957
2942
                            if wt_sha1 != basis_tree.get_file_sha1(file_id):
2958
2943
                                keep_content = True
2959
2944
                        elif target_kind is None and not target_versioned:
2989
2974
                        basis_tree = working_tree.basis_tree()
2990
2975
                        basis_tree.lock_read()
2991
2976
                    new_sha1 = target_tree.get_file_sha1(file_id)
2992
 
                    if (basis_tree.has_id(file_id) and
2993
 
                        new_sha1 == basis_tree.get_file_sha1(file_id)):
 
2977
                    if (file_id in basis_tree and new_sha1 ==
 
2978
                        basis_tree.get_file_sha1(file_id)):
2994
2979
                        if file_id in merge_modified:
2995
2980
                            del merge_modified[file_id]
2996
2981
                    else:
3048
3033
    pb = ui.ui_factory.nested_progress_bar()
3049
3034
    try:
3050
3035
        for n in range(10):
3051
 
            pb.update(gettext('Resolution pass'), n+1, 10)
 
3036
            pb.update('Resolution pass', n+1, 10)
3052
3037
            conflicts = tt.find_conflicts()
3053
3038
            if len(conflicts) == 0:
3054
3039
                return new_conflicts
3147
3132
        elif c_type == 'unversioned parent':
3148
3133
            file_id = tt.inactive_file_id(conflict[1])
3149
3134
            # special-case the other tree root (move its children instead)
3150
 
            if path_tree and path_tree.has_id(file_id):
 
3135
            if path_tree and file_id in path_tree:
3151
3136
                if path_tree.path2id('') == file_id:
3152
3137
                    # This is the root entry, skip it
3153
3138
                    continue
3171
3156
 
3172
3157
def cook_conflicts(raw_conflicts, tt):
3173
3158
    """Generate a list of cooked conflicts, sorted by file path"""
 
3159
    from bzrlib.conflicts import Conflict
3174
3160
    conflict_iter = iter_cook_conflicts(raw_conflicts, tt)
3175
 
    return sorted(conflict_iter, key=conflicts.Conflict.sort_key)
 
3161
    return sorted(conflict_iter, key=Conflict.sort_key)
3176
3162
 
3177
3163
 
3178
3164
def iter_cook_conflicts(raw_conflicts, tt):
 
3165
    from bzrlib.conflicts import Conflict
3179
3166
    fp = FinalPaths(tt)
3180
3167
    for conflict in raw_conflicts:
3181
3168
        c_type = conflict[0]
3183
3170
        modified_path = fp.get_path(conflict[2])
3184
3171
        modified_id = tt.final_file_id(conflict[2])
3185
3172
        if len(conflict) == 3:
3186
 
            yield conflicts.Conflict.factory(
3187
 
                c_type, action=action, path=modified_path, file_id=modified_id)
 
3173
            yield Conflict.factory(c_type, action=action, path=modified_path,
 
3174
                                     file_id=modified_id)
3188
3175
 
3189
3176
        else:
3190
3177
            conflicting_path = fp.get_path(conflict[3])
3191
3178
            conflicting_id = tt.final_file_id(conflict[3])
3192
 
            yield conflicts.Conflict.factory(
3193
 
                c_type, action=action, path=modified_path,
3194
 
                file_id=modified_id,
3195
 
                conflict_path=conflicting_path,
3196
 
                conflict_file_id=conflicting_id)
 
3179
            yield Conflict.factory(c_type, action=action, path=modified_path,
 
3180
                                   file_id=modified_id,
 
3181
                                   conflict_path=conflicting_path,
 
3182
                                   conflict_file_id=conflicting_id)
3197
3183
 
3198
3184
 
3199
3185
class _FileMover(object):