git hash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.commons.codec.digest.DigestUtils; | |
public class GitSha1 { | |
public static String githash(String aString){ | |
return DigestUtils.sha1Hex("blob " + aString.length() + "\0" + aString); | |
} | |
public static void main(String[] args) { | |
String theString = "this is the end, there is nothing else"; | |
String expected = "c9ee5714232648dfdaea316c8ae5a2549632e0bb"; | |
String result = githash(theString); | |
System.out.println(result + " " + (result.equals(expected)?"correct":"incorrect")); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hashlib import sha1 | |
def githash(data): | |
s = sha1() | |
s.update("blob %u\0" % len(data)) | |
s.update(data) | |
return s.hexdigest() | |
# [klang@ergates aws-python]$ python -i sha1.py | |
# >>> githash("this is the end, there is nothing else") | |
# 'c9ee5714232648dfdaea316c8ae5a2549632e0bb' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git_sha1 () { printf 'blob %s\0' "$(ls -l "$1" | awk '{print $5;}')" | cat - "$1" | sha1sum | awk '{print $1}'; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment