/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 bzrlib/workingtree.py

  • Committer: Alexander Belchenko
  • Date: 2011-03-28 08:27:18 UTC
  • mfrom: (5742 +trunk)
  • mto: (5759.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5760.
  • Revision ID: bialix@ukr.net-20110328082718-wb3emf38d4iffmcp
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
    ignores,
59
59
    inventory,
60
60
    merge,
 
61
    registry,
61
62
    revision as _mod_revision,
62
63
    revisiontree,
63
64
    trace,
253
254
    def control_transport(self):
254
255
        return self._transport
255
256
 
 
257
    def is_control_filename(self, filename):
 
258
        """True if filename is the name of a control file in this tree.
 
259
 
 
260
        :param filename: A filename within the tree. This is a relative path
 
261
        from the root of this tree.
 
262
 
 
263
        This is true IF and ONLY IF the filename is part of the meta data
 
264
        that bzr controls in this tree. I.E. a random .bzr directory placed
 
265
        on disk will not be a control file for this tree.
 
266
        """
 
267
        return self.bzrdir.is_control_filename(filename)
 
268
 
256
269
    def _detect_case_handling(self):
257
270
        wt_trans = self.bzrdir.get_workingtree_transport(None)
258
271
        try:
1652
1665
            # - RBC 20060907
1653
1666
            self._write_inventory(self._inventory)
1654
1667
 
1655
 
    def _iter_conflicts(self):
1656
 
        conflicted = set()
1657
 
        for info in self.list_files():
1658
 
            path = info[0]
1659
 
            stem = get_conflicted_stem(path)
1660
 
            if stem is None:
1661
 
                continue
1662
 
            if stem not in conflicted:
1663
 
                conflicted.add(stem)
1664
 
                yield stem
1665
 
 
1666
1668
    @needs_write_lock
1667
1669
    def pull(self, source, overwrite=False, stop_revision=None,
1668
1670
             change_reporter=None, possible_transports=None, local=False,
2427
2429
    def add_conflicts(self, arg):
2428
2430
        raise errors.UnsupportedOperation(self.add_conflicts, self)
2429
2431
 
2430
 
    @needs_read_lock
2431
2432
    def conflicts(self):
2432
 
        conflicts = _mod_conflicts.ConflictList()
2433
 
        for conflicted in self._iter_conflicts():
2434
 
            text = True
2435
 
            try:
2436
 
                if file_kind(self.abspath(conflicted)) != "file":
2437
 
                    text = False
2438
 
            except errors.NoSuchFile:
2439
 
                text = False
2440
 
            if text is True:
2441
 
                for suffix in ('.THIS', '.OTHER'):
2442
 
                    try:
2443
 
                        kind = file_kind(self.abspath(conflicted+suffix))
2444
 
                        if kind != "file":
2445
 
                            text = False
2446
 
                    except errors.NoSuchFile:
2447
 
                        text = False
2448
 
                    if text == False:
2449
 
                        break
2450
 
            ctype = {True: 'text conflict', False: 'contents conflict'}[text]
2451
 
            conflicts.append(_mod_conflicts.Conflict.factory(ctype,
2452
 
                             path=conflicted,
2453
 
                             file_id=self.path2id(conflicted)))
2454
 
        return conflicts
 
2433
        raise NotImplementedError(self.conflicts)
2455
2434
 
2456
2435
    def walkdirs(self, prefix=""):
2457
2436
        """Walk the directories of this tree.
2716
2695
        return ShelfManager(self, self._transport)
2717
2696
 
2718
2697
 
2719
 
class WorkingTree2(WorkingTree):
2720
 
    """This is the Format 2 working tree.
2721
 
 
2722
 
    This was the first weave based working tree.
2723
 
     - uses os locks for locking.
2724
 
     - uses the branch last-revision.
2725
 
    """
2726
 
 
2727
 
    def __init__(self, *args, **kwargs):
2728
 
        super(WorkingTree2, self).__init__(*args, **kwargs)
2729
 
        # WorkingTree2 has more of a constraint that self._inventory must
2730
 
        # exist. Because this is an older format, we don't mind the overhead
2731
 
        # caused by the extra computation here.
2732
 
 
2733
 
        # Newer WorkingTree's should only have self._inventory set when they
2734
 
        # have a read lock.
2735
 
        if self._inventory is None:
2736
 
            self.read_working_inventory()
2737
 
 
2738
 
    def _get_check_refs(self):
2739
 
        """Return the references needed to perform a check of this tree."""
2740
 
        return [('trees', self.last_revision())]
2741
 
 
2742
 
    def lock_tree_write(self):
2743
 
        """See WorkingTree.lock_tree_write().
2744
 
 
2745
 
        In Format2 WorkingTrees we have a single lock for the branch and tree
2746
 
        so lock_tree_write() degrades to lock_write().
2747
 
 
2748
 
        :return: An object with an unlock method which will release the lock
2749
 
            obtained.
2750
 
        """
2751
 
        self.branch.lock_write()
2752
 
        try:
2753
 
            self._control_files.lock_write()
2754
 
            return self
2755
 
        except:
2756
 
            self.branch.unlock()
2757
 
            raise
2758
 
 
2759
 
    def unlock(self):
2760
 
        # do non-implementation specific cleanup
2761
 
        self._cleanup()
2762
 
 
2763
 
        # we share control files:
2764
 
        if self._control_files._lock_count == 3:
2765
 
            # _inventory_is_modified is always False during a read lock.
2766
 
            if self._inventory_is_modified:
2767
 
                self.flush()
2768
 
            self._write_hashcache_if_dirty()
2769
 
 
2770
 
        # reverse order of locking.
2771
 
        try:
2772
 
            return self._control_files.unlock()
2773
 
        finally:
2774
 
            self.branch.unlock()
2775
 
 
2776
 
 
2777
2698
class WorkingTree3(WorkingTree):
2778
2699
    """This is the Format 3 working tree.
2779
2700
 
2852
2773
            self.branch.unlock()
2853
2774
 
2854
2775
 
2855
 
def get_conflicted_stem(path):
2856
 
    for suffix in _mod_conflicts.CONFLICT_SUFFIXES:
2857
 
        if path.endswith(suffix):
2858
 
            return path[:-len(suffix)]
2859
 
 
2860
 
 
2861
 
class WorkingTreeFormat(object):
 
2776
class WorkingTreeFormatRegistry(controldir.ControlComponentFormatRegistry):
 
2777
    """Registry for working tree formats."""
 
2778
 
 
2779
    def __init__(self, other_registry=None):
 
2780
        super(WorkingTreeFormatRegistry, self).__init__(other_registry)
 
2781
        self._default_format = None
 
2782
 
 
2783
    def get_default(self):
 
2784
        """Return the current default format."""
 
2785
        return self._default_format
 
2786
 
 
2787
    def set_default(self, format):
 
2788
        self._default_format = format
 
2789
 
 
2790
 
 
2791
format_registry = WorkingTreeFormatRegistry()
 
2792
 
 
2793
 
 
2794
class WorkingTreeFormat(controldir.ControlComponentFormat):
2862
2795
    """An encapsulation of the initialization and open routines for a format.
2863
2796
 
2864
2797
    Formats provide three things:
2876
2809
    object will be created every time regardless.
2877
2810
    """
2878
2811
 
2879
 
    _default_format = None
2880
 
    """The default format used for new trees."""
2881
 
 
2882
 
    _formats = {}
2883
 
    """The known formats."""
2884
 
 
2885
 
    _extra_formats = []
2886
 
    """Extra formats that can not be used in a metadir."""
2887
 
 
2888
2812
    requires_rich_root = False
2889
2813
 
2890
2814
    upgrade_recommended = False
2902
2826
        try:
2903
2827
            transport = a_bzrdir.get_workingtree_transport(None)
2904
2828
            format_string = transport.get_bytes("format")
2905
 
            return klass._formats[format_string]
 
2829
            return format_registry.get(format_string)
2906
2830
        except errors.NoSuchFile:
2907
2831
            raise errors.NoWorkingTree(base=transport.base)
2908
2832
        except KeyError:
2909
2833
            raise errors.UnknownFormatError(format=format_string,
2910
2834
                                            kind="working tree")
2911
2835
 
 
2836
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
 
2837
                   accelerator_tree=None, hardlink=False):
 
2838
        """Initialize a new working tree in a_bzrdir.
 
2839
 
 
2840
        :param a_bzrdir: BzrDir to initialize the working tree in.
 
2841
        :param revision_id: allows creating a working tree at a different
 
2842
            revision than the branch is at.
 
2843
        :param from_branch: Branch to checkout
 
2844
        :param accelerator_tree: A tree which can be used for retrieving file
 
2845
            contents more quickly than the revision tree, i.e. a workingtree.
 
2846
            The revision tree will be used for cases where accelerator_tree's
 
2847
            content is different.
 
2848
        :param hardlink: If true, hard-link files from accelerator_tree,
 
2849
            where possible.
 
2850
        """
 
2851
        raise NotImplementedError(self.initialize)
 
2852
 
2912
2853
    def __eq__(self, other):
2913
2854
        return self.__class__ is other.__class__
2914
2855
 
2916
2857
        return not (self == other)
2917
2858
 
2918
2859
    @classmethod
 
2860
    @symbol_versioning.deprecated_method(
 
2861
        symbol_versioning.deprecated_in((2, 4, 0)))
2919
2862
    def get_default_format(klass):
2920
2863
        """Return the current default format."""
2921
 
        return klass._default_format
 
2864
        return format_registry.get_default()
2922
2865
 
2923
2866
    def get_format_string(self):
2924
2867
        """Return the ASCII format string that identifies this format."""
2946
2889
        return False
2947
2890
 
2948
2891
    @classmethod
 
2892
    @symbol_versioning.deprecated_method(
 
2893
        symbol_versioning.deprecated_in((2, 4, 0)))
2949
2894
    def register_format(klass, format):
2950
 
        klass._formats[format.get_format_string()] = format
 
2895
        format_registry.register(format)
2951
2896
 
2952
2897
    @classmethod
 
2898
    @symbol_versioning.deprecated_method(
 
2899
        symbol_versioning.deprecated_in((2, 4, 0)))
2953
2900
    def register_extra_format(klass, format):
2954
 
        klass._extra_formats.append(format)
 
2901
        format_registry.register_extra(format)
2955
2902
 
2956
2903
    @classmethod
 
2904
    @symbol_versioning.deprecated_method(
 
2905
        symbol_versioning.deprecated_in((2, 4, 0)))
2957
2906
    def unregister_extra_format(klass, format):
2958
 
        klass._extra_formats.remove(format)
 
2907
        format_registry.unregister_extra(format)
2959
2908
 
2960
2909
    @classmethod
 
2910
    @symbol_versioning.deprecated_method(
 
2911
        symbol_versioning.deprecated_in((2, 4, 0)))
2961
2912
    def get_formats(klass):
2962
 
        return klass._formats.values() + klass._extra_formats
 
2913
        return format_registry._get_all()
2963
2914
 
2964
2915
    @classmethod
 
2916
    @symbol_versioning.deprecated_method(
 
2917
        symbol_versioning.deprecated_in((2, 4, 0)))
2965
2918
    def set_default_format(klass, format):
2966
 
        klass._default_format = format
 
2919
        format_registry.set_default(format)
2967
2920
 
2968
2921
    @classmethod
 
2922
    @symbol_versioning.deprecated_method(
 
2923
        symbol_versioning.deprecated_in((2, 4, 0)))
2969
2924
    def unregister_format(klass, format):
2970
 
        del klass._formats[format.get_format_string()]
2971
 
 
2972
 
 
2973
 
class WorkingTreeFormat2(WorkingTreeFormat):
2974
 
    """The second working tree format.
2975
 
 
2976
 
    This format modified the hash cache from the format 1 hash cache.
2977
 
    """
2978
 
 
2979
 
    upgrade_recommended = True
2980
 
 
2981
 
    requires_normalized_unicode_filenames = True
2982
 
 
2983
 
    case_sensitive_filename = "Branch-FoRMaT"
2984
 
 
2985
 
    missing_parent_conflicts = False
2986
 
 
2987
 
    def get_format_description(self):
2988
 
        """See WorkingTreeFormat.get_format_description()."""
2989
 
        return "Working tree format 2"
2990
 
 
2991
 
    def _stub_initialize_on_transport(self, transport, file_mode):
2992
 
        """Workaround: create control files for a remote working tree.
2993
 
 
2994
 
        This ensures that it can later be updated and dealt with locally,
2995
 
        since BzrDirFormat6 and BzrDirFormat5 cannot represent dirs with
2996
 
        no working tree.  (See bug #43064).
2997
 
        """
2998
 
        sio = StringIO()
2999
 
        inv = inventory.Inventory()
3000
 
        xml5.serializer_v5.write_inventory(inv, sio, working=True)
3001
 
        sio.seek(0)
3002
 
        transport.put_file('inventory', sio, file_mode)
3003
 
        transport.put_bytes('pending-merges', '', file_mode)
3004
 
 
3005
 
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
3006
 
                   accelerator_tree=None, hardlink=False):
