Branch: Tag:

2010-09-25

2010-09-25 14:43:41 by Marcus Comstedt <marcus@mc.pp.se>

Handle foreign_idents.

57:      class PreCommitHook   { +  string get_staged_file(string filename) +  { +  string sha; +  if (2 != sscanf(run_git("ls-files", "--stage", "--", filename), +  "%*o %s ", sha)) +  fail("Unable to parse output from git ls-files...\n"); +  return run_git("cat-file", "blob", sha); +  } +     int check_attributes_staged()    {    // We don't allow .gitattributes to differ between wt and index,
70:    }    }    +  int check_ident(string filename) +  { +  string data = get_staged_file(filename); +  int p=0; +  while ((p = search(data, "$Id", p))>=0) { +  if (data[p..p+3] != "$Id$") { +  write("File %s contains an expanded ident.\n" +  "Try 'git reset %s; git add %s', " +  "or remove the ident manually.\n", +  @({filename})*3); +  return 1; +  } +  p += 4; +  } +  return 0; +  } +     int check_blocker_attributes(array(string) files_to_commit)    { -  constant attrs_to_check = ({ "foreign_ident", "block_commit" }); +  constant attrs_to_check = ({ "foreign_ident", "block_commit", "ident" });    foreach(run_git("check-attr", @attrs_to_check,    "--", @files_to_commit) / "\n" - ({""}),    string line) {
89:    write("File %s is blocked from committing: %s\n", filename,    replace(value, "-", " "));    return 1; +  case "ident": +  if (value == "unset") +  break; +  if (check_ident(filename)) +  return 1; +  break;    }    }    }