graph/history.go
55235e12
 package graph
 
 import (
 	"strings"
 
0b2fa9c7
 	"github.com/docker/docker/api/types"
55235e12
 	"github.com/docker/docker/image"
a2b0c977
 	"github.com/docker/docker/utils"
55235e12
 )
 
5c7c3fea
 func (s *TagStore) History(name string) ([]*types.ImageHistory, error) {
55235e12
 	foundImage, err := s.LookupImage(name)
 	if err != nil {
5c7c3fea
 		return nil, err
55235e12
 	}
 
 	lookupMap := make(map[string][]string)
 	for name, repository := range s.Repositories {
 		for tag, id := range repository {
 			// If the ID already has a reverse lookup, do not update it unless for "latest"
 			if _, exists := lookupMap[id]; !exists {
 				lookupMap[id] = []string{}
 			}
a2b0c977
 			lookupMap[id] = append(lookupMap[id], utils.ImageReference(name, tag))
55235e12
 		}
 	}
 
5c7c3fea
 	history := []*types.ImageHistory{}
0b2fa9c7
 
55235e12
 	err = foundImage.WalkHistory(func(img *image.Image) error {
5c7c3fea
 		history = append(history, &types.ImageHistory{
0b2fa9c7
 			ID:        img.ID,
b261ce5f
 			Created:   img.Created.Unix(),
767df67e
 			CreatedBy: strings.Join(img.ContainerConfig.Cmd.Slice(), " "),
0b2fa9c7
 			Tags:      lookupMap[img.ID],
 			Size:      img.Size,
bf573395
 			Comment:   img.Comment,
0b2fa9c7
 		})
55235e12
 		return nil
 	})
0b2fa9c7
 
5c7c3fea
 	return history, err
55235e12
 }