<commit_before>package etcd

import (
	"context"
	"fmt"
	"strings"

	etcdv3 "github.com/coreos/etcd/clientv3"
	"github.com/hashicorp/terraform/backend"
	"github.com/hashicorp/terraform/state"
	"github.com/hashicorp/terraform/state/remote"
	"github.com/hashicorp/terraform/terraform"
)

const (
	keyEnvPrefix = "-env:"
)

func (b *Backend) States() ([]string, error) {
	client, err := b.rawClient()
	if err != nil {
		return nil, err
	}

	prefix := b.determineKey("")
	res, err := client.Get(context.TODO(), prefix, etcdv3.WithPrefix(), etcdv3.WithKeysOnly())
	if err != nil {
		return nil, err
	}

	result := make([]string, 1, len(res.Kvs)+1)
	result[0] = backend.DefaultStateName
	for _, kv := range res.Kvs {
		result = append(result, strings.TrimPrefix(string(kv.Key), prefix))
	}

	return result, nil
}

func (b *Backend) DeleteState(name string) error {
	if name == backend.DefaultStateName || name == "" {
		return fmt.Errorf("Can't delete default state.")
	}

	client, err := b.rawClient()
	if err != nil {
		return err
	}

	path := b.determineKey(name)

	_, err = client.Delete(context.TODO(), path)
	return err
}

func (b *Backend) State(name string) (state.State, error) {<commit_msg>Sort the result of 'Backend.States()'.<commit_after>package etcd

import (
	"context"
	"fmt"
	"sort"
	"strings"

	etcdv3 "github.com/coreos/etcd/clientv3"
	"github.com/hashicorp/terraform/backend"
	"github.com/hashicorp/terraform/state"
	"github.com/hashicorp/terraform/state/remote"
	"github.com/hashicorp/terraform/terraform"
)

const (
	keyEnvPrefix = "-env:"
)

func (b *Backend) States() ([]string, error) {
	client, err := b.rawClient()
	if err != nil {
		return nil, err
	}

	prefix := b.determineKey("")
	res, err := client.Get(context.TODO(), prefix, etcdv3.WithPrefix(), etcdv3.WithKeysOnly())
	if err != nil {
		return nil, err
	}

	result := make([]string, 1, len(res.Kvs)+1)
	result[0] = backend.DefaultStateName
	for _, kv := range res.Kvs {
		result = append(result, strings.TrimPrefix(string(kv.Key), prefix))
	}
	sort.Strings(result[1:])

	return result, nil
}

func (b *Backend) DeleteState(name string) error {
	if name == backend.DefaultStateName || name == "" {
		return fmt.Errorf("Can't delete default state.")
	}

	client, err := b.rawClient()
	if err != nil {
		return err
	}

	path := b.determineKey(name)

	_, err = client.Delete(context.TODO(), path)
	return err
}

func (b *Backend) State(name string) (state.State, error) {
{'fraction_non_alphanumeric': 0.16510012259910095, 'fraction_numerical': 0.006129955046996322, 'mean_word_length': 4.230769230769231, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1551184', 'n_tokens_mistral': 940, 'n_tokens_neox': 926, 'n_words': 202}