Skip to content

Commit 568e769

Browse files
committed
Implement the main command, git-sizer
It can compute various dimensions about a tree object in a Git repository, in a way that is robust against git bombs. For now it must be passed the path to a Git repository and one or more tree object specifications (like `HEAD^{tree}` or `HEAD:src`). That is likely to change. To avoid starting up lots of processes, we use `git cat-file --batch` to read trees. But for blobs we only need to know the size, so use `git cat-file --batch-check` for blobs. This unfortunately means that we need to keep two `git` processes running, which means paying the git startup time twice.
0 parents  commit 568e769

15 files changed

Lines changed: 1015 additions & 0 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/.gopath
2+
/bin
3+
/libexec
4+
/log
5+
/repositories
6+
/vendor

Brewfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
brew "go"

Makefile

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
ROOTDIR := $(abspath $(CURDIR))
2+
export ROOTDIR
3+
4+
GO := $(CURDIR)/script/go
5+
GOFMT := $(CURDIR)/script/gofmt
6+
7+
BIN := libexec
8+
9+
GOBIN := $(abspath $(BIN))
10+
export GOBIN
11+
12+
GOFLAGS := \
13+
--tags "static" \
14+
-ldflags "-X main.BuildVersion=$(shell git rev-parse HEAD) -X main.BuildDescribe=$(shell git describe --tags --always --dirty)"
15+
GO_CMDS := \
16+
$(BIN)/git-sizer
17+
GO_PKGS := $(shell cd .gopath/src; find github.com/github/git-sizer/ -type f -name '*.go' | xargs -n1 dirname | sort -u)
18+
SHELL_CMDS :=
19+
RUBY_CMDS :=
20+
DEPS := \
21+
github.com/stretchr/testify
22+
GO_SRCS := $(shell find src -type f -name '*.go')
23+
24+
TEST_SH_RUNNERS := 2
25+
26+
.PHONY: all
27+
all: $(GO_CMDS) $(SHELL_CMDS) $(RUBY_CMDS)
28+
29+
libexec/%: bin/% $(GO_SRCS)
30+
$(GO) install $(GOFLAGS) github.com/github/git-sizer/$*
31+
32+
.PRECIOUS: bin/%
33+
bin/%: src/shim.sh
34+
mkdir -p bin
35+
cp $< bin/$*
36+
chmod +x bin/$*
37+
38+
.PHONY: $(SHELL_CMDS)
39+
$(SHELL_CMDS): $(BIN)/%: bin/%.sh
40+
cp $< $@
41+
42+
.PHONY: $(RUBY_CMDS)
43+
$(RUBY_CMDS): $(BIN)/%: bin/%.rb
44+
cp $< $@
45+
46+
.PHONY: deps
47+
deps:
48+
$(GO) get $(DEPS)
49+
50+
.PHONY: test
51+
test: gotest shtest
52+
53+
.PHONY: gotest
54+
gotest:
55+
$(GO) test -timeout 60s $(GOFLAGS) $(GO_PKGS)
56+
57+
.PHONY: shtest
58+
shtest: libexec/git-sizer
59+
ls -1 test/test-*.sh | xargs -I % -P $(TEST_SH_RUNNERS) -n 1 $(SHELL) % --batch
60+
61+
.PHONY: gofmt
62+
gofmt:
63+
find src test -name "*.go" -print0 | xargs -0 $(GOFMT) -l -w | sed -e 's/^/Fixing /'
64+
65+
.PHONY: goimports
66+
goimports:
67+
find src -name "*.go" -print0 | xargs -0 goimports -l -w -e
68+
69+
.PHONY: govet
70+
govet:
71+
$(GO) vet $(GO_PKGS)
72+
73+
.PHONY: clean
74+
clean:
75+
rm -rf bin libexec

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# git-sizer
2+
3+
Is your Git repository busting at the seams?
4+
5+
## Getting started
6+
7+
1. Build:
8+
9+
script/bootstrap
10+
make

script/bootstrap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
cd $(dirname "$0")/..
6+
7+
if [[ "$(uname -s)" = "Darwin" ]]; then
8+
brew bundle
9+
fi
10+
script/ensure-go-installed
11+
12+
rm -f .gopath/src/github.com/github/git-sizer
13+
mkdir -p .gopath/src/github.com/github
14+
ln -s "$PWD/src" .gopath/src/github.com/github/git-sizer
15+
16+
make deps

script/build

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
cd $(dirname "$0")/..
6+
7+
make

script/cibuild

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
cd $(dirname "$0")/..
6+
7+
script/install-vendored-go
8+
script/bootstrap
9+
script/build
10+
make test

script/ensure-go-installed

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
4+
5+
# Is go installed, and at least 1.7?
6+
go_ok() {
7+
case "$(go version 2>/dev/null | sed -n 's/.*go\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/p' | head -n 1)" in
8+
""|0.*|1.[0123456])
9+
false ;;
10+
*)
11+
true ;;
12+
esac
13+
}
14+
15+
# If a local go is installed, use it.
16+
set_up_vendored_go() {
17+
GO_VERSION=go1.8.1
18+
VENDORED_GOROOT="$ROOTDIR/vendor/$GO_VERSION/go"
19+
if [ -x "$VENDORED_GOROOT/bin/go" ]; then
20+
export GOROOT="$VENDORED_GOROOT"
21+
export PATH="$GOROOT/bin:$PATH"
22+
fi
23+
}
24+
25+
set_up_vendored_go
26+
27+
if ! go_ok; then
28+
script/install-vendored-go >/dev/null || exit 1
29+
set_up_vendored_go
30+
fi

script/go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
export ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
6+
. $ROOTDIR/script/ensure-go-installed
7+
export GOPATH=$ROOTDIR/.gopath
8+
9+
exec "$(basename $0)" "$@"

script/gofmt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
go

0 commit comments

Comments
 (0)