diff --git a/internal/cli/formatters.go b/internal/cli/formatters.go index 3e336441..34696ac1 100644 --- a/internal/cli/formatters.go +++ b/internal/cli/formatters.go @@ -4,6 +4,7 @@ package cli import ( + "strings" "time" "github.com/ryanuber/columnize" @@ -34,3 +35,16 @@ func formatTime(t time.Time) string { func formatTimeDifference(first, second time.Time, d time.Duration) string { return second.Truncate(d).Sub(first.Truncate(d)).String() } + +func formatSHA1Reference(in string) string { + // a SHA1 hash is 20 bytes written as a hexadecimal string (40 chars) + if len(in) != 40 && len(strings.Trim(strings.ToLower(in), "0123456789abcdef")) != 0 { + // if it can't be a sha1, return it unchanged + return in + } + l := 8 + if len(in) < l { + l = len(in) + } + return in[:l] +} diff --git a/internal/cli/helpers.go b/internal/cli/helpers.go index 1dfee9c0..ec8bf19f 100644 --- a/internal/cli/helpers.go +++ b/internal/cli/helpers.go @@ -66,10 +66,10 @@ func registryTableRow(cachedRegistry *cache.Registry) []terminal.TableEntry { Value: cachedRegistry.Name, }, { - Value: cachedRegistry.Ref, + Value: formatSHA1Reference(cachedRegistry.Ref), }, { - Value: cachedRegistry.LocalRef, + Value: formatSHA1Reference(cachedRegistry.LocalRef), }, { Value: cachedRegistry.Source, @@ -85,11 +85,11 @@ func registryPackRow(cachedRegistry *cache.Registry, cachedPack *cache.Pack) []t }, // The revision from where the registryPack was cloned { - Value: cachedPack.Ref, + Value: formatSHA1Reference(cachedPack.Ref), }, // The canonical revision from where the registryPack was cloned { - Value: cachedRegistry.LocalRef, + Value: formatSHA1Reference(cachedRegistry.LocalRef), }, // The metadata version {