cli/command/formatter: add TrunateID utility
We were depending on pkg/stringid to truncate IDs for presentation. While traditionally, we used a fixed length for "truncated" IDs, this is not a strict requirement (any ID-prefix should work, but conflicts may happen on shorter IDs). This patch adds a local `TruncateID()` utility in the formatter package; it's currently using the same implementation and length as the `stringid.TruncateID` function, but may diverge in future. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@ -7,7 +7,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types/build"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/docker/go-units"
|
||||
)
|
||||
|
||||
@ -115,7 +114,7 @@ func (c *buildCacheContext) MarshalJSON() ([]byte, error) {
|
||||
func (c *buildCacheContext) ID() string {
|
||||
id := c.v.ID
|
||||
if c.trunc {
|
||||
id = stringid.TruncateID(c.v.ID)
|
||||
id = TruncateID(c.v.ID)
|
||||
}
|
||||
if c.v.InUse {
|
||||
return id + "*"
|
||||
@ -131,7 +130,7 @@ func (c *buildCacheContext) Parent() string {
|
||||
parent = c.v.Parent //nolint:staticcheck // Ignore SA1019: Field was deprecated in API v1.42, but kept for backward compatibility
|
||||
}
|
||||
if c.trunc {
|
||||
return stringid.TruncateID(parent)
|
||||
return TruncateID(parent)
|
||||
}
|
||||
return parent
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user