/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/repository.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:
18
18
 
19
19
import os
20
20
 
21
 
from objects import ShaFile
 
21
from objects import (ShaFile,
 
22
                     Commit,
 
23
                     Tree,
 
24
                     Blob,
 
25
                     )
22
26
 
23
27
objectdir = 'objects'
24
28
symref = 'ref: '
59
63
  def head(self):
60
64
    return self.ref('HEAD')
61
65
 
62
 
  def get_object(self, sha):
63
 
    assert len(sha) == 40, "Incorrect sha length"
 
66
  def _get_object(self, sha, cls):
 
67
    assert len(sha) == 40, "Incorrect length sha: %s" % str(sha)
64
68
    dir = sha[:2]
65
69
    file = sha[2:]
66
70
    path = os.path.join(self.object_dir(), dir, file)
67
71
    if not os.path.exists(path):
68
72
      return None
69
 
    return ShaFile.from_file(path)
 
73
    return cls.from_file(path)
 
74
 
 
75
  def get_object(self, sha):
 
76
    return self._get_object(sha, ShaFile)
 
77
 
 
78
  def get_commit(self, sha):
 
79
    return self._get_object(sha, Commit)
 
80
 
 
81
  def get_tree(self, sha):
 
82
    return self._get_object(sha, Tree)
 
83
 
 
84
  def get_blob(self, sha):
 
85
    return self._get_object(sha, Blob)
70
86