/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 breezy/transform.py

  • Committer: Vincent Ladeuil
  • Author(s): Jelmer Vernooij
  • Date: 2018-03-01 05:46:59 UTC
  • mfrom: (6861.4.1 pb-context)
  • Revision ID: v.ladeuil+lp@free.fr-20180301054659-7fzum8cexsk421r3
Make progress bars context managers.

Merged from https://code.launchpad.net/~jelmer/brz/pb-context/+merge/339449

Show diffs side-by-side

added added

removed removed

Lines of Context:
1721
1721
            hook(self._tree, self)
1722
1722
        if not no_conflicts:
1723
1723
            self._check_malformed()
1724
 
        child_pb = ui.ui_factory.nested_progress_bar()
1725
 
        try:
 
1724
        with ui.ui_factory.nested_progress_bar() as child_pb:
1726
1725
            if precomputed_delta is None:
1727
1726
                child_pb.update(gettext('Apply phase'), 0, 2)
1728
1727
                inventory_delta = self._generate_inventory_delta()
1744
1743
                raise
1745
1744
            else:
1746
1745
                mover.apply_deletions()
1747
 
        finally:
1748
 
            child_pb.finished()
1749
1746
        if self.final_file_id(self.root) is None:
1750
1747
            inventory_delta = [e for e in inventory_delta if e[0] != '']
1751
1748
        self._tree.apply_inventory_delta(inventory_delta)
1757
1754
    def _generate_inventory_delta(self):
1758
1755
        """Generate an inventory delta for the current transform."""
1759
1756
        inventory_delta = []
1760
 
        child_pb = ui.ui_factory.nested_progress_bar()
1761
1757
        new_paths = self._inventory_altered()
1762
1758
        total_entries = len(new_paths) + len(self._removed_id)
1763
 
        try:
 
1759
        with ui.ui_factory.nested_progress_bar() as child_pb:
1764
1760
            for num, trans_id in enumerate(self._removed_id):
1765
1761
                if (num % 10) == 0:
1766
1762
                    child_pb.update(gettext('removing file'), num, total_entries)
1811
1807
                    new_entry.executable = new_executability
1812
1808
                inventory_delta.append(
1813
1809
                    (old_path, path, new_entry.file_id, new_entry))
1814
 
        finally:
1815
 
            child_pb.finished()
1816
1810
        return inventory_delta
1817
1811
 
1818
1812
    def _apply_removals(self, mover):
1825
1819
        If inventory_delta is None, no inventory delta generation is performed.
1826
1820
        """
1827
1821
        tree_paths = sorted(viewitems(self._tree_path_ids), reverse=True)
1828
 
        child_pb = ui.ui_factory.nested_progress_bar()
1829
 
        try:
 
1822
        with ui.ui_factory.nested_progress_bar() as child_pb:
1830
1823
            for num, (path, trans_id) in enumerate(tree_paths):
1831
1824
                # do not attempt to move root into a subdirectory of itself.
1832
1825
                if path == '':
1845
1838
                            raise
1846
1839
                    else:
1847
1840
                        self.rename_count += 1
1848
 
        finally:
1849
 
            child_pb.finished()
1850
1841
 
1851
1842
    def _apply_insertions(self, mover):
1852
1843
        """Perform tree operations that insert directory/inventory names.
1862
1853
        modified_paths = []
1863
1854
        new_path_file_ids = dict((t, self.final_file_id(t)) for p, t in
1864
1855
                                 new_paths)
1865
 
        child_pb = ui.ui_factory.nested_progress_bar()
1866
 
        try:
 
1856
        with ui.ui_factory.nested_progress_bar() as child_pb:
1867
1857
            for num, (path, trans_id) in enumerate(new_paths):
1868
1858
                if (num % 10) == 0:
1869
1859
                    child_pb.update(gettext('adding file'), num, len(new_paths))
1890
1880
                    o_sha1, o_st_val = self._observed_sha1s[trans_id]
1891
1881
                    st = osutils.lstat(full_path)
1892
1882
                    self._observed_sha1s[trans_id] = (o_sha1, st)
1893
 
        finally:
1894
 
            child_pb.finished()
1895
1883
        for path, trans_id in new_paths:
1896
1884
            # new_paths includes stuff like workingtree conflicts. Only the
1897
1885
            # stuff in new_contents actually comes from limbo.
2598
2586
        pp.next_phase()
2599
2587
        file_trans_id[wt.get_root_id()] = \
2600
2588
            tt.trans_id_tree_file_id(wt.get_root_id())
2601
 
        pb = ui.ui_factory.nested_progress_bar()
2602
 
        try:
 
2589
        with ui.ui_factory.nested_progress_bar() as pb:
2603
2590
            deferred_contents = []
2604
2591
            num = 0
2605
2592
            total = len(tree.all_versioned_paths())
2663
2650
            offset = num + 1 - len(deferred_contents)
2664
2651
            _create_files(tt, tree, deferred_contents, pb, offset,
2665
2652
                          accelerator_tree, hardlink)
2666
 
        finally:
2667
 
            pb.finished()
2668
2653
        pp.next_phase()
2669
2654
        divert_trans = set(file_trans_id[f] for f in divert)
2670
2655
        resolver = lambda t, c: resolve_checkout(t, c, divert_trans)
2885
2870
def _prepare_revert_transform(working_tree, target_tree, tt, filenames,
2886
2871
                              backups, pp, basis_tree=None,
2887
2872
                              merge_modified=None):
2888
 
    child_pb = ui.ui_factory.nested_progress_bar()
2889
 
    try:
 
2873
    with ui.ui_factory.nested_progress_bar() as child_pb:
2890
2874
        if merge_modified is None:
2891
2875
            merge_modified = working_tree.merge_modified()
2892
2876
        merge_modified = _alter_files(working_tree, target_tree, tt,
2893
2877
                                      child_pb, filenames, backups,
2894
2878
                                      merge_modified, basis_tree)
2895
 
    finally:
2896
 
        child_pb.finished()
2897
 
    child_pb = ui.ui_factory.nested_progress_bar()
2898
 
    try:
 
2879
    with ui.ui_factory.nested_progress_bar() as child_pb:
2899
2880
        raw_conflicts = resolve_conflicts(tt, child_pb,
2900
2881
            lambda t, c: conflict_pass(t, c, target_tree))
2901
 
    finally:
2902
 
        child_pb.finished()
2903
2882
    conflicts = cook_conflicts(raw_conflicts, tt)
2904
2883
    return conflicts, merge_modified
2905
2884
 
3042
3021
    if pass_func is None:
3043
3022
        pass_func = conflict_pass
3044
3023
    new_conflicts = set()
3045
 
    pb = ui.ui_factory.nested_progress_bar()
3046
 
    try:
 
3024
    with ui.ui_factory.nested_progress_bar() as pb:
3047
3025
        for n in range(10):
3048
3026
            pb.update(gettext('Resolution pass'), n+1, 10)
3049
3027
            conflicts = tt.find_conflicts()
3051
3029
                return new_conflicts
3052
3030
            new_conflicts.update(pass_func(tt, conflicts))
3053
3031
        raise MalformedTransform(conflicts=conflicts)
3054
 
    finally:
3055
 
        pb.finished()
3056
3032
 
3057
3033
 
3058
3034
def conflict_pass(tt, conflicts, path_tree=None):