Browse code

* API: Send all tags on History API call

Guillaume J. Charmes authored on 2013/06/19 02:31:07
Showing 4 changed files
... ...
@@ -1,8 +1,8 @@
1 1
 package docker
2 2
 
3 3
 type APIHistory struct {
4
-	ID        string `json:"Id"`
5
-	Tag       string `json:",omitempty"`
4
+	ID        string   `json:"Id"`
5
+	Tags      []string `json:",omitempty"`
6 6
 	Created   int64
7 7
 	CreatedBy string `json:",omitempty"`
8 8
 }
... ...
@@ -627,7 +627,10 @@ func (cli *DockerCli) CmdHistory(args ...string) error {
627 627
 	fmt.Fprintln(w, "ID\tCREATED\tCREATED BY")
628 628
 
629 629
 	for _, out := range outs {
630
-		fmt.Fprintf(w, "%s (%s)\t%s ago\t%s\n", out.ID, out.Tag, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.CreatedBy)
630
+		if out.Tags != nil {
631
+			out.ID = out.Tags[0]
632
+		}
633
+		fmt.Fprintf(w, "%s \t%s ago\t%s\n", out.ID, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.CreatedBy)
631 634
 	}
632 635
 	w.Flush()
633 636
 	return nil
... ...
@@ -691,7 +691,7 @@ Get the history of an image
691 691
 	   [
692 692
 		{
693 693
 			"Id":"b750fe79269d",
694
-			"Tag":"base:latest",
694
+			"Tag":["base:latest"],
695 695
 			"Created":1364102658,
696 696
 			"CreatedBy":"/bin/bash"
697 697
 		},
... ...
@@ -218,16 +218,14 @@ func (srv *Server) ImageHistory(name string) ([]APIHistory, error) {
218 218
 		return nil, err
219 219
 	}
220 220
 
221
-	lookupMap := make(map[string]string)
221
+	lookupMap := make(map[string][]string)
222 222
 	for name, repository := range srv.runtime.repositories.Repositories {
223 223
 		for tag, id := range repository {
224 224
 			// If the ID already has a reverse lookup, do not update it unless for "latest"
225
-			if _, exists := lookupMap[id]; exists {
226
-				if tag != "latest" {
227
-					continue
228
-				}
225
+			if _, exists := lookupMap[id]; !exists {
226
+				lookupMap[id] = []string{}
229 227
 			}
230
-			lookupMap[id] = name + ":" + tag
228
+			lookupMap[id] = append(lookupMap[id], name+":"+tag)
231 229
 		}
232 230
 	}
233 231
 
... ...
@@ -237,7 +235,7 @@ func (srv *Server) ImageHistory(name string) ([]APIHistory, error) {
237 237
 		out.ID = srv.runtime.repositories.ImageName(img.ShortID())
238 238
 		out.Created = img.Created.Unix()
239 239
 		out.CreatedBy = strings.Join(img.ContainerConfig.Cmd, " ")
240
-		out.Tag = lookupMap[img.ID]
240
+		out.Tags = lookupMap[img.ID]
241 241
 		outs = append(outs, out)
242 242
 		return nil
243 243
 	})