~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

  • Committer: Vincent Ladeuil
  • Date: 2011-11-24 15:48:29 UTC
  • mfrom: (6289 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6337.
  • Revision ID: v.ladeuil+lp@free.fr-20111124154829-avowjpsxdl8yp2vz
merge trunk resolving conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
from bzrlib import (
31
31
    annotate,
32
32
    bencode,
33
 
    bzrdir,
 
33
    controldir,
34
34
    commit,
35
35
    conflicts,
36
36
    delta,
37
 
    errors,
38
37
    inventory,
39
38
    multiparent,
40
39
    osutils,
42
41
    ui,
43
42
    urlutils,
44
43
    )
 
44
from bzrlib.i18n import gettext
45
45
""")
46
 
from bzrlib.errors import (DuplicateKey, MalformedTransform, NoSuchFile,
 
46
from bzrlib.errors import (DuplicateKey, MalformedTransform,
47
47
                           ReusingTransform, CantMoveRoot,
48
48
                           ExistingLimbo, ImmortalLimbo, NoFinalPath,
49
49
                           UnableCreateSymlink)
231
231
        new_roots = [k for k, v in self._new_parent.iteritems() if v is
232
232
                     ROOT_PARENT]
233
233
        if len(new_roots) < 1:
234
 
            if self.final_kind(self.root) is None:
235
 
                self.cancel_deletion(self.root)
236
 
            if self.final_file_id(self.root) is None:
237
 
                self.version_file(self.tree_file_id(self.root),
238
 
                                     self.root)
239
234
            return
240
235
        if len(new_roots) != 1:
241
236
            raise ValueError('A tree cannot have two roots!')
566
561
        for trans_id in self._removed_id:
567
562
            file_id = self.tree_file_id(trans_id)
568
563
            if file_id is not None:
569
 
                # XXX: This seems like something that should go via a different
570
 
                #      indirection.
571
 
                if self._tree.inventory[file_id].kind == 'directory':
 
564
                if self._tree.stored_kind(file_id) == 'directory':
572
565
                    parents.append(trans_id)
573
566
            elif self.tree_kind(trans_id) == 'directory':
574
567
                parents.append(trans_id)
1731
1724
        child_pb = ui.ui_factory.nested_progress_bar()
1732
1725
        try:
1733
1726
            if precomputed_delta is None:
1734
 
                child_pb.update('Apply phase', 0, 2)
 
1727
                child_pb.update(gettext('Apply phase'), 0, 2)
1735
1728
                inventory_delta = self._generate_inventory_delta()
1736
1729
                offset = 1
1737
1730
            else:
1742
1735
            else:
1743
1736
                mover = _mover
1744
1737
            try:
1745
 
                child_pb.update('Apply phase', 0 + offset, 2 + offset)
 
1738
                child_pb.update(gettext('Apply phase'), 0 + offset, 2 + offset)
1746
1739
                self._apply_removals(mover)
1747
 
                child_pb.update('Apply phase', 1 + offset, 2 + offset)
 
1740
                child_pb.update(gettext('Apply phase'), 1 + offset, 2 + offset)
1748
1741
                modified_paths = self._apply_insertions(mover)
1749
1742
            except:
1750
1743
                mover.rollback()
1753
1746
                mover.apply_deletions()
1754
1747
        finally:
1755
1748
            child_pb.finished()
 
1749
        if self.final_file_id(self.root) is None:
 
1750
            inventory_delta = [e for e in inventory_delta if e[0] != '']
1756
1751
        self._tree.apply_inventory_delta(inventory_delta)
1757
1752
        self._apply_observed_sha1s()
1758
1753
        self._done = True
1768
1763
        try:
1769
1764
            for num, trans_id in enumerate(self._removed_id):
1770
1765
                if (num % 10) == 0:
1771
 
                    child_pb.update('removing file', num, total_entries)
 
1766
                    child_pb.update(gettext('removing file'), num, total_entries)
1772
1767
                if trans_id == self._new_root:
1773
1768
                    file_id = self._tree.get_root_id()
1774
1769
                else:
1786
1781
            final_kinds = {}
1787
1782
            for num, (path, trans_id) in enumerate(new_paths):
1788
1783
                if (num % 10) == 0:
1789
 
                    child_pb.update('adding file',
 
1784
                    child_pb.update(gettext('adding file'),
1790
1785
                                    num + len(self._removed_id), total_entries)
1791
1786
                file_id = new_path_file_ids[trans_id]
1792
1787
                if file_id is None:
1836
1831
                # do not attempt to move root into a subdirectory of itself.
1837
1832
                if path == '':
1838
1833
                    continue
1839
 
                child_pb.update('removing file', num, len(tree_paths))
 
1834
                child_pb.update(gettext('removing file'), num, len(tree_paths))
1840
1835
                full_path = self._tree.abspath(path)
1841
1836
                if trans_id in self._removed_contents:
1842
1837
                    delete_path = os.path.join(self._deletiondir, trans_id)
1871
1866
        try:
1872
1867
            for num, (path, trans_id) in enumerate(new_paths):
1873
1868
                if (num % 10) == 0:
1874
 
                    child_pb.update('adding file', num, len(new_paths))
 
1869
                    child_pb.update(gettext('adding file'), num, len(new_paths))
1875
1870
                full_path = self._tree.abspath(path)
1876
1871
                if trans_id in self._needs_rename:
1877
1872
                    try:
2261
2256
        else:
2262
2257
            return None
2263
2258
 
 
2259
    def get_file_verifier(self, file_id, path=None, stat_value=None):
 
2260
        trans_id = self._transform.trans_id_file_id(file_id)
 
2261
        kind = self._transform._new_contents.get(trans_id)
 
2262
        if kind is None:
 
2263
            return self._transform._tree.get_file_verifier(file_id)
 
2264
        if kind == 'file':
 
2265
            fileobj = self.get_file(file_id)
 
2266
            try:
 
2267
                return ("SHA1", sha_file(fileobj))
 
2268
            finally:
 
2269
                fileobj.close()
 
2270
 
2264
2271
    def get_file_sha1(self, file_id, path=None, stat_value=None):
2265
2272
        trans_id = self._transform.trans_id_file_id(file_id)
2266
2273
        kind = self._transform._new_contents.get(trans_id)
2537
2544
    file_trans_id = {}
2538
2545
    top_pb = ui.ui_factory.nested_progress_bar()
2539
2546
    pp = ProgressPhase("Build phase", 2, top_pb)
2540
 
    if tree.inventory.root is not None:
 
2547
    if tree.get_root_id() is not None:
2541
2548
        # This is kind of a hack: we should be altering the root
2542
2549
        # as part of the regular tree shape diff logic.
2543
2550
        # The conditional test here is to avoid doing an
2558
2565
        try:
2559
2566
            deferred_contents = []
2560
2567
            num = 0
2561
 
            total = len(tree.inventory)
 
2568
            total = len(tree.all_file_ids())
2562
2569
            if delta_from_tree:
2563
2570
                precomputed_delta = []
2564
2571
            else:
2573
2580
                for dir, files in wt.walkdirs():
2574
2581
                    existing_files.update(f[0] for f in files)
2575
2582
            for num, (tree_path, entry) in \
2576
 
                enumerate(tree.inventory.iter_entries_by_dir()):
2577
 
                pb.update("Building tree", num - len(deferred_contents), total)
 
2583
                enumerate(tree.iter_entries_by_dir()):
 
2584
                pb.update(gettext("Building tree"), num - len(deferred_contents), total)
2578
2585
                if entry.parent_id is None:
2579
2586
                    continue
2580
2587
                reparent = False
2586
2593
                    kind = file_kind(target_path)
2587
2594
                    if kind == "directory":
2588
2595
                        try:
2589
 
                            bzrdir.BzrDir.open(target_path)
 
2596
                            controldir.ControlDir.open(target_path)
2590
2597
                        except errors.NotBranchError:
2591
2598
                            pass
2592
2599
                        else:
2664
2671
                new_desired_files.append((file_id,
2665
2672
                    (trans_id, tree_path, text_sha1)))
2666
2673
                continue
2667
 
            pb.update('Adding file contents', count + offset, total)
 
2674
            pb.update(gettext('Adding file contents'), count + offset, total)
2668
2675
            if hardlink:
2669
2676
                tt.create_hardlink(accelerator_tree.abspath(accelerator_path),
2670
2677
                                   trans_id)
2691
2698
            contents = filtered_output_bytes(contents, filters,
2692
2699
                ContentFilterContext(tree_path, tree))
2693
2700
        tt.create_file(contents, trans_id, sha1=text_sha1)
2694
 
        pb.update('Adding file contents', count + offset, total)
 
2701
        pb.update(gettext('Adding file contents'), count + offset, total)
2695
2702
 
2696
2703
 
2697
2704
def _reparent_children(tt, old_parent, new_parent):
2829
2836
            return new_name
2830
2837
 
2831
2838
 
2832
 
def _entry_changes(file_id, entry, working_tree):
2833
 
    """Determine in which ways the inventory entry has changed.
2834
 
 
2835
 
    Returns booleans: has_contents, content_mod, meta_mod
2836
 
    has_contents means there are currently contents, but they differ
2837
 
    contents_mod means contents need to be modified
2838
 
    meta_mod means the metadata needs to be modified
2839
 
    """
2840
 
    cur_entry = working_tree.inventory[file_id]
2841
 
    try:
2842
 
        working_kind = working_tree.kind(file_id)
2843
 
        has_contents = True
2844
 
    except NoSuchFile:
2845
 
        has_contents = False
2846
 
        contents_mod = True
2847
 
        meta_mod = False
2848
 
    if has_contents is True:
2849
 
        if entry.kind != working_kind:
2850
 
            contents_mod, meta_mod = True, False
2851
 
        else:
2852
 
            cur_entry._read_tree_state(working_tree.id2path(file_id),
2853
 
                                       working_tree)
2854
 
            contents_mod, meta_mod = entry.detect_changes(cur_entry)
2855
 
            cur_entry._forget_tree_state()
2856
 
    return has_contents, contents_mod, meta_mod
2857
 
 
2858
 
 
2859
2839
def revert(working_tree, target_tree, filenames, backups=False,
2860
2840
           pb=None, change_reporter=None):
2861
2841
    """Revert a working tree's contents to those of a target tree."""
3038
3018
    pb = ui.ui_factory.nested_progress_bar()
3039
3019
    try:
3040
3020
        for n in range(10):
3041
 
            pb.update('Resolution pass', n+1, 10)
 
3021
            pb.update(gettext('Resolution pass'), n+1, 10)
3042
3022
            conflicts = tt.find_conflicts()
3043
3023
            if len(conflicts) == 0:
3044
3024
                return new_conflicts
3068
3048
                existing_file, new_file = conflict[2], conflict[1]
3069
3049
            else:
3070
3050
                existing_file, new_file = conflict[1], conflict[2]
3071
 
            new_name = tt.final_name(existing_file)+'.moved'
 
3051
            new_name = tt.final_name(existing_file) + '.moved'
3072
3052
            tt.adjust_path(new_name, final_parent, existing_file)
3073
3053
            new_conflicts.add((c_type, 'Moved existing file to',
3074
3054
                               existing_file, new_file))