~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revisionspec.py

  • Committer: Aaron Bentley
  • Date: 2005-10-20 02:57:55 UTC
  • mto: (1185.25.1)
  • mto: This revision was merged to the branch mainline in revision 1474.
  • Revision ID: aaron.bentley@utoronto.ca-20051020025755-e03df41c52aa3156
tweaked spacing

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
        # TODO: otherwise, it should depend on how I was built -
58
58
        # if it's in_history(branch), then check revision_history(),
59
59
        # if it's in_store(branch), do the check below
60
 
        return self.rev_id in self.branch.revision_store
 
60
        return self.branch.revision_store.has_id(self.rev_id)
61
61
 
62
62
    def __len__(self):
63
63
        return 2
151
151
        revs = branch.revision_history()
152
152
        return self._match_on_and_check(branch, revs)
153
153
 
 
154
        # FIXME: in_history is somewhat broken,
 
155
        # it will return non-history revisions in many
 
156
        # circumstances. The expected facility is that
 
157
        # in_history only returns revision-history revs,
 
158
        # in_store returns any rev. RBC 20051010
 
159
    # aliases for now, when we fix the core logic, then they
 
160
    # will do what you expect.
 
161
    in_store = in_history
 
162
    in_branch = in_store
 
163
        
154
164
    def __repr__(self):
155
165
        # this is mostly for helping with testing
156
166
        return '<%s %s%s>' % (self.__class__.__name__,
200
210
 
201
211
 
202
212
class RevisionSpec_last(RevisionSpec):
 
213
 
203
214
    prefix = 'last:'
204
215
 
205
216
    def _match_on(self, branch, revs):
215
226
SPEC_TYPES.append(RevisionSpec_last)
216
227
 
217
228
 
 
229
class RevisionSpec_before(RevisionSpec):
 
230
 
 
231
    prefix = 'before:'
 
232
    
 
233
    def _match_on(self, branch, revs):
 
234
        r = RevisionSpec(self.spec)._match_on(branch, revs)
 
235
        if (r.revno is None) or (r.revno == 0):
 
236
            return r
 
237
        return RevisionInfo(branch, r.revno - 1)
 
238
 
 
239
SPEC_TYPES.append(RevisionSpec_before)
 
240
 
 
241
 
218
242
class RevisionSpec_tag(RevisionSpec):
219
243
    prefix = 'tag:'
220
244
 
237
261
        Spec for date revisions:
238
262
          date:value
239
263
          value can be 'yesterday', 'today', 'tomorrow' or a YYYY-MM-DD string.
240
 
          it can also start with a '+/-/='. '+' says match the first
241
 
          entry after the given date. '-' is match the first entry before the date
242
 
          '=' is match the first entry after, but still on the given date.
243
 
 
244
 
          +2005-05-12 says find the first matching entry after May 12th, 2005 at 0:00
245
 
          -2005-05-12 says find the first matching entry before May 12th, 2005 at 0:00
246
 
          =2005-05-12 says find the first match after May 12th, 2005 at 0:00 but before
247
 
              May 13th, 2005 at 0:00
 
264
          matches the first entry after a given date (either at midnight or
 
265
          at a specified time).
248
266
 
249
267
          So the proper way of saying 'give me all entries for today' is:
250
 
              -r {date:+today}:{date:-tomorrow}
251
 
          The default is '=' when not supplied
 
268
              -r date:today..date:tomorrow
252
269
        """
253
 
        match_style = '='
254
 
        if self.spec[:1] in ('+', '-', '='):
255
 
            match_style = self.spec[:1]
256
 
            self.spec = self.spec[1:]
257
 
 
258
 
        # XXX: this should probably be using datetime.date instead
259
 
        today = datetime.datetime.today().replace(hour=0, minute=0, second=0,
260
 
                                                  microsecond=0)
 
270
        today = datetime.datetime.fromordinal(datetime.date.today().toordinal())
261
271
        if self.spec.lower() == 'yesterday':
262
272
            dt = today - datetime.timedelta(days=1)
263
273
        elif self.spec.lower() == 'today':
286
296
            dt = datetime.datetime(year=year, month=month, day=day,
287
297
                    hour=hour, minute=minute, second=second)
288
298
        first = dt
289
 
        last = None
290
 
        reversed = False
291
 
        if match_style == '-':
292
 
            reversed = True
293
 
        elif match_style == '=':
294
 
            last = dt + datetime.timedelta(days=1)
295
 
 
296
 
        if reversed:
297
 
            for i in range(len(revs)-1, -1, -1):
298
 
                r = branch.get_revision(revs[i])
299
 
                # TODO: Handle timezone.
300
 
                dt = datetime.datetime.fromtimestamp(r.timestamp)
301
 
                if first >= dt and (last is None or dt >= last):
302
 
                    return RevisionInfo(branch, i+1,)
303
 
        else:
304
 
            for i in range(len(revs)):
305
 
                r = branch.get_revision(revs[i])
306
 
                # TODO: Handle timezone.
307
 
                dt = datetime.datetime.fromtimestamp(r.timestamp)
308
 
                if first <= dt and (last is None or dt <= last):
309
 
                    return RevisionInfo(branch, i+1,)
 
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)
310
306
 
311
307
SPEC_TYPES.append(RevisionSpec_date)
312
308
 
317
313
    def _match_on(self, branch, revs):
318
314
        from branch import Branch
319
315
        from revision import common_ancestor, MultipleRevisionSources
320
 
        other_branch = Branch.open_containing(self.spec)
321
 
        revision_a = branch.last_patch()
322
 
        revision_b = other_branch.last_patch()
 
316
        other_branch = Branch.open_containing(self.spec)[0]
 
317
        revision_a = branch.last_revision()
 
318
        revision_b = other_branch.last_revision()
323
319
        for r, b in ((revision_a, branch), (revision_b, other_branch)):
324
320
            if r is None:
325
321
                raise NoCommits(b)
332
328
        return RevisionInfo(branch, revno, rev_id)
333
329
        
334
330
SPEC_TYPES.append(RevisionSpec_ancestor)
 
331
 
 
332
class RevisionSpec_branch(RevisionSpec):
 
333
    """A branch: revision specifier.
 
334
 
 
335
    This takes the path to a branch and returns its tip revision id.
 
336
    """
 
337
    prefix = 'branch:'
 
338
 
 
339
    def _match_on(self, branch, revs):
 
340
        from branch import Branch
 
341
        from fetch import greedy_fetch
 
342
        other_branch = Branch.open_containing(self.spec)[0]
 
343
        revision_b = other_branch.last_revision()
 
344
        if revision_b is None:
 
345
            raise NoCommits(other_branch)
 
346
        # pull in the remote revisions so we can diff
 
347
        greedy_fetch(branch, other_branch, revision=revision_b)
 
348
        try:
 
349
            revno = branch.revision_id_to_revno(revision_b)
 
350
        except NoSuchRevision:
 
351
            revno = None
 
352
        return RevisionInfo(branch, revno, revision_b)
 
353
        
 
354
SPEC_TYPES.append(RevisionSpec_branch)