Skip to content

Commit

Permalink
Remove unnecessary string() conversions; Exponential deepening 100, 2…
Browse files Browse the repository at this point in the history
…00, 400
  • Loading branch information
shiroyasha committed Mar 31, 2021
1 parent 0ae07ec commit 4016ef3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
17 changes: 10 additions & 7 deletions pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package git

import (
"fmt"
"math"
"os/exec"
"strconv"
"strings"
Expand Down Expand Up @@ -69,16 +70,18 @@ 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++ {
if canResolveCommitRnage(commitRange) {
return nil
}

err := deepen()
deepenBy := InitialDeepenBy * int(math.Exp2(float64(i)))

err := deepen(deepenBy)
if err != nil {
return err
}
Expand All @@ -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
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/change_in_large_commit_diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/change_in_large_commit_diff_on_default_branch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4016ef3

Please sign in to comment.