/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 git/objects.py

  • Committer: James Westby
  • Date: 2007-03-25 14:38:19 UTC
  • mto: (0.215.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jw+debian@jameswestby.net-20070325143819-f16swssc40jbebxu
Add methods to repo to get objects of a certain type.

Now get_blob etc. will ensure that you get an object of the type you want.
There needs to be the addition to get the type by going via a higher type
where possible, e.g. tree from commit, but it's not done yet.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import sha
25
25
import zlib
26
26
 
 
27
from errors import (NotCommitError,
 
28
                    NotTreeError,
 
29
                    NotBlobError,
 
30
                    )
 
31
 
27
32
blob_id = "blob"
28
33
tree_id = "tree"
29
34
commit_id = "commit"
156
161
  @classmethod
157
162
  def from_file(cls, filename):
158
163
    blob = ShaFile.from_file(filename)
159
 
    assert blob._type == cls._type, "%s is not a blob object" % filename
 
164
    if blob._type != cls._type:
 
165
      raise NotBlobError(filename)
160
166
    return blob
161
167
 
162
168
  @classmethod
175
181
  @classmethod
176
182
  def from_file(cls, filename):
177
183
    tree = ShaFile.from_file(filename)
178
 
    assert tree._type == cls._type, "%s is not a tree object" % filename
 
184
    if tree._type != cls._type:
 
185
      raise NotTreeError(filename)
179
186
    return tree
180
187
 
181
188
  def entries(self):
216
223
  @classmethod
217
224
  def from_file(cls, filename):
218
225
    commit = ShaFile.from_file(filename)
219
 
    assert commit._type == cls._type, "%s is not a commit object" % filename
 
226
    if commit._type != cls._type:
 
227
      raise NotCommitError(filename)
220
228
    return commit
221
229
 
222
230
  def _parse_text(self):