domain

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2017 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BySizeDesc

type BySizeDesc []GitObject

BySizeDesc implements sort.Interface for []GitObject based on size

Example
object := []GitObject{
	{"87a6asmall", 100, 500, "./"},
	{"87a6axxl", 31500, 500, "./"},
	{"87a6abig", 2100, 500, "./"},
	{"87a6amedium", 800, 500, "./"},
}

sort.Sort(BySizeDesc(object))
fmt.Println(object)
Output:

[{87a6axxl 31500 500 ./} {87a6abig 2100 500 ./} {87a6amedium 800 500 ./} {87a6asmall 100 500 ./}]

func (BySizeDesc) Len

func (objects BySizeDesc) Len() int

Len implementation for sorting

func (BySizeDesc) Less

func (objects BySizeDesc) Less(i, j int) bool

Less implementation for sorting

func (BySizeDesc) Swap

func (objects BySizeDesc) Swap(i, j int)

Swap implementation for sorting

type Columnizer

type Columnizer interface {
	Columnize(rows []string) string
}

Columnizer create columnes in plain text

type Converter

type Converter interface {
	HumanReadable(size uint64) string
}

Converter converts byte sizes

type ErrorFactory

type ErrorFactory interface {
	New(err string) error
}

ErrorFactory error factory

type Exister

type Exister interface {
	Exists(path string) bool
}

Exister is an interface for existence checkers

type GitManager

type GitManager struct {
	Runner  Runner
	Exister Exister
}

GitManager is a git repo manager

func (*GitManager) EnsureRepoPath

func (m *GitManager) EnsureRepoPath(path string) (string, error)

EnsureRepoPath ensure there is a Git repo

func (*GitManager) RevList

func (m *GitManager) RevList(path string) (*bufio.Scanner, error)

RevList executes git rev-list

func (*GitManager) VerifyPack

func (m *GitManager) VerifyPack(path string) (*bufio.Scanner, error)

VerifyPack executes git verify-pack

type GitObject

type GitObject struct {
	// contains filtered or unexported fields
}

GitObject Git object with properties splitted

type GitObjectManager

type GitObjectManager struct {
	Git RepoManager
}

GitObjectManager manages git objects

Example
mockGit := &MockGitRepoManager{}

mockGit.EnsureRepoPathFn = func(path string) (string, error) {
	return "/path/test", nil
}

mockGit.VerifyPackFn = func(path string) (*bufio.Scanner, error) {
	const input = `931179a7cb9827b662968f36f0732dceaae9cc8e blob   3530 3544 534211
0623de54c9501be250cd0907bd09f6b452c53fe6 blob   4053 4067 537755
b9018b11dd21302f850984fe9b49e49828101a00 blob   4770 4751 541822
cb87bc696798d4636453465657e67546009890dd blob   3244 2342 234234
76854567ed47567645a7906a0987ac09879c0978 blob   503032 234234 234235`

	return bufio.NewScanner(strings.NewReader(input)), nil
}

mockGit.RevListFn = func(path string) (*bufio.Scanner, error) {
	const input = `0623de54c9501be250cd0907bd09f6b452c53fe6 app/AppKernel.php
76854567ed47567645a7906a0987ac09879c0978 app/AppKernel.php
931179a7cb9827b662968f36f0732dceaae9cc8e app/config
b9018b11dd21302f850984fe9b49e49828101a00 app/config/config.yml
ab6785ab65a75ba875b78a65baa758765c6578c5 file`

	return bufio.NewScanner(strings.NewReader(input)), nil
}

gom := GitObjectManager{
	Git: mockGit,
}

objects, err := gom.Get("./path/to/repo")

uniqueObjects := gom.GroupObjectsByFile(objects)

fmt.Println(err)
fmt.Println(objects)
fmt.Println(uniqueObjects)
Output:

<nil>
[{76854567ed47567645a7906a0987ac09879c0978 503032 234234 app/AppKernel.php} {b9018b11dd21302f850984fe9b49e49828101a00 4770 4751 app/config/config.yml} {0623de54c9501be250cd0907bd09f6b452c53fe6 4053 4067 app/AppKernel.php} {931179a7cb9827b662968f36f0732dceaae9cc8e 3530 3544 app/config}]
[{ 507085 234234 app/AppKernel.php} { 4770 4751 app/config/config.yml} { 3530 3544 app/config}]

