githelper.git / githelper.pike

version» Context lines:

githelper.git/githelper.pike:105:    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;   }    + int is_encoding_utf8(string name) + { +  return (!name) || (<"utf-8", "utf8">)[lower_case(name)]; + } +  + string check_encoding(string data, string|void encoding) + { +  if(is_encoding_utf8(encoding)) +  encoding = "UTF-8"; +  mixed err = catch { +  Locale.Charset.Decoder decoder = Locale.Charset.decoder(encoding); +  if(search(decoder->feed(data)->drain(), "\ufffd")>=0) +  return "Undefinied character detected\n"; +  }; +  return err && err[0]; + } +  + string check_commit_msg(string commit) + { +  string message = run_git("cat-file", "commit", commit); +  string encoding = 0; +  string headers = (message/"\n\n")[0]; +  foreach(headers/"\n", string headerline) { +  if(has_prefix(headerline, "encoding ")) +  encoding = headerline[9..]; +  } +  return check_encoding(message, encoding); + } +    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:438:    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;    } +  string cm_test = check_commit_msg(sha); +  if (cm_test) { +  write("Commit message encoding problem:\n%s", cm_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:531:    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");    } +  string cm_test = check_commit_msg("HEAD"); +  if (cm_test) { +  write("NOTICE: Your commit message has an encoding problem:\n%s", cm_test); +  write("Please ament it before pushing.\n"); +  }    return 0;    }   }      /* Filters */      /* A sample filter, not really useful... */      class NiceIdentFilter   {