3007
 
        """See WorkingTreeFormat.initialize()."""
3008
 
        if not isinstance(a_bzrdir.transport, LocalTransport):
3009
 
            raise errors.NotLocalUrl(a_bzrdir.transport.base)
3010
 
        if from_branch is not None:
3011
 
            branch = from_branch
3012
 
        else:
3013
 
            branch = a_bzrdir.open_branch()
3014
 
        if revision_id is None:
3015
 
            revision_id = _mod_revision.ensure_null(branch.last_revision())
3016
 
        branch.lock_write()
3017
 
        try:
3018
 
            branch.generate_revision_history(revision_id)
3019
 
        finally:
3020
 
            branch.unlock()
3021
 
        inv = inventory.Inventory()
3022
 
        wt = WorkingTree2(a_bzrdir.root_transport.local_abspath('.'),
3023
 
                         branch,
3024
 
                         inv,
3025
 
                         _internal=True,
3026
 
                         _format=self,
3027
 
                         _bzrdir=a_bzrdir,
3028
 
                         _control_files=branch.control_files)
3029
 
        basis_tree = branch.repository.revision_tree(revision_id)
3030
 
        if basis_tree.inventory.root is not None:
3031
 
            wt.set_root_id(basis_tree.get_root_id())
3032
 
        # set the parent list and cache the basis tree.
