~emersion/drmdb

2d913cce724e27d6201cd8531c323ec0d00537c4 — Simon Ser 2 years ago 5dee14f
drmtree: sort maps in FormatTree
1 files changed, 25 insertions(+), 4 deletions(-)

M drmtree/drmtree.go
M drmtree/drmtree.go => drmtree/drmtree.go +25 -4
@@ 4,6 4,7 @@ package drmtree
import (
	"encoding/json"
	"fmt"
	"sort"
	"strings"

	"git.sr.ht/~emersion/drmdb/treefmt"


@@ 55,7 56,20 @@ func (drv *Driver) FormatTree(tf treefmt.Formatter) {
	tf.Printf("Driver: %v (%v) version %v on %v", drv.Name, drv.Desc, &drv.Version, &drv.Kernel)
	tfc := tf.NewChild()

	for c, v := range drv.Caps {
	capNames := make([]string, 0, len(drv.Caps))
	for c := range drv.Caps {
		capNames = append(capNames, c)
	}
	sort.Strings(capNames)

	clientCapNames := make([]string, 0, len(drv.ClientCaps))
	for c := range drv.ClientCaps {
		clientCapNames = append(clientCapNames, c)
	}
	sort.Strings(clientCapNames)

	for _, c := range capNames {
		v := drv.Caps[c]
		if v != nil {
			if c == "PRIME" {
				tfc.Printf("DRM_CAP_PRIME supported")


@@ 70,8 84,8 @@ func (drv *Driver) FormatTree(tf treefmt.Formatter) {
		}
	}

	for c, ok := range drv.ClientCaps {
		if ok {
	for _, c := range clientCapNames {
		if drv.ClientCaps[c] {
			tfc.Printf("DRM_CLIENT_CAP_%v supported", c)
		} else {
			tfc.Printf("DRM_CLIENT_CAP_%v unsupported", c)


@@ 322,7 336,14 @@ func (m *PropertyMap) UnmarshalJSON(b []byte) error {
}

func (m *PropertyMap) FormatTree(tf treefmt.Formatter) {
	for name, prop := range *m {
	names := make([]string, 0, len(*m))
	for name := range *m {
		names = append(names, name)
	}
	sort.Strings(names)

	for _, name := range names {
		prop := (*m)[name]
		// TODO: immutable, atomic
		// TODO: type-specific property data
		val := prop.Data