2017-08-01 13:12:04 +03:00
|
|
|
# age.py
|
|
|
|
#
|
|
|
|
# Copyright 2017 Facebook, Inc.
|
|
|
|
#
|
|
|
|
# This software may be used and distributed according to the terms of the
|
|
|
|
# GNU General Public License version 2 or any later version.
|
|
|
|
"""
|
|
|
|
a revset predicate for filtering by changeset age.
|
|
|
|
|
|
|
|
Adds the `age()` revset predicate.
|
|
|
|
|
|
|
|
This revset predicate differs from the built-in `date` by providing a more
|
|
|
|
granular way of considering relative time rather than absolute time.
|
|
|
|
|
|
|
|
The built-in `date()` predicate does provide full day resolution, so
|
|
|
|
`age("<Xd")` is equivalent to `date("-X")`.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from __future__ import absolute_import
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2017-08-01 13:12:04 +03:00
|
|
|
import re
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
import time
|
|
|
|
|
2018-06-22 17:26:47 +03:00
|
|
|
from mercurial import dagop, error, registrar, revset
|
|
|
|
from mercurial.i18n import _
|
2017-08-01 13:12:04 +03:00
|
|
|
|
|
|
|
|
|
|
|
revsetpredicate = registrar.revsetpredicate()
|
|
|
|
|
2018-06-22 17:26:47 +03:00
|
|
|
_ageparser = re.compile(r"^(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s?)?$")
|
|
|
|
|
|
|
|
|
|
|
|
def parseage(age):
|
|
|
|
m = _ageparser.match(age)
|
|
|
|
if not m:
|
|
|
|
raise error.ParseError("invalid age in age range: %s" % age)
|
|
|
|
days, hours, minutes, seconds = m.groups()
|
|
|
|
agedelta = 0
|
|
|
|
agedelta += int(days or 0) * 60 * 60 * 24
|
|
|
|
agedelta += int(hours or 0) * 60 * 60
|
|
|
|
agedelta += int(minutes or 0) * 60
|
|
|
|
agedelta += int(seconds or 0)
|
|
|
|
return agedelta
|
|
|
|
|
|
|
|
|
|
|
|
def parseagerange(agerange):
|
|
|
|
now = time.time()
|
|
|
|
if agerange.startswith("<"):
|
|
|
|
start = now - parseage(agerange[1:])
|
|
|
|
end = None
|
|
|
|
elif agerange.startswith(">"):
|
|
|
|
start = None
|
|
|
|
end = now - parseage(agerange[1:])
|
|
|
|
elif "-" in agerange:
|
|
|
|
a1, a2 = agerange.split("-", 1)
|
|
|
|
start = now - parseage(a2)
|
|
|
|
end = now - parseage(a1)
|
|
|
|
else:
|
|
|
|
raise error.ParseError("invalid age range")
|
|
|
|
return start, end
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2017-08-01 13:12:04 +03:00
|
|
|
|
2018-06-22 17:26:49 +03:00
|
|
|
@revsetpredicate("age(string)", weight=10)
|
2017-08-01 13:12:04 +03:00
|
|
|
def age(repo, subset, x):
|
2018-06-22 17:26:47 +03:00
|
|
|
"""Changesets that are in a specific age range.
|
2017-08-01 13:12:04 +03:00
|
|
|
|
|
|
|
The age range can be specified in days, hours, minutes or seconds:
|
|
|
|
|
|
|
|
- ``<30d`` : Newer than 30 days old
|
|
|
|
- ``>4h30m``: Older than 4 hours 30 minutes old
|
|
|
|
- ``<15s`` : Newer than 15 seconds old
|
2018-06-22 17:26:47 +03:00
|
|
|
- ``1h-5h`` : Between 1 and 5 hours old
|
2017-08-01 13:12:04 +03:00
|
|
|
|
|
|
|
If no unit is specified, seconds are assumed.
|
|
|
|
"""
|
2018-06-22 17:26:47 +03:00
|
|
|
agerange = revset.getstring(x, "age requires an age range")
|
|
|
|
start, end = parseagerange(agerange)
|
|
|
|
|
|
|
|
def agefunc(x):
|
|
|
|
xdate = repo[x].date()[0]
|
|
|
|
return (start is None or start < xdate) and (end is None or xdate < end)
|
|
|
|
|
|
|
|
return subset.filter(agefunc, condrepr=("<age %r>", agerange))
|
|
|
|
|
|
|
|
|
|
|
|
@revsetpredicate("ancestorsaged(set, agerange)")
|
|
|
|
def ancestorsaged(repo, subset, x):
|
|
|
|
"""Ancestors in an age range, stopping at the first that is too old
|
|
|
|
|
|
|
|
Similar to ``ancestors(set) & age(agerange)`` except that all ancestors that
|
|
|
|
are ancestors of any commit that is older than the age range are also
|
|
|
|
excluded. This only matters if there are changesets that have ancestors that
|
|
|
|
are newer than them.
|
|
|
|
|
|
|
|
For example, given the changesets:
|
|
|
|
|
|
|
|
o aaa (1 hour ago)
|
|
|
|
|
|
|
|
|
o bbb (2 hours ago)
|
|
|
|
|
|
|
|
|
o ccc (3 hours ago)
|
|
|
|
|
|
|
|
|
o ddd (4 hours ago)
|
|
|
|
|
|
|
|
|
o eee (2 hours ago)
|
|
|
|
|
|
|
|
|
o fff (5 hours ago)
|
|
|
|
|
|
|
|
|
~
|
2017-08-01 13:12:04 +03:00
|
|
|
|
2018-06-22 17:26:47 +03:00
|
|
|
The expression ``ancestorsaged(aaa, "30m-3h30m")`` would match changesets
|
|
|
|
``bbb`` and ``ccc`` only. The changeset ``eee`` is excluded by virtue of
|
|
|
|
being an ancestor of ``ddd``, which is outside the age range.
|
|
|
|
|
|
|
|
The age range can be specified in days, hours, minutes or seconds:
|
|
|
|
|
|
|
|
- ``<30d`` : Newer than 30 days old
|
|
|
|
- ``>4h30m``: Older than 4 hours 30 minutes old
|
|
|
|
- ``<15s`` : Newer than 15 seconds old
|
|
|
|
- ``1h-5h`` : Between 1 and 5 hours old
|
|
|
|
|
|
|
|
If no unit is specified, seconds are assumed.
|
|
|
|
"""
|
|
|
|
args = revset.getargsdict(x, "ancestorsaged", "set agerange")
|
|
|
|
if "set" not in args or "agerange" not in args:
|
|
|
|
# i18n: "ancestorsaged" is a keyword
|
|
|
|
raise error.ParseError(_("ancestorsaged takes at least 2 arguments"))
|
|
|
|
heads = revset.getset(repo, revset.fullreposet(repo), args["set"])
|
|
|
|
if not heads:
|
|
|
|
return revset.baseset()
|
|
|
|
agerange = revset.getstring(
|
|
|
|
args["agerange"], _("ancestorsaged requires an age range")
|
|
|
|
)
|
|
|
|
start, end = parseagerange(agerange)
|
2017-08-01 13:12:04 +03:00
|
|
|
|
|
|
|
def older(x):
|
2018-06-22 17:26:47 +03:00
|
|
|
return repo[x].date()[0] < start
|
2017-08-01 13:12:04 +03:00
|
|
|
|
2018-06-22 17:26:47 +03:00
|
|
|
def notyounger(x):
|
|
|
|
return repo[x].date()[0] < end
|
|
|
|
|
|
|
|
s = dagop.revancestors(repo, heads, cutfunc=older if start is not None else None)
|
|
|
|
if end is not None:
|
|
|
|
s = s.filter(notyounger)
|
|
|
|
|
|
|
|
return subset & s
|