3033
 
        if _mod_revision.is_null(revision_id):
3034
 
            parent_trees = []
3035
 
        else:
3036
 
            parent_trees = [(revision_id, basis_tree)]
3037
 
        wt.set_parent_trees(parent_trees)
3038
 
        transform.build_tree(basis_tree, wt)
3039
 
        return wt
3040
 
 
3041
 
    def __init__(self):
3042
 
        super(WorkingTreeFormat2, self).__init__()
3043
 
        self._matchingbzrdir = bzrdir.BzrDirFormat6()
3044
 
 
3045
 
    def open(self, a_bzrdir, _found=False):
3046
 
        """Return the WorkingTree object for a_bzrdir
3047
 
 
3048
 
        _found is a private parameter, do not use it. It is used to indicate
3049
 
               if format probing has already been done.
3050
 
        """
3051
 
        if not _found:
3052
 
            # we are being called directly and must probe.
3053
 
            raise NotImplementedError
3054
 
        if not isinstance(a_bzrdir.transport, LocalTransport):
3055
 
            raise errors.NotLocalUrl(a_bzrdir.transport.base)
3056
 
        wt = WorkingTree2(a_bzrdir.root_transport.local_abspath('.'),
3057
 
                           _internal=True,
3058
 
                           _format=self,
3059
 
                           _bzrdir=a_bzrdir,
3060
 
                           _control_files=a_bzrdir.open_branch().control_files)
