Skip to content

Commit 1f88663

Browse files
authored
Merge pull request moby#50503 from thaJeztah/pkg_stringid_docs
pkg/stringid: TruncateID: touch-up doc
2 parents f37c1c6 + 3205fcf commit 1f88663

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

pkg/stringid/stringid.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@ const (
1212
fullLen = 64
1313
)
1414

15-
// TruncateID returns a shorthand version of a string identifier for convenience.
16-
// A collision with other shorthands is very unlikely, but possible.
17-
// In case of a collision a lookup with TruncIndex.Get() will fail, and the caller
18-
// will need to use a longer prefix, or the full-length Id.
15+
// TruncateID returns a shorthand version of a string identifier for presentation.
16+
// For convenience, it accepts both digests ("sha256:xxxx") and IDs without an
17+
// algorithm prefix. It truncates the algorithm (if any) before truncating the
18+
// ID. The length of the truncated ID is currently fixed, but users should make
19+
// no assumptions of this to not change; it is merely a prefix of the ID that
20+
// provides enough uniqueness for common scenarios.
21+
//
22+
// Truncated IDs ("ID-prefixes") usually can be used to uniquely identify an
23+
// object (such as a container or network), but collisions may happen, in
24+
// which case an "ambiguous result" error is produced. In case of a collision,
25+
// the caller should try with a longer prefix or the full-length ID.
1926
func TruncateID(id string) string {
2027
if i := strings.IndexRune(id, ':'); i >= 0 {
2128
id = id[i+1:]

0 commit comments

Comments
 (0)