~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revisionspec.py

  • Committer: Martin Pool
  • Date: 2005-09-30 06:39:42 UTC
  • mfrom: (1185.10.11)
  • mto: (1185.14.2)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: mbp@sourcefrog.net-20050930063942-3eab86500bffba49
- merge merge and export fixes from aaron
aaron.bentley@utoronto.ca-20050930040234-71c1a151f795e806

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
import datetime
19
19
import re
20
 
import bisect
21
20
from bzrlib.errors import BzrError, NoSuchRevision, NoCommits
22
21
 
23
22
_marker = []
58
57
        # TODO: otherwise, it should depend on how I was built -
59
58
        # if it's in_history(branch), then check revision_history(),
60
59
        # if it's in_store(branch), do the check below
61
 
        return self.branch.repository.has_revision(self.rev_id)
 
60
        return self.rev_id in self.branch.revision_store
62
61
 
63
62
    def __len__(self):
64
63
        return 2
69
68
        raise IndexError(index)
70
69
 
71
70
    def get(self):
72
 
        return self.branch.repository.get_revision(self.rev_id)
 
71
        return self.branch.get_revision(self.rev_id)
73
72
 
74
73
    def __eq__(self, other):
75
74
        if type(other) not in (tuple, list, type(self)):
152
151
        revs = branch.revision_history()
153
152
        return self._match_on_and_check(branch, revs)
154
153
 
155
 
        # FIXME: in_history is somewhat broken,
156
 
        # it will return non-history revisions in many
157
 
        # circumstances. The expected facility is that
158
 
        # in_history only returns revision-history revs,
159
 
        # in_store returns any rev. RBC 20051010
160
 
    # aliases for now, when we fix the core logic, then they
161
 
    # will do what you expect.
162
 
    in_store = in_history
163
 
    in_branch = in_store
164
 
        
165
154
    def __repr__(self):
166
155
        # this is mostly for helping with testing
167
156
        return '<%s %s%s>' % (self.__class__.__name__,
205
194
        try:
206
195
            return RevisionInfo(branch, revs.index(self.spec) + 1, self.spec)
207
196
        except ValueError:
208
 
            return RevisionInfo(branch, None, self.spec)
 
197
            return RevisionInfo(branch, None)
209
198
 
210
199
SPEC_TYPES.append(RevisionSpec_revid)
211
200
 
249
238
SPEC_TYPES.append(RevisionSpec_tag)
250
239
 
251
240
 
252
 
class RevisionSpec_revs:
253
 
    def __init__(self, revs, branch):
254
 
        self.revs = revs
255
 
        self.branch = branch
256
 
    def __getitem__(self, index):
257
 
        r = self.branch.repository.get_revision(self.revs[index])
258
 
        # TODO: Handle timezone.
259
 
        return datetime.datetime.fromtimestamp(r.timestamp)
260
 
    def __len__(self):
261
 
        return len(self.revs)
262
 
 
263
 
 
264
241
class RevisionSpec_date(RevisionSpec):
265
242
    prefix = 'date:'
266
243
    _date_re = re.compile(
308
285
 
309
286
            dt = datetime.datetime(year=year, month=month, day=day,
310
287
                    hour=hour, minute=minute, second=second)
311
 
        branch.lock_read()
312
 
        try:
313
 
            rev = bisect.bisect(RevisionSpec_revs(revs, branch), dt)
314
 
        finally:
315
 
            branch.unlock()
316
 
        if rev == len(revs):
317
 
            return RevisionInfo(branch, None)
318
 
        else:
319
 
            return RevisionInfo(branch, rev + 1)
 
288
        first = dt
 
289
        for i in range(len(revs)):
 
290
            r = branch.get_revision(revs[i])
 
291
            # TODO: Handle timezone.
 
292
            dt = datetime.datetime.fromtimestamp(r.timestamp)
 
293
            if first <= dt:
 
294
                return RevisionInfo(branch, i+1)
 
295
        return RevisionInfo(branch, None)
320
296
 
321
297
SPEC_TYPES.append(RevisionSpec_date)
322
298
 
327
303
    def _match_on(self, branch, revs):
328
304
        from branch import Branch
329
305
        from revision import common_ancestor, MultipleRevisionSources
330
 
        other_branch = Branch.open_containing(self.spec)[0]
 
306
        other_branch = Branch.open_containing(self.spec)
331
307
        revision_a = branch.last_revision()
332
308
        revision_b = other_branch.last_revision()
333
309
        for r, b in ((revision_a, branch), (revision_b, other_branch)):
334
310
            if r is None:
335
311
                raise NoCommits(b)
336
 
        revision_source = MultipleRevisionSources(branch.repository,
337
 
                                                  other_branch.repository)
 
312
        revision_source = MultipleRevisionSources(branch, other_branch)
338
313
        rev_id = common_ancestor(revision_a, revision_b, revision_source)
339
314
        try:
340
315
            revno = branch.revision_id_to_revno(rev_id)
343
318
        return RevisionInfo(branch, revno, rev_id)
344
319
        
345
320
SPEC_TYPES.append(RevisionSpec_ancestor)
346
 
 
347
 
class RevisionSpec_branch(RevisionSpec):
348
 
    """A branch: revision specifier.
349
 
 
350
 
    This takes the path to a branch and returns its tip revision id.
351
 
    """
352
 
    prefix = 'branch:'
353
 
 
354
 
    def _match_on(self, branch, revs):
355
 
        from branch import Branch
356
 
        other_branch = Branch.open_containing(self.spec)[0]
357
 
        revision_b = other_branch.last_revision()
358
 
        if revision_b is None:
359
 
            raise NoCommits(other_branch)
360
 
        # pull in the remote revisions so we can diff
361
 
        branch.fetch(other_branch, revision_b)
362
 
        try:
363
 
            revno = branch.revision_id_to_revno(revision_b)
364
 
        except NoSuchRevision:
365
 
            revno = None
366
 
        return RevisionInfo(branch, revno, revision_b)
367
 
        
368
 
SPEC_TYPES.append(RevisionSpec_branch)