3061
 
        return wt
 
2925
        format_registry.remove(format)
 
2926
 
3062
2927
 
3063
2928
class WorkingTreeFormat3(WorkingTreeFormat):
3064
2929
    """The second working tree format updated to record a format marker.
3194
3059
 
3195
3060
 
3196
3061
__default_format = WorkingTreeFormat6()
3197
 
WorkingTreeFormat.register_format(__default_format)
3198
 
WorkingTreeFormat.register_format(WorkingTreeFormat5())
3199
 
WorkingTreeFormat.register_format(WorkingTreeFormat4())
3200
 
WorkingTreeFormat.register_format(WorkingTreeFormat3())
3201
 
WorkingTreeFormat.set_default_format(__default_format)
3202
 
# Register extra formats which have no format string are not discoverable
3203
 
# and not independently creatable. They are implicitly created as part of
3204
 
# e.g. older Bazaar formats or foreign formats.
3205
 
WorkingTreeFormat.register_extra_format(WorkingTreeFormat2())
 
3062
format_registry.register_lazy("Bazaar Working Tree Format 4 (bzr 0.15)\n",
 
3063
    "bzrlib.workingtree_4", "WorkingTreeFormat4")
 
3064
format_registry.register_lazy("Bazaar Working Tree Format 5 (bzr 1.11)\n",
 
3065
    "bzrlib.workingtree_4", "WorkingTreeFormat5")
 
3066
format_registry.register_lazy("Bazaar Working Tree Format 6 (bzr 1.14)\n",
 
3067
    "bzrlib.workingtree_4", "WorkingTreeFormat6")
 
3068
format_registry.register(WorkingTreeFormat3())
 
3069
format_registry.set_default(__default_format)