~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revisionspec.py

  • Committer: John Arbash Meinel
  • Date: 2005-11-30 15:43:57 UTC
  • mto: (1185.50.1 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1518.
  • Revision ID: john@arbash-meinel.com-20051130154357-614206b3a7b83cd0
Refactored bzrlib/ui.py into a module with the possibility for multiple ui forms.

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.branch.revision_store.has_id(self.rev_id)
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)):
205
204
        try:
206
205
            return RevisionInfo(branch, revs.index(self.spec) + 1, self.spec)
207
206
        except ValueError:
208
 
            return RevisionInfo(branch, None, self.spec)
 
207
            return RevisionInfo(branch, None)
209
208
 
210
209
SPEC_TYPES.append(RevisionSpec_revid)
211
210
 
249
248
SPEC_TYPES.append(RevisionSpec_tag)
250
249
 
251
250
 
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
251
class RevisionSpec_date(RevisionSpec):
265
252
    prefix = 'date:'
266
253
    _date_re = re.compile(
308
295
 
309
296
            dt = datetime.datetime(year=year, month=month, day=day,
310
297
                    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)
 
298
        first = dt
 
299
        for i in range(len(revs)):
 
300
            r = branch.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)
320
306
 
321
307
SPEC_TYPES.append(RevisionSpec_date)
322
308
 
333
319
        for r, b in ((revision_a, branch), (revision_b, other_branch)):
334
320
            if r is None:
335
321
                raise NoCommits(b)
336
 
        revision_source = MultipleRevisionSources(branch.repository,
337
 
                                                  other_branch.repository)
 
322
        revision_source = MultipleRevisionSources(branch, other_branch)
338
323
        rev_id = common_ancestor(revision_a, revision_b, revision_source)
339
324
        try:
340
325
            revno = branch.revision_id_to_revno(rev_id)
353
338
 
354
339
    def _match_on(self, branch, revs):
355
340
        from branch import Branch
 
341
        from fetch import greedy_fetch
356
342
        other_branch = Branch.open_containing(self.spec)[0]
357
343
        revision_b = other_branch.last_revision()
358
344
        if revision_b is None:
359
345
            raise NoCommits(other_branch)
360
346
        # pull in the remote revisions so we can diff
361
 
        branch.fetch(other_branch, revision_b)
 
347
        greedy_fetch(branch, other_branch, revision=revision_b)
362
348
        try:
363
349
            revno = branch.revision_id_to_revno(revision_b)
364
350
        except NoSuchRevision: