~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revisionspec.py

  • Committer: Jamie Wilkinson
  • Date: 2006-07-18 23:59:52 UTC
  • mfrom: (1868 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1874.
  • Revision ID: jaq@spacepants.org-20060718235952-1e362401a7858958
merge from bzr.dev

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
20
21
from bzrlib.errors import BzrError, NoSuchRevision, NoCommits
21
22
 
22
23
_marker = []
148
149
            raise NoSuchRevision(branch, str(self.spec))
149
150
 
150
151
    def in_history(self, branch):
151
 
        revs = branch.revision_history()
 
152
        if branch:
 
153
            revs = branch.revision_history()
 
154
        else:
 
155
            revs = None
152
156
        return self._match_on_and_check(branch, revs)
153
157
 
154
158
        # FIXME: in_history is somewhat broken,
189
193
 
190
194
    def _match_on(self, branch, revs):
191
195
        """Lookup a revision by revision number"""
192
 
        try:
193
 
            return RevisionInfo(branch, int(self.spec))
194
 
        except ValueError:
195
 
            return RevisionInfo(branch, None)
 
196
        if self.spec.find(':') == -1:
 
197
            try:
 
198
                return RevisionInfo(branch, int(self.spec))
 
199
            except ValueError:
 
200
                return RevisionInfo(branch, None)
 
201
        else:
 
202
            from branch import Branch
 
203
            revname = self.spec[self.spec.find(':')+1:]
 
204
            other_branch = Branch.open_containing(revname)[0]
 
205
            try:
 
206
                revno = int(self.spec[:self.spec.find(':')])
 
207
            except ValueError:
 
208
                return RevisionInfo(other_branch, None)
 
209
            revid = other_branch.get_rev_id(revno)
 
210
            return RevisionInfo(other_branch, revno)
196
211
 
197
212
SPEC_TYPES.append(RevisionSpec_revno)
198
213
 
248
263
SPEC_TYPES.append(RevisionSpec_tag)
249
264
 
250
265
 
 
266
class RevisionSpec_revs:
 
267
    def __init__(self, revs, branch):
 
268
        self.revs = revs
 
269
        self.branch = branch
 
270
    def __getitem__(self, index):
 
271
        r = self.branch.repository.get_revision(self.revs[index])
 
272
        # TODO: Handle timezone.
 
273
        return datetime.datetime.fromtimestamp(r.timestamp)
 
274
    def __len__(self):
 
275
        return len(self.revs)
 
276
 
 
277
 
251
278
class RevisionSpec_date(RevisionSpec):
252
279
    prefix = 'date:'
253
280
    _date_re = re.compile(
295
322
 
296
323
            dt = datetime.datetime(year=year, month=month, day=day,
297
324
                    hour=hour, minute=minute, second=second)
298
 
        first = dt
299
 
        for i in range(len(revs)):
300
 
            r = branch.repository.get_revision(revs[i])
301
 
            # TODO: Handle timezone.
302
 
            dt = datetime.datetime.fromtimestamp(r.timestamp)
303
 
            if first <= dt:
304
 
                return RevisionInfo(branch, i+1)
305
 
        return RevisionInfo(branch, None)
 
325
        branch.lock_read()
 
326
        try:
 
327
            rev = bisect.bisect(RevisionSpec_revs(revs, branch), dt)
 
328
        finally:
 
329
            branch.unlock()
 
330
        if rev == len(revs):
 
331
            return RevisionInfo(branch, None)
 
332
        else:
 
333
            return RevisionInfo(branch, rev + 1)
306
334
 
307
335
SPEC_TYPES.append(RevisionSpec_date)
308
336