diff --git a/commands/command_migrate.go b/commands/command_migrate.go index e4176f4b..943f8bbd 100644 --- a/commands/command_migrate.go +++ b/commands/command_migrate.go @@ -209,6 +209,7 @@ func init() { info := NewCommand("info", migrateInfoCommand) info.Flags().IntVar(&migrateInfoTopN, "top", 5, "--top=") info.Flags().StringVar(&migrateInfoAboveFmt, "above", "1mb", "--above=") + info.Flags().StringVar(&migrateInfoUnitFmt, "unit", "", "--unit=") RegisterCommand("migrate", nil, func(cmd *cobra.Command) { // Adding flags directly to cmd.Flags() doesn't apply those diff --git a/commands/command_migrate_info.go b/commands/command_migrate_info.go index 1899df75..b9ad8d8f 100644 --- a/commands/command_migrate_info.go +++ b/commands/command_migrate_info.go @@ -27,6 +27,14 @@ var ( // migrateInfoAbove is the number of bytes parsed from the above // migrateInfoAboveFmt flag. migrateInfoAbove uint64 + + // migrateInfoUnitFmt is a flag given to the git-lfs-migrate(1) + // subcommand 'info' specifying a human-readable string of units with + // which to display the number of bytes. + migrateInfoUnitFmt string + // migrateInfoUnit is the number of bytes in the unit given as + // migrateInfoUnitFmt. + migrateInfoUnit uint64 ) func migrateInfoCommand(cmd *cobra.Command, args []string) { @@ -37,6 +45,15 @@ func migrateInfoCommand(cmd *cobra.Command, args []string) { ExitWithError(errors.Wrap(err, "cannot parse --above=")) } + if u := cmd.Flag("unit"); u.Changed { + unit, err := humanize.ParseByteUnit(u.Value.String()) + if err != nil { + ExitWithError(errors.Wrap(err, "cannot parse --unit=")) + } + + migrateInfoUnit = unit + } + migrateInfoAbove = above migrate(cmd, args, func(path string, b *odb.Blob) (*odb.Blob, error) { @@ -123,17 +140,25 @@ func (e EntriesBySize) Print(to io.Writer) (int, error) { percentages := make([]string, 0, len(e)) for _, entry := range e { + bytesAbove := uint64(entry.BytesAbove) above := entry.TotalAbove total := entry.Total percentAbove := 100 * (float64(above) / float64(total)) + var size string + if migrateInfoUnit > 0 { + size = humanize.FormatBytesUnit(bytesAbove, migrateInfoUnit) + } else { + size = humanize.FormatBytes(bytesAbove) + } + stat := fmt.Sprintf("%d/%d files(s)", above, total) percentage := fmt.Sprintf("%.0f%%", percentAbove) extensions = append(extensions, entry.Qualifier) - sizes = append(sizes, humanize.FormatBytes(uint64(entry.BytesAbove))) + sizes = append(sizes, size) stats = append(stats, stat) percentages = append(percentages, percentage) } diff --git a/docs/man/git-lfs-migrate.1.ronn b/docs/man/git-lfs-migrate.1.ronn index 0fffbceb..a363e532 100644 --- a/docs/man/git-lfs-migrate.1.ronn +++ b/docs/man/git-lfs-migrate.1.ronn @@ -44,6 +44,15 @@ The 'info' mode has these additional options: Only include the top 'n' entries, ordered by how many total files match the given pathspec. +* `--unit=` + Format the number of bytes in each entry as a quantity of the storage unit + provided. Valid units include: + * b, kib, mib, gib, tib, pib - for IEC storage units + * b, kb, mb, gb, tb, pb - for SI storage units + + If a --unit is not specified, the largest unit that can fit the number of + counted bytes as a whole number quantity is chosen. + ## INCLUDE AND EXCLUDE You can configure Git LFS to only migrate tree entries whose pathspec matches diff --git a/test/test-migrate-info.sh b/test/test-migrate-info.sh index b9c26722..a3fcbcd1 100755 --- a/test/test-migrate-info.sh +++ b/test/test-migrate-info.sh @@ -219,3 +219,21 @@ begin_test "migrate info (above threshold, top)" ) end_test +begin_test "migrate info (given unit)" +( + set -e + + setup_multiple_local_branches + + original_head="$(git rev-parse HEAD)" + + diff -u <(git lfs migrate info --above=0b --unit=kb 2>&1) <(cat <<-EOF + *.md 0.1 1/1 files(s) 100% + *.txt 0.1 1/1 files(s) 100% + EOF) + + migrated_head="$(git rev-parse HEAD)" + + assert_ref_unmoved "HEAD" "$original_head" "$migrated_head" +) +end_test