<commit_before>package commands

import (
	"fmt"
	"io"
	"os"
	"path/filepath"
	"sort"
	"strings"

	"github.com/git-lfs/git-lfs/git/odb"
	"github.com/git-lfs/git-lfs/tools"
	"github.com/spf13/cobra"
)

var MigrateInfoCommand = NewCommand("info", migrateInfoCommand)

var (
	// migrateInfoTopN is a flag given to the git-lfs-migrate(1) subcommand
	// 'info' which specifies how many info entries to show by default.
	migrateInfoTopN int
)

func migrateInfoCommand(cmd *cobra.Command, args []string) {
	exts := make(map[string]int64)

	migrate(cmd, args, func(path string, b *odb.Blob) (*odb.Blob, error) {
		ext := fmt.Sprintf("*%s", filepath.Ext(path))
		if len(ext) > 1 {
			exts[ext] = exts[ext] + b.Size
		}

		return b, nil
	})

	entries := EntriesBySize(MapToEntries(exts))
	sort.Sort(sort.Reverse(entries))

	migrateInfoTopN = tools.ClampInt(migrateInfoTopN, 0, len(entries))

	entries = entries[:tools.MaxInt(0, migrateInfoTopN)]

	entries.Print(os.Stderr)
}

// MigrateInfoEntry represents a tuple of filetype to total size taken by that
// file type.
type MigrateInfoEntry struct {
	// Qualifier is the filepath's extension.
	Qualifier string
	// Size is the total size in bytes taken by that filepath's extension.
	Size int64
}

// MapToEntries creates a set of `*MigrateInfoEntry`'s for a given map of<commit_msg>commands/migrate_info: fix arguments to tools.ClampInt<commit_after>package commands

import (
	"fmt"
	"io"
	"os"
	"path/filepath"
	"sort"
	"strings"

	"github.com/git-lfs/git-lfs/git/odb"
	"github.com/git-lfs/git-lfs/tools"
	"github.com/spf13/cobra"
)

var MigrateInfoCommand = NewCommand("info", migrateInfoCommand)

var (
	// migrateInfoTopN is a flag given to the git-lfs-migrate(1) subcommand
	// 'info' which specifies how many info entries to show by default.
	migrateInfoTopN int
)

func migrateInfoCommand(cmd *cobra.Command, args []string) {
	exts := make(map[string]int64)

	migrate(cmd, args, func(path string, b *odb.Blob) (*odb.Blob, error) {
		ext := fmt.Sprintf("*%s", filepath.Ext(path))
		if len(ext) > 1 {
			exts[ext] = exts[ext] + b.Size
		}

		return b, nil
	})

	entries := EntriesBySize(MapToEntries(exts))
	sort.Sort(sort.Reverse(entries))

	migrateInfoTopN = tools.ClampInt(migrateInfoTopN, len(entries), 0)

	entries = entries[:tools.MaxInt(0, migrateInfoTopN)]

	entries.Print(os.Stderr)
}

// MigrateInfoEntry represents a tuple of filetype to total size taken by that
// file type.
type MigrateInfoEntry struct {
	// Qualifier is the filepath's extension.
	Qualifier string
	// Size is the total size in bytes taken by that filepath's extension.
	Size int64
}

// MapToEntries creates a set of `*MigrateInfoEntry`'s for a given map of
{'fraction_non_alphanumeric': 0.1269073315965761, 'fraction_numerical': 0.00744324525493115, 'mean_word_length': 4.3017751479289945, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7036320', 'n_tokens_mistral': 1043, 'n_tokens_neox': 989, 'n_words': 255}