githelper.git
/
githelper.pike
version
»
Context lines:
10
20
40
80
file
none
3
githelper.git/githelper.pike:81:
{ string blob; string treeentry = run_git("ls-tree", sha, "--", filename); if (allow_empty && !sizeof(treeentry)) return ""; if (2 != sscanf(treeentry, "%*o blob %s\t", blob)) fail("Unexpected output from git ls-tree\n"); return run_git("cat-file", "blob", blob); }
+
string check_commit_timestamps(string commit)
+
{
+
int cct, cat, pct, pat;
+
string parents;
+
int sysclock = time() + 60;
+
if(3 != sscanf(run_git("log", "-n", "1", "--format=%ct %at %P", commit),
+
"%d %d %s\n", cct, cat, parents))
+
fail("Unexpected output from git log");
+
if (cat > sysclock)
+
return "Author time is in the future";
+
if (cct > sysclock)
+
return "Commit time is in the future";
+
if (cat > cct)
+
return "Author time is later than commit time";
+
foreach(parents/" ", string parent) {
+
if(2 != sscanf(run_git("log", "-n", "1", "--format=%ct %at", parent),
+
"%d %d", pct, pat))
+
fail("Unexpected output from git log");
+
if (cct < pct)
+
return "Commit time is before that of parent "+parent;
+
}
+
return 0;
+
}
+
class GitAttributes { enum { ATTR_TRUE = 1, ATTR_FALSE = 2, ATTR_UNSET = 3 }; class AttrState(string attr, string|int setto) { static string _sprintf(int type) {
githelper.git/githelper.pike:409:
sizeof(run_git("ls-tree", sha, "--", filename)); } int check_commit(string sha) { write("Checking commit %s\n", sha); this_program::sha = sha; files_to_commit = split_z(run_git("diff", "--name-only", "-z", sha, sha+"^")); attrs = GitAttributes(get_file(".gitattributes", 1));
+
string ts_test = check_commit_timestamps(sha);
+
if (ts_test) {
+
write("Invalid timestamps: %s\n", ts_test);
+
return 1;
+
}
return check_blocker_attributes() || check_gitattributes_files(); } int check_tag_push(string old_sha, string new_sha, string ref_name) { string oldtag = String.trim_all_whites(run_git_ex(1, "rev-parse", "--verify", "-q", ref_name)); if (sizeof(oldtag) && oldtag != new_sha) {
githelper.git/githelper.pike:497:
} int hook() { array(string) committed_files = split_z(run_git("diff", "--name-only", "-z", "HEAD", "HEAD^")); GitAttributes attrs = GitAttributes(get_committed_file("HEAD", ".gitattributes", 1)); foreach(committed_files, string filename) cleanup(filename, attrs->checkattr(filename));
+
string ts_test = check_commit_timestamps("HEAD");
+
if (ts_test) {
+
write("NOTICE: Your commit has invalid timestamps: %s\n", ts_test);
+
write("Please amend it before pushing.\n");
+
}
return 0; } } /* Filters */ /* A sample filter, not really useful... */ class NiceIdentFilter {