Skip to content

Instantly share code, notes, and snippets.

@MichaelEvans
Last active January 4, 2016 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MichaelEvans/8570324 to your computer and use it in GitHub Desktop.
Save MichaelEvans/8570324 to your computer and use it in GitHub Desktop.
package main
import (
"crypto/sha1"
"fmt"
"io"
"bytes"
"os/exec"
)
func sha(str string) string {
h := sha1.New()
io.WriteString(h, str)
return fmt.Sprintf("%x", h.Sum(nil))
}
func main(){
cmd := exec.Command("git", "write-tree")
tree, err := cmd.Output()
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%s", tree)
cmd = exec.Command("git", "rev-parse", "HEAD")
parent, err := cmd.Output()
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%s", parent)
s := `tree %s
parent %s
author CTF user <me@example.com> 1390424498 +0000
committer CTF user <me@example.com> 1390424498 +0000
Give me a Gitcoin
%d
`
counter := 0
for {
hash := sha(fmt.Sprintf(s, tree, parent, counter))
if bytes.Compare([]byte(hash), []byte("000001")) < 0{
fmt.Println(counter)
break
}
counter++
}
}
@MichaelEvans
Copy link
Author

prepare_index && git hash-object -t commit sample -w && git push origin master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment