Skip to content

Commit cf93294

Browse files
authored
Merge pull request #21 from github/maybe-finalize-tags
Call `r.maybeFinalize()` rather than `g.finalizeTagSize()` from `tagRecord.initialize()`
2 parents 42b73da + 3e4be54 commit cf93294

File tree

8 files changed

+1675
-5
lines changed

8 files changed

+1675
-5
lines changed

Gopkg.lock

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git_sizer_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import (
77
"os"
88
"os/exec"
99
"testing"
10+
"time"
1011

1112
"github.com/github/git-sizer/counts"
1213
"github.com/github/git-sizer/git"
1314
"github.com/github/git-sizer/sizes"
1415

1516
"github.com/stretchr/testify/assert"
17+
"github.com/stretchr/testify/require"
1618
)
1719

1820
// Smoke test that the program runs.
@@ -24,6 +26,24 @@ func TestExec(t *testing.T) {
2426
}
2527
}
2628

29+
func gitCommand(t *testing.T, repo *git.Repository, args ...string) *exec.Cmd {
30+
cmd := exec.Command("git", args...)
31+
cmd.Env = append(os.Environ(), "GIT_DIR="+repo.Path())
32+
return cmd
33+
}
34+
35+
func addAuthorInfo(cmd *exec.Cmd, timestamp *time.Time) {
36+
cmd.Env = append(cmd.Env,
37+
"GIT_AUTHOR_NAME=Arthur",
38+
39+
fmt.Sprintf("GIT_AUTHOR_DATE=%d -0700", timestamp.Unix()),
40+
"GIT_COMMITTER_NAME=Constance",
41+
42+
fmt.Sprintf("GIT_COMMITTER_DATE=%d -0700", timestamp.Unix()),
43+
)
44+
*timestamp = timestamp.Add(60 * time.Second)
45+
}
46+
2747
func newGitBomb(
2848
repoName string, depth, breadth int, body string,
2949
) (repo *git.Repository, err error) {
@@ -113,6 +133,7 @@ func pow(x uint64, n int) uint64 {
113133
}
114134

115135
func TestBomb(t *testing.T) {
136+
t.Parallel()
116137
assert := assert.New(t)
117138

118139
repo, err := newGitBomb("bomb", 10, 10, "boom!\n")
@@ -157,3 +178,44 @@ func TestBomb(t *testing.T) {
157178
assert.Equal(counts.Count32(0), h.MaxExpandedLinkCount, "max expanded link count")
158179
assert.Equal(counts.Count32(0), h.MaxExpandedSubmoduleCount, "max expanded submodule count")
159180
}
181+
182+
func TestTaggedTags(t *testing.T) {
183+
t.Parallel()
184+
path, err := ioutil.TempDir("", "tagged-tags")
185+
require.NoError(t, err, "creating temporary directory")
186+
187+
defer func() {
188+
os.RemoveAll(path)
189+
}()
190+
191+
cmd := exec.Command("git", "init", path)
192+
require.NoError(t, cmd.Run(), "initializing repo")
193+
repo, err := git.NewRepository(path)
194+
require.NoError(t, err, "initializing Repository object")
195+
196+
timestamp := time.Unix(1112911993, 0)
197+
198+
cmd = gitCommand(t, repo, "commit", "-m", "initial", "--allow-empty")
199+
addAuthorInfo(cmd, &timestamp)
200+
require.NoError(t, cmd.Run(), "creating commit")
201+
202+
// The lexicographical order of these tags is important, hence
203+
// their strange names.
204+
cmd = gitCommand(t, repo, "tag", "-m", "tag 1", "tag", "master")
205+
addAuthorInfo(cmd, &timestamp)
206+
require.NoError(t, cmd.Run(), "creating tag 1")
207+
208+
cmd = gitCommand(t, repo, "tag", "-m", "tag 2", "bag", "tag")
209+
addAuthorInfo(cmd, &timestamp)
210+
require.NoError(t, cmd.Run(), "creating tag 2")
211+
212+
cmd = gitCommand(t, repo, "tag", "-m", "tag 3", "wag", "bag")
213+
addAuthorInfo(cmd, &timestamp)
214+
require.NoError(t, cmd.Run(), "creating tag 3")
215+
216+
h, err := sizes.ScanRepositoryUsingGraph(
217+
repo, git.AllReferencesFilter, sizes.NameStyleNone, false,
218+
)
219+
require.NoError(t, err, "scanning repository")
220+
assert.Equal(t, counts.Count32(3), h.MaxTagDepth, "tag depth")
221+
}

sizes/graph.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -786,9 +786,7 @@ func (r *tagRecord) initialize(g *Graph, oid git.OID, tag *git.Tag) {
786786
default:
787787
}
788788

789-
if r.pending == 0 {
790-
g.finalizeTagSize(r.oid, r.size, r.objectSize)
791-
}
789+
r.maybeFinalize(g)
792790
}
793791

794792
func (r *tagRecord) maybeFinalize(g *Graph) {

vendor/github.com/stretchr/testify/require/doc.go

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/stretchr/testify/require/forward_requirements.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)