~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revisionspec.py

  • Committer: Michael Ellerman
  • Date: 2006-02-28 14:45:51 UTC
  • mto: (1558.1.18 Aaron's integration)
  • mto: This revision was merged to the branch mainline in revision 1586.
  • Revision ID: michael@ellerman.id.au-20060228144551-3d9941ecde4a0b0a
Update contrib/pwk for -p1 diffs from bzr

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 = []
149
148
            raise NoSuchRevision(branch, str(self.spec))
150
149
 
151
150
    def in_history(self, branch):
152
 
        if branch:
153
 
            revs = branch.revision_history()
154
 
        else:
155
 
            revs = None
 
151
        revs = branch.revision_history()
156
152
        return self._match_on_and_check(branch, revs)
157
153
 
158
154
        # FIXME: in_history is somewhat broken,
193
189
 
194
190
    def _match_on(self, branch, revs):
195
191
        """Lookup a revision by revision number"""
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)
 
192
        try:
 
193
            return RevisionInfo(branch, int(self.spec))
 
194
        except ValueError:
 
195
            return RevisionInfo(branch, None)
211
196
 
212
197
SPEC_TYPES.append(RevisionSpec_revno)
213
198
 
263
248
SPEC_TYPES.append(RevisionSpec_tag)
264
249
 
265
250
 
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
 
 
278
251
class RevisionSpec_date(RevisionSpec):
279
252
    prefix = 'date:'
280
253
    _date_re = re.compile(
322
295
 
323
296
            dt = datetime.datetime(year=year, month=month, day=day,
324
297
                    hour=hour, minute=minute, second=second)
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)
 
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)
334
306
 
335
307
SPEC_TYPES.append(RevisionSpec_date)
336
308