151
143
revs = branch.revision_history()
152
144
return self._match_on_and_check(branch, revs)
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
164
146
def __repr__(self):
165
147
# this is mostly for helping with testing
166
148
return '<%s %s%s>' % (self.__class__.__name__,
226
207
SPEC_TYPES.append(RevisionSpec_last)
229
class RevisionSpec_before(RevisionSpec):
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):
237
return RevisionInfo(branch, r.revno - 1)
239
SPEC_TYPES.append(RevisionSpec_before)
242
210
class RevisionSpec_tag(RevisionSpec):
261
229
Spec for date revisions:
263
231
value can be 'yesterday', 'today', 'tomorrow' or a YYYY-MM-DD string.
264
matches the first entry after a given date (either at midnight or
265
at a specified time).
232
it can also start with a '+/-/='. '+' says match the first
233
entry after the given date. '-' is match the first entry before the date
234
'=' is match the first entry after, but still on the given date.
236
+2005-05-12 says find the first matching entry after May 12th, 2005 at 0:00
237
-2005-05-12 says find the first matching entry before May 12th, 2005 at 0:00
238
=2005-05-12 says find the first match after May 12th, 2005 at 0:00 but before
239
May 13th, 2005 at 0:00
267
241
So the proper way of saying 'give me all entries for today' is:
268
-r date:today..date:tomorrow
242
-r {date:+today}:{date:-tomorrow}
243
The default is '=' when not supplied
270
today = datetime.datetime.fromordinal(datetime.date.today().toordinal())
246
if self.spec[:1] in ('+', '-', '='):
247
match_style = self.spec[:1]
248
self.spec = self.spec[1:]
250
# XXX: this should probably be using datetime.date instead
251
today = datetime.datetime.today().replace(hour=0, minute=0, second=0,
271
253
if self.spec.lower() == 'yesterday':
272
254
dt = today - datetime.timedelta(days=1)
273
255
elif self.spec.lower() == 'today':
296
278
dt = datetime.datetime(year=year, month=month, day=day,
297
279
hour=hour, minute=minute, second=second)
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)
304
return RevisionInfo(branch, i+1)
305
return RevisionInfo(branch, None)
283
if match_style == '-':
285
elif match_style == '=':
286
last = dt + datetime.timedelta(days=1)
289
for i in range(len(revs)-1, -1, -1):
290
r = branch.get_revision(revs[i])
291
# TODO: Handle timezone.
292
dt = datetime.datetime.fromtimestamp(r.timestamp)
293
if first >= dt and (last is None or dt >= last):
294
return RevisionInfo(branch, i+1,)
296
for i in range(len(revs)):
297
r = branch.get_revision(revs[i])
298
# TODO: Handle timezone.
299
dt = datetime.datetime.fromtimestamp(r.timestamp)
300
if first <= dt and (last is None or dt <= last):
301
return RevisionInfo(branch, i+1,)
307
303
SPEC_TYPES.append(RevisionSpec_date)
310
class RevisionSpec_ancestor(RevisionSpec):
313
def _match_on(self, branch, revs):
314
from branch import Branch
315
from revision import common_ancestor, MultipleRevisionSources
316
other_branch = Branch.open_containing(self.spec)[0]
317
revision_a = branch.last_revision()
318
revision_b = other_branch.last_revision()
319
for r, b in ((revision_a, branch), (revision_b, other_branch)):
322
revision_source = MultipleRevisionSources(branch, other_branch)
323
rev_id = common_ancestor(revision_a, revision_b, revision_source)
325
revno = branch.revision_id_to_revno(rev_id)
326
except NoSuchRevision:
328
return RevisionInfo(branch, revno, rev_id)
330
SPEC_TYPES.append(RevisionSpec_ancestor)
332
class RevisionSpec_branch(RevisionSpec):
333
"""A branch: revision specifier.
335
This takes the path to a branch and returns its tip revision id.
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)
349
revno = branch.revision_id_to_revno(revision_b)
350
except NoSuchRevision:
352
return RevisionInfo(branch, revno, revision_b)
354
SPEC_TYPES.append(RevisionSpec_branch)