@@ -67,12 +67,17 @@ func main() {
67
67
68
68
possibilities := make (chan try , 512 )
69
69
go explore (possibilities )
70
+
70
71
winner := make (chan solution )
72
+ done := make (chan struct {})
73
+
71
74
for i := 0 ; i < * cpu ; i ++ {
72
- go bruteForce (obj , winner , possibilities )
75
+ go bruteForce (obj , winner , possibilities , done )
73
76
}
74
77
75
78
w := <- winner
79
+ close (done )
80
+
76
81
cmd := exec .Command ("git" , "commit" , "--amend" , "--date=" + w .author .String (), "--file=-" )
77
82
cmd .Env = append ([]string {"GIT_COMMITTER_DATE=" + w .committer .String ()}, os .Environ ()... )
78
83
cmd .Stdout = os .Stdout
91
96
commiterDateRx = regexp .MustCompile (`(?m)^committer.+> (.+)` )
92
97
)
93
98
94
- func bruteForce (obj []byte , winner chan <- solution , possibilities <- chan try ) {
99
+ func bruteForce (obj []byte , winner chan <- solution , possibilities <- chan try , done <- chan struct {} ) {
95
100
// blob is the blob to mutate in-place repatedly while testing
96
101
// whether we have a match.
97
102
blob := []byte (fmt .Sprintf ("commit %d\x00 %s" , len (obj ), obj ))
@@ -103,17 +108,23 @@ func bruteForce(obj []byte, winner chan<- solution, possibilities <-chan try) {
103
108
hexBuf := make ([]byte , 0 , sha1 .Size * 2 )
104
109
105
110
for t := range possibilities {
106
- ad := date {startUnix - int64 (t .authorBehind ), authorDate .tz }
107
- cd := date {startUnix - int64 (t .commitBehind ), commitDate .tz }
108
- strconv .AppendInt (blob [:adatei ], ad .n , 10 )
109
- strconv .AppendInt (blob [:cdatei ], cd .n , 10 )
110
- s1 .Reset ()
111
- s1 .Write (blob )
112
- if ! bytes .HasPrefix (hexInPlace (s1 .Sum (hexBuf [:0 ])), wantHexPrefix ) {
113
- continue
111
+ select {
112
+ case <- done :
113
+ return
114
+ default :
115
+ ad := date {startUnix - int64 (t .authorBehind ), authorDate .tz }
116
+ cd := date {startUnix - int64 (t .commitBehind ), commitDate .tz }
117
+ strconv .AppendInt (blob [:adatei ], ad .n , 10 )
118
+ strconv .AppendInt (blob [:cdatei ], cd .n , 10 )
119
+ s1 .Reset ()
120
+ s1 .Write (blob )
121
+ if ! bytes .HasPrefix (hexInPlace (s1 .Sum (hexBuf [:0 ])), wantHexPrefix ) {
122
+ continue
123
+ }
124
+
125
+ winner <- solution {ad , cd }
126
+ return
114
127
}
115
- winner <- solution {ad , cd }
116
- return // at least yield one goroutine's CPU for git commit to run.
117
128
}
118
129
}
119
130
0 commit comments