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

  • Committer: Martin Pool
  • Date: 2005-06-28 03:02:31 UTC
  • Revision ID: mbp@sourcefrog.net-20050628030231-d311e4ebcd467ef4
Merge John's import-speedup branch:

                                                                                         
  777 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 22:20:32 -0500
      revision-id: john@arbash-meinel.com-20050627032031-e82a50db3863b18e
      bzr selftest was not using the correct bzr

  776 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 22:20:22 -0500
      revision-id: john@arbash-meinel.com-20050627032021-c9f21fde989ddaee
      Add was using an old mutter

  775 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 22:02:33 -0500
      revision-id: john@arbash-meinel.com-20050627030233-9165cfe98fc63298
      Cleaned up to be less different

  774 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:54:53 -0500
      revision-id: john@arbash-meinel.com-20050627025452-4260d0e744edef43
      Allow BZR_PLUGIN_PATH='' to negate plugin loading.

  773 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:49:34 -0500
      revision-id: john@arbash-meinel.com-20050627024933-b7158f67b7b9eae5
      Finished the previous cleanup (allowing load_plugins to be called twice)

  772 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:45:08 -0500
      revision-id: john@arbash-meinel.com-20050627024508-723b1df510d196fc
      Work on making the tests pass. versioning.py is calling run_cmd directly, but plugins have been loaded.

  771 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:32:29 -0500
      revision-id: john@arbash-meinel.com-20050627023228-79972744d7c53e15
      Got it down a little bit more by removing import of tree and inventory.

  770 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:26:05 -0500
      revision-id: john@arbash-meinel.com-20050627022604-350b9773ef622f95
      Reducing the number of import from bzrlib/__init__.py and bzrlib/branch.py

  769 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 20:32:25 -0500
      revision-id: john@arbash-meinel.com-20050627013225-32dd044f10d23948
      Updated revision.py and xml.py to include SubElement.

  768 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 20:03:56 -0500
      revision-id: john@arbash-meinel.com-20050627010356-ee66919e1c377faf
      Minor typo

  767 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 20:03:13 -0500
      revision-id: john@arbash-meinel.com-20050627010312-40d024007eb85051
      Caching the import

  766 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 19:51:47 -0500
      revision-id: john@arbash-meinel.com-20050627005147-5281c99e48ed1834
      Created wrapper functions for lazy import of ElementTree

  765 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 19:46:37 -0500
      revision-id: john@arbash-meinel.com-20050627004636-bf432902004a94c5
      Removed all of the test imports of cElementTree

  764 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 19:43:59 -0500
      revision-id: john@arbash-meinel.com-20050627004358-d137fbe9570dd71b
      Trying to make bzr startup faster.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
 
19
19
 
20
 
class RevisionReference(object):
 
20
from xml import XMLMixin, Element, SubElement
 
21
 
 
22
from errors import BzrError
 
23
 
 
24
 
 
25
class RevisionReference:
21
26
    """
22
27
    Reference to a stored revision.
23
28
 
25
30
    """
26
31
    revision_id = None
27
32
    revision_sha1 = None
28
 
    def __init__(self, revision_id, revision_sha1=None):
 
33
    def __init__(self, revision_id, revision_sha1):
29
34
        if revision_id == None \
30
35
           or isinstance(revision_id, basestring):
31
36
            self.revision_id = revision_id
41
46
                
42
47
 
43
48
 
44
 
class Revision(object):
 
