@@ -283,27 +283,37 @@ def incremental_build(
283283def get_smart_tag_range (
284284 tags : list [GitTag ], newest : str , oldest : str | None = None
285285) -> list [GitTag ]:
286- """Smart because it finds the N+1 tag.
286+ """Get a range of tags including the next tag after the oldest tag.
287287
288- This is because we need to find until the next tag
288+ Args:
289+ tags: List of git tags
290+ newest: Name of the newest tag to include
291+ oldest: Name of the oldest tag to include. If None, same as newest.
292+
293+ Returns:
294+ List of tags from newest to oldest, plus one tag after oldest if it exists.
295+ For nonexistent end tag, returns all tags.
296+ For nonexistent start tag, returns tags starting from second tag.
297+ For nonexistent start and end tags, returns empty list.
289298 """
290- accumulator = []
291- keep = False
292- if not oldest :
293- oldest = newest
294- for index , tag in enumerate (tags ):
295- if tag .name == newest :
296- keep = True
297- if keep :
298- accumulator .append (tag )
299- if tag .name == oldest :
300- keep = False
301- try :
302- accumulator .append (tags [index + 1 ])
303- except IndexError :
304- pass
305- break
306- return accumulator
299+ oldest = oldest or newest
300+
301+ names = [tag .name for tag in tags ]
302+ has_newest = newest in names
303+ has_oldest = oldest in names
304+ if not has_newest and not has_oldest :
305+ return []
306+
307+ if not has_newest :
308+ return tags [1 :]
309+
310+ if not has_oldest :
311+ return tags
312+
313+ newest_idx = next (i for i , tag in enumerate (tags ) if tag .name == newest )
314+ oldest_idx = next (i for i , tag in enumerate (tags ) if tag .name == oldest )
315+
316+ return tags [newest_idx : oldest_idx + 2 ]
307317
308318
309319def get_oldest_and_newest_rev (
0 commit comments