Use min(desiredLength, commitIdLength) for substring