~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revisionspec.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-21 23:40:43 UTC
  • mto: This revision was merged to the branch mainline in revision 1979.
  • Revision ID: john@arbash-meinel.com-20060821234043-f47d2b2ea7d45b73
Some tests for the date: spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
312
312
SPEC_TYPES.append(RevisionSpec_tag)
313
313
 
314
314
 
315
 
class RevisionSpec_revs:
 
315
class _RevListToTimestamps(object):
 
316
    """This takes a list of revisions, and allows you to bisect by date"""
 
317
 
 
318
    __slots__ = ['revs', 'branch']
 
319
 
316
320
    def __init__(self, revs, branch):
317
321
        self.revs = revs
318
322
        self.branch = branch
 
323
 
319
324
    def __getitem__(self, index):
 
325
        """Get the date of the index'd item"""
320
326
        r = self.branch.repository.get_revision(self.revs[index])
321
327
        # TODO: Handle timezone.
322
328
        return datetime.datetime.fromtimestamp(r.timestamp)
 
329
 
323
330
    def __len__(self):
324
331
        return len(self.revs)
325
332
 
353
360
        else:
354
361
            m = self._date_re.match(self.spec)
355
362
            if not m or (not m.group('date') and not m.group('time')):
356
 
                raise BzrError('Invalid revision date %r' % self.spec)
357
 
 
358
 
            if m.group('date'):
359
 
                year, month, day = int(m.group('year')), int(m.group('month')), int(m.group('day'))
360
 
            else:
361
 
                year, month, day = today.year, today.month, today.day
362
 
            if m.group('time'):
363
 
                hour = int(m.group('hour'))
364
 
                minute = int(m.group('minute'))
365
 
                if m.group('second'):
366
 
                    second = int(m.group('second'))
367
 
                else:
368
 
                    second = 0
369
 
            else:
370
 
                hour, minute, second = 0,0,0
 
363
                raise errors.InvalidRevisionSpec(self.prefix + self.spec,
 
364
                                                 branch, 'invalid date')
 
365
 
 
366
            try:
 
367
                if m.group('date'):
 
368
                    year = int(m.group('year'))
 
369
                    month = int(m.group('month'))
 
370
                    day = int(m.group('day'))
 
371
                else:
 
372
                    year = today.year
 
373
                    month = today.month
 
374
                    day = today.day
 
375
 
 
376
                if m.group('time'):
 
377
                    hour = int(m.group('hour'))
 
378
                    minute = int(m.group('minute'))
 
379
                    if m.group('second'):
 
380
                        second = int(m.group('second'))
 
381
                    else:
 
382
                        second = 0
 
383
                else:
 
384
                    hour, minute, second = 0,0,0
 
385
            except ValueError:
 
386
                raise errors.InvalidRevisionSpec(self.prefix + self.spec,
 
387
                                                 branch, 'invalid date')
371
388
 
372
389
            dt = datetime.datetime(year=year, month=month, day=day,
373
390
                    hour=hour, minute=minute, second=second)
374
391
        branch.lock_read()
375
392
        try:
376
 
            rev = bisect.bisect(RevisionSpec_revs(revs, branch), dt)
 
393
            rev = bisect.bisect(_RevListToTimestamps(revs, branch), dt)
377
394
        finally:
378
395
            branch.unlock()
379
396
        if rev == len(revs):