312
312
SPEC_TYPES.append(RevisionSpec_tag)
315
class RevisionSpec_revs:
315
class _RevListToTimestamps(object):
316
"""This takes a list of revisions, and allows you to bisect by date"""
318
__slots__ = ['revs', 'branch']
316
320
def __init__(self, revs, branch):
318
322
self.branch = branch
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)
323
330
def __len__(self):
324
331
return len(self.revs)
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)
359
year, month, day = int(m.group('year')), int(m.group('month')), int(m.group('day'))
361
year, month, day = today.year, today.month, today.day
363
hour = int(m.group('hour'))
364
minute = int(m.group('minute'))
365
if m.group('second'):
366
second = int(m.group('second'))
370
hour, minute, second = 0,0,0
363
raise errors.InvalidRevisionSpec(self.prefix + self.spec,
364
branch, 'invalid date')
368
year = int(m.group('year'))
369
month = int(m.group('month'))
370
day = int(m.group('day'))
377
hour = int(m.group('hour'))
378
minute = int(m.group('minute'))
379
if m.group('second'):
380
second = int(m.group('second'))
384
hour, minute, second = 0,0,0
386
raise errors.InvalidRevisionSpec(self.prefix + self.spec,
387
branch, 'invalid date')
372
389
dt = datetime.datetime(year=year, month=month, day=day,
373
390
hour=hour, minute=minute, second=second)
374
391
branch.lock_read()
376
rev = bisect.bisect(RevisionSpec_revs(revs, branch), dt)
393
rev = bisect.bisect(_RevListToTimestamps(revs, branch), dt)
379
396
if rev == len(revs):