@@ -305,27 +305,37 @@ def incremental_build(
305305def get_smart_tag_range (
306306 tags : Sequence [GitTag ], newest : str , oldest : str | None = None
307307) -> list [GitTag ]:
308- """Smart because it finds the N+1 tag.
308+ """Get a range of tags including the next tag after the oldest tag.
309309
310- This is because we need to find until the next tag
310+ Args:
311+ tags: List of git tags
312+ newest: Name of the newest tag to include
313+ oldest: Name of the oldest tag to include. If None, same as newest.
314+
315+ Returns:
316+ List of tags from newest to oldest, plus one tag after oldest if it exists.
317+ For nonexistent end tag, returns all tags.
318+ For nonexistent start tag, returns tags starting from second tag.
319+ For nonexistent start and end tags, returns empty list.
311320 """
312- accumulator = []
313- keep = False
314- if not oldest :
315- oldest = newest
316- for index , tag in enumerate (tags ):
317- if tag .name == newest :
318- keep = True
319- if keep :
320- accumulator .append (tag )
321- if tag .name == oldest :
322- keep = False
323- try :
324- accumulator .append (tags [index + 1 ])
325- except IndexError :
326- pass
327- break
328- return accumulator
321+ oldest = oldest or newest
322+
323+ names = set (tag .name for tag in tags )
324+ has_newest = newest in names
325+ has_oldest = oldest in names
326+ if not has_newest and not has_oldest :
327+ return []
328+
329+ if not has_newest :
330+ return tags [1 :]
331+
332+ if not has_oldest :
333+ return tags
334+
335+ newest_idx = next (i for i , tag in enumerate (tags ) if tag .name == newest )
336+ oldest_idx = next (i for i , tag in enumerate (tags ) if tag .name == oldest )
337+
338+ return tags [newest_idx : oldest_idx + 2 ]
329339
330340
331341def get_oldest_and_newest_rev (
0 commit comments