49
class Revision(XMLMixin):
45
50
    """Single revision on a branch.
46
51
 
47
52
    Revisions may know their revision_hash, but only once they've been
49
54
    into the file it describes.
50
55
 
51
56
    After bzr 0.0.5 revisions are allowed to have multiple parents.
 
57
    To support old clients this is written out in a slightly redundant
 
58
    form: the first parent as the predecessor.  This will eventually
 
59
    be dropped.
52
60
 
53
61
    parents
54
62
        List of parent revisions, each is a RevisionReference.
65
73
        self.__dict__.update(args)
66
74
        self.parents = []
67
75
 
 
76
    def _get_precursor(self):
 
77
        from warnings import warn
 
78
        warn("Revision.precursor is deprecated", stacklevel=2)
 
79
        if self.parents:
 
80
            return self.parents[0].revision_id
 
81
        else:
 
82
            return None
 
83
 
 
84
 
 
85
    def _get_precursor_sha1(self):
 
86
        from warnings import warn
 
87
        warn("Revision.precursor_sha1 is deprecated", stacklevel=2)
 
88
        if self.parents:
 
89
            return self.parents[0].revision_sha1
 
90
        else:
 
91
            return None    
 
92
 
 
93
 
 
94
    def _fail(self):
 
95
        raise Exception("can't assign to precursor anymore")
 
96
 
 
97
 
 
98
    precursor = property(_get_precursor, _fail, _fail)
 
99
    precursor_sha1 = property(_get_precursor_sha1, _fail, _fail)
 
100
 
 
101
 
68
102
 
69
103
    def __repr__(self):
70
104
        return "<Revision id %s>" % self.revision_id
71
105
 
72
106
        
73
107
    def to_element(self):
74
 
        from bzrlib.xml import Element, SubElement
75
 
        
76
108
        root = Element('revision',
77
109
                       committer = self.committer,
78
110
                       timestamp = '%.9f' % self.timestamp,
89
121
        msg.tail = '\n'
90
122
 
91
123
        if self.parents:
 
124
            # first parent stored as precursor for compatability with 0.0.5 and
 
125
            # earlier
 
126
            pr = self.parents[0]
 
127
            assert pr.revision_id
 
128
            root.set('precursor', pr.revision_id)
 
129
            if pr.revision_sha1:
 
130
                root.set('precursor_sha1', pr.revision_sha1)
 
131
                
 
132
        if self.parents:
92
133
            pelts = SubElement(root, 'parents')
93
134
            pelts.tail = pelts.text = '\n'
94
135
            for rr in self.parents:
113
154
def unpack_revision(elt):
114
155
    """Convert XML element into Revision object."""
115
156
    # <changeset> is deprecated...
116
 
    from bzrlib.errors import BzrError
117
 
    
118
157
    if elt.tag not in ('revision', 'changeset'):
119
158
        raise BzrError("unexpected tag in revision file: %r" % elt)
120
159
 
130
169
 
131
170
    pelts = elt.find('parents')
132
171
 
133
 
    if pelts:
 
172
    if precursor:
 
173
        # revisions written prior to 0.0.5 have a single precursor
 
174
        # give as an attribute
 
175
        rev_ref = RevisionReference(precursor, precursor_sha1)
 
176
        rev.parents.append(rev_ref)
 
177
    elif pelts:
134
178
        for p in pelts:
135
179
            assert p.tag == 'revision_ref', \
136
180
                   "bad parent node tag %r" % p.tag
138
182
                                        p.get('revision_sha1'))
139
183
            rev.parents.append(rev_ref)
140
184
 
141
 
        if precursor:
142
 
            # must be consistent
143
 
            prec_parent = rev.parents[0].revision_id
144
 
            assert prec_parent == precursor
145
 
    elif precursor:
146
 
        # revisions written prior to 0.0.5 have a single precursor
147
 
        # give as an attribute
148
 
        rev_ref = RevisionReference(precursor, precursor_sha1)
149
 
        rev.parents.append(rev_ref)
150
 
 
151
185
    v = elt.get('timezone')
152
186
    rev.timezone = v and int(v)
153
187
 
154
188
    rev.message = elt.findtext('message') # text of <message>
155
189
    return rev
156
 
 
157
 
 
158
 
 
159
 
REVISION_ID_RE = None
160
 
 
161
 
def validate_revision_id(rid):
162
 
    """Check rid is syntactically valid for a revision id."""
163
 
    global REVISION_ID_RE
164
 
    if not REVISION_ID_RE:
165
 
        import re
166
 
        REVISION_ID_RE = re.compile('[\w.-]+@[\w.-]+--?\d+--?[0-9a-f]+\Z')
167
 
 
168
 
    if not REVISION_ID_RE.match(rid):
169
 
        raise ValueError("malformed revision-id %r" % rid)
170
 
 
171
 
def is_ancestor(revision_id, candidate_id, revision_source):
172
 
    """Return true if candidate_id is an ancestor of revision_id.
173
 
    A false negative will be returned if any intermediate descendent of
174
 
    candidate_id is not present in any of the revision_sources.
175
 
    
176
 
    revisions_source is an object supporting a get_revision operation that
177
 
    behaves like Branch's.
178
 
    """
179
 
 
180
 
    from bzrlib.branch import NoSuchRevision
181
 
    ancestors = (revision_id,)
182
 
    while len(ancestors) > 0:
183
 
        new_ancestors = []
184
 
        for ancestor in ancestors:
185
 
            if ancestor == candidate_id:
186
 
                return True
187
 
            try:
188
 
                revision = revision_source.get_revision(ancestor)
189
 
            except NoSuchRevision, e:
190
 
                if e.revision == revision_id:
191
 
                    raise e
192
 
                else:
193
 
                    continue
194
 
            new_ancestors.extend([p.revision_id for p in revision.parents])
195
 
        ancestors = new_ancestors
196
 
 
197
 
 
198
 
class MultipleRevisionSources(object):
199
 
    def __init__(self, *args):
200
 
        object.__init__(self)
201
 
        assert len(args) != 0
202
 
        self._revision_sources = args
203
 
 
204
 
    def get_revision(self, revision_id):
205
 
        from bzrlib.branch import NoSuchRevision
206
 
        for source in self._revision_sources:
207
 
            try:
208
 
                return source.get_revision(revision_id)
209
 
            except NoSuchRevision, e:
210
 
                pass
211
 
        raise e