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

  • Committer: Martin Pool
  • Date: 2007-01-16 13:21:38 UTC
  • mto: (2220.2.19 tags)
  • mto: This revision was merged to the branch mainline in revision 2309.
  • Revision ID: mbp@sourcefrog.net-20070116132138-vhziz9hpfc8za0uj
Add tag command and basic implementation

Show diffs side-by-side

added added

removed removed

Lines of Context:
1090
1090
class KnitRepository2(KnitRepository):
1091
1091
    """Experimental enhanced knit format"""
1092
1092
 
 
1093
    # corresponds to RepositoryFormatKnit2
 
1094
    
 
1095
    # TODO: within a lock scope, we could keep the tags in memory...
 
1096
 
1093
1097
    def __init__(self, _format, a_bzrdir, control_files, _revision_store,
1094
1098
                 control_store, text_store):
1095
1099
        KnitRepository.__init__(self, _format, a_bzrdir, control_files,
1096
1100
                              _revision_store, control_store, text_store)
 
1101
        self._transport = control_files._transport
1097
1102
        self._serializer = xml6.serializer_v6
1098
1103
 
1099
1104
    def deserialise_inventory(self, revision_id, xml):
1133
1138
        return RootCommitBuilder(self, parents, config, timestamp, timezone,
1134
1139
                                 committer, revprops, revision_id)
1135
1140
 
1136
 
    def get_tags(self):
1137
 
        return None
 
1141
    @needs_read_lock
 
1142
    def get_tag_dict(self):
 
1143
        tag_content = self.control_files.get_utf8('tags').read()
 
1144
        return self._format._deserialize_tag_dict(tag_content)
 
1145
 
 
1146
    @needs_write_lock
 
1147
    def _set_tag_dict(self, new_dict):
 
1148
        """Replace all tag definitions
 
1149
 
 
1150
        :param new_dict: Dictionary from tag name to target.
 
1151
        """
 
1152
        self.control_files.put_utf8('tags', self._format._serialize_tag_dict(new_dict))
 
1153
 
 
1154
    @needs_write_lock
 
1155
    def make_tag(self, tag_name, tag_target):
 
1156
        """Add a tag definition to the repository.
 
1157
 
 
1158
        Behaviour if the tag is already present is not defined (yet).
 
1159
        """
 
1160
        # all done with a write lock held, so this looks atomic
 
1161
        td = self.get_tag_dict()
 
1162
        td[tag_name] = tag_target
 
1163
        self._set_tag_dict(td)
 
1164
 
 
1165
    def lookup_tag(self, tag_name):
 
1166
        """Return the referent string of a tag"""
 
1167
        td = self.get_tag_dict()
 
1168
        try:
 
1169
            return td[tag_name]
 
1170
        except KeyError:
 
1171
            raise errors.NoSuchTag(tag_name)
1138
1172
 
1139
1173
 
1140
1174
class RepositoryFormat(object):
1222
1256
        from bzrlib.store.revision.text import TextRevisionStore
1223
1257
        dir_mode = control_files._dir_mode
1224
1258
        file_mode = control_files._file_mode
1225
 
        text_store =TextStore(transport.clone(name),
 
1259
        text_store = TextStore(transport.clone(name),
1226
1260
                              prefixed=prefixed,
1227
1261
                              compressed=compressed,
1228
1262
                              dir_mode=dir_mode,
1801
1835
                               control_files=control_files,
1802
1836
                               _revision_store=_revision_store,
1803
1837
                               control_store=control_store,
1804
 
                               text_store=text_store)
 
1838
                                text_store=text_store)
 
1839
 
 
1840
    def initialize(self, a_bzrdir, shared=False):
 
1841
        repo = super(RepositoryFormatKnit2, self).initialize(a_bzrdir, shared)
 
1842
        repo._transport.put_bytes_non_atomic('tags', '')
 
1843
        return repo
1805
1844
 
1806
1845
    def supports_tags(self):
1807
1846
        return True
1808
1847
 
 
1848
    def _serialize_tag_dict(self, tag_dict):
 
1849
        s = []
 
1850
        for tag, target in sorted(tag_dict.items()):
 
1851
            # TODO: check that tag names and targets are acceptable
 
1852
            s.append(tag + '\t' + target + '\n')
 
1853
        return ''.join(s)
 
1854
 
 
1855
    def _deserialize_tag_dict(self, tag_content):
 
1856
        """Convert the tag file into a dictionary of tags"""
 
1857
        d = {}
 
1858
        for l in tag_content.splitlines():
 
1859
            tag, target = l.split('\t', 1)
 
1860
            d[tag] = target
 
1861
        return d
 
1862
 
1809
1863
 
1810
1864
 
1811
1865
# formats which have no format string are not discoverable