~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revisionspec.py

Late bind to PatienceSequenceMatcher to allow plugin to override.

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 = []
57
58
        # TODO: otherwise, it should depend on how I was built -
58
59
        # if it's in_history(branch), then check revision_history(),
59
60
        # if it's in_store(branch), do the check below
60
 
        return self.branch.revision_store.has_id(self.rev_id)
 
61
        return self.branch.repository.has_revision(self.rev_id)
61
62
 
62
63
    def __len__(self):
63
64
        return 2
68
69
        raise IndexError(index)
69
70
 
70
71
    def get(self):
71
 
        return self.branch.get_revision(self.rev_id)
 
72
        return self.branch.repository.get_revision(self.rev_id)
72
73
 
73
74
    def __eq__(self, other):
74
75
        if type(other) not in (tuple, list, type(self)):
204
205
        try:
205
206
            return RevisionInfo(branch, revs.index(self.spec) + 1, self.spec)
206
207
        except ValueError:
207
 
            return RevisionInfo(branch, None)
 
208
            return RevisionInfo(branch, None, self.spec)
208
209
 
209
210
SPEC_TYPES.append(RevisionSpec_revid)
210
211
 
248
249
SPEC_TYPES.append(RevisionSpec_tag)
249
250
 
250
251
 
 
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
class RevisionSpec_revs:
 
265
    def __init__(self, revs, branch):
 
266
        self.revs = revs
 
267
        self.branch = branch
 
268
    def __getitem__(self, index):
 
269
        r = self.branch.repository.get_revision(self.revs[index])
 
270
        # TODO: Handle timezone.
 
271
        return datetime.datetime.fromtimestamp(r.timestamp)
 
272
    def __len__(self):
 
273
        return len(self.revs)
 
274
 
 
275
 
251
276
class RevisionSpec_date(RevisionSpec):
252
277
    prefix = 'date:'
253
278
    _date_re = re.compile(
295
320
 
296
321
            dt = datetime.datetime(year=year, month=month, day=day,
297
322
                    hour=hour, minute=minute, second=second)
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)
 
323
        branch.lock_read()
 
324
        try:
 
325
            rev = bisect.bisect(RevisionSpec_revs(revs, branch), dt)
 
326
        finally:
 
327
            branch.unlock()
 
328
        if rev == len(revs):
 
329
            return RevisionInfo(branch, None)
 
330
        else:
 
331
            return RevisionInfo(branch, rev + 1)
306
332
 
307
333
SPEC_TYPES.append(RevisionSpec_date)
308
334
 
319
345
        for r, b in ((revision_a, branch), (revision_b, other_branch)):
320
346
            if r is None:
321
347
                raise NoCommits(b)
322
 
        revision_source = MultipleRevisionSources(branch, other_branch)
 
348
        revision_source = MultipleRevisionSources(branch.repository,
 
349
                                                  other_branch.repository)
323
350
        rev_id = common_ancestor(revision_a, revision_b, revision_source)
324
351
        try:
325
352
            revno = branch.revision_id_to_revno(rev_id)
338
365
 
339
366
    def _match_on(self, branch, revs):
340
367
        from branch import Branch
341
 
        from fetch import greedy_fetch
342
368
        other_branch = Branch.open_containing(self.spec)[0]
343
369
        revision_b = other_branch.last_revision()
344
370
        if revision_b is None:
345
371
            raise NoCommits(other_branch)
346
372
        # pull in the remote revisions so we can diff
347
 
        greedy_fetch(branch, other_branch, revision=revision_b)
 
373
        branch.fetch(other_branch, revision_b)
348
374
        try:
349
375
            revno = branch.revision_id_to_revno(revision_b)
350
376
        except NoSuchRevision: