]> xenbits.xensource.com Git - people/gdunlap/xsatool.git/commitdiff
xsa: Add 'canonicalize' command
authorGeorge Dunlap <george.dunlap@citrix.com>
Fri, 8 Dec 2017 14:58:01 +0000 (14:58 +0000)
committerGeorge Dunlap <george.dunlap@citrix.com>
Fri, 8 Dec 2017 14:58:01 +0000 (14:58 +0000)
Canonicalize will simply read the metadata file and write it out
again.  This may be useful after editing it by hand or with external
JSON tools, to put it back in "golang canonical" form.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
README.md
main.go
xsa.go

index 97b35848399a5162381efbe601bad3589f09061a..e1d3a2431e4b319531a2f23ef999a15d6e9f45e6 100644 (file)
--- a/README.md
+++ b/README.md
@@ -374,6 +374,15 @@ longer supported.
 (Eventually this will be implemented by the `xsatool global
 end-support [version]` command.)
 
+## 'Canonicalizing' metadata files
+
+After editing metadata files by hand or with other JSON-parsing tools,
+the order of fields may be signicantly different.  You can run
+
+`xsatool NNN canonicalize`
+
+to reformat a file according to Golang's default format.
+
 # Potential future functionality
 
 ## Automatically de-duplicating patches
diff --git a/main.go b/main.go
index ba59bfcdd224371280137d124988ad658490975a..e01b5cdcb97833e36b6a33aede7c0e2db7b11edd 100644 (file)
--- a/main.go
+++ b/main.go
@@ -140,6 +140,8 @@ func XsaMain(args []string) int {
                        checkXSARepos = false
                case "dedup-patches":
                        main = MainDedupPatches
+               case "canonicalize":
+                       main = MainCanonicalize
                default:
                        fmt.Printf("Unknown command: %s\n", cmd)
                        return 1
diff --git a/xsa.go b/xsa.go
index 0e55968118f91acddf38fe8d586ad8bea87a5e0b..a1a217f8281544f2a57356d74f1442573cc226c9 100644 (file)
--- a/xsa.go
+++ b/xsa.go
@@ -460,3 +460,11 @@ func MainDedupPatches(xsa *XSAMeta, args []string) (ret int) {
        
        return 0
 }
+
+func MainCanonicalize(xsa *XSAMeta, args []string) (ret int) {
+       xsa.dirty = true
+
+       xsa.Save()
+
+       return 0
+}