diff --git a/pkg/git/git.go b/pkg/git/git.go index d3c2c98..e97c968 100644 --- a/pkg/git/git.go +++ b/pkg/git/git.go @@ -2,6 +2,7 @@ package git import ( "fmt" + "math" "os/exec" "strconv" "strings" @@ -69,8 +70,8 @@ func Diff(commitRange string) ([]string, string, error) { return difflines, "", nil } -const MaxUnshallowIterations = 100 -const DeepeningPerCycle = 100 // commits +const MaxUnshallowIterations = 10 +const InitialDeepenBy = 100 func Unshallow(commitRange string) error { for i := 0; i < MaxUnshallowIterations; i++ { @@ -78,7 +79,9 @@ func Unshallow(commitRange string) error { return nil } - err := deepen() + deepenBy := InitialDeepenBy * int(math.Exp2(float64(i))) + + err := deepen(deepenBy) if err != nil { return err } @@ -87,11 +90,11 @@ func Unshallow(commitRange string) error { return fmt.Errorf("commit range %s is not resolvable", commitRange) } -func deepen() error { - output, err := run("fetch", "origin", "--deepen", strconv.Itoa(DeepeningPerCycle)) +func deepen(numberOfCommits int) error { + output, err := run("fetch", "origin", "--deepen", strconv.Itoa(numberOfCommits)) if err != nil { consolelogger.Infof("Git failed with %s\n", err.Error()) - consolelogger.Info(string(output)) + consolelogger.Info(output) return err } @@ -102,7 +105,7 @@ func deepen() error { func canResolveCommitRnage(commitRange string) bool { output, err := run("diff", "--shortstat", commitRange) if err != nil { - consolelogger.Info(string(output)) + consolelogger.Info(output) } return err == nil diff --git a/test/e2e/change_in_large_commit_diff.rb b/test/e2e/change_in_large_commit_diff.rb index b742970..b70c85c 100644 --- a/test/e2e/change_in_large_commit_diff.rb +++ b/test/e2e/change_in_large_commit_diff.rb @@ -32,13 +32,13 @@ # diverge master and dev by 100 commits origin.create_branch("dev") -300.times do |index| +350.times do |index| origin.add_file("lib/B#{index}.txt", "hello") origin.commit!("Changes in dev number #{index}") end origin.switch_branch("master") -300.times do |index| +350.times do |index| origin.add_file("lib/B#{index}.txt", "hello") origin.commit!("Changes in master number #{index}") end diff --git a/test/e2e/change_in_large_commit_diff_on_default_branch.rb b/test/e2e/change_in_large_commit_diff_on_default_branch.rb index 5e71341..39ab9a9 100644 --- a/test/e2e/change_in_large_commit_diff_on_default_branch.rb +++ b/test/e2e/change_in_large_commit_diff_on_default_branch.rb @@ -29,7 +29,7 @@ origin.add_file("lib/A.txt", "hello") origin.commit!("Changes on master") -300.times do |index| +350.times do |index| origin.add_file("lib/B#{index}.txt", "hello") origin.commit!("Changes in master number #{index}") end