Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

docs: kdoc: coalesce the new-section handling

Merge the duplicated code back into a single implementation. Code movement
only, no logic changes.

Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/r/20250621203512.223189-6-corbet@lwn.net

+13 -36
+13 -36
scripts/lib/kdoc/kdoc_parser.py
··· 1310 1310 else: 1311 1311 self.emit_msg(ln, f"Cannot find identifier on line:\n{line}") 1312 1312 1313 - def process_decl(self, ln, line): 1314 - """ 1315 - STATE_DECLARATION: We've seen the beginning of a declaration 1316 - """ 1313 + # 1314 + # Helper function to determine if a new section is being started. 1315 + # 1316 + def is_new_section(self, ln, line): 1317 1317 if doc_sect.search(line): 1318 1318 self.entry.in_doc_sect = True 1319 1319 newsection = doc_sect.group(1) ··· 1346 1346 self.entry.contents += "\n" 1347 1347 1348 1348 self.state = state.BODY 1349 + return True 1350 + return False 1351 + 1352 + def process_decl(self, ln, line): 1353 + """ 1354 + STATE_DECLARATION: We've seen the beginning of a declaration 1355 + """ 1356 + if self.is_new_section(ln, line): 1349 1357 return 1350 1358 1351 1359 if doc_end.search(line): ··· 1403 1395 """ 1404 1396 STATE_BODY: the bulk of a kerneldoc comment. 1405 1397 """ 1406 - if doc_sect.search(line): 1407 - self.entry.in_doc_sect = True 1408 - newsection = doc_sect.group(1) 1409 - 1410 - if newsection.lower() in ["description", "context"]: 1411 - newsection = newsection.title() 1412 - 1413 - # Special case: @return is a section, not a param description 1414 - if newsection.lower() in ["@return", "@returns", 1415 - "return", "returns"]: 1416 - newsection = "Return" 1417 - 1418 - # Perl kernel-doc has a check here for contents before sections. 1419 - # the logic there is always false, as in_doc_sect variable is 1420 - # always true. So, just don't implement Wcontents_before_sections 1421 - 1422 - # .title() 1423 - newcontents = doc_sect.group(2) 1424 - if not newcontents: 1425 - newcontents = "" 1426 - 1427 - if self.entry.contents.strip("\n"): 1428 - self.dump_section() 1429 - 1430 - self.entry.begin_section(ln, newsection) 1431 - self.entry.leading_space = None 1432 - 1433 - self.entry.contents = newcontents.lstrip() 1434 - if self.entry.contents: 1435 - self.entry.contents += "\n" 1436 - 1437 - self.state = state.BODY 1398 + if self.is_new_section(ln, line): 1438 1399 return 1439 1400 1440 1401 if doc_end.search(line):