~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: John Arbash Meinel
  • Date: 2007-02-10 02:48:43 UTC
  • mto: This revision was merged to the branch mainline in revision 2294.
  • Revision ID: john@arbash-meinel.com-20070210024843-oz2ed16luwjca48h
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
Get tests to pass again.

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
        )
91
91
 
92
92
    @needs_write_lock
93
 
    def add_inventory(self, revid, inv, parents):
94
 
        """Add the inventory inv to the repository as revid.
 
93
    def add_inventory(self, revision_id, inv, parents):
 
94
        """Add the inventory inv to the repository as revision_id.
95
95
        
96
 
        :param parents: The revision ids of the parents that revid
 
96
        :param parents: The revision ids of the parents that revision_id
97
97
                        is known to have and are in the repository already.
98
98
 
99
99
        returns the sha1 of the serialized inventory.
100
100
        """
101
 
        _mod_revision.check_not_reserved_id(revid)
102
 
        assert inv.revision_id is None or inv.revision_id == revid, \
 
101
        revision_id = osutils.safe_revision_id(revision_id)
 
102
        _mod_revision.check_not_reserved_id(revision_id)
 
103
        assert inv.revision_id is None or inv.revision_id == revision_id, \
103
104
            "Mismatch between inventory revision" \
104
 
            " id and insertion revid (%r, %r)" % (inv.revision_id, revid)
 
105
            " id and insertion revid (%r, %r)" % (inv.revision_id, revision_id)
105
106
        assert inv.root is not None
106
107
        inv_text = self.serialise_inventory(inv)
107
108
        inv_sha1 = osutils.sha_string(inv_text)
108
109
        inv_vf = self.control_weaves.get_weave('inventory',
109
110
                                               self.get_transaction())
110
 
        self._inventory_add_lines(inv_vf, revid, parents, osutils.split_lines(inv_text))
 
111
        self._inventory_add_lines(inv_vf, revision_id, parents,
 
112
                                  osutils.split_lines(inv_text))
111
113
        return inv_sha1
112
114
 
113
 
    def _inventory_add_lines(self, inv_vf, revid, parents, lines):
 
115
    def _inventory_add_lines(self, inv_vf, revision_id, parents, lines):
114
116
        final_parents = []
115
117
        for parent in parents:
116
118
            if parent in inv_vf:
117
119
                final_parents.append(parent)
118
120
 
119
 
        inv_vf.add_lines(revid, final_parents, lines)
 
121
        inv_vf.add_lines(revision_id, final_parents, lines)
120
122
 
121
123
    @needs_write_lock
122
 
    def add_revision(self, rev_id, rev, inv=None, config=None):
123
 
        """Add rev to the revision store as rev_id.
 
124
    def add_revision(self, revision_id, rev, inv=None, config=None):
 
125
        """Add rev to the revision store as revision_id.
124
126
 
125
 
        :param rev_id: the revision id to use.
 
127
        :param revision_id: the revision id to use.
126
128
        :param rev: The revision object.
127
129
        :param inv: The inventory for the revision. if None, it will be looked
128
130
                    up in the inventory storer
130
132
                       If supplied its signature_needed method will be used
131
133
                       to determine if a signature should be made.
132
134
        """
133
 
        _mod_revision.check_not_reserved_id(rev_id)
 
135
        revision_id = osutils.safe_revision_id(revision_id)
 
136
        _mod_revision.check_not_reserved_id(revision_id)
134
137
        if config is not None and config.signature_needed():
135
138
            if inv is None:
136
 
                inv = self.get_inventory(rev_id)
 
139
                inv = self.get_inventory(revision_id)
137
140
            plaintext = Testament(rev, inv).as_short_text()
138
141
            self.store_revision_signature(
139
 
                gpg.GPGStrategy(config), plaintext, rev_id)
140
 
        if not rev_id in self.get_inventory_weave():
 
142
                gpg.GPGStrategy(config), plaintext, revision_id)
 
143
        if not revision_id in self.get_inventory_weave():
141
144
            if inv is None:
142
 
                raise errors.WeaveRevisionNotPresent(rev_id,
 
145
                raise errors.WeaveRevisionNotPresent(revision_id,
143
146
                                                     self.get_inventory_weave())
144
147
            else:
145
148
                # yes, this is not suitable for adding with ghosts.
146
 
                self.add_inventory(rev_id, inv, rev.parent_ids)
 
149
                self.add_inventory(revision_id, inv, rev.parent_ids)
147
150
        self._revision_store.add_revision(rev, self.get_transaction())
148
151
 
149
152
    @needs_read_lock
292
295
        :param revprops: Optional dictionary of revision properties.
293
296
        :param revision_id: Optional revision id.
294
297
        """
 
298
        revision_id = osutils.safe_revision_id(revision_id)
295
299
        return _CommitBuilder(self, parents, config, timestamp, timezone,
296
300
                              committer, revprops, revision_id)
297
301
 
777
781
                    revision_id.encode('ascii')
778
782
                except UnicodeEncodeError:
779
783
                    raise errors.NonAsciiRevisionId(method, self)
 
784
            else:
 
785
                try:
 
786
                    revision_id.decode('ascii')
 
787
                except UnicodeDecodeError:
 
788
                    raise errors.NonAsciiRevisionId(method, self)
780
789
 
781
790
 
782
791
class AllInOneRepository(Repository):