Skip to content
Merged
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
18 changes: 14 additions & 4 deletions carthage/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,25 @@ async def async_resolve(self):


def permute_identifier(id, maxlen):
"Add to or replace the last character of the identifier; use as generator and stop consuming when a unique one is found"
"""
Use as a generator to yield a unique identifier.

First attempt to yield the provided identifier, then just add one character if maxlen allows,
otherwise walk backwards through chars in id replacing one at a time until a unique combination is found.

Raises ValueError if no unique combination can be found.
"""
yield id
if len(id) < maxlen:
for i in range(26):
yield id + chr(97 + i)
else:
id = id[:-1]
for i in range(26):
yield id + chr(97 + i)
for i in range(len(id) - 1, -1, -1):
original_char = id[i]
for t in range(26):
if original_char == chr(97+t):
continue
yield id[:i] + chr(97+t) + id[i+1:]
raise ValueError("No unique combination found")


Expand Down
Loading