Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
which one (in a terminal), or prints the `tree add` command to finish.
Series a maintainer's mail calls applied are included, so their tree
can confirm it.
- More ways of saying "applied" count as one: the verb-last shorthand
("Patch applied. Thanks.", as crypto's maintainer writes it; "Both
applied", "Series queued for 6.20"), "Thanks! Applied", "Thank you,
applied", and "Pushed to drm-misc-next" or "Merged, thanks". Numbers
in the line ("Patches 1-3 applied") say which patches.
- An applied series missing from more than two trees says "not in any
of the N trees checked" instead of naming them all.

Expand Down
39 changes: 36 additions & 3 deletions src/patchtrack/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,35 @@
B4_CHANGE_ID_RE = re.compile(r"^\d{8}-(.+?)(?:-[0-9a-f]{12})?$")
# b4 ty: "[1/2] subject\n commit: <sha>"
B4_TY_RE = re.compile(r"^\s*\[(\d+)/(\d+)\]\s.*\n\s+commit:\s*([0-9a-f]{7,40})", re.M)
# "Thanks, ", "Thank you! ", "Thx. " before the announcement
_THANKS = r"(?:(?:thanks|thank you|thx)[,.!]?\s+)?"
# Shorthand with the verb last: "Patch applied.", "Patches 1-3 applied to
# for-next", "Both applied.", "Series queued, thanks."; it must end there or
# name where, so that a tester's "Patch applied cleanly on v6.1" is not one.
_SHORTHAND = (
r"(?:(?:both|all|the whole|whole|entire)\s+)?"
r"(?:(?:patch(?:es)?|series|changes?|commits?)\s+)?"
r"(?:\d+(?:/\d+)?(?:\s*(?:-|,|and|to)\s*\d+(?:/\d+)?)*\s+)?"
r"(?:now\s+|both\s+|all\s+)?(?:applied|queued|picked up|merged|pushed)"
r"(?:[.!,:;]|\s+(?:to|into|for|in)\b|\s*$)"
)
APPLIED_LINE_RE = re.compile(
r"^\s*(?:"
r"(?:thanks,?\s+)?(?:applied|queued|picked up)\b"
r"|(?:i'?ve|i have|i)\s+(?:now\s+)?(?:applied|queued|picked up)\b.*\b(?:to|into|thanks)\b"
+ _THANKS + r"(?:applied|queued|picked up)\b"
# drm and others: "Pushed to drm-misc-next.", "Merged, thanks."
r"|" + _THANKS + r"(?:merged|pushed|committed)(?:[.!,]|\s+(?:to|into)\b)"
# crypto: "Patch applied. Thanks."
r"|" + _THANKS + _SHORTHAND
+ r"|(?:i'?ve|i have|i)\s+(?:now\s+)?(?:applied|queued|picked up)\b.*\b(?:to|into|thanks)\b"
r"|this (?:patch|series) was applied to"
# QEMU: "This was merged into master (<sha>)."
r"|(?:this|the) (?:patch |series |change )?(?:was|has been|is now|got) (?:merged|applied|pushed|committed)"
r" (?:into|to|in)\b"
r")",
re.I,
)
# Patch numbers named in the announcement: "Patches 1-3 applied", "Applied patch 2 and 4/5"
NUMBERED_RE = re.compile(r"\bpatch(?:es)?\s+(\d+(?:/\d+)?(?:\s*(?:-|,|and|&|to)\s*\d+(?:/\d+)?)*)", re.I)


@dataclass
Expand Down Expand Up @@ -196,7 +214,9 @@ def trailers(body):


# A line that is nothing but an announcement: "Applied.", "Queued, thanks."
BARE_APPLIED_RE = re.compile(r"^\s*(?:thanks,?\s+)?(?:applied|queued)[.!]?(?:,?\s*thanks[.!]?)?\s*$", re.I)
BARE_APPLIED_RE = re.compile(
r"^\s*(?:thanks,?\s+)?(?:(?:patch(?:es)?|series|both|all)\s+)?(?:applied|queued)[.!]?(?:,?\s*thanks[.!]?)?\s*$",
re.I)


def _paragraph_starts(body):
Expand Down Expand Up @@ -230,6 +250,7 @@ def applied(body, subject=""):
if line is None:
return None
indices = sorted({int(i) for i, _, _ in B4_TY_RE.findall(text)})
indices = indices or numbered(line)
return Applied(line=line, indices=indices, subset=parse_subject(subject).subset or partial(line))


Expand All @@ -238,6 +259,18 @@ def applied(body, subject=""):
re.I)


def numbered(line):
"""The patch numbers an announcement names: "Patches 1-3 and 5 applied" -> [1, 2, 3, 5]."""
m = NUMBERED_RE.search(line or "")
if not m:
return []
got = set()
for part in re.split(r"\s*(?:,|and|&)\s*", m.group(1)):
ends = [int(n.split("/")[0]) for n in re.split(r"\s*(?:-|to)\s*", part) if n]
got |= set(range(ends[0], ends[-1] + 1)) if len(ends) == 2 else set(ends)
return sorted(got)


def partial(line):
return bool(PARTIAL_RE.search(line or ""))

Expand Down
21 changes: 20 additions & 1 deletion tests/test_patchtrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,33 @@ def test_bare_line_after_prose(self):
def test_after_a_quote(self):
self.assertIsNotNone(parse.applied("> [PATCH] foo\nApplied to master, thanks!\n"))

def test_shorthand(self):
# crypto, drm, and the other verb-last forms
for body in ("> [PATCH] hwrng: mtk - foo\n\nPatch applied. Thanks.\n",
"Fairly simple.\nPatch applied. Thanks.\n",
"Both applied, thanks.\n", "All applied.\n", "Series applied to cryptodev.\n",
"Thanks! Applied to soc/dt.\n", "Thank you, applied.\n",
"Pushed to drm-misc-next, thanks!\n", "Thanks, merged.\n", "Now applied to mmc-next.\n"):
self.assertIsNotNone(parse.applied(body), body)

def test_numbered(self):
self.assertEqual(parse.applied("Patches 1-3 applied to for-next, thanks.\n").indices, [1, 2, 3])
self.assertEqual(parse.applied("Applied patches 1 and 3, thanks.\n").indices, [1, 3])
self.assertEqual(parse.applied("Patch 2/4 queued for 6.20.\n").indices, [2])

def test_not_applied(self):
# The last three are wrapped sentences seen on gcc-patches, git@ and xen-devel.
for body in ("> Applied, thanks!\nWhy?\n",
"Can this be applied to stable as well?\n",
"Thanks.\n-- \nApplied Signal Corp\n",
'The attribute is now\napplied to struct after its definition".\n',
"This one depends on the other being\napplied first.\n",
"Those tests will be\npicked up and run automatically in Gitlab CI.\n"):
"Those tests will be\npicked up and run automatically in Gitlab CI.\n",
# a tester's report, not an announcement
"Patch applied cleanly on top of v6.1 and tested.\n",
"The patch applied fine but the build fails.\n",
"Merged with the other one?\n", "Pushed back on this approach before.\n",
"All of this applied to the old driver too.\n"):
self.assertIsNone(parse.applied(body), body)

def test_change_id(self):
Expand Down
Loading