Skip to contentSkip to conversation

models.py: Improve Series naming when no cover letter is provided

PATCH Superseded Jose Lamego 1 participant 4 messages Apr 17, 2017 – May 4, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 models.py: Improve Series naming when no cover letter is provided

The number/order prefix from a patch Subject line is inapropriately included when naming a Series where a cover letter is not provided and an additional prefix is present at the Subject.

This change improves the substitution regex to omit the number/order and any other prefix that may be present.

[YOCTO #11305]

---

Notes:
Changes in v2: Ommit all of the prefixes that may be present in first patch to name the series

 patchwork/models.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
patchwork/models.py +1 -1
index ddc3254..a34e0fc 100644
@@ -1046,7 +1046,7 @@ def _on_revision_complete(sender, revision, **kwargs):
     # so we can update the name for series without a cover letter
     if series.name == SERIES_DEFAULT_NAME:
         name = series.latest_revision().ordered_patches()[0].name
-        n = re.compile(r'(\[\d+\/\d+\]\s?)')
+        n = re.compile(r'(\[.*\]\s?)')
         name = n.sub('', name)
         c = len(series.latest_revision().ordered_patches())
         # For one-patch series (1/1) without cover letter
Signature · 1 line
2.7.4
#1 lore raw

PATCH v3 1/1 models.py: Improve Series naming when no cover letter is provided

The number/order prefix from a patch Subject line is inapropriately included when naming a Series where a cover letter is not provided and an additional prefix is present at the Subject.

This change improves the substitution regex to omit the number/order prefix but include any other prefix that may be present.

[YOCTO #11305]

---

Notes:
Changes in V3: remove the number/order prefix without changing any other other existing prefix, as this may be required for mapping the patch to additional branches other than master.

 patchwork/models.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
patchwork/models.py +6 -2
index ddc3254..7944b98 100644
@@ -1046,8 +1046,12 @@ def _on_revision_complete(sender, revision, **kwargs):
     # so we can update the name for series without a cover letter
     if series.name == SERIES_DEFAULT_NAME:
         name = series.latest_revision().ordered_patches()[0].name
-        n = re.compile(r'(\[\d+\/\d+\]\s?)')
-        name = n.sub('', name)
+        n = re.compile(
+            r'((\[.*\]\s?)*\[.*\w+.*(\W+\d+\/\d+)+\s*\]\s?)|(\[\d+\/\d+\]\s?)')
+        if n.match(name):
+            name = re.sub(
+                r'n.match(name).group(3) or re.escape(n.match(name).group(4)',
+                name)
         c = len(series.latest_revision().ordered_patches())
         # For one-patch series (1/1) without cover letter
         if c == 1:
Signature · 1 line
2.7.4
#2 lore raw

PATCH v4 1/1 models.py: Improve Series naming when no cover letter is provided

The number/order prefix from a patch Subject line is inapropriately included when naming a Series where a cover letter is not provided and an additional prefix is present at the Subject.

This change improves the substitution regex to omit the number/order prefix but include any other prefix that may be present.

[YOCTO #11305]

---

Notes:
Changes in V4: use group naming in regex instead of integer indexing for readibility purposes

Changes in V3: remove the number/order prefix without changing any other other existing prefix, as this may be required for mapping the patch to additional branches other than master.

 patchwork/models.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
patchwork/models.py +8 -2
index ddc3254..ae9ed9f 100644
@@ -1046,8 +1046,14 @@ def _on_revision_complete(sender, revision, **kwargs):
     # so we can update the name for series without a cover letter
     if series.name == SERIES_DEFAULT_NAME:
         name = series.latest_revision().ordered_patches()[0].name
-        n = re.compile(r'(\[\d+\/\d+\]\s?)')
-        name = n.sub('', name)
+        n = re.compile(r'((\[.*\]\s?)*\[.*\w+.*'
+                       '(?P<comb_pref>\W+\d+\/\d+)+\s*\]\s?)'
+                       '|(?P<ind_pref>\[\d+\/\d+\]\s?)')
+        if n.match(name):
+            name = re.sub(
+                r'n.match(name).group("comb_pref") or '
+                're.escape(n.match(name).group("ind_pref")',
+                name)
         c = len(series.latest_revision().ordered_patches())
         # For one-patch series (1/1) without cover letter
         if c == 1:
Signature · 1 line
2.7.4
#3 lore raw

PATCH v5 1/1 models.py: Improve Series naming when no cover letter is provided

In reply to Jose Lamego

The number/order prefix from a patch Subject line is inapropriately included when naming a Series where a cover letter is not provided and an additional prefix is present at the Subject.

This change improves the substitution regex to omit the number/order prefix but include any other prefix that may be present.

[YOCTO #11305]

---

Notes:
Changes in V5: Fixed argument formatting in re.sub function

Changes in V4: use group naming in regex instead of integer indexing for readibility purposes

Changes in V3: remove the number/order prefix without changing any other other existing prefix, as this may be required for mapping the patch to additional branches other than master.

 patchwork/models.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
patchwork/models.py +8 -2
index ddc3254..7dd8120 100644
@@ -1046,8 +1046,14 @@ def _on_revision_complete(sender, revision, **kwargs):
     # so we can update the name for series without a cover letter
     if series.name == SERIES_DEFAULT_NAME:
         name = series.latest_revision().ordered_patches()[0].name
-        n = re.compile(r'(\[\d+\/\d+\]\s?)')
-        name = n.sub('', name)
+        n = re.compile(r'((\[.*\]\s?)*\[.*\w+.*'
+                       '(?P<comb_pref>\W+\d+\/\d+)+\s*\]\s?)'
+                       '|(?P<ind_pref>\[\d+\/\d+\]\s?)')
+        if n.match(name):
+            name = re.sub(
+                n.match(name).group("comb_pref") or
+                re.escape(n.match(name).group("ind_pref")),
+                '', name)
         c = len(series.latest_revision().ordered_patches())
         # For one-patch series (1/1) without cover letter
         if c == 1:
Signature · 1 line
2.7.4