From 63e46cc85cb0a9523e9c48db7a88039e0baeac29 Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Tue, 26 Nov 2019 16:08:04 +0100 Subject: Add support for image name history We leverage the containers/storage image history tracking feature to show the previously used image names when running: `podman images --history` Signed-off-by: Sascha Grunert --- libpod/image/image.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'libpod/image') diff --git a/libpod/image/image.go b/libpod/image/image.go index fa75be44d..129ccd376 100644 --- a/libpod/image/image.go +++ b/libpod/image/image.go @@ -335,6 +335,21 @@ func (i *Image) Names() []string { return i.image.Names } +// NamesHistory returns a string array of names previously associated with the +// image, which may be a mixture of tags and digests +func (i *Image) NamesHistory() []string { + if len(i.image.Names) > 0 && len(i.image.NamesHistory) > 0 && + // We compare the latest (time-referenced) tags for equality and skip + // it in the history if they match to not display them twice. We have + // to compare like this, because `i.image.Names` (latest last) gets + // appended on retag, whereas `i.image.NamesHistory` gets prepended + // (latest first) + i.image.Names[len(i.image.Names)-1] == i.image.NamesHistory[0] { + return i.image.NamesHistory[1:] + } + return i.image.NamesHistory +} + // RepoTags returns a string array of repotags associated with the image func (i *Image) RepoTags() ([]string, error) { var repoTags []string -- cgit v1.2.3-54-g00ecf