func (*GitObjectManager) Get

func (gom *GitObjectManager) Get(path string) ([]GitObject, error)

Get gets all objects including their size and other data, sorted by size Based on https://stackoverflow.com/questions/10622179/how-to-find-identify-large-files-commits-in-git-history

func (*GitObjectManager) GroupObjectsByFile

func (gom *GitObjectManager) GroupObjectsByFile(oldObjects []GitObject) []GitObject

GroupObjectsByFile groups git objects by file to calculate size

type ListCommand

type ListCommand struct {
	Converter     Converter
	Columnizer    Columnizer
	ObjectManager ObjectManager
}

ListCommand implements Command and lists heavier file objects in the repository history

Example
// Example1
mockObjectManager := &MockObjectManager{}
mockObjectManager.GetFn = func(path string) ([]GitObject, error) {
	return []GitObject{{
		sha:            "aa11",
		size:           1234,
		compressedSize: 700,
		path:           "./file1.txt",
	}, {
		sha:            "aa12",
		size:           2234,
		compressedSize: 720,
		path:           "./file2.txt",
	}, {
		sha:            "aa13",
		size:           3234,
		compressedSize: 730,
		path:           "./file3.txt",
	}, {
		sha:            "aa14",
		size:           4234,
		compressedSize: 740,
		path:           "./file4.txt",
	}, {
		sha:            "aa15",
		size:           51234,
		compressedSize: 7550,
		path:           "./file5.txt",
	}}, nil
}
mockObjectManager.GroupObjectsByFileFn = func(oldObjects []GitObject) []GitObject {
	return []GitObject{{
		size:           1234,
		compressedSize: 700,
		path:           "./file21.txt",
	}, {
		size:           2234,
		compressedSize: 720,
		path:           "./file22.txt",
	}, {
		size:           3234,
		compressedSize: 730,
		path:           "./file23.txt",
	}}
}

mockConverter := &MockConverter{}
mockConverter.HumanReadableFn = func(size uint64) string {
	return strconv.FormatUint(size, 10) + "test"
}

var toColumnizeRows []string
mockColumnizer := &MockColumnizer{}
mockColumnizer.ColumnizeFn = func(rows []string) string {
	toColumnizeRows = rows
	return "exit"
}

listCommand := ListCommand{}
listCommand.ObjectManager = mockObjectManager
listCommand.Columnizer = mockColumnizer
listCommand.Converter = mockConverter
listCommand.Exec("/path/repo", 10, false, false)
fmt.Println(mockObjectManager.GroupObjectsByFileInvoked)
fmt.Println(mockConverter.HumanReadableInvoked)
for _, row := range toColumnizeRows {
	fmt.Println(row)
}

listCommand = ListCommand{}
listCommand.ObjectManager = mockObjectManager
listCommand.Columnizer = mockColumnizer
listCommand.Converter = mockConverter
listCommand.Exec("/path/repo", 2, true, true)
fmt.Println(mockObjectManager.GroupObjectsByFileInvoked)
fmt.Println(mockConverter.HumanReadableInvoked)
for _, row := range toColumnizeRows {
	fmt.Println(strings.TrimSpace(row))
}
Output:

exit
false
false
1234 | ./file1.txt | aa11
2234 | ./file2.txt | aa12
3234 | ./file3.txt | aa13
4234 | ./file4.txt | aa14
51234 | ./file5.txt | aa15
exit
true
true
1234test | ./file21.txt |
2234test | ./file22.txt |

func (*ListCommand) Exec

func (lc *ListCommand) Exec(path string, max int, humanReadable bool, unique bool) error

Exec executes the command

type ObjectManager

type ObjectManager interface {
	Get(path string) ([]GitObject, error)
	GroupObjectsByFile(oldObjects []GitObject) []GitObject
}

ObjectManager is an interface for object management

type RepoManager

type RepoManager interface {
	VerifyPack(path string) (*bufio.Scanner, error)
	RevList(path string) (*bufio.Scanner, error)
	EnsureRepoPath(path string) (string, error)
}

RepoManager is an interface for git style repo managers

type Runner

type Runner interface {
	Run(string) (*bufio.Scanner, error)
}

Runner is a command runner

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL