/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/tag.py

  • Committer: Martin von Gagern
  • Date: 2010-04-20 08:47:38 UTC
  • mfrom: (5167 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5195.
  • Revision ID: martin.vgagern@gmx.net-20100420084738-ygymnqmdllzrhpfn
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007-2010 Canonical Ltd
2
2
#
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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tag strategies.
18
18
 
19
 
These are contained within a branch and normally constructed 
20
 
when the branch is opened.  Clients should typically do 
 
19
These are contained within a branch and normally constructed
 
20
when the branch is opened.  Clients should typically do
21
21
 
22
22
  Branch.tags.add('name', 'value')
23
23
"""
26
26
# called tags* are ctags files... mbp 20070220.
27
27
 
28
28
 
29
 
from warnings import warn
30
 
 
31
29
from bzrlib import (
 
30
    bencode,
32
31
    errors,
33
32
    trace,
34
33
    )
35
 
from bzrlib.util import bencode
36
34
 
37
35
 
38
36
class _Tags(object):
53
51
    def _not_supported(self, *a, **k):
54
52
        raise errors.TagsNotSupported(self.branch)
55
53
 
56
 
    def supports_tags(self):
57
 
        return False
58
 
 
59
54
    set_tag = _not_supported
60
55
    get_tag_dict = _not_supported
61
56
    _set_tag_dict = _not_supported
66
61
        # we never have anything to copy
67
62
        pass
68
63
 
 
64
    def rename_revisions(self, rename_map):
 
65
        # No tags, so nothing to rename
 
66
        pass
 
67
 
69
68
    def get_reverse_tag_dict(self):
70
69
        # There aren't any tags, so the reverse mapping is empty.
71
70
        return {}
75
74
    """Tag storage in an unversioned branch control file.
76
75
    """
77
76
 
78
 
    def supports_tags(self):
79
 
        return True
80
 
 
81
77
    def set_tag(self, tag_name, tag_target):
82
78
        """Add a tag definition to the branch.
83
79
 
107
103
        self.branch.lock_read()
108
104
        try:
109
105
            try:
110
 
                tag_content = self.branch._transport.get_bytes('tags')
 
106
                tag_content = self.branch._get_tags_bytes()
111
107
            except errors.NoSuchFile, e:
112
108
                # ugly, but only abentley should see this :)
113
109
                trace.warning('No branch/tags file in %s.  '
154
150
    def _set_tag_dict(self, new_dict):
155
151
        """Replace all tag definitions
156
152
 
 
153
        WARNING: Calling this on an unlocked branch will lock it, and will
 
154
        replace the tags without warning on conflicts.
 
155
 
157
156
        :param new_dict: Dictionary from tag name to target.
158
157
        """
159
 
        self.branch.lock_write()
160
 
        try:
161
 
            self.branch._transport.put_bytes('tags',
162
 
                self._serialize_tag_dict(new_dict))
163
 
        finally:
164
 
            self.branch.unlock()
 
158
        return self.branch._set_tags_bytes(self._serialize_tag_dict(new_dict))
165
159
 
166
160
    def _serialize_tag_dict(self, tag_dict):
167
161
        td = dict((k.encode('utf-8'), v)
185
179
 
186
180
    def merge_to(self, to_tags, overwrite=False):
187
181
        """Copy tags between repositories if necessary and possible.
188
 
        
189
 
        This method has common command-line behaviour about handling 
 
182
 
 
183
        This method has common command-line behaviour about handling
190
184
        error cases.
191
185
 
192
186
        All new definitions are copied across, except that tags that already
195
189
        :param to_tags: Branch to receive these tags
196
190
        :param overwrite: Overwrite conflicting tags in the target branch
197
191
 
198
 
        :returns: A list of tags that conflicted, each of which is 
 
192
        :returns: A list of tags that conflicted, each of which is
199
193
            (tagname, source_target, dest_target), or None if no copying was
200
194
            done.
201
195
        """
202
196
        if self.branch == to_tags.branch:
203
197
            return
204
 
        if not self.supports_tags():
 
198
        if not self.branch.supports_tags():
205
199
            # obviously nothing to copy
206
200
            return
207
201
        source_dict = self.get_tag_dict()
220
214
            to_tags.branch.unlock()
221
215
        return conflicts
222
216
 
 
217
    def rename_revisions(self, rename_map):
 
218
        """Rename revisions in this tags dictionary.
 
219
        
 
220
        :param rename_map: Dictionary mapping old revids to new revids
 
221
        """
 
222
        reverse_tags = self.get_reverse_tag_dict()
 
223
        for revid, names in reverse_tags.iteritems():
 
224
            if revid in rename_map:
 
225
                for name in names:
 
226
                    self.set_tag(name, rename_map[revid])
 
227
 
223
228
    def _reconcile_tags(self, source_dict, dest_dict, overwrite):
224
229
        """Do a two-way merge of two tag dictionaries.
225
230
 
246
251
 
247
252
def _merge_tags_if_possible(from_branch, to_branch):
248
253
    from_branch.tags.merge_to(to_branch.tags